BUG-139: Implement PCEP state synchronization avoidance
[bgpcep.git] / pcep / ietf-stateful07 / src / test / java / org / opendaylight / protocol / pcep / ietf / Stateful07SessionProposalFactoryModuleTest.java
index 974c43f3c3dd247842863614f3d45dd378bd750d..20e3755779464d4157b57f9ccc88df6346fe89b3 100644 (file)
@@ -7,12 +7,11 @@
  */
 package org.opendaylight.protocol.pcep.ietf;
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-
 import javax.management.InstanceAlreadyExistsException;
 import javax.management.ObjectName;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.config.api.ValidationException;
@@ -30,13 +29,13 @@ public class Stateful07SessionProposalFactoryModuleTest extends AbstractConfigTe
 
     @Before
     public void setUp() throws Exception {
-        super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, new Stateful07PCEPSessionProposalFactoryModuleFactory()));
+        super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(this.mockedContext, new Stateful07PCEPSessionProposalFactoryModuleFactory()));
     }
 
     @Test
     public void testValidationExceptionDeadTimerValueNotSet() throws Exception {
         try {
-            createInstance(null, (short) 100, true, true, true);
+            createInstance(null, (short) 100, true, true, true, true, true, true, true);
             fail();
         } catch (final ValidationException e) {
             assertTrue(e.getMessage().contains("DeadTimerValue value is not set"));
@@ -46,7 +45,7 @@ public class Stateful07SessionProposalFactoryModuleTest extends AbstractConfigTe
     @Test
     public void testValidationExceptionKeepAliveTimerNotSet() throws Exception {
         try {
-            createInstance((short) 200, null, true, true, true);
+            createInstance((short) 200, null, true, true, true, true, true, true, true);
             fail();
         } catch (final ValidationException e) {
             assertTrue(e.getMessage().contains("KeepAliveTimerValue value is not set"));
@@ -56,7 +55,7 @@ public class Stateful07SessionProposalFactoryModuleTest extends AbstractConfigTe
     @Test
     public void testValidationExceptionStatefulNotSet() throws Exception {
         try {
-            createInstance((short) 200, (short) 100, null, false, false);
+            createInstance((short) 200, (short) 100, null, false, false, false, false, false, false);
             fail();
         } catch (final ValidationException e) {
             assertTrue(e.getMessage().contains("Stateful value is not set"));
@@ -66,7 +65,7 @@ public class Stateful07SessionProposalFactoryModuleTest extends AbstractConfigTe
     @Test
     public void testValidationExceptionActiveNotSet() throws Exception {
         try {
-            createInstance((short) 200, (short) 100, true, null, true);
+            createInstance((short) 200, (short) 100, true, null, true, true, true, true, true);
             fail();
         } catch (final ValidationException e) {
             assertTrue(e.getMessage().contains("Active value is not set"));
@@ -76,17 +75,57 @@ public class Stateful07SessionProposalFactoryModuleTest extends AbstractConfigTe
     @Test
     public void testValidationExceptionInstantiatedNotSet() throws Exception {
         try {
-            createInstance((short) 200, (short) 100, true, true, null);
+            createInstance((short) 200, (short) 100, true, true, null, true, true, true, true);
             fail();
         } catch (final ValidationException e) {
             assertTrue(e.getMessage().contains("Initiated value is not set"));
         }
     }
 
+    @Test
+    public void testValidationExceptionTriggeredSyncNotSet() throws Exception {
+        try {
+            createInstance((short) 200, (short) 100, true, true, true, null, true, true, true);
+            fail();
+        } catch (final ValidationException e) {
+            assertTrue(e.getMessage().contains("TriggeredInitialSync value is not set"));
+        }
+    }
+
+    @Test
+    public void testValidationExceptionTriggeredResyncNotSet() throws Exception {
+        try {
+            createInstance((short) 200, (short) 100, true, true, true, true, null, true, true);
+            fail();
+        } catch (final ValidationException e) {
+            assertTrue(e.getMessage().contains("TriggeredResync value is not set"));
+        }
+    }
+
+    @Test
+    public void testValidationExceptionDeltaLspSyncNotSet() throws Exception {
+        try {
+            createInstance((short) 200, (short) 100, true, true, true, true, true, null, true);
+            fail();
+        } catch (final ValidationException e) {
+            assertTrue(e.getMessage().contains("DeltaLspSyncCapability value is not set"));
+        }
+    }
+
+    @Test
+    public void testValidationExceptionIncludeDBVersionNotSet() throws Exception {
+        try {
+            createInstance((short) 200, (short) 100, true, true, true, true, true, true, null);
+            fail();
+        } catch (final ValidationException e) {
+            assertTrue(e.getMessage().contains("IncludeDbVersion value is not set"));
+        }
+    }
+
     @Test
     public void testValidationExceptionKeepAliveTimerMinValue() throws Exception {
         try {
-            createInstance((short) 200, (short) -10, true, true, true);
+            createInstance((short) 200, (short) -10, true, true, true, true, true, true, true);
             fail();
         } catch (final ValidationException e) {
             assertTrue(e.getMessage().contains("minimum value is 1."));
@@ -95,13 +134,40 @@ public class Stateful07SessionProposalFactoryModuleTest extends AbstractConfigTe
 
     @Test
     public void testStatefulAfterCommitted() throws Exception {
-        createInstance((short) 200, (short) 100, false, true, true);
+        createInstance((short) 200, (short) 100, false, true, true, true, false, true, true);
         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
         final Stateful07PCEPSessionProposalFactoryModuleMXBean mxBean = transaction.newMXBeanProxy(transaction.lookupConfigBean(
                 FACTORY_NAME, INSTANCE_NAME), Stateful07PCEPSessionProposalFactoryModuleMXBean.class);
         assertTrue(mxBean.getStateful());
     }
 
+    @Test
+    public void testNotStatefulAfterCommitted() throws Exception {
+        createInstance((short) 200, (short) 100, false, false, false, false, false, false, false);
+        final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
+        final Stateful07PCEPSessionProposalFactoryModuleMXBean mxBean = transaction.newMXBeanProxy(transaction.lookupConfigBean(
+                FACTORY_NAME, INSTANCE_NAME), Stateful07PCEPSessionProposalFactoryModuleMXBean.class);
+        assertFalse(mxBean.getStateful());
+    }
+
+    @Test
+    public void testIncludeDbVersionAfterCommitted() throws Exception {
+        createInstance((short) 200, (short) 100, false, false, false, false, false, true, false);
+        final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
+        final Stateful07PCEPSessionProposalFactoryModuleMXBean mxBean = transaction.newMXBeanProxy(transaction.lookupConfigBean(
+                FACTORY_NAME, INSTANCE_NAME), Stateful07PCEPSessionProposalFactoryModuleMXBean.class);
+        assertTrue(mxBean.getIncludeDbVersion());
+    }
+
+    @Test
+    public void testNotIncludeDbVersionAfterCommitted() throws Exception {
+        createInstance((short) 200, (short) 100, false, false, false, false, false, false, false);
+        final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
+        final Stateful07PCEPSessionProposalFactoryModuleMXBean mxBean = transaction.newMXBeanProxy(transaction.lookupConfigBean(
+                FACTORY_NAME, INSTANCE_NAME), Stateful07PCEPSessionProposalFactoryModuleMXBean.class);
+        assertFalse(mxBean.getIncludeDbVersion());
+    }
+
     @Test
     public void testCreateBean() throws Exception {
         final CommitStatus status = createInstance();
@@ -132,9 +198,9 @@ public class Stateful07SessionProposalFactoryModuleTest extends AbstractConfigTe
     }
 
     private CommitStatus createInstance(final Short deadTimer, final Short keepAlive, final Boolean stateful, final Boolean active,
-            final Boolean instant) throws Exception {
+            final Boolean instant, final Boolean triggeredInitialSync, final Boolean triggeredResync, final Boolean deltaLspSyncCapability, final Boolean includeDbVersion) throws Exception {
         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
-        createInstance(transaction, deadTimer, keepAlive, stateful, active, instant);
+        createInstance(transaction, deadTimer, keepAlive, stateful, active, instant, triggeredInitialSync, triggeredResync, deltaLspSyncCapability, includeDbVersion);
         return transaction.commit();
     }
 
@@ -145,11 +211,12 @@ public class Stateful07SessionProposalFactoryModuleTest extends AbstractConfigTe
     }
 
     public static ObjectName createStateful07SessionProposalInstance(final ConfigTransactionJMXClient transaction) throws Exception {
-        return createInstance(transaction, (short) 200, (short) 100, true, true, true);
+        return createInstance(transaction, (short) 200, (short) 100, true, true, true, true, true, true, true);
     }
 
     private static ObjectName createInstance(final ConfigTransactionJMXClient transaction, final Short deadTimer, final Short keepAlive,
-            final Boolean stateful, final Boolean active, final Boolean instant) throws InstanceAlreadyExistsException {
+            final Boolean stateful, final Boolean active, final Boolean instant,
+            final Boolean triggeredInitialSync, final Boolean triggeredResync, final Boolean deltaLspSyncCapability, final Boolean includeDbVersion) throws InstanceAlreadyExistsException {
         final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
         final Stateful07PCEPSessionProposalFactoryModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated,
                 Stateful07PCEPSessionProposalFactoryModuleMXBean.class);
@@ -158,6 +225,10 @@ public class Stateful07SessionProposalFactoryModuleTest extends AbstractConfigTe
         mxBean.setInitiated(instant);
         mxBean.setKeepAliveTimerValue(keepAlive);
         mxBean.setStateful(stateful);
+        mxBean.setTriggeredInitialSync(triggeredInitialSync);
+        mxBean.setTriggeredResync(triggeredResync);
+        mxBean.setDeltaLspSyncCapability(deltaLspSyncCapability);
+        mxBean.setIncludeDbVersion(includeDbVersion);
         return nameCreated;
     }