-1

I am working on this test class and trying to change the response expected to a bean response as I have changed the requests to bean requests.

private void assertXmlResponse(Document xmlResponse, int Elements,
            String Message, String Code, String name,
            String Funds)
{
    Node topLevelElement = xmlResponse.getFirstChild();
    NodeList childElements = topLevelElement.getChildNodes();

    assertEquals("result", topLevelElement.getNodeName());
    assertEquals(Elements, childElements.getLength());

    assertEquals("message", childElements.item(0).getNodeName());
    assertEquals(Message, childElements.item(0).getTextContent());

    assertEquals("code", childElements.item(1).getNodeName());
    assertEquals(Code, childElements.item(1).getTextContent());

    assertEquals("name", childElements.item(2).getNodeName());
    assertEquals(name, childElements.item(2).getTextContent());
} 

Please can someone point me in the right direction or even let me know if it's possible?

Thanks

djv
  • 15,168
  • 7
  • 48
  • 72
Tim
  • 23
  • 3

1 Answers1

1

You are about to make POJO(Plain Old Java Objects).

     public Class A{
      private int Elements; 
      private String Message;
      private String Funds;
      private String code;
      private String name;
      //getters and setters



       }

Keep the reference of this class as Parameter in your method.

Use the getters for accessing the value in your method.

pd30
  • 240
  • 1
  • 7
  • Thanks, having a little trouble understanding. I can make the objects and set and get methods. But how would I then be able to put this as it is written above such as: assertEquals("result", topLevelElement.getNodeName()); as these get picked from what I pass through my tests? assertEquals(Elements, childElements.getLength()); – Tim Sep 26 '14 at 14:18
  • Suppose x is object of class A,then in your assertEquals(x.getMessage(),childElements.item(0).getTextContent()) – pd30 Sep 26 '14 at 14:52
  • childElements comes from the Node interface so throws an error at this point as we are not using Nodes. Not sure what to do at this point I have created them as objects and set them before executing assertEquals(x.getMessage(),childElements.item(0).getTextContent()) – Tim Sep 28 '14 at 08:55
  • So get the elements from Node interface and treat them as actual response whereas the object you created and set all the properties is the expected response.Thats it – pd30 Sep 29 '14 at 09:00