Geek
Geek

Reputation: 99

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

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);
}

Upvotes: 0

Views: 686

Answers (1)

Christoph Deppisch
Christoph Deppisch

Reputation: 2216

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.

Upvotes: 0

Related Questions