diff options
Diffstat (limited to 'infra/translate-utils/src/test/java/io/fd')
3 files changed, 20 insertions, 9 deletions
diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/impl/write/util/TransactionWriteContextTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/impl/write/util/TransactionWriteContextTest.java index 79155bdd6..182375bfc 100644 --- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/impl/write/util/TransactionWriteContextTest.java +++ b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/impl/write/util/TransactionWriteContextTest.java @@ -60,11 +60,14 @@ public class TransactionWriteContextTest { private MappingContext contextBroker; private TransactionWriteContext transactionWriteContext; + private YangInstanceIdentifier yangId; @Before public void setUp() { initMocks(this); transactionWriteContext = new TransactionWriteContext(serializer, beforeTx, afterTx, contextBroker); + yangId = YangInstanceIdentifier.builder().node(QName.create("n", "d")).build(); + when(serializer.toYangInstanceIdentifier(any(InstanceIdentifier.class))).thenReturn(yangId); } @Test @@ -90,8 +93,6 @@ public class TransactionWriteContextTest { final InstanceIdentifier<DataObjects.DataObject1> instanceId = InstanceIdentifier.create(DataObjects.DataObject1.class); - final YangInstanceIdentifier yangId = YangInstanceIdentifier.builder().node(QName.create("n", "d")).build(); - when(serializer.toYangInstanceIdentifier(any(InstanceIdentifier.class))).thenReturn(yangId); when(serializer.fromNormalizedNode(eq(yangId), any(NormalizedNode.class))).thenReturn(entry); when(entry.getValue()).thenReturn(mock(DataObjects.DataObject1.class)); @@ -105,14 +106,14 @@ public class TransactionWriteContextTest { @Test(expected = IllegalStateException.class) public void testReadBeforeFailed() throws Exception { - when(beforeTx.read(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class))).thenReturn( + when(beforeTx.read(LogicalDatastoreType.CONFIGURATION, yangId)).thenReturn( Futures.immediateFailedCheckedFuture(mock(ReadFailedException.class))); transactionWriteContext.readBefore(mock(InstanceIdentifier.class)); } @Test(expected = IllegalStateException.class) public void testReadAfterFailed() throws Exception { - when(afterTx.read(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class))).thenReturn( + when(afterTx.read(LogicalDatastoreType.CONFIGURATION, yangId)).thenReturn( Futures.immediateFailedCheckedFuture(mock(ReadFailedException.class))); transactionWriteContext.readAfter(mock(InstanceIdentifier.class)); } diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/KeepaliveReaderWrapperTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/KeepaliveReaderWrapperTest.java index ca2872139..738e715b0 100644 --- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/KeepaliveReaderWrapperTest.java +++ b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/KeepaliveReaderWrapperTest.java @@ -18,6 +18,7 @@ package io.fd.honeycomb.translate.util.read; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Matchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -41,6 +42,7 @@ public class KeepaliveReaderWrapperTest { @Mock private ReadContext ctx; + private InstanceIdentifier<DataObject> iid = InstanceIdentifier.create(DataObject.class); @Mock private Reader<DataObject, Builder<DataObject>> delegate; @Mock @@ -53,7 +55,8 @@ public class KeepaliveReaderWrapperTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); exec = Executors.newScheduledThreadPool(1); - when(delegate.read(any(InstanceIdentifier.class), any(ReadContext.class))).thenThrow(TestingException.class); + when(delegate.getManagedDataObjectType()).thenReturn(iid); + when(delegate.read(eq(iid), any(ReadContext.class))).thenThrow(TestingException.class); } @After diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/registry/FlatWriterRegistryBuilderTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/registry/FlatWriterRegistryBuilderTest.java index 48c6e8ea3..7822c8926 100644 --- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/registry/FlatWriterRegistryBuilderTest.java +++ b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/write/registry/FlatWriterRegistryBuilderTest.java @@ -23,7 +23,7 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -74,15 +74,22 @@ public class FlatWriterRegistryBuilderTest { final Writer<? extends DataObject> writer = mockWriter(DataObjects.DataObject3.class); flatWriterRegistryBuilder.add(writer); final WriterRegistry build = flatWriterRegistryBuilder.build(); + final InstanceIdentifier<DataObjects.DataObject3> id = InstanceIdentifier.create(DataObjects.DataObject3.class); final DataObjectUpdate update = mock(DataObjectUpdate.class); + doReturn(id).when(update).getId(); + final DataObjects.DataObject3 before = mock(DataObjects.DataObject3.class); + final DataObjects.DataObject3 after = mock(DataObjects.DataObject3.class); + when(update.getDataBefore()).thenReturn(before); + when(update.getDataAfter()).thenReturn(after); + WriterRegistry.DataObjectUpdates updates = new WriterRegistry.DataObjectUpdates( Multimaps.forMap(Collections.singletonMap(id, update)), Multimaps.forMap(Collections.emptyMap())); - build.update(updates, mock(WriteContext.class)); + final WriteContext ctx = mock(WriteContext.class); + build.update(updates, ctx); - verify(writer) - .update(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), any(WriteContext.class)); + verify(writer).update(id, before, after, ctx); } @Test(expected = IllegalArgumentException.class) |