XMLUnit-2 is failing with `withNodeMatcher` API for random order of List<Map>

203 Views Asked by At

I've used below DiffBuilder using XMLUnit-2

diff = DiffBuilder.compare(control).withTest(test).checkForSimilar()
.normalizeWhitespace().ignoreComments()
.ignoreWhitespace().ignoreElementContentWhitespace()
.withNodeFilter(node -> (filter(node, attrsToIgnore)))
.withAttributeFilter(fields -> (filterFields(fields, fieldsToIgnore)))
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)).build();

It works well for shuffling the List<> values or random value in List<> as shown below

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE ResourceObject PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<ResourceObject displayName="aggaccnm1" identity="U013JFHQ59D" objectType="account">
  <Attributes>
    <Map>
      <entry key="costCenter" value="1111"/>
      <entry key="department" value="QA"/>
      <entry key="displayName" value="AggACCDN1"/>
      <entry key="groups">
        <value>
          <List>
            <String>S013J6S7STH</String>
            <String>S013S71EMLN</String>
            <String>S013S71GTU6</String>
          </List>
        </value>
      </entry>
    </Map>
  </Attributes>
</ResourceObject>

But, When I've List < Map {} > it fails.. what can be done to handle both random order of List<String> values as well as List < Map {} > value orders.

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE ResourceObject PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<ResourceObject displayName="aggaccnm1" identity="U013JFHQ59D" objectType="account">
  <Attributes>
    <Map>
      <entry key="costCenter" value="1111"/>
      <entry key="department" value="QA"/>
      <entry key="displayName" value="AggACCDN1"/>
      <entry key="groups">
        <value>
          <List>
            <String>S013J6S7STH</String>
            <String>S013S71EMLN</String>
            <String>S013S71GTU6</String>
          </List>
        </value>
      </entry>
      <entry key="groups_objects">
        <value>
          <List>
            <Map>
              <entry key="display" value="Agggrp1"/>
              <entry key="value" value="S013S71EMLN"/>
            </Map>
            <Map>
              <entry key="display" value="Agggrp5"/>
              <entry key="value" value="S013S71GTU6"/>
            </Map>
            <Map>
              <entry key="display" value="Agggrp7"/>
              <entry key="value" value="S013S71HVU6"/>
            </Map>
          </List>
        </value>
      </entry>
    </Map>
  </Attributes>
</ResourceObject>

In above example you can notice I've List < Map {} > and my above implementation working well for simple List<> but not for List < Map {} >

I want to ignore the order of both, someone please let me know how this can be achieved?

Thanks,

Swapnil.

0

There are 0 best solutions below