Introduce E2E testing 56/18356/16
authorRyan Moats <rmoats@us.ibm.com>
Wed, 15 Apr 2015 15:10:50 +0000 (10:10 -0500)
committerRyan Moats <rmoats@us.ibm.com>
Mon, 1 Jun 2015 16:25:08 +0000 (11:25 -0500)
Individual tests go into separate classes

Change-Id: I29486cade054a61d6017aa5e529f7e9cf3b0e6fa
Signed-off-by: Ryan Moats <rmoats@us.ibm.com>
integration/test/pom.xml [new file with mode: 0644]
integration/test/src/main/features/features.xml [new file with mode: 0644]
integration/test/src/test/java/org/opendaylight/neutron/e2etest/NeutronE2ETest.java [new file with mode: 0644]
integration/test/src/test/java/org/opendaylight/neutron/e2etest/NeutronNetworkTests.java [new file with mode: 0644]
pom.xml

diff --git a/integration/test/pom.xml b/integration/test/pom.xml
new file mode 100644 (file)
index 0000000..29b294a
--- /dev/null
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.opendaylight.odlparent</groupId>
+    <artifactId>features-parent</artifactId>
+    <version>1.6.0-SNAPSHOT</version>
+    <relativePath/>
+  </parent>
+
+  <groupId>org.opendaylight.neutron</groupId>
+  <artifactId>integration-test</artifactId>
+  <version>0.6.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.opendaylight.neutron</groupId>
+      <artifactId>features-neutron</artifactId>
+      <version>${project.version}</version>
+      <classifier>features</classifier>
+      <type>xml</type>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>dummyprovider</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+  </dependencies>
+  <scm>
+    <connection>scm:git:ssh://git.opendaylight.org:29418/neutron.git</connection>
+    <developerConnection>scm:git:ssh://git.opendaylight.org:29418/neutron.git</developerConnection>
+    <tag>HEAD</tag>
+    <url>https://wiki.opendaylight.org/view/NeutronNorthBound:Main</url>
+  </scm>
+</project>
diff --git a/integration/test/src/main/features/features.xml b/integration/test/src/main/features/features.xml
new file mode 100644 (file)
index 0000000..7cbee23
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<features name="odl-neutron-test-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.2.0"
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0">
+   <repository>mvn:org.opendaylight.neutron/features-neutron/${project.version}/xml/features</repository>
+   <feature name='odl-neutron-dummyprovider-test' version='${project.version}' description="OpenDaylight :: Neutron :: Dummy Provider Test">
+    <feature version='${project.version}'>odl-neutron-service</feature>
+    <bundle>mvn:org.opendaylight.neutron/dummyprovider/${project.version}</bundle>
+  </feature>
+</features>
diff --git a/integration/test/src/test/java/org/opendaylight/neutron/e2etest/NeutronE2ETest.java b/integration/test/src/test/java/org/opendaylight/neutron/e2etest/NeutronE2ETest.java
new file mode 100644 (file)
index 0000000..35c8526
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2015 IBM, Inc.
+ *
+ * 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.neutron.e2etest;
+
+import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.debugConfiguration;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
+import static org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
+
+import java.io.File;
+import java.io.OutputStreamWriter;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import javax.inject.Inject;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+@RunWith(PaxExam.class)
+public class NeutronE2ETest {
+
+    @Inject
+    private BundleContext bundleContext;
+
+    @Inject
+    private ConfigurationAdmin configurationAdmin;
+
+    @Configuration
+    public Option[] config() {
+        return new Option[] {
+            // Provision and launch a container based on a distribution of Karaf (Apache ServiceMix).
+            // FIXME: need to *NOT* hardcode the version here - it breaks on
+            // version bumps
+            karafDistributionConfiguration()
+                .frameworkUrl(
+                    maven()
+                        .groupId("org.opendaylight.neutron")
+                        .artifactId("neutron-karaf")
+                        .type("zip")
+                        .version("0.6.0-SNAPSHOT"))
+                .karafVersion("3.0.3")
+                .name("Neutron")
+                .unpackDirectory(new File("target/pax"))
+                .useDeployFolder(false),
+       // It is really nice if the container sticks around after the test so you can check the contents
+       // of the data directory when things go wrong.
+            keepRuntimeFolder(),
+       // Don't bother with local console output as it just ends up cluttering the logs
+            configureConsole().ignoreLocalConsole(),
+       // Force the log level to INFO so we have more details during the test.  It defaults to WARN.
+            logLevel(LogLevel.INFO),
+       // provision the needed features for this test
+       //    features("mvn:org.opendaylight.neutron/features-test/0.5.0-SNAPSHOT/xml/features",
+       //        "features-neutron-test"),
+       // Remember that the test executes in another process.  If you want to debug it, you need
+       // to tell Pax Exam to launch that process with debugging enabled.  Launching the test class itself with
+       // debugging enabled (for example in Eclipse) will not get you the desired results.
+       //   debugConfiguration("5000", true),
+       };
+    }
+
+    final String base = "http://127.0.0.1:8080/controller/nb/v2/neutron";
+
+    @Test
+    public void test() {
+        NeutronNetworkTests network_tester = new NeutronNetworkTests(base);
+        network_tester.network_collection_get_test();
+        network_tester.singleton_network_create_test();
+    }
+}
diff --git a/integration/test/src/test/java/org/opendaylight/neutron/e2etest/NeutronNetworkTests.java b/integration/test/src/test/java/org/opendaylight/neutron/e2etest/NeutronNetworkTests.java
new file mode 100644 (file)
index 0000000..2aad4b3
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2015 IBM, Inc.
+ *
+ * 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.neutron.e2etest;
+
+import java.io.OutputStreamWriter;
+
+import java.lang.Thread;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.junit.Assert;
+
+public class NeutronNetworkTests {
+    String base;
+
+    public NeutronNetworkTests(String base) {
+        this.base = base;
+    }
+
+    public void network_collection_get_test() {
+        String url_s = base + "/networks";
+        try {
+            int i = 0;
+            while (i < 60) {
+                URL url = new URL(url_s);
+                HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
+                httpConn.setRequestMethod("GET");
+                httpConn.setRequestProperty("Content-Type", "application/json");
+                httpConn.setRequestProperty("Authorization", "Basic YWRtaW46YWRtaW4=");
+                if (httpConn.getResponseCode() != 200) {
+                    System.out.println("trial "+Integer.toString(i)+": failed with: " +
+                                       Integer.toString(httpConn.getResponseCode()));
+                    Thread.sleep(1000);
+                    i+=1;
+                } else {
+                    Assert.assertEquals("Network Collection GET failed",
+                        200, httpConn.getResponseCode());
+                    return;
+                }
+            }
+            Assert.assertFalse("Network Collection GET failed", true);
+        } catch (Exception e) {
+            Assert.assertFalse("E2E Tests Failed", true);
+        }
+    }
+
+    //TODO handle SB check
+    public void singleton_network_create_test() {
+        String url_s = base + "/networks";
+        String content = "{ \"network\": {" +
+            " \"status\": \"ACTIVE\", \"subnets\": [], " +
+            " \"name\": \"net1\", \"admin_state_up\": true, " +
+            " \"tenant_id\": \"9bacb3c5d39d41a79512987f338cf177\", " +
+            " \"router:external\": false, \"segments\": [ " +
+            " { \"provider:segmentation_id\": 2, " +
+            " \"provider:physical_network\": \"8bab8453-1bc9-45af-8c70-f83aa9b50453\", " +
+            " \"provider:network_type\": \"vlan\" }, { " +
+            " \"provider:segmentation_id\": null, " +
+            " \"provider:physical_network\": \"8bab8453-1bc9-45af-8c70-f83aa9b50453\", " +
+            " \"provider:network_type\": \"stt\" } ], " +
+            " \"shared\": false, \"id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\" " +
+            " } } ";
+
+        try {
+            URL url = new URL(url_s);
+            HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
+            httpConn.setRequestMethod("POST");
+            httpConn.setRequestProperty("Content-Type", "application/json");
+            httpConn.setRequestProperty("Authorization", "Basic YWRtaW46YWRtaW4=");
+            httpConn.setDoOutput(true);
+            OutputStreamWriter out = new OutputStreamWriter(
+                httpConn.getOutputStream());
+            out.write(content);
+            out.close();
+            Assert.assertEquals("Singleton Network Post Failed NB",
+                201, httpConn.getResponseCode());
+        } catch (Exception e) {
+            Assert.assertFalse("E2E Tests Failed", true);
+        }
+    }
+}
diff --git a/pom.xml b/pom.xml
index 2778bcab437f8bc3a158655a7f758a871d1b362d..c41e9530e3efd2db8a8d183479a8af5e02a3b920 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -94,6 +94,7 @@
     <module>features/production</module>
     <module>features/test</module>
     <module>karaf</module>
+    <module>integration/test</module>
     <module>model</module>
   </modules>
   <scm>