summaryrefslogtreecommitdiffstats
path: root/infra/it
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2018-01-17 08:56:09 +0100
committerMarek Gradzki <mgradzki@cisco.com>2018-01-17 08:01:39 +0000
commit8734030b57613cc416fc86c9d75f169938ad0b9f (patch)
treea39b0acfde73f2c49176dabef519a1395bf000dd /infra/it
parent677a81daf4349220de65880fcac26537bcd9cb0c (diff)
Integration test for SubtreeWriter update
Change-Id: Ic8d2cd524ea2d22859df28cb48aa41d5539efbee Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'infra/it')
-rw-r--r--infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/SubtreeWriteTest.java50
1 files changed, 49 insertions, 1 deletions
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
index f46174754..3055429fb 100644
--- 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
@@ -154,9 +154,57 @@ public final class SubtreeWriteTest extends AbstractInfraTest {
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
+ // Then delete for C2 and C3, 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));
}
+
+ @Test
+ public void testUpdate() 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).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 change C2
+ final C2 modifiedC2 = new C2Builder().setLeaf2(22).build();
+ final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> c2NormalizedNode =
+ serializer.toNormalizedNode(Ids.C2_ID, modifiedC2);
+ dataModification = modifiableDataTreeDelegator.newModification();
+ dataModification.write(c2NormalizedNode.getKey(), c2NormalizedNode.getValue());
+ dataModification.commit();
+
+ // Check that in total, there were 2 invocations of processModification
+ // TODO (HONEYCOMB-422)
+ // verify(c1Writer, times(2)).processModification(any(), any(), any(), any());
+ verify(c1Writer, times(3)).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 and create for C2, because c1Writer does not support direct updates
+ final C1 modifiedC1 = new C1Builder().setC2(modifiedC2).setC3(c3).build();
+ // TODO (HONEYCOMB-422)
+ // inOrder.verify(c1Writer).processModification(eq(Ids.C1_ID), eq(c1), eq(modifiedC1), any(WriteContext.class));
+ inOrder.verify(c1Writer, times(2))
+ .processModification(eq(Ids.C1_ID), eq(c1), eq(modifiedC1), any(WriteContext.class));
+ }
} \ No newline at end of file