diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-05-02 10:41:35 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-05-02 11:31:10 +0000 |
commit | 9faea02da937dc9468f557a00ed5c9dacec7f2e2 (patch) | |
tree | 08d7ee5d4ce09d0d5669cd04eacd7c17f3f6f9c7 /lisp/lisp2vpp/src | |
parent | d8b2e9bf2db11dec21a8ebd27c038c4ab6bd1473 (diff) |
HC2VPP-131 - checking of lisp state before/after according to operation
Change-Id: I190562527c68d022a9b16fc76ad6a011161f4308
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'lisp/lisp2vpp/src')
24 files changed, 103 insertions, 55 deletions
diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/VrfSubtableCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/VrfSubtableCustomizer.java index 80d6cbd83..99923cf73 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/VrfSubtableCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/read/VrfSubtableCustomizer.java @@ -29,7 +29,6 @@ import io.fd.honeycomb.translate.spi.read.Initialized; import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager.DumpCacheManagerBuilder; -import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; import io.fd.vpp.jvpp.core.dto.OneEidTableMapDetails; import io.fd.vpp.jvpp.core.dto.OneEidTableMapDetailsReplyDump; import io.fd.vpp.jvpp.core.future.FutureJVppCore; @@ -57,7 +56,7 @@ public class VrfSubtableCustomizer extends FutureJVppCustomizer super(futureJvpp); dumpManager = new DumpCacheManagerBuilder<OneEidTableMapDetailsReplyDump, SubtableDumpParams>() .withExecutor(createExecutor(futureJvpp)) - .acceptOnly(LispEidTableMapDetailsReplyDump.class) + .acceptOnly(OneEidTableMapDetailsReplyDump.class) .build(); } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckService.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckService.java index ab0ea797c..81256a3c5 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckService.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckService.java @@ -26,9 +26,18 @@ import javax.annotation.Nonnull; public interface LispStateCheckService { /** + * Checks whether lisp is enabled while operating inside {@link WriteContext}. + * Covers cases when removing lisp data + * @throws IllegalStateException if lisp feature is disabled + */ + void checkLispEnabledBefore(@Nonnull final WriteContext ctx); + + /** * Checks whether lisp is enabled while operating inside {@link WriteContext} + * Covers cases when creating/updating lisp data + * @throws IllegalStateException if lisp feature is disabled */ - void checkLispEnabled(@Nonnull final WriteContext ctx); + void checkLispEnabledAfter(@Nonnull final WriteContext ctx); /** * Checks whether lisp is enabled while operating inside {@link ReadContext} diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckServiceImpl.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckServiceImpl.java index a93f08349..65e409d53 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckServiceImpl.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/service/LispStateCheckServiceImpl.java @@ -52,7 +52,15 @@ public final class LispStateCheckServiceImpl implements LispStateCheckService, J .build(); } - public void checkLispEnabled(@Nonnull final WriteContext ctx) { + @Override + public void checkLispEnabledBefore(@Nonnull final WriteContext ctx) { + // no need to dump here, can be read directly from context + checkState(ctx.readBefore(InstanceIdentifier.create(Lisp.class)) + .or(STATIC_LISP_INSTANCE).isEnable(), "Lisp feature not enabled"); + } + + @Override + public void checkLispEnabledAfter(@Nonnull final WriteContext ctx) { // no need to dump here, can be read directly from context checkState(ctx.readAfter(InstanceIdentifier.create(Lisp.class)) .or(STATIC_LISP_INSTANCE).isEnable(), "Lisp feature not enabled"); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizer.java index 90dc0efb6..2674aa489 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizer.java @@ -75,7 +75,11 @@ public class ItrRemoteLocatorSetCustomizer extends CheckedLispCustomizer impleme private void addDelItrRemoteLocatorSet(final boolean add, @Nonnull final ItrRemoteLocatorSet data, @Nonnull final WriteContext context) throws TimeoutException, VppBaseCallException { - lispStateCheckService.checkLispEnabled(context); + if (add) { + lispStateCheckService.checkLispEnabledAfter(context); + } else { + lispStateCheckService.checkLispEnabledBefore(context); + } OneAddDelMapRequestItrRlocs request = new OneAddDelMapRequestItrRlocs(); request.isAdd = booleanToByte(add); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizer.java index 04ca7262e..f8babdfcf 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizer.java @@ -72,7 +72,7 @@ public class LocatorSetCustomizer extends CheckedLispCustomizer public void writeCurrentAttributes(@Nonnull InstanceIdentifier<LocatorSet> id, @Nonnull LocatorSet dataAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); checkState(isNonEmptyLocatorSet(writeContext.readAfter(id).get()), "Creating empty locator-sets is not allowed"); final String locatorSetName = dataAfter.getName(); @@ -99,7 +99,7 @@ public class LocatorSetCustomizer extends CheckedLispCustomizer public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<LocatorSet> id, @Nonnull LocatorSet dataBefore, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledBefore(writeContext); final String locatorSetName = dataBefore.getName(); final Optional<EidTable> eidTableData = writeContext.readAfter(InstanceIdentifier.create(Lisp.class) diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizer.java index ff306e51c..cfa5618f9 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRegisterCustomizer.java @@ -41,6 +41,7 @@ public class MapRegisterCustomizer extends CheckedLispCustomizer public void writeCurrentAttributes(@Nonnull InstanceIdentifier<MapRegister> instanceIdentifier, @Nonnull MapRegister mapRegister, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabledAfter(writeContext); enableDisableMapRegister(mapRegister.isEnabled(), instanceIdentifier, writeContext); } @@ -49,6 +50,7 @@ public class MapRegisterCustomizer extends CheckedLispCustomizer @Nonnull MapRegister mapRegisterBefore, @Nonnull MapRegister mapRegisterAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabledAfter(writeContext); enableDisableMapRegister(mapRegisterAfter.isEnabled(), instanceIdentifier, writeContext); } @@ -56,12 +58,12 @@ public class MapRegisterCustomizer extends CheckedLispCustomizer public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<MapRegister> instanceIdentifier, @Nonnull MapRegister mapRegister, @Nonnull WriteContext writeContext) throws WriteFailedException { + lispStateCheckService.checkLispEnabledBefore(writeContext); enableDisableMapRegister(false, instanceIdentifier, writeContext); } private void enableDisableMapRegister(final boolean enable, @Nonnull final InstanceIdentifier<MapRegister> id, @Nonnull final WriteContext context) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(context); OneMapRegisterEnableDisable request = new OneMapRegisterEnableDisable(); request.isEnabled = booleanToByte(enable); getReplyForWrite(getFutureJVpp().oneMapRegisterEnableDisable(request).toCompletableFuture(), id); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizer.java index 64e66b2d4..1acfec7b6 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapRequestModeCustomizer.java @@ -44,7 +44,7 @@ public class MapRequestModeCustomizer extends CheckedLispCustomizer public void writeCurrentAttributes(@Nonnull InstanceIdentifier<MapRequestMode> instanceIdentifier, @Nonnull MapRequestMode mapRequestMode, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); getReplyForWrite(mapRequestModeRequestFuture(mapRequestMode), instanceIdentifier); } @@ -53,7 +53,7 @@ public class MapRequestModeCustomizer extends CheckedLispCustomizer @Nonnull MapRequestMode mapRequestModeBefore, @Nonnull MapRequestMode mapRequestModeAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); getReplyForUpdate(mapRequestModeRequestFuture(mapRequestModeAfter), instanceIdentifier, mapRequestModeBefore, mapRequestModeAfter); } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizer.java index 934cc218a..b2d08700f 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizer.java @@ -51,7 +51,7 @@ public class MapResolverCustomizer extends CheckedLispCustomizer public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<MapResolver> id, @Nonnull final MapResolver dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); checkNotNull(dataAfter, "Data is null"); checkNotNull(dataAfter.getIpAddress(), "Address is null"); @@ -73,7 +73,7 @@ public class MapResolverCustomizer extends CheckedLispCustomizer public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<MapResolver> id, @Nonnull final MapResolver dataBefore, @Nonnull final WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledBefore(writeContext); checkNotNull(dataBefore, "Data is null"); checkNotNull(dataBefore.getIpAddress(), "Address is null"); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizer.java index 6dc201516..306788a31 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/MapServerCustomizer.java @@ -44,7 +44,7 @@ public class MapServerCustomizer extends CheckedLispCustomizer public void writeCurrentAttributes(@Nonnull InstanceIdentifier<MapServer> instanceIdentifier, @Nonnull MapServer mapServer, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); addDelMapServer(true, instanceIdentifier, mapServer); } @@ -59,7 +59,7 @@ public class MapServerCustomizer extends CheckedLispCustomizer @Override public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<MapServer> instanceIdentifier, @Nonnull MapServer mapServer, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledBefore(writeContext); addDelMapServer(false, instanceIdentifier, mapServer); } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizer.java index 6c985ff0e..9d25c5fd7 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PetrCfgCustomizer.java @@ -44,7 +44,7 @@ public class PetrCfgCustomizer extends CheckedLispCustomizer public void writeCurrentAttributes(@Nonnull InstanceIdentifier<PetrCfg> instanceIdentifier, @Nonnull PetrCfg petrCfg, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); enablePetrCfg(instanceIdentifier, petrCfg); } @@ -53,7 +53,7 @@ public class PetrCfgCustomizer extends CheckedLispCustomizer @Nonnull PetrCfg petrCfgBefore, @Nonnull PetrCfg petrCfgAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); if (petrCfgAfter.getPetrAddress() != null) { enablePetrCfg(instanceIdentifier, petrCfgAfter); } else { @@ -63,7 +63,7 @@ public class PetrCfgCustomizer extends CheckedLispCustomizer @Override public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<PetrCfg> instanceIdentifier, @Nonnull PetrCfg petrCfg, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledBefore(writeContext); disablePetrCfg(instanceIdentifier); } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizer.java index 6944940c1..1597fe4eb 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizer.java @@ -51,7 +51,7 @@ public class PitrCfgCustomizer extends CheckedLispCustomizer @Override public void writeCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfg dataAfter, WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); checkNotNull(dataAfter, "PitrCfg is null"); checkNotNull(dataAfter.getLocatorSet(), "Locator set name is null"); @@ -65,7 +65,7 @@ public class PitrCfgCustomizer extends CheckedLispCustomizer @Override public void updateCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfg dataBefore, PitrCfg dataAfter, WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); checkNotNull(dataAfter, "PitrCfg is null"); checkNotNull(dataAfter.getLocatorSet(), "Locator set name is null"); @@ -79,7 +79,7 @@ public class PitrCfgCustomizer extends CheckedLispCustomizer @Override public void deleteCurrentAttributes(InstanceIdentifier<PitrCfg> id, PitrCfg dataBefore, WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledBefore(writeContext); checkNotNull(dataBefore, "PitrCfg is null"); checkNotNull(dataBefore.getLocatorSet(), "Locator set name is null"); diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizer.java index e984a16d1..ebe00ec03 100644 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/RlocProbeCustomizer.java @@ -41,7 +41,7 @@ public class RlocProbeCustomizer extends CheckedLispCustomizer public void writeCurrentAttributes(@Nonnull InstanceIdentifier<RlocProbe> instanceIdentifier, @Nonnull RlocProbe rlocProbe, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); enableDisableRlocProbe(rlocProbe.isEnabled(), instanceIdentifier); } @@ -50,7 +50,7 @@ public class RlocProbeCustomizer extends CheckedLispCustomizer @Nonnull RlocProbe rlocProbeBefore, @Nonnull RlocProbe rlocProbeAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); enableDisableRlocProbe(rlocProbeAfter.isEnabled(), instanceIdentifier); } @@ -58,7 +58,7 @@ public class RlocProbeCustomizer extends CheckedLispCustomizer public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<RlocProbe> instanceIdentifier, @Nonnull RlocProbe rlocProbe, @Nonnull WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledBefore(writeContext); enableDisableRlocProbe(false, instanceIdentifier); } diff --git a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizer.java b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizer.java index e6fe3db45..0cc939392 100755 --- a/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizer.java +++ b/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizer.java @@ -46,7 +46,7 @@ public class VniTableCustomizer extends CheckedLispCustomizer implements ListWri @Override public void writeCurrentAttributes(InstanceIdentifier<VniTable> id, VniTable dataAfter, WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledAfter(writeContext); checkAtLeastOnChildExists(id, writeContext, false); } @@ -59,7 +59,7 @@ public class VniTableCustomizer extends CheckedLispCustomizer implements ListWri @Override public void deleteCurrentAttributes(InstanceIdentifier<VniTable> id, VniTable dataBefore, WriteContext writeContext) throws WriteFailedException { - lispStateCheckService.checkLispEnabled(writeContext); + lispStateCheckService.checkLispEnabledBefore(writeContext); checkAtLeastOnChildExists(id, writeContext, true); } 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) { |