Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xmlPath returns inconsistent results on not matching root path #1247

Open
gcwiak opened this issue Dec 30, 2019 · 0 comments
Open

xmlPath returns inconsistent results on not matching root path #1247

gcwiak opened this issue Dec 30, 2019 · 0 comments

Comments

@gcwiak
Copy link

gcwiak commented Dec 30, 2019

When executing xmlPath query, without explicit setting root path , which starts with incorrect root node name I would expect to get a meaningful empty result.

Please consider the following test cases.
The first one shows correct behaviour for matching root element name.
The second one demonstrates incorrect, in my opinion, behaviour. Especially the last case, when the actual value of the firstName element is returned despite that wrong root is specified in the path.
For the other cases the whole xml tree is returned which also does not seem right for me.

After setting setRootPath("greeting") it behaves as expected.

Is this a desired behaviour? I have not found any documentation about this.

Or am I missing something?

Cheers,
Grzegorz

Tested with RestAssured version: 4.1.2

private static final String XML = "<greeting>" +
            "      <firstName>John</firstName>\n" +
            "      <lastName>Doe</lastName>\n" +
            "    </greeting>";

    @Test // WORKS FINE 
    void should_get_result_for_matching_root_path() {
        assertThat(new XmlPath(XML).get("greeting").toString()).isEqualTo("JohnDoe");
        assertThat(new XmlPath(XML).get("greeting.firstName").toString()).isEqualTo("John");
    }

    @Test // FAILS FOR ALL ASSERTIONS
    void should_get_meaningful_result_for_not_matching_root_path() {
        // Whole xml is returned here
        assertThat(new XmlPath(XML).get("notExisting").toString()).isBlank(); // Expecting blank but was:<"JohnDoe">

        // Whole xml is returned here
        assertThat(new XmlPath(XML).get("firstName").toString()).isBlank(); // Expecting blank but was:<"JohnDoe">

        // Actual element value, despite wrong root path, is returned
        assertThat(new XmlPath(XML).get("notExisting.firstName").toString()).isBlank(); // Expecting blank but was:<"John">
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant