diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2016-10-04 16:44:47 +0200 |
---|---|---|
committer | Maros Marsalek <mmarsale@cisco.com> | 2016-10-05 11:52:37 +0000 |
commit | 5d1054b26f144948be321f30204b4b2a7cbbc03e (patch) | |
tree | 2104b21d9a2e728b8275d5d9f2a554c414db8c31 /lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizerTest.java | |
parent | 512143ddd9995d16d9bb055481721fa276ccfa01 (diff) |
HONEYCOMB-138 - Lisp L2 Support
Change-Id: Idff4776a64a88be2e0a45ab1927978e40876ea92
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizerTest.java')
-rw-r--r-- | lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizerTest.java | 97 |
1 files changed, 49 insertions, 48 deletions
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizerTest.java index 126498304..4df89dfa3 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizerTest.java @@ -1,86 +1,87 @@ package io.fd.honeycomb.lisp.translate.write; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; + +import static org.junit.Assert.fail; import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; +import com.google.common.base.Optional; +import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import org.junit.Before; import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtableBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMap; -import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMapReply; - public class VniTableCustomizerTest extends WriterCustomizerTest { - @Captor - private ArgumentCaptor<LispEidTableAddDelMap> requestCaptor; - private VniTableCustomizer customizer; - private InstanceIdentifier<VniTable> emptyId; - - private VniTable emptyData; + private InstanceIdentifier<VniTable> validId; private VniTable validData; @Before public void init() { + initMocks(this); customizer = new VniTableCustomizer(api); - emptyId = InstanceIdentifier.create(VniTable.class); - - emptyData = new VniTableBuilder().build(); - validData = new VniTableBuilder().setTableId(2L).setVirtualNetworkIdentifier(3L).build(); + validId = InstanceIdentifier.create(VniTable.class); + validData = new VniTableBuilder() + .setVrfSubtable(new VrfSubtableBuilder() + .build()).build(); + } - when(api.lispEidTableAddDelMap(any())).thenReturn(future(new LispEidTableAddDelMapReply())); + @Test + public void testWriteSuccessfull() { + whenReadAfterReturnValid(); + try { + customizer.writeCurrentAttributes(validId, validData, writeContext); + } catch (Exception e) { + fail("Test should pass without exception"); + } } - @Test(expected = NullPointerException.class) - public void testWriteCurrentAttributesEmptyData() throws Exception { - customizer.writeCurrentAttributes(emptyId, emptyData, writeContext); + @Test(expected = IllegalStateException.class) + public void testWriteFailed() throws WriteFailedException { + whenReadAfterReturnInvalid(); + customizer.writeCurrentAttributes(validId, validData, writeContext); } + @Test(expected = UnsupportedOperationException.class) + public void testUpdate() throws WriteFailedException { + customizer.updateCurrentAttributes(validId, validData, validData, writeContext); + } @Test - public void testWriteCurrentAttributes() throws Exception { - customizer.writeCurrentAttributes(emptyId, validData, writeContext); - verify(api, times(1)).lispEidTableAddDelMap(requestCaptor.capture()); - verifyRequest(requestCaptor.getValue(), (byte) 1, 2L, 3L); + public void testDeleteSuccessfull() { + whenReadBeforeReturnValid(); + try { + customizer.deleteCurrentAttributes(validId, validData, writeContext); + } catch (Exception e) { + fail("Test should pass without exception"); + } } - - @Test(expected = UnsupportedOperationException.class) - public void testUpdateCurrentAttributes() throws Exception { - customizer.updateCurrentAttributes(emptyId, emptyData, emptyData, writeContext); + @Test(expected = IllegalStateException.class) + public void testDeleteFailed() throws WriteFailedException { + whenReadBeforeReturnInvalid(); + customizer.deleteCurrentAttributes(validId, validData, writeContext); } - @Test(expected = NullPointerException.class) - public void testDeleteCurrentAttributesEmptyData() throws Exception { - customizer.deleteCurrentAttributes(emptyId, emptyData, writeContext); + private void whenReadBeforeReturnValid() { + when(writeContext.readBefore(validId)).thenReturn(Optional.of(validData)); } - @Test - public void testDeleteCurrentAttributes() throws Exception { - customizer.deleteCurrentAttributes(emptyId, validData, writeContext); - verify(api, times(1)).lispEidTableAddDelMap(requestCaptor.capture()); - verifyRequest(requestCaptor.getValue(), (byte) 0, 2L, 3L); + private void whenReadBeforeReturnInvalid() { + when(writeContext.readBefore(validId)).thenReturn(Optional.absent()); } - private static void verifyRequest(final LispEidTableAddDelMap request, final byte isAdd, - final long dpTable, - final long vni) { - assertNotNull(request); - assertEquals(isAdd, request.isAdd); - assertEquals(dpTable, request.dpTable); - assertEquals(vni, request.vni); - + private void whenReadAfterReturnValid() { + when(writeContext.readAfter(validId)).thenReturn(Optional.of(validData)); } + private void whenReadAfterReturnInvalid() { + when(writeContext.readAfter(validId)).thenReturn(Optional.absent()); + } }
\ No newline at end of file |