From 9faea02da937dc9468f557a00ed5c9dacec7f2e2 Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Tue, 2 May 2017 10:41:35 +0200 Subject: HC2VPP-131 - checking of lisp state before/after according to operation Change-Id: I190562527c68d022a9b16fc76ad6a011161f4308 Signed-off-by: Jan Srnicek --- .../service/LispStateCheckServiceImplTest.java | 33 ++++++++++++++++++---- .../translate/write/LispWriterCustomizerTest.java | 9 ++++-- .../translate/write/LocatorSetCustomizerTest.java | 4 +-- .../translate/write/MapRegisterCustomizerTest.java | 6 ++-- .../write/MapRequestModeCustomizerTest.java | 4 +-- .../translate/write/MapResolverCustomizerTest.java | 4 +-- .../translate/write/MapServerCustomizerTest.java | 4 +-- .../translate/write/PetrCfgCustomizerTest.java | 6 ++-- .../translate/write/PitrCfgCustomizerTest.java | 6 ++-- .../translate/write/RlocProbeCustomizerTest.java | 6 ++-- .../translate/write/VniTableCustomizerTest.java | 4 +-- 11 files changed, 56 insertions(+), 30 deletions(-) (limited to 'lisp/lisp2vpp/src/test/java') diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckServiceImplTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckServiceImplTest.java index 4aa9335bc..78a897e71 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckServiceImplTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckServiceImplTest.java @@ -57,24 +57,45 @@ public class LispStateCheckServiceImplTest implements FutureProducer { } @Test(expected = IllegalStateException.class) - public void testCheckLispEnabledNoConfig() throws Exception { + public void testCheckLispEnabledBeforeNoConfig() throws Exception { + when(writeContext.readBefore(InstanceIdentifier.create(Lisp.class))).thenReturn(Optional.absent()); + impl.checkLispEnabledBefore(writeContext); + } + + @Test(expected = IllegalStateException.class) + public void testCheckLispEnabledBeforeDisabledConfig() throws Exception { + when(writeContext.readBefore(InstanceIdentifier.create(Lisp.class))) + .thenReturn(Optional.of(new LispBuilder().setEnable(false).build())); + impl.checkLispEnabledBefore(writeContext); + } + + @Test + public void testCheckLispEnabledBeforeEnabledConfig() throws Exception { + // no exception should be thrown here + when(writeContext.readBefore(InstanceIdentifier.create(Lisp.class))) + .thenReturn(Optional.of(new LispBuilder().setEnable(true).build())); + impl.checkLispEnabledBefore(writeContext); + } + + @Test(expected = IllegalStateException.class) + public void testCheckLispEnabledAfterNoConfig() throws Exception { when(writeContext.readAfter(InstanceIdentifier.create(Lisp.class))).thenReturn(Optional.absent()); - impl.checkLispEnabled(writeContext); + impl.checkLispEnabledAfter(writeContext); } @Test(expected = IllegalStateException.class) - public void testCheckLispEnabledDisabledConfig() throws Exception { + public void testCheckLispEnabledAfterDisabledConfig() throws Exception { when(writeContext.readAfter(InstanceIdentifier.create(Lisp.class))) .thenReturn(Optional.of(new LispBuilder().setEnable(false).build())); - impl.checkLispEnabled(writeContext); + impl.checkLispEnabledAfter(writeContext); } @Test - public void testCheckLispEnabledEnabledConfig() throws Exception { + public void testCheckLispEnabledAfterEnabledConfig() throws Exception { // no exception should be thrown here when(writeContext.readAfter(InstanceIdentifier.create(Lisp.class))) .thenReturn(Optional.of(new LispBuilder().setEnable(true).build())); - impl.checkLispEnabled(writeContext); + impl.checkLispEnabledAfter(writeContext); } @Test diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LispWriterCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LispWriterCustomizerTest.java index a2d772159..51ef1255b 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LispWriterCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LispWriterCustomizerTest.java @@ -29,9 +29,14 @@ public abstract class LispWriterCustomizerTest extends WriterCustomizerTest{ @Mock protected LispStateCheckService lispStateCheckService; - protected void mockLispDisabled(){ + protected void mockLispDisabledAfter(){ doThrow(IllegalArgumentException.class) - .when(lispStateCheckService).checkLispEnabled(any(WriteContext.class)); + .when(lispStateCheckService).checkLispEnabledAfter(any(WriteContext.class)); + } + + protected void mockLispDisabledBefore(){ + doThrow(IllegalArgumentException.class) + .when(lispStateCheckService).checkLispEnabledBefore(any(WriteContext.class)); } diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizerTest.java index 00c9f3eff..ba4163fde 100755 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizerTest.java @@ -203,7 +203,7 @@ public class LocatorSetCustomizerTest extends LispWriterCustomizerTest { @Test public void testWriteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledAfter(); try { customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { @@ -215,7 +215,7 @@ public class LocatorSetCustomizerTest extends LispWriterCustomizerTest { @Test public void testDeleteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledBefore(); try { customizer.deleteCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizerTest.java index f4f3d2fb6..f8a95ca84 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizerTest.java @@ -90,7 +90,7 @@ public class MapRegisterCustomizerTest extends LispWriterCustomizerTest implemen @Test public void testWriteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledAfter(); try { customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { @@ -102,7 +102,7 @@ public class MapRegisterCustomizerTest extends LispWriterCustomizerTest implemen @Test public void testUpdateLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledAfter(); try { customizer.updateCurrentAttributes(EMPTY_ID, EMPTY_DATA,EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { @@ -114,7 +114,7 @@ public class MapRegisterCustomizerTest extends LispWriterCustomizerTest implemen @Test public void testDeleteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledBefore(); try { customizer.deleteCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizerTest.java index c43960e20..7a48e84a4 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizerTest.java @@ -79,7 +79,7 @@ public class MapRequestModeCustomizerTest extends LispWriterCustomizerTest { @Test public void testWriteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledAfter(); try { customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { @@ -91,7 +91,7 @@ public class MapRequestModeCustomizerTest extends LispWriterCustomizerTest { @Test public void testUpdateLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledAfter(); try { customizer.updateCurrentAttributes(EMPTY_ID, EMPTY_DATA,EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizerTest.java index bc7703b20..a18fa0ef6 100755 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizerTest.java @@ -106,7 +106,7 @@ public class MapResolverCustomizerTest extends LispWriterCustomizerTest implemen @Test public void testWriteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledAfter(); try { customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { @@ -118,7 +118,7 @@ public class MapResolverCustomizerTest extends LispWriterCustomizerTest implemen @Test public void testDeleteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledBefore(); try { customizer.deleteCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizerTest.java index 14ff2c58c..fb4561c38 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizerTest.java @@ -91,7 +91,7 @@ public class MapServerCustomizerTest extends LispWriterCustomizerTest implements @Test public void testWriteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledAfter(); try { customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { @@ -103,7 +103,7 @@ public class MapServerCustomizerTest extends LispWriterCustomizerTest implements @Test public void testDeleteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledBefore(); try { customizer.deleteCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizerTest.java index f46d79547..329aeb35d 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizerTest.java @@ -86,7 +86,7 @@ public class PetrCfgCustomizerTest extends LispWriterCustomizerTest { @Test public void testWriteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledAfter(); try { customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { @@ -98,7 +98,7 @@ public class PetrCfgCustomizerTest extends LispWriterCustomizerTest { @Test public void testUpdateLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledAfter(); try { customizer.updateCurrentAttributes(EMPTY_ID, EMPTY_DATA,EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { @@ -110,7 +110,7 @@ public class PetrCfgCustomizerTest extends LispWriterCustomizerTest { @Test public void testDeleteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledBefore(); try { customizer.deleteCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizerTest.java index 520b5ee72..9c301fb42 100755 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizerTest.java @@ -120,7 +120,7 @@ public class PitrCfgCustomizerTest extends LispWriterCustomizerTest { @Test public void testWriteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledAfter(); try { customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { @@ -132,7 +132,7 @@ public class PitrCfgCustomizerTest extends LispWriterCustomizerTest { @Test public void testUpdateLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledAfter(); try { customizer.updateCurrentAttributes(EMPTY_ID, EMPTY_DATA,EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { @@ -144,7 +144,7 @@ public class PitrCfgCustomizerTest extends LispWriterCustomizerTest { @Test public void testDeleteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledBefore(); try { customizer.deleteCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizerTest.java index 6ae8277e4..5917ddded 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizerTest.java @@ -82,7 +82,7 @@ public class RlocProbeCustomizerTest extends LispWriterCustomizerTest implements @Test public void testWriteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledAfter(); try { customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { @@ -94,7 +94,7 @@ public class RlocProbeCustomizerTest extends LispWriterCustomizerTest implements @Test public void testUpdateLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledAfter(); try { customizer.updateCurrentAttributes(EMPTY_ID, EMPTY_DATA,EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { @@ -106,7 +106,7 @@ public class RlocProbeCustomizerTest extends LispWriterCustomizerTest implements @Test public void testDeleteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledBefore(); try { customizer.deleteCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizerTest.java index 1bf4b772f..04a50bc6c 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizerTest.java @@ -89,7 +89,7 @@ public class VniTableCustomizerTest extends LispWriterCustomizerTest { @Test public void testWriteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledAfter(); try { customizer.writeCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { @@ -101,7 +101,7 @@ public class VniTableCustomizerTest extends LispWriterCustomizerTest { @Test public void testDeleteLispDisabled() throws WriteFailedException { - mockLispDisabled(); + mockLispDisabledBefore(); try { customizer.deleteCurrentAttributes(EMPTY_ID, EMPTY_DATA, writeContext); } catch (IllegalArgumentException e) { -- cgit 1.2.3-korg