Announcement Announcement Module
Collapse
No announcement yet.
Unable to use xpath method ResponseMatchers class in spring-ws-test Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to use xpath method ResponseMatchers class in spring-ws-test

    Code:
    @Test
    public final void testUnlinkFail() throws Exception{
    		
              Source requestPayload = new StreamSource(unlinkFailRequest);		
              Source responsePayload = new StreamSource(unlinkFailResponse);
    		
              mockClient.sendRequest(withPayload(requestPayload))
              .andExpect((ResponseMatcher)xpath("//ControlNumber[1]"));
    	
    }
    Im trying to use xpath method of ResponseMatchers class to test an xpath expression exists on my web service response. But I'm getting a class cast exception as follows.

    java.lang.ClassCastException: org.springframework.ws.test.server.XPathExpectatio nsHelperAdapter
    cannot be cast to org.springframework.ws.test.server.ResponseMatcher .

    Fair enough which makes sense. My problem is the spring web service 2.0 documentation
    http://static.springsource.org/spring-ws/site/reference/html/server.html on section 5.7.3states that you can use xpath() method in this scenario. But it returns XPathExpectationsHelperAdapter object which cannot be cast to ResponseMatcher.

  • #2
    Okay, so I'm late responding to this thread; however, I just came across this issue myself this morning and to save those who follow me a lot of headaches.
    Here is what I did:

    mockClient.sendRequest(withPayload(requestPayload) )
    .andExpect((ResponseMatcher)xpath("//ControlNumber[1]").exits());

    The exists() method returns an ResponseMatcher!

    Which is what .andExpect() method wants to see!

    These other methods do as well:
    doesNotExist()
    evaluatesTo(boolean expectedValue)
    evaluatesTo(double expectedValue)
    evaluatesTo(int expectedValue)
    evaluatesTo(String expectedValue)

    So hope this helps others.




    Originally posted by moustapha01 View Post
    Code:
    @Test
    public final void testUnlinkFail() throws Exception{
    		
              Source requestPayload = new StreamSource(unlinkFailRequest);		
              Source responsePayload = new StreamSource(unlinkFailResponse);
    		
              mockClient.sendRequest(withPayload(requestPayload))
              .andExpect((ResponseMatcher)xpath("//ControlNumber[1]"));
    	
    }
    Im trying to use xpath method of ResponseMatchers class to test an xpath expression exists on my web service response. But I'm getting a class cast exception as follows.

    java.lang.ClassCastException: org.springframework.ws.test.server.XPathExpectatio nsHelperAdapter
    cannot be cast to org.springframework.ws.test.server.ResponseMatcher .

    Fair enough which makes sense. My problem is the spring web service 2.0 documentation
    http://static.springsource.org/spring-ws/site/reference/html/server.html on section 5.7.3states that you can use xpath() method in this scenario. But it returns XPathExpectationsHelperAdapter object which cannot be cast to ResponseMatcher.

    Comment


    • #3
      Thought I should post the exact syntax I would use to avoid confusion:

      mockClient.sendRequest(withPayload(requestPayload) )
      .andExpect(ResponseMatchers.xpath("//ControlNumber[1]").exists());

      Comment

      Working...
      X