X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-data-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fdata%2Fimpl%2Fschema%2FBuilderTest.java;h=d1e1d72fb6c68b637e34a79529854e360457b34c;hb=1e8209bb1e52b827e0e1e783a9c11cb6b8241d12;hp=800912dd710dbd637c3e3c6f235efa9a323169a6;hpb=ff066b463c04c7b8380e02706cc3a6bb5a700ad8;p=yangtools.git diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java index 800912dd71..d1e1d72fb6 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java @@ -11,7 +11,7 @@ package org.opendaylight.yangtools.yang.data.impl.schema; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.mockito.Mockito.mock; +import static org.junit.Assert.assertThrows; import java.io.File; import java.net.URISyntaxException; @@ -37,25 +37,18 @@ import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode; import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder; +import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAugmentationNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeSchemaAwareBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeSchemaAwareBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeSchemaAwareBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeSchemaAwareBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserLeafSetNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserLeafSetNodeSchemaAwareBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserMapNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserMapNodeSchemaAwareBuilder; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; @@ -119,20 +112,20 @@ public class BuilderTest { final UserMapNode orderedMapNodeCreateNode = ImmutableUserMapNodeBuilder.create(orderedMapNodeCreateNull) .removeChild(mapEntryPath) .build(); - final UserMapNode orderedMapNodeSchemaAware = ImmutableUserMapNodeSchemaAwareBuilder.create(list) + final UserMapNode orderedMapNodeSchemaAware = ImmutableUserMapNodeBuilder.create() + .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST) .withChild(LIST_MAIN_CHILD_1) .build(); - final UserMapNode orderedMapNodeSchemaAwareMapNodeConst = ImmutableUserMapNodeSchemaAwareBuilder.create( - list, getImmutableUserMapNode()) + final UserMapNode orderedMapNodeSchemaAwareMapNodeConst = + ImmutableUserMapNodeBuilder.create(getImmutableUserMapNode()) .build(); - assertNotNull(Builders.orderedMapBuilder(list)); assertEquals(SIZE, orderedMapNodeCreateNull.size()); assertEquals(orderedMapNodeCreateNode.size(), orderedMapNodeCreateNull.size() - 1); assertEquals(NODE_IDENTIFIER_LIST, orderedMapNodeCreateSize.getIdentifier()); - assertEquals(LIST_MAIN_CHILD_1, orderedMapNodeCreateNull.getChild(0)); + assertEquals(LIST_MAIN_CHILD_1, orderedMapNodeCreateNull.childAt(0)); assertEquals(SIZE, orderedMapNodeCreateNull.size()); - assertEquals(orderedMapNodeSchemaAware.getChild(0), orderedMapNodeSchemaAwareMapNodeConst.getChild(0)); + assertEquals(orderedMapNodeSchemaAware.childAt(0), orderedMapNodeSchemaAwareMapNodeConst.childAt(0)); } @Test @@ -146,18 +139,16 @@ public class BuilderTest { final LinkedList> mapEntryNodeColl = new LinkedList<>(); mapEntryNodeColl.add(orderedLeafSet); final UnmodifiableCollection leafSetCollection = (UnmodifiableCollection)orderedLeafSet.body(); - final NormalizedNode orderedMapNodeSchemaAware = ImmutableUserLeafSetNodeSchemaAwareBuilder.create( - leafList).withChildValue("baz").build(); + final NormalizedNode orderedMapNodeSchemaAware = ImmutableUserLeafSetNodeBuilder.create() + .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST) + .withChildValue("baz") + .build(); final UnmodifiableCollection SchemaAwareleafSetCollection = (UnmodifiableCollection) orderedMapNodeSchemaAware.body(); - final NormalizedNode orderedLeafSetShemaAware = ImmutableUserLeafSetNodeSchemaAwareBuilder.create( - leafList, (UserLeafSetNode) orderedLeafSet).build(); - assertNotNull(Builders.orderedLeafSetBuilder(leafList)); assertNotNull(Builders.anyXmlBuilder()); - assertNotNull(orderedLeafSetShemaAware); assertEquals(1, ((UserLeafSetNode)orderedLeafSet).size()); - assertEquals("baz", orderedLeafSet.getChild(0).body()); + assertEquals("baz", orderedLeafSet.childAt(0).body()); assertNull(orderedLeafSet.childByArg(BAR_PATH)); assertEquals(1, leafSetCollection.size()); assertEquals(1, SchemaAwareleafSetCollection.size()); @@ -173,9 +164,6 @@ public class BuilderTest { collectionNodeBuilder.withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST); collectionNodeBuilder.withValue(mapEntryNodeColl); final SystemMapNode mapNode = collectionNodeBuilder.build(); - final SystemMapNode mapNodeSchemaAware = ImmutableMapNodeSchemaAwareBuilder.create(list, - getImmutableMapNode()).build(); - assertNotNull(mapNodeSchemaAware); assertNotNull(Builders.mapBuilder(mapNode)); } @@ -189,10 +177,8 @@ public class BuilderTest { .build(); final UnkeyedListEntryNode unkeyedListEntryNodeNode = ImmutableUnkeyedListEntryNodeBuilder .create(unkeyedListEntryNode).build(); - assertEquals(unkeyedListEntryNode.getNodeType().getLocalName(), unkeyedListEntryNodeSize.getNodeType() - .getLocalName()); - assertEquals(unkeyedListEntryNodeSize.getNodeType().getLocalName(), unkeyedListEntryNodeNode.getNodeType() - .getLocalName()); + assertEquals(unkeyedListEntryNode.getIdentifier(), unkeyedListEntryNodeSize.getIdentifier()); + assertEquals(unkeyedListEntryNodeSize.getIdentifier(), unkeyedListEntryNodeNode.getIdentifier()); } @Test @@ -211,16 +197,12 @@ public class BuilderTest { .build(); final UnkeyedListNode unkeyedListNodeCreated = ImmutableUnkeyedListNodeBuilder.create(unkeyedListNode) .build(); - try { - unkeyedListNodeSize.getChild(1); - } catch (IndexOutOfBoundsException e) { - // Ignored on purpose - } + + assertThrows(IndexOutOfBoundsException.class, () -> unkeyedListNodeSize.childAt(1)); assertNotNull(unkeyedListNodeSize.body()); - assertEquals(unkeyedListEntryNode, unkeyedListNodeCreated.getChild(0)); - assertEquals(unkeyedListNode.getNodeType().getLocalName(), unkeyedListNodeSize.getNodeType() - .getLocalName()); + assertEquals(unkeyedListEntryNode, unkeyedListNodeCreated.childAt(0)); + assertEquals(unkeyedListNode.getIdentifier(), unkeyedListNodeSize.getIdentifier()); assertNotNull(unkeyedListNodeCreated); } @@ -233,79 +215,51 @@ public class BuilderTest { } - @Test(expected = NullPointerException.class) + @Test public void immutableAugmentationNodeBuilderExceptionTest() { - ImmutableAugmentationNodeBuilder.create(1).build(); + final var builder = ImmutableAugmentationNodeBuilder.create(1); + assertThrows(NullPointerException.class, builder::build); } - @Test(expected = NullPointerException.class) + @Test public void immutableContainerNodeBuilderExceptionTest() { final ContainerNode immutableContainerNode = ImmutableContainerNodeBuilder.create(1) .withNodeIdentifier(NODE_IDENTIFIER_LIST) .build(); assertNotNull(immutableContainerNode); - final ContainerSchemaNode containerSchemaNode = mock(ContainerSchemaNode.class); - ImmutableContainerNodeSchemaAwareBuilder.create(containerSchemaNode, immutableContainerNode) - .withNodeIdentifier(NODE_IDENTIFIER_LIST) - .build(); } - @Test(expected = NullPointerException.class) + @Test public void immutableLeafSetNodeBuilderExceptionTest() { final SystemLeafSetNode leafSetNode = ImmutableLeafSetNodeBuilder.create(1) - .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST).build(); + .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST) + .build(); assertNotNull(leafSetNode); - ImmutableLeafSetNodeSchemaAwareBuilder.create(mock(LeafListSchemaNode.class), leafSetNode).build(); } - @Test(expected = UnsupportedOperationException.class) - public void immutableLeafSetEntryNodeSchemaAwareBuilderExceptionTest() { - final LeafListSchemaNode leafListSchemaNode = mock(LeafListSchemaNode.class); - ImmutableLeafSetEntryNodeSchemaAwareBuilder.create(leafListSchemaNode).withNodeIdentifier(BAR_PATH).build(); - } - - @Test(expected = NullPointerException.class) + @Test public void immutableMapEntryNodeBuilderExceptionTest() { - ImmutableMapEntryNodeBuilder.create(1).build(); + final var builder = ImmutableMapEntryNodeBuilder.create(1); + assertThrows(NullPointerException.class, builder::build); } - @Test(expected = UnsupportedOperationException.class) + @Test public void immutableUnkeyedListNodeBuilderExceptionTest() { - ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LEAF) - .removeChild(NODE_IDENTIFIER_LIST).build(); - } - - @Test(expected = UnsupportedOperationException.class) - public void immutableMapNodeSchemaAwareExceptionTest() { - ImmutableMapNodeSchemaAwareBuilder.create(list, getImmutableMapNode()).withNodeIdentifier(NODE_IDENTIFIER_LIST) - .build(); - } - - @Test(expected = UnsupportedOperationException.class) - public void immutableOrderedMapSchemaAwareExceptionTest1() { - ImmutableUserMapNodeSchemaAwareBuilder.create(list).withNodeIdentifier(NODE_IDENTIFIER_LIST).build(); - } - - @Test(expected = UnsupportedOperationException.class) - public void immutableUserLeafSetNodeSchemaAwareExceptionTest1() { - ImmutableUserLeafSetNodeSchemaAwareBuilder.create(leafList).withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST) - .build(); - } - - private static SystemLeafSetNode getImmutableLeafSetNode() { - final ListNodeBuilder> leafSetBuilder = Builders.leafSetBuilder(); - leafSetBuilder.withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST); - leafSetBuilder.addChild(LEAF_SET_ENTRY_NODE); - return leafSetBuilder.build(); + final var builder = ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LEAF); + assertThrows(UnsupportedOperationException.class, () -> builder.removeChild(NODE_IDENTIFIER_LIST)); } private static SystemMapNode getImmutableMapNode() { - return ImmutableMapNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LIST).withChild(LIST_MAIN_CHILD_1) - .build(); + return ImmutableMapNodeBuilder.create() + .withNodeIdentifier(NODE_IDENTIFIER_LIST) + .withChild(LIST_MAIN_CHILD_1) + .build(); } private static UserMapNode getImmutableUserMapNode() { - return ImmutableUserMapNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LIST) - .withChild(LIST_MAIN_CHILD_1).build(); + return ImmutableUserMapNodeBuilder.create() + .withNodeIdentifier(NODE_IDENTIFIER_LIST) + .withChild(LIST_MAIN_CHILD_1) + .build(); } }