Added test for bgp mock config module. 10/2810/1
authorMilos Fabian <milfabia@cisco.com>
Thu, 14 Nov 2013 12:48:55 +0000 (13:48 +0100)
committerMilos Fabian <milfabia@cisco.com>
Mon, 18 Nov 2013 09:20:04 +0000 (10:20 +0100)
Change-Id: Ib30f4b956044aaa0eb547a6582e6a94a97f51715
Signed-off-by: Milos Fabian <milfabia@cisco.com>
bgp/update-mock-config/pom.xml
bgp/update-mock-config/src/test/java/org/opendaylight/controller/config/yang/bgp/mock/BgpMockModuleTest.java [new file with mode: 0644]

index 1a76a758cfe01b4217b68bfcd561e4117de0ed5a..a2e78ecd457dabb0d1461886ab477935b03ea6bd 100644 (file)
    </prerequisites>
 
    <dependencies>
+      <dependency>
+         <groupId>junit</groupId>
+         <artifactId>junit</artifactId>
+      </dependency>
       <dependency>
          <groupId>org.opendaylight.controller</groupId>
          <artifactId>config-api</artifactId>
          <artifactId>bgp-rib-mock</artifactId>
          <version>${project.version}</version>
       </dependency>
+
+      <!--test dependencies -->
+      <dependency>
+         <groupId>org.opendaylight.controller</groupId>
+         <artifactId>config-manager</artifactId>
+         <version>${controller.config.version}</version>
+         <scope>test</scope>
+         <type>test-jar</type>
+      </dependency>
+      <dependency>
+         <groupId>org.opendaylight.controller</groupId>
+         <artifactId>config-manager</artifactId>
+         <version>${controller.config.version}</version>
+         <scope>test</scope>
+      </dependency>
+      <dependency>
+         <groupId>org.opendaylight.controller</groupId>
+         <artifactId>config-util</artifactId>
+         <version>${controller.config.version}</version>
+         <scope>test</scope>
+      </dependency>
+      <dependency>
+         <groupId>${project.groupId}</groupId>
+         <artifactId>mockito-configuration</artifactId>
+         <version>${project.version}</version>
+         <scope>test</scope>
+      </dependency>
+      <dependency>
+         <groupId>org.opendaylight.controller</groupId>
+         <artifactId>threadpool-config-impl</artifactId>
+         <version>${controller.config.version}</version>
+         <scope>test</scope>
+      </dependency>
    </dependencies>
 
    <build>
diff --git a/bgp/update-mock-config/src/test/java/org/opendaylight/controller/config/yang/bgp/mock/BgpMockModuleTest.java b/bgp/update-mock-config/src/test/java/org/opendaylight/controller/config/yang/bgp/mock/BgpMockModuleTest.java
new file mode 100644 (file)
index 0000000..ec7886e
--- /dev/null
@@ -0,0 +1,84 @@
+package org.opendaylight.controller.config.yang.bgp.mock;
+
+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;
+import org.opendaylight.controller.config.api.jmx.CommitStatus;
+import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
+import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
+import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
+import org.opendaylight.controller.config.yang.threadpool.impl.EventBusModuleFactory;
+import org.opendaylight.controller.config.yang.threadpool.impl.EventBusModuleMXBean;
+
+
+public class BgpMockModuleTest extends AbstractConfigTest {
+
+       private final String instanceName = "bgp-mock";
+       
+       private BgpMockModuleFactory factory;
+       
+       private EventBusModuleFactory eventBusFactory;
+       
+       @Before
+       public void setUp() throws Exception {
+               this.factory = new BgpMockModuleFactory();
+               this.eventBusFactory = new EventBusModuleFactory();
+               super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(
+                               this.factory, this.eventBusFactory));
+       }
+       
+       @Test
+       public void testValidationExceptionBothAttributesSet()
+                       throws InstanceAlreadyExistsException {
+               try {
+                       ConfigTransactionJMXClient transaction = configRegistryClient
+                                       .createTransaction();
+                       createInstance(transaction, this.factory.getImplementationName(),
+                                       instanceName, new byte[]{1}, "hexMsg", this.eventBusFactory.getImplementationName());
+                       transaction.validateConfig();
+                       fail();
+               } catch (ValidationException e) {
+                       assertTrue(e.getMessage().contains("Both 'HexDump' and 'BinDump' contain value"));
+               }
+       }
+       
+       @Test
+       public void testCreateBean() throws Exception {
+               ConfigTransactionJMXClient transaction = configRegistryClient
+                               .createTransaction();
+               createInstance(transaction, this.factory.getImplementationName(),
+                               instanceName, null, "hexString", this.eventBusFactory.getImplementationName());
+               transaction.validateConfig();
+               CommitStatus status = transaction.commit();
+               assertBeanCount(1, factory.getImplementationName());
+               assertStatus(status, 2, 0, 0);
+       }
+       
+       public static ObjectName createInstance(
+                       final ConfigTransactionJMXClient transaction,
+                       final String moduleName, final String instanceName,
+                       final byte[] binDump, final String hexDump, final String eventBusImplName) throws InstanceAlreadyExistsException {
+               ObjectName nameCreated = transaction.createModule(moduleName,
+                               instanceName);
+               BgpMockModuleMXBean mxBean = transaction.newMBeanProxy(
+                               nameCreated, BgpMockModuleMXBean.class);
+               mxBean.setBinDump(binDump);
+               mxBean.setHexDump(hexDump);
+               mxBean.setEventBus(createEventBus(transaction, eventBusImplName, "event-bus1"));
+               return nameCreated;
+       }
+       
+       public static ObjectName createEventBus(final ConfigTransactionJMXClient transaction,
+                       final String moduleName, final String instanceName) throws InstanceAlreadyExistsException {
+               ObjectName nameCreated = transaction.createModule(moduleName, instanceName);
+               transaction.newMBeanProxy(nameCreated, EventBusModuleMXBean.class);
+               return nameCreated;
+       }
+       
+}