Answer the question
In order to leave comments, you need to log in
How to check value as number?
I am writing a rest test. Rest returns xml, in one of the elements of which the value has a numeric form.
How can I check that this number is non-zero? I'm trying to defeat this issue with org.hamcrest.xml.HasXPath.hasXPath and org.hamcrest.Matchers.greaterThan, but nothing comes out yet. I need an example, but I did not find anything suitable by Google.
Answer the question
In order to leave comments, you need to log in
Here is a piece of working code
@Test
public void myTest() throws Exception {
final HttpURLConnection urlConnection = getConnection(HOST_URL + MY_URL);
prepareConnection(urlConnection);
urlConnection.setRequestMethod("POST");
BufferedReader br = new BufferedReader(new InputStreamReader((urlConnection.getInputStream())));
StringBuilder sb = new StringBuilder();
String output;
while ((output = br.readLine()) != null) {
sb.append(output);
}
assertThat("Incorrect fields or values in the response xml.", parse(sb.toString()), hasXPath("ParentNode/ChildNode", containsString("42")));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question