summaryrefslogtreecommitdiffstats
path: root/infra/it/it-test
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2018-01-16 13:59:41 +0100
committerMarek Gradzki <mgradzki@cisco.com>2018-01-16 13:50:33 +0000
commit677a81daf4349220de65880fcac26537bcd9cb0c (patch)
treeee650bab6609f17602e380ed432e766791509288 /infra/it/it-test
parent06e15d12a08b7ab5d708d17dea7b352f2ae75cf9 (diff)
Improve integration tests for SubtreeWriter
Change-Id: I20209b800eaa892e0fb742066003e956d00bbb22 Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'infra/it/it-test')
-rw-r--r--infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/AbstractInfraTest.java3
-rw-r--r--infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/HoneycombWriteInfraTest.java51
-rw-r--r--infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/SubtreeWriteTest.java162
3 files changed, 164 insertions, 52 deletions
diff --git a/infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/AbstractInfraTest.java b/infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/AbstractInfraTest.java
index 3e25733df..ebe9862d9 100644
--- a/infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/AbstractInfraTest.java
+++ b/infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/AbstractInfraTest.java
@@ -71,7 +71,8 @@ abstract class AbstractInfraTest {
final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
moduleInfoBackedContext.addModuleInfos(Arrays.asList(
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.test.rev150105.$YangModuleInfoImpl.getInstance(),
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.aug.test.rev161222.$YangModuleInfoImpl.getInstance()
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.aug.test.rev161222.$YangModuleInfoImpl.getInstance(),
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.subtree.test.rev180116.$YangModuleInfoImpl.getInstance()
));
return moduleInfoBackedContext;
diff --git a/infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/HoneycombWriteInfraTest.java b/infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/HoneycombWriteInfraTest.java
index 54b93c768..6d8099c6e 100644
--- a/infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/HoneycombWriteInfraTest.java
+++ b/infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/HoneycombWriteInfraTest.java
@@ -16,10 +16,8 @@
package io.fd.honeycomb.data.impl;
-import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -522,53 +520,4 @@ public class HoneycombWriteInfraTest extends AbstractInfraTest {
// No modification
verifyNoMoreInteractions(simpleContainerWriter);
}
-
- @Test
- public void testSubtreeWriter() throws Exception {
- writerRegistry = new FlatWriterRegistryBuilder(new YangDAG())
- // Handles also container from grouping
- .subtreeAdd(Sets.newHashSet(Ids.CONTAINER_FROM_GROUPING_ID), containerWithChoiceWriter)
- .build();
-
- final ModifiableDataTreeDelegator modifiableDataTreeDelegator =
- new ModifiableDataTreeDelegator(serializer, dataTree, schemaContext, writerRegistry, contextBroker);
-
- final ContainerWithChoice containerWithChoice =
- new ContainerWithChoiceBuilder().setContainerFromGrouping(getContainerFromGrouping()).build();
-
- // Test write subtree node
- DataModification dataModification = modifiableDataTreeDelegator.newModification();
- writeContainerFromGrouping(dataModification);
- dataModification.commit();
-
- verify(containerWithChoiceWriter, atLeastOnce()).getManagedDataObjectType();
- verify(containerWithChoiceWriter)
- .processModification(eq(Ids.CONTAINER_WITH_CHOICE_ID), eq(null), eq(containerWithChoice), any(WriteContext.class));
- verifyNoMoreInteractions(containerWithChoiceWriter);
-
- // Test delete sub-node
- dataModification = modifiableDataTreeDelegator.newModification();
- final ContainerWithChoice containerWithChoiceEmpty = new ContainerWithChoiceBuilder().build();
- deleteContainerFromGrouping(dataModification);
- dataModification.commit();
-
- verify(containerWithChoiceWriter, atLeastOnce()).getManagedDataObjectType();
- verify(containerWithChoiceWriter)
- .processModification(eq(Ids.CONTAINER_WITH_CHOICE_ID), eq(containerWithChoice), eq(containerWithChoiceEmpty), any(WriteContext.class));
- verifyNoMoreInteractions(containerWithChoiceWriter);
-
- // Test write with subtree node that's not handled by subtree writer
- dataModification = modifiableDataTreeDelegator.newModification();
- writeContainerWithChoice(dataModification);
- try {
- dataModification.commit();
- fail("Missing writer for C3 should occur");
- } catch (IllegalArgumentException e) {
- return;
- }
- }
-
- private void deleteContainerFromGrouping(final DataModification dataModification) {
- dataModification.delete(serializer.toYangInstanceIdentifier(Ids.CONTAINER_FROM_GROUPING_ID));
- }
} \ No newline at end of file
diff --git a/infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/SubtreeWriteTest.java b/infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/SubtreeWriteTest.java
new file mode 100644
index 000000000..f46174754
--- /dev/null
+++ b/infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/SubtreeWriteTest.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 2018 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.data.impl;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.Sets;
+import io.fd.honeycomb.data.DataModification;
+import io.fd.honeycomb.subtree.test.model.Ids;
+import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder;
+import io.fd.honeycomb.translate.util.YangDAG;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.honeycomb.translate.write.Writer;
+import io.fd.honeycomb.translate.write.registry.WriterRegistry;
+import java.util.Map;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.subtree.test.rev180116.C1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.subtree.test.rev180116.C1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.subtree.test.rev180116.c1.C2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.subtree.test.rev180116.c1.C2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.subtree.test.rev180116.c1.C3;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.subtree.test.rev180116.c1.C3Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.subtree.test.rev180116.c1.C4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.subtree.test.rev180116.c1.C4Builder;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
+import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
+
+/**
+ * Testing honeycomb writes from data tree up to mocked writers.
+ */
+public final class SubtreeWriteTest extends AbstractInfraTest {
+
+ private TipProducingDataTree dataTree;
+
+ @Mock
+ private Writer<C1> c1Writer;
+
+ @Override
+ void postSetup() {
+ dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION);
+ dataTree.setSchemaContext(schemaContext);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testMissingWriter() throws Exception {
+ when(c1Writer.getManagedDataObjectType()).thenReturn(Ids.C1_ID);
+
+ final WriterRegistry writerRegistry = new FlatWriterRegistryBuilder(new YangDAG())
+ .subtreeAdd(Sets.newHashSet(Ids.C2_ID, Ids.C3_ID), c1Writer)
+ .build();
+
+ // Prepare modification for C4
+ final ModifiableDataTreeDelegator modifiableDataTreeDelegator =
+ new ModifiableDataTreeDelegator(serializer, dataTree, schemaContext, writerRegistry, contextBroker);
+ final C4 c4 = new C4Builder().setLeaf4(4).build();
+ final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> c4NormalizedNode =
+ serializer.toNormalizedNode(Ids.C4_ID, c4);
+ final DataModification dataModification = modifiableDataTreeDelegator.newModification();
+ dataModification.write(c4NormalizedNode.getKey(), c4NormalizedNode.getValue());
+
+ // Commit modification and fail with missing writer for C4
+ dataModification.commit();
+ }
+
+ @Test
+ public void testWrite() throws Exception {
+ when(c1Writer.getManagedDataObjectType()).thenReturn(Ids.C1_ID);
+
+ final WriterRegistry writerRegistry = new FlatWriterRegistryBuilder(new YangDAG())
+ .subtreeAdd(Sets.newHashSet(Ids.C2_ID, Ids.C3_ID), c1Writer)
+ .build();
+
+ // Prepare modification for C1 and C2 containers
+ final ModifiableDataTreeDelegator modifiableDataTreeDelegator =
+ new ModifiableDataTreeDelegator(serializer, dataTree, schemaContext, writerRegistry, contextBroker);
+ final C2 c2 = new C2Builder().setLeaf2(2).build();
+ final C3 c3 = new C3Builder().setLeaf3(3).build();
+ final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> c2NormalizedNode =
+ serializer.toNormalizedNode(Ids.C2_ID, c2);
+ final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> c3NormalizedNode =
+ serializer.toNormalizedNode(Ids.C3_ID, c3);
+
+ // Create data
+ final DataModification dataModification = modifiableDataTreeDelegator.newModification();
+ dataModification.write(c2NormalizedNode.getKey(), c2NormalizedNode.getValue());
+ dataModification.write(c3NormalizedNode.getKey(), c3NormalizedNode.getValue());
+ dataModification.commit();
+
+ // Check if updates for two child containers are wrapped into single update
+ verify(c1Writer).processModification(any(), any(), any(), any());
+
+ // Verify that writer received create modification for C1 with C2 and C3 included
+ final C1 expectedC1 = new C1Builder().setC2(c2).setC3(c3).build();
+ verify(c1Writer).processModification(eq(Ids.C1_ID), eq(null), eq(expectedC1), any(WriteContext.class));
+ }
+
+ @Test
+ public void testDelete() throws Exception {
+ when(c1Writer.getManagedDataObjectType()).thenReturn(Ids.C1_ID);
+
+ final WriterRegistry writerRegistry = new FlatWriterRegistryBuilder(new YangDAG())
+ .subtreeAdd(Sets.newHashSet(Ids.C2_ID, Ids.C3_ID), c1Writer)
+ .build();
+
+ // Prepare C1 with leaf1 and C1, C2 containers
+ final ModifiableDataTreeDelegator modifiableDataTreeDelegator =
+ new ModifiableDataTreeDelegator(serializer, dataTree, schemaContext, writerRegistry, contextBroker);
+ final C2 c2 = new C2Builder().setLeaf2(2).build();
+ final C3 c3 = new C3Builder().setLeaf3(3).build();
+ final C1 c1 = new C1Builder().setC2(c2).setC3(c3).setLeaf1("some-value").build();
+ final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> c1NormalizedNode =
+ serializer.toNormalizedNode(Ids.C1_ID, c1);
+
+ // Create data
+ DataModification dataModification = modifiableDataTreeDelegator.newModification();
+ dataModification.write(c1NormalizedNode.getKey(), c1NormalizedNode.getValue());
+ dataModification.commit();
+ verify(c1Writer).processModification(eq(Ids.C1_ID), eq(null), eq(c1), any(WriteContext.class));
+
+ // Now delete C1 and C2
+ dataModification = modifiableDataTreeDelegator.newModification();
+ dataModification.delete(serializer.toYangInstanceIdentifier(Ids.C2_ID));
+ dataModification.delete(serializer.toYangInstanceIdentifier(Ids.C3_ID));
+ dataModification.commit();
+
+ // Check that in total, there were 2 invocations of processModification
+ verify(c1Writer, times(2)).processModification(any(), any(), any(), any());
+
+ // First create for C1
+ final InOrder inOrder = Mockito.inOrder(c1Writer);
+ inOrder.verify(c1Writer).processModification(eq(Ids.C1_ID), eq(null), eq(c1), any(WriteContext.class));
+
+ // Then delete for C1 and C2, but wrapped in C1 update
+ final C1 c1WithoutC2AndC3 = new C1Builder().setLeaf1("some-value").build();
+ inOrder.verify(c1Writer)
+ .processModification(eq(Ids.C1_ID), eq(c1), eq(c1WithoutC2AndC3), any(WriteContext.class));
+ }
+} \ No newline at end of file