JHipster unit tests fail for all Rest test - jhipster

After creating a first entity, the unit test fails for all rest POST and PUT method tests with an error 415, Unsupported Media Type, And the 406 error for GET mehtod on a single entity retrieve and 500 for all In the restcontroller, I remove the produces without a luck.
#RequestMapping(value = "/myEntities", method = RequestMethod.POST), produces = MediaType.APPLICATION_JSON_VALUE)
I use Spring Boot 1.3.0.M2 instead 1.2.5.RELEASE in the build.

Related

No MessageBodyWriter for Single

I'm trying to use resteasy-rxjava2 to provide an XML document using jaxb, within a vertx application (using a non-vertx legacy library we have). But I get:
Could not find MessageBodyWriter for response object of type:
org.jboss.resteasy.rxjava2.propagation.ContextPropagatorOnSingleAssemblyAction$ContextPropagatorSingle of media type:
application/xml;charset=UTF-8
From what I can tell, this comes down to the difference between a MessageBodyWriter and the AsyncResponseProvider that is in the resteasy-rxjava2 dependency for a Single (SingleProvider).
I have the following resteasy service definition
#GET
#Path(FdsnwsPaths.QUERY)
#Produces(MediaType.APPLICATION_XML)
#Stream
// CHECKSTYLE:OFF too many parameters
public Response getQuery(...)
How do I get resteasy to properly serve the data asynchrously, using the SingleProvider or otherwise.
The #Get method must return the Single explicitly or it doesn't work. (Can't use Response or Object). In my case, the Single contains the jaxb xml root element.
#GET
#Path(FdsnwsPaths.QUERY)
#Produces(MediaType.APPLICATION_XML)
#Stream
public Single<FDSNStationXML> getQuery(...)
Then, to make things more complicated, in order to handle specific exception types and map them to specific response status codes, I have to create a custom ExceptionMapper which creates the Response object I used to be able to create directly in the method. (in resteasy-vertx, I found no documentation on how to do this, but in my case, I am creating my own VertxRestEasyDeployment object so I can register the class of the ExceptionMapper(s) like this:
VertxResteasyDeployment deployment = new VertxResteasyDeployment();
deployment.getActualProviderClasses().addAll(providerClasses);
For reference, this is all being done with:
RestEasy 5.0.3.Final (including resteasy-rxjava2)
RxJava 2.2.20
Vertx 3.9.5

Why does cxf throw an unmarshalling error on elements that have no namespace prefix when the namespace should be inherited

I am creating a SOAP client that runs in a Java 11 Spring Boot server and makes requests to a Java 8 server. I'm using cxf-rt-frontend-jaxws:3.4.3 and cxf-rt-transports:3.4.3 in a Gradle 6.9 build with the com.github.bjornvester.wsdl2java Gradle plugin version 1.1.
My client can call a simple echo test SOAP operation with no problem. That service passes a request object containing a single String and gets a response object containing the String. So I know the basic connection is working and the other end is responding.
My problem arises when I call an operation that has no input and returns a list of objects in the response. I get this error:
org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected element (uri:"", local:"ProposalInfo"). Expected elements are <{http://V2.pub.proposal.server.ws.cayuse.com/}ProposalInfo>
I am told that other systems call these operations with no problem.
I have stepped through the cxf and JAXB code and notice that the IntelliJ shows this text associated with a BranchingReaderSource. Not sure if this is a true error or just a side-effect of the debugger trying to call toString() on this class (which has no such method).
Method threw 'java.lang.NullPointerException' exception. Cannot evaluate com.ctc.wstx.io.BranchingReaderSource.toString()
I also notice that a class called ValidationEventLocatorImpl gets a NullPointerException on this line because "toURL" is null. I think this is because toURL comes from the empty prefix of in the response.
this.url = toURL(loc.getSystemId());
I have tried using wrapping-style "false" but that does not change anything.
I also tried to use TransformInInterceptor to map elements with no prefix to the desired prefix, but that did not work. It seems the unmarshalling error gets thrown before the interceptor runs.
Here is the WSDL used for this service; the operation that I am calling is getUnpairedProposals. I also attach a copy of the response to this operation -- the operation that is not getting unmarshalled properly. My reading of this response is that the namespace defined on the ns2:getUnPairedProposalsResponse tag should apply to the child elements such as .
Additional info:
I made several attempts to use TransformInterceptor to map the elements:
Added a map entry for "getUnPairedProposalsResponse -> {http://V2.pub.proposal.server.ws.cayuse.com/}getUnPairedProposalsResponse". This did nothing.
Inserted the TransformInterceptor at Phase.PRE_STREAM. Also had no effect.
Changed the mapping from #1 to the same but added a prefix {}, as in {}getUnPairedProposalsResponse -> {http://V2.pub.proposal.server.ws.cayuse.com/}getUnPairedProposalsResponse. This got me a null pointer exception in cxf at TransformUtils line 128 in the convertToQnamesMap method.

assertEquals(String, String) is failing in drone build

I am writing Junit test for apache camel route. I have a mock endpoint here.
So instead of writing to a file I will get the body content to the mock end point.
In the test method I am using assertEquals to validate the body that I receive in mock endpoint.
Below is the code
private static final String EXPECTED_RESULT = "COMPANY\n" +
"\"CUSTOMER\",\"2018-12-11\"";
.....(Below is the test method)
#Test
public void testFileCreation() throws Exception{
.....
List<Exchange> exchanges = resultEndpoint.getExchanges();
//Expects the same body content as EXPECTED_RESULT
Assert.assertEquals(EXPECTED_RESULT,
exchanges.get(0).getIn().getBody().toString());
}
Note: In the above code resultEndPoint is the mock endpoint.
In the local when I do gradle build it's satisfying the assert statement and test is passing.
But when I commit to github then in drone the gradle build is failing at this assert statement.
I tried using the logs to display the value of exchanges.get(0).getIn().getBody().toString()) in drone build but the value is same as EXPECTED_RESULT.
Not sure why it is failing only in drone build. Any comments on this?
Thanks in advance..

Describe Mockito sample code

In the http://mockito.org/ website the following sample code is given to describe the usage of the mockito framework. However i am not able to understand what the following code is trying to test. Please comment on the following code as what is it exactly testing. If it is testing the add method of the List, what does it expect?
import static org.mockito.Mockito.*;
// mock creation
List mockedList = mock(List.class);
// using mock object - it does not throw any "unexpected interaction" exception
mockedList.add("one");
mockedList.clear();
// selective, explicit, highly readable verification
verify(mockedList).add("one");
verify(mockedList).clear();
In your case, you've a test preparation
// mock creation
List mockedList = mock(List.class);
a test execution
// using mock object - it does not throw any "unexpected interaction" exception
mockedList.add("one");
mockedList.clear();
and a test verification (without mockito mostly done with something like assertEquals)
// selective, explicit, highly readable verification
verify(mockedList).add("one");
verify(mockedList).clear();
The last block (the test verifaction) is testing, if
the add method of the mockedList was called with a parameter that equals the String "one"
the clear method of the mockedList was called
It is just a basic demo of how the interaction with a mocked class can be verified (since you cannot verify the contents of the List because it has been mocked and the calls of add("one") and clear() don't change the contents of the List).

using groovy script to validate assertions in robot framework when executing soap test by using suds library

In my soapui test I have written a groovy script to validate all the assertions.I want to do the same in robot framework .
I am executing soapui test from robot framework using suds library.
How can I use my groovy script in Robot framework to verify all the assertions in single go like we do in SOAPUI.
please help
Thanks
You can do your verification in Groovy, but its not very simple. If your verifications are all on the XML and not things like headers or status codes, you can take the XML response from SudsLibrary and pass it to a user library. I did all the tasks to make this work manually, but if you use Maven and the plugins for Groovy and Robot Framework, it would be easier to work with.
The user library must be compiled to a .class file using the compiler, groovyc. Here you can use the SoapUI helper classes you are familiar with. They need to be on the class path when compiling. From the SoapUI installation folder, I added bin\soapui-5.2.0.jar and lib\* to the class path. For Robot Framework to use your Groovy script, classes and public methods must be used per the test library API.
package com.example.soapui;
import com.eviware.soapui.support.XmlHolder
public class Verifications {
public void checkResponse(String xml) {
def holder = new XmlHolder(xml)
holder.namespaces["ns1"] = "http://www.webserviceX.NET"
def average = holder.getNodeValue("//ns1:Average[1]")
assert average == "2.5"
}
}
Here is a simple test that calls a public web service and invokes the Groovy script to check the response.
*** Settings ***
Library SudsLibrary
Library Collections
Library com.example.soapui.Verifications
*** Test Cases ***
Simple
Create Soap Client http://www.webservicex.net/Statistics.asmx?WSDL
Set Return Xml True # soap calls from now one will return XML
${dbl array}= Create Wsdl Object ArrayOfDouble
Append To List ${dbl array.double} 2.0
Append To List ${dbl array.double} 3.0
${result}= Call Soap Method GetStatistics ${dbl array}
Check Response ${result} # pass the XML to the user keyword written in Groovy
During execution, both Groovy and SoapUI jar files need to be on the class path.
C:\ws\groovy>jybot groovy.robot
==============================================================================
Groovy
==============================================================================
Simple | PASS |
------------------------------------------------------------------------------
Groovy | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: C:\ws\groovy\output.xml
Log: C:\ws\groovy\log.html
Report: C:\ws\groovy\report.html

Resources