BUG-6857: Protocol config loader tests 14/47514/9
authorClaudio D. Gasparini <cgaspari@cisco.com>
Tue, 25 Oct 2016 11:28:51 +0000 (13:28 +0200)
committerClaudio D. Gasparini <cgaspari@cisco.com>
Fri, 28 Oct 2016 10:18:47 +0000 (10:18 +0000)
Protocol config loader tests

Change-Id: I0dfb4db04b23cab700ee7dd41a59734bfd4ce690
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
bgp/config-loader-impl/pom.xml
bgp/config-loader-impl/src/test/java/org/opendaylight/protocol/bgp/config/loader/impl/AbstractConfigLoader.java
bgp/controller-config/pom.xml
bgp/rib-impl/pom.xml
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ProtocolsConfigFileProcessorTest.java [new file with mode: 0644]
bgp/topology-provider/pom.xml

index 67e4b5e9c79c6eb89ecbfb410d17c07ae02708db..9b6243a9e2c52dad6f0e3f3ebb51988a52b9d81e 100644 (file)
         </dependency>
     </dependencies>
 
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
     <scm>
         <connection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</connection>
         <developerConnection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</developerConnection>
index c192fc5a32c7f810bdfc036fdfe529dc7de67636..d1803f213884ca6ca401b5aee4b89c82f0a1f23e 100644 (file)
@@ -65,10 +65,7 @@ public abstract class AbstractConfigLoader {
         final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
         registerModules(moduleInfoBackedContext);
         this.mappingService.onGlobalContextUpdated(moduleInfoBackedContext.tryToCreateSchemaContext().get());
-        doAnswer(invocation -> {
-           // clearEvent();
-            return true;
-        }).when(this.watchKey).reset();
+        doAnswer(invocation -> true).when(this.watchKey).reset();
         doReturn(this.eventList).when(this.watchKey).pollEvents();
         doReturn(this.watchKey).when(this.watchService).take();
         doReturn("watchKey").when(this.watchKey).toString();
index e05e64d631fb1c05bb4a9358c44154dd1829b5c1..33833772f1a4bc7acd47ca5098d5258169443ddd 100644 (file)
 
     <build>
         <plugins>
+            <plugin>
+                <artifactId>maven-remote-resources-plugin</artifactId>
+                <version>1.5</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>bundle</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <includes>
+                        <include>**/network-topology-config.xml</include>
+                        <include>**/protocols-config.xml</include>
+                    </includes>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>build-helper-maven-plugin</artifactId>
index 890558a55ef5f98a079be659a4265545aa80ccd2..d9579fd0b86b8d9dae88010e1fbc651a0e658840 100644 (file)
             <type>test-jar</type>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>bgp-config-loader-impl</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>bgp-config-loader-impl</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-core</artifactId>
             <type>test-jar</type>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>bgp-controller-config</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>config-manager</artifactId>
                     </properties-->
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-remote-resources-plugin</artifactId>
+                <version>1.5</version>
+                <configuration>
+                    <attachToMain>false</attachToMain>
+                    <resourceBundles>
+                        <resourceBundle>${project.groupId}:bgp-controller-config:${project.version}</resourceBundle>
+                    </resourceBundles>
+                </configuration>
+                <executions>
+                    <execution>
+                        <phase>process-test-sources</phase>
+                        <goals>
+                            <goal>process</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
     </build>
 
diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ProtocolsConfigFileProcessorTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ProtocolsConfigFileProcessorTest.java
new file mode 100644 (file)
index 0000000..affd2c3
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.rib.impl;
+
+import static junit.framework.TestCase.assertNotNull;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.protocol.bgp.config.loader.impl.AbstractConfigLoader;
+import org.opendaylight.protocol.bgp.rib.impl.spi.BgpDeployer;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.NetworkInstances;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstance;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstanceKey;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.Protocols;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Protocol1;
+import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+
+public class ProtocolsConfigFileProcessorTest extends AbstractConfigLoader {
+    private static final InstanceIdentifier<NetworkInstance> NETWORK_INSTANCE_IID = InstanceIdentifier.create(NetworkInstances.class)
+        .child(NetworkInstance.class, new NetworkInstanceKey("GLOBAL"));
+    @Mock
+    private BgpDeployer bgpDeployer;
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        doReturn(NETWORK_INSTANCE_IID).when(this.bgpDeployer).getInstanceIdentifier();
+        doNothing().when(this.bgpDeployer).onGlobalModified(any(), any(), any());
+        doNothing().when(this.bgpDeployer).onNeighborModified(any(), any(), any());
+    }
+
+    @Override
+    protected String getResourceFolder() {
+        return ClassLoader.getSystemClassLoader().getResource("initial").getPath();
+    }
+
+    @Override
+    protected void registerModules(final ModuleInfoBackedContext moduleInfoBackedContext) throws Exception {
+        moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(NetworkInstances.class));
+        moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(Protocols.class));
+        moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(Protocol.class));
+        moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(Protocol1.class));
+    }
+
+    @Override
+    protected List<String> getYangModelsPaths() {
+        final List<String> paths = Lists.newArrayList(
+            "/META-INF/yang/openconfig-extensions.yang",
+            "/META-INF/yang/bgp-openconfig-extensions.yang",
+            "/META-INF/yang/ietf-interfaces.yang",
+            "/META-INF/yang/openconfig-network-instance-types.yang",
+            "/META-INF/yang/openconfig-interfaces.yang",
+            "/META-INF/yang/openconfig-network-instance.yang",
+            "/META-INF/yang/openconfig-routing-policy.yang",
+            "/META-INF/yang/openconfig-policy-types.yang",
+            "/META-INF/yang/openconfig-routing-policy.yang",
+            "/META-INF/yang/openconfig-local-routing.yang",
+            "/META-INF/yang/openconfig-bgp-operational.yang",
+            "/META-INF/yang/openconfig-bgp-types.yang",
+            "/META-INF/yang/openconfig-types.yang",
+            "/META-INF/yang/openconfig-bgp-multiprotocol.yang",
+            "/META-INF/yang/openconfig-bgp.yang",
+            "/META-INF/yang/bgp-rib.yang",
+            "/META-INF/yang/ietf-inet-types@2013-07-15.yang",
+            "/META-INF/yang/bgp-message.yang",
+            "/META-INF/yang/bgp-multiprotocol.yang",
+            "/META-INF/yang/bgp-types.yang",
+            "/META-INF/yang/network-concepts.yang",
+            "/META-INF/yang/ieee754.yang",
+            "/META-INF/yang/ietf-yang-types@2013-07-15.yang",
+            "/META-INF/yang/yang-ext.yang"
+        );
+        return paths;
+    }
+
+    @Test
+    public void configFileTest() throws Exception {
+        assertNotNull(ClassLoader.getSystemClassLoader().getResource("initial/protocols-config.xml"));
+        verify(this.bgpDeployer, never()).onGlobalModified(any(), any(), any());
+        verify(this.bgpDeployer, never()).onNeighborModified(any(), any(), any());
+
+        final ProtocolsConfigFileProcessor processor = new ProtocolsConfigFileProcessor(this.configLoader, this.bgpDeployer);
+        assertEquals(SchemaPath.create(true, NetworkInstances.QNAME, NetworkInstance.QNAME, Protocols.QNAME), processor.getSchemaPath());
+
+        verify(this.bgpDeployer).onGlobalModified(any(), any(), any());
+        verify(this.bgpDeployer, times(2)).onNeighborModified(any(), any(), any());
+        processor.close();
+    }
+}
\ No newline at end of file
index 4d3b3e4dfd1d8392529d0bfa9fb304281d88379f..66cbf062b1eb29ea22092ae9473038799c227f70 100644 (file)
         </dependency>
 
         <!-- Test dependencies -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>bgp-config-loader-impl</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>config-manager</artifactId>