0

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.

Swapnil Kotwal
  • 5,418
  • 6
  • 48
  • 92
  • Try like this. https://stackoverflow.com/questions/57768836/how-can-i-compare-map-like-elements-with-xmlunit?rq=1 – Prakash Boda Mar 01 '21 at 08:28
  • The problem is `` isn't fix, it can be any random entry and It will consist of any `List< Map {}>`. So, I need some generic solution which can work for any `List< Map {}>` where the order of elements isn't fixed. – Swapnil Kotwal Mar 01 '21 at 08:35

0 Answers0