Package de.danielbechler.diff.node

Examples of de.danielbechler.diff.node.DiffNode


  public void testCompareBeanWithIgnoredMapProperty()
  {
    final ObjectWithIgnoredMap working = new ObjectWithIgnoredMap();
    working.getMap().put("foo", "bar");

    final DiffNode node = objectDiffer.compare(working, new ObjectWithIgnoredMap());

    NodeAssertions.assertThat(node).self().hasState(DiffNode.State.UNTOUCHED);
    NodeAssertions.assertThat(node).self().hasNoChildren();
  }
View Full Code Here


    objectDifferBuilder.inclusion()
        .exclude()
        .node(NodePath.with("collection"));
    objectDiffer = objectDifferBuilder.build();

    final DiffNode node = objectDiffer.compare(working, new ObjectWithCollection());

    NodeAssertions.assertThat(node).self().hasState(DiffNode.State.UNTOUCHED);
    NodeAssertions.assertThat(node).self().hasNoChildren();
  }
View Full Code Here

  public void testCompareCollectionWithAddedItem() throws Exception
  {
    final Collection<String> working = new LinkedList<String>(asList("foo"));
    final Collection<String> base = new LinkedList<String>();

    final DiffNode node = ObjectDifferBuilder.buildDefault().compare(working, base);

    NodeAssertions.assertThat(node).self().hasState(DiffNode.State.CHANGED);
    NodeAssertions.assertThat(node).child(new CollectionItemElementSelector("foo")).hasState(DiffNode.State.ADDED);
  }
View Full Code Here

  public void testCompareCollectionWithRemovedItem() throws Exception
  {
    final Collection<String> working = new LinkedList<String>();
    final Collection<String> base = new LinkedList<String>(asList("foo"));

    final DiffNode node = ObjectDifferBuilder.buildDefault().compare(working, base);

    NodeAssertions.assertThat(node).self().hasState(DiffNode.State.CHANGED);
    NodeAssertions.assertThat(node).child(new CollectionItemElementSelector("foo")).hasState(DiffNode.State.REMOVED);
  }
View Full Code Here

    final ObjectWithNestedObject base = new ObjectWithNestedObject("1");
    final ObjectWithNestedObject working = new ObjectWithNestedObject("1", new ObjectWithNestedObject("2", new ObjectWithNestedObject("foo")));
    final ObjectDifferBuilder objectDifferBuilder = ObjectDifferBuilder.startBuilding();
    // final Configuration2 objectDifferBuilder = new Configuration2().withChildrenOfAddedNodes();

    final DiffNode node = objectDifferBuilder.build().compare(working, base);

    node.visit(new NodeHierarchyVisitor());
    NodeAssertions.assertThat(node).root().hasState(DiffNode.State.CHANGED);
    NodeAssertions.assertThat(node).child("object").hasState(DiffNode.State.ADDED);
    NodeAssertions.assertThat(node).child("object", "object").hasState(DiffNode.State.ADDED);
  }
View Full Code Here

  public static void main(final String[] args)
  {
    final Person bruceWayne = new Person("Bruce", "Wayne");
    final Person batman = new Person("Batman", null);
    final DiffNode rootNode = ObjectDifferBuilder.buildDefault().compare(batman, bruceWayne);
    rootNode.visit(new NodeHierarchyVisitor(10));
    rootNode.visit(new PrintingVisitor(batman, bruceWayne)
    {
      @Override
      protected boolean filter(final DiffNode node)
      {
        return true;
View Full Code Here

    final AddressBook baseAddressBook = new AddressBook();
    final Contact baseContact = new Contact("Walter White");
    baseAddressBook.setContacts(asList(baseContact));

    final DiffNode rootNode = ObjectDifferBuilder.buildDefault()
        .compare(workingAddressBook, baseAddressBook);
    final DiffNode contactsNode = rootNode.getChild("contacts");
    final DiffNode contactNode = contactsNode.getChild(new CollectionItemElementSelector(baseContact));
    final DiffNode nicknameNode = contactNode.getChild("nickname");

    rootNode.visit(new NodeHierarchyVisitor());

    /*

    Output:

    / ===> DefaultNode(state=CHANGED, type=de.danielbechler.diff.example.CanonicalAccessorExample.AddressBook, 1 child, accessed via root element)
      /contacts ===> CollectionNode(state=CHANGED, type=java.util.List, 1 child, accessed via property 'contacts')
        /contacts[Contact{name='Walter White'}] ===> DefaultNode(state=CHANGED, type=de.danielbechler.diff.example.CanonicalAccessorExample.Contact, 1 child, accessed via collection item [Contact{name='Walter White'}])
          /contacts[Contact{name='Walter White'}]/nickname ===> DefaultNode(state=ADDED, type=java.lang.String, no children, accessed via property 'nickname')

     */

    final AddressBook addressBook = (AddressBook) rootNode.get(workingAddressBook);
    final List<Contact> contacts = (List<Contact>) contactsNode.get(addressBook);
    final Contact contact = (Contact) contactNode.get(contacts);

    assert rootNode.get(workingAddressBook) == rootNode.canonicalGet(workingAddressBook);
    assert contactsNode.get(addressBook) == contactsNode.canonicalGet(workingAddressBook);
    assert contactNode.get(contacts) == contactNode.canonicalGet(workingAddressBook);
    assert nicknameNode.get(contact) == nicknameNode.canonicalGet(workingAddressBook);
  }
View Full Code Here

  public static void main(final String[] args)
  {
    final Point base = new Point(new Coordinate3D(1, 2, 3));
    final Point working = new Point(new Coordinate3D(1, 2, 30));
    final DiffNode node = ObjectDifferBuilder.buildDefault().compare(working, base);

    assert node.getChild("coordinate").getChild("z").isChanged() :
        "The changed 'z' coordinate should have been detected because the property type should be resolved to Coordinate3D at runtime.";
  }
View Full Code Here

    final ObjectDifferBuilder builder = ObjectDifferBuilder.startBuilding();

    // (Option 1) Causes the ObjectDiffer to ignore the 'password' property of the root object
    builder.inclusion().exclude().node(NodePath.with("password"));

    final DiffNode node = builder.build().compare(working, base);

    node.visit(new PrintingVisitor(working, base));

    // Output with ignore: Property at path '/' has not changed
    // Output without ignore: Property at path '/password' has changed from [ 1234 ] to [ 9876 ]
  }
View Full Code Here

    final PhoneBook modifiedPhoneBook = PhoneBook.from(phoneBook);
    modifiedPhoneBook.getContact("Jesse", "Pinkman").setMiddleName("Bruce");
    modifiedPhoneBook.getContact("Walter", "White").setMiddleName("Hartwell");

    final ObjectDiffer objectDiffer = ObjectDifferBuilder.buildDefault();
    final DiffNode node = objectDiffer.compare(modifiedPhoneBook, phoneBook);

    assertThat(node.hasChanges(), is(true));
    assertThat(node.hasChildren(), is(true));
    assertThat(node.childCount(), is(1));

    final DiffNode contactsNode = node.getChild("contacts");
    assertThat(contactsNode, IsNull.notNullValue());
    assertThat(contactsNode.hasChanges(), is(true));

    final DiffNode pinkmanNode = contactsNode.getChild(new CollectionItemElementSelector(jessePinkman));
    assertThat(pinkmanNode.hasChanges(), is(true));

    final DiffNode middleNameNode = pinkmanNode.getChild("middleName");
    assertThat(middleNameNode.hasChanges(), is(true));
    assertThat(middleNameNode.canonicalGet(phoneBook), IsNull.nullValue());
    assertThat((String) middleNameNode.canonicalGet(modifiedPhoneBook), IsEqual.equalTo("Bruce"));

    final DiffNode whiteNode = contactsNode.getChild(new CollectionItemElementSelector(walterWhite));
    assertThat(whiteNode.hasChanges(), is(true));

    final DiffNode whiteMiddleNameNode = whiteNode.getChild("middleName");
    assertThat(whiteMiddleNameNode.hasChanges(), is(true));
    assertThat(whiteMiddleNameNode.canonicalGet(phoneBook), IsNull.nullValue());
    assertThat((String) whiteMiddleNameNode.canonicalGet(modifiedPhoneBook), IsEqual.equalTo("Hartwell"));
  }
View Full Code Here

TOP

Related Classes of de.danielbechler.diff.node.DiffNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.