diff options
-rw-r--r-- | infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/SubtreeWriteTest.java | 50 |
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 |