Using message type as JSON, got error message during validation like "receive message payload was empty" - citrus-framework

Using the below code, i tried validating the mongodb data for name field but the test case failed with
20193 [main] INFO com.consol.citrus.Citrus - FAILURE: Caused by: ValidationException: Unable to validate message elements - receive message payload was empty
Same test is passing if i comment out .messageType(MessageType.JSON) in the below code.
Please let me know your inputs on this error and also the steps to validate the output json message.
10491 [main] INFO com.consol.citrus.validation.xml.DomXmlMessageValidator - XML message validation successful: All values OK
10495 [main] INFO com.consol.citrus.validation.DefaultMessageHeaderValidator - Message header validation successful: All values OK
#CitrusTest
public void def_DI7381AndDI7383_CreateNamespace() {
echo("----#CitrusTest Calling API services---- ");
String strCname1="";
String strId1="";
http()
.client(DIAPI)
.send()
.post("modeler/api/internal/namespace")
// .name("todoRequest")
.accept("application/json")
.header("Content-type","application/json")
.header("access","application/json")
.payload(new ClassPathResource("updatedJsonFiles/NameSpace/UpdValidNameSpace.json"));
// .payload(new ClassPathResource("UpdValidNameSpace.json"));
http()
.client(DIAPI)
.receive()
.response(HttpStatus.CREATED)
// .messageType(MessageType.JSON)
// .payload(new ClassPathResource("updatedJsonFiles/NameSpace/UpdValidNameSpace.json"))
// .payload("citrus:jsonPath(citrus:message(todoRequest.payload()), '$..name')");
// .validate("$..id",id)
.validate("$.name", strCname);
// .validate("$..namespaceId", namespaceId)
// .validate("$..description", description);
}

If you leave out .messageType(MessageType.JSON) Citrus is using the default message type which is XML. This is why you see XML message validation successful in the logs.
As the XML message validator is not able to apply the given JsonPath expressions your test is green. So you need to use .messageType(MessageType.JSON).
The root cause of your problem is that the system under test responds to the Http request with an empty message body. As you expect a message body in your validation Citrus raises the ValidationException: Unable to validate message elements - receive message payload was empty
So please make sure that your system under test is sending a proper JSON message body as response and your validation will perform as expected.

Related

Failed to read HTTP message:ion: JSON parse error: Unexpected end-of-input in VALUE_STRING : Unexpected EOF read on the socket

When a client is sending an image to one of the rest endpoints, only part of the data is being received.
To be sure what is happening I made a trace with Wireshark and analyzed it. The application is indeed not receiving the last part of the message. This is because the application is not able to receive all the data within the 900ms timeout that is specified on the Client side. Its buffers are full halfway through the reception.
I get application warning
org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver
[http-nio-0.0.0.0-9999-exec-35] Failed to read HTTP message:
org.springframework.http.converter.HttpMessageNotReadableException:
I/O error while reading input message; nested exception is
java.io.EOFException: Unexpected EOF read on the socket
And the client gets Connection timeout.
I have got a solution to my problem. I have increased the socket buffer size in my application. I have added following code to my Application class.
#Bean
public EmbeddedServletContainerFactory embeddedServletContainerFactory() {
TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory = new TomcatEmbeddedServletContainerFactory();
tomcatEmbeddedServletContainerFactory.setProtocol("org.apache.coyote.http11.Http11Nio2Protocol");
tomcatEmbeddedServletContainerFactory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
connector.setProperty("socket.rxBufSize", "5000000");
});
return tomcatEmbeddedServletContainerFactory;
}

How to get ResponseEntity body in spring-integration

I am using xml based configuration - http outbound gateway to trii=gger a rest service, the response is ResponseEntity and I dont know that service details. The output I receive should be put in a JMS Queue.
How can I update the below to extract only the body of response entity and pass to output-channel? If there is a transformer, please give example. Is it possible using config?
<int:chain input-channel="gsInChannel" output-channel="dest-channel">
<int-http:outbound-gateway
url="https://ia-zatie.str13.tst.belst.nu/ia-zaatie/rest/signal/v2"
http-method="POST"
header-mapper="headerMapper"
request-factory="sslFactory"
>
</int-http:outbound-gateway>
</int:chain>
dest-channel is jms:outbound-channel-adapter
boot version 1.4.3 and integration version 4.3.6
Error: org.springframework.messaging.MessageHandlingException: error
occurred in message handler
[org.springframework.integration.jms.JmsSendingMessageHandler#0];
nested exception is
org.springframework.jms.support.converter.MessageConversionException:
Cannot convert object of type
[org.springframework.http.ResponseEntity] to JMS message. Supported
message payloads are: String, byte array, Map, Serializable
object.
I was using HTTP POST method and so not expecting, a response. SoO has not included expected-response-type, which returns the body
<int-http:outbound-gateway
url="https://ia-zatie.str13.tst.belst.nu/ia-zaatie/rest/signal/v2"
http-method="POST"
header-mapper="headerMapper"
request-factory="sslFactory"
expected-response-type="java.lang.String">

Show sent request in groovy script in SoapIU

I try to create integration tests in SoapUI:
There are property myId=1234 in property file.
I send soap request (named myRequest) contains <messageId>${myId}</messageId>
This request is valid, because ${myId} is replaced by 1234. I receive response.
In my groovy script I want show sent request, value of <messageId>:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def request = groovyUtils.getXmlHolder("myRequest#Request");
log.info(request["//messageId"]);
output: ${myId}
Expected output: 1234
Do you have any idea?
It is possible achieve this without using an additional Groovy Script test step by using Script Assertion for the same request step.
Use below Script Assertion to show the request along with values being replace or the actual request being sent to the server.
//Check if you have got the response
assert context.response, "Response is null or empty"
//show the actual request is being sent
log.info context.rawRequest

Jmeter : How to check for empty text response

I am writing a jmeter framework to validate Rest web services.I have a csv file having the list of URLS , Response code and response messages Eg :
/api/input/checkUploadRequirement application/x-www-form-urlencoded 200 NOTREQUIRED
likewise I have many URL's.Few of the URL's does not return anything and for them I have empty cell\field in the csv file Eg:
/api/input/savedetail sessionTrackingID=58ec9684-dfd-4c8f4796-f897 application/x-www-form-urlencoded 200 .
Now If I validate the empty Text response in Jmeter for above URL, I am getting "Assertion failure message: Response was null"
Please help me to validate empty text response from http request
You can use Size Assertion and test for size of response:
http://jmeter.apache.org/usermanual/component_reference.html#Size_Assertion
You can do it via Beanshell Assertion. If null response is something you expect, substitute Response Assertion with Beanshell Assertion. Use the following code in "Script" area:
if (ResponseData.length != 0) {
Failure = true;
FailureMessage = "Expected empty response, got: " + new String(ResponseData);
}
This code will mark parent sampler as passed if response is empty and fail it if even a single character will be returned.
See How to Use JMeter Assertions in Three Easy Steps guide for advanced information on conditionally setting pass/fail criteria in your JMeter test

customize soap fault message in spring integration

I am currently learning spring integration.I want to create a soap response from fault message.If any error is occurred spring gives response with fault in message body.I want to customize it.Instead of showing it i need to show a response object which contains pain response object.For eg:
if soap fault message is like this
<SOAP-ENV:Fault>
<faultcode xsi:type="xsd:string">SOAP-ENV:Client</faultcode>
<faultstring xsi:type="xsd:string">
Failed to locate method (ValidateCreditCard) in class (examplesCreditCard) at /usr/local/ActivePerl-5.6/lib/site_perl/5.6.0/SOAP/Lite.pm line 1555.
</faultstring>
</SOAP-ENV:Fault>
in its place i need to show its response as follows
<m:myResponse xmlns:m ="http://www.example.org/myschema">
<m:error> Failed to locate method (ValidateCreditCard) in class (examplesCreditCard) at /usr/local/ActivePerl-5.6/lib/site_perl/5.6.0/SOAP/Lite.pm line 1555</m:error>
</m:myResponse>
The <int-ws:inbound-gateway> has error-channel option to provide an ability to treat any downstream Exception with some error handling flow and return a desired result from there. That result is used as a SOAP response.
Hope I am clear.