2 * Copyright (C) 2015 IBM, Inc.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.neutron.e2etest;
11 import static org.ops4j.pax.exam.CoreOptions.maven;
12 import static org.ops4j.pax.exam.CoreOptions.vmOption;
13 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
14 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.debugConfiguration;
15 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
16 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
17 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
18 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
19 import static org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
22 import java.io.OutputStreamWriter;
24 import java.net.HttpURLConnection;
27 import javax.inject.Inject;
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
33 import org.ops4j.pax.exam.Option;
34 import org.ops4j.pax.exam.Configuration;
35 import org.ops4j.pax.exam.junit.PaxExam;
37 import org.osgi.framework.BundleContext;
38 import org.osgi.service.cm.ConfigurationAdmin;
40 @RunWith(PaxExam.class)
41 public class ITNeutronE2E {
44 private BundleContext bundleContext;
47 private ConfigurationAdmin configurationAdmin;
50 public Option[] config() {
52 // Provision and launch a container based on a distribution of Karaf (Apache ServiceMix).
53 // FIXME: need to *NOT* hardcode the version here - it breaks on
55 karafDistributionConfiguration()
58 .groupId("org.opendaylight.neutron")
59 .artifactId("neutron-karaf")
61 .versionAsInProject())
62 .karafVersion("3.0.3")
64 .unpackDirectory(new File("target/pax"))
65 .useDeployFolder(false),
66 // It is really nice if the container sticks around after the test so you can check the contents
67 // of the data directory when things go wrong.
68 vmOption("-javaagent:../jars/org.jacoco.agent.jar=destfile=jacoco-it.exec"),
70 // Don't bother with local console output as it just ends up cluttering the logs
71 configureConsole().ignoreLocalConsole(),
72 // Force the log level to INFO so we have more details during the test. It defaults to WARN.
73 logLevel(LogLevel.INFO),
74 // provision the needed features for this test
75 // features("mvn:org.opendaylight.neutron/features-test/0.5.0-SNAPSHOT/xml/features",
76 // "features-neutron-test"),
77 // Remember that the test executes in another process. If you want to debug it, you need
78 // to tell Pax Exam to launch that process with debugging enabled. Launching the test class itself with
79 // debugging enabled (for example in Eclipse) will not get you the desired results.
80 // debugConfiguration("5000", true),
84 final String base = "http://127.0.0.1:8080/controller/nb/v2/neutron";
88 NeutronNetworkTests.runTests(base);
89 NeutronSubnetTests.runTests(base);
90 NeutronPortTests.runTests(base);
91 NeutronRouterTests.runTests(base);
92 NeutronFloatingIPTests.runTests(base);
93 NeutronSecurityGroupTests.runTests(base);
94 NeutronSecurityRuleTests.runTests(base);
95 NeutronLoadBalancerTests.runTests(base);
96 NeutronLBListenerTests.runTests(base);
97 NeutronLBPoolTests.runTests(base);
98 NeutronLBHealthMonitorTests.runTests(base);
99 // TODO: add LoadBalancerPoolMembers testing
100 NeutronMeteringLabelTests.runTests(base);
101 NeutronMeteringRuleTests.runTests(base);
102 NeutronVPNServicesTests.runTests(base);
103 NeutronIPSECPoliciesTests.runTests(base);
104 NeutronIPSECSiteConnectionTests.runTests(base);
105 NeutronIKEPoliciesTests.runTests(base);
107 // tests related to bugs
108 Neutron_Bug3812_Tests.runTests(base);
109 Tempest_PortsIpV6TestJSON.runTests(base);
110 Neutron_Bug4027_Tests.runTests(base);
113 static HttpURLConnection HttpURLConnectionFactoryGet(URL url) throws Exception {
114 HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
115 httpConn.setRequestMethod("GET");
116 httpConn.setRequestProperty("Content-Type", "application/json");
117 httpConn.setRequestProperty("Authorization", "Basic YWRtaW46YWRtaW4=");
121 static HttpURLConnection HttpURLConnectionFactoryDelete(URL url) throws Exception {
122 HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
123 httpConn.setRequestMethod("DELETE");
124 httpConn.setRequestProperty("Content-Type", "application/json");
125 httpConn.setRequestProperty("Authorization", "Basic YWRtaW46YWRtaW4=");
129 static HttpURLConnection HttpURLConnectionFactoryPost(URL url, String content) throws Exception {
130 HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
131 httpConn.setRequestMethod("POST");
132 httpConn.setRequestProperty("Content-Type", "application/json");
133 httpConn.setRequestProperty("Authorization", "Basic YWRtaW46YWRtaW4=");
134 httpConn.setDoOutput(true);
135 OutputStreamWriter out = new OutputStreamWriter(
136 httpConn.getOutputStream());
142 static HttpURLConnection HttpURLConnectionFactoryPut(URL url, String content) throws Exception {
143 HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
144 httpConn.setRequestMethod("PUT");
145 httpConn.setRequestProperty("Content-Type", "application/json");
146 httpConn.setRequestProperty("Authorization", "Basic YWRtaW46YWRtaW4=");
147 httpConn.setDoOutput(true);
148 OutputStreamWriter out = new OutputStreamWriter(
149 httpConn.getOutputStream());
155 static void test_create(String url_s, String content, String context) {
157 URL url = new URL(url_s);
158 HttpURLConnection httpConn = HttpURLConnectionFactoryPost(url, content);
159 Assert.assertEquals(context, 201, httpConn.getResponseCode());
160 } catch (Exception e) {
161 e.printStackTrace(); // temporary, remove me
162 Assert.assertFalse("E2E Tests Failed", true);
166 static void test_modify(String url_s, String content, String context) {
168 URL url = new URL(url_s);
169 HttpURLConnection httpConn = HttpURLConnectionFactoryPut(url, content);
170 Assert.assertEquals(context, 200, httpConn.getResponseCode());
171 } catch (Exception e) {
172 e.printStackTrace(); // temporary, remove me
173 Assert.assertFalse("E2E Tests Failed", true);
177 static void test_fetch(String url_s, String context) {
179 URL url = new URL(url_s);
180 HttpURLConnection httpConn = HttpURLConnectionFactoryGet(url);
181 Assert.assertEquals(context, 200, httpConn.getResponseCode());
182 } catch (Exception e) {
183 e.printStackTrace(); // temporary, remove me
184 Assert.assertFalse("E2E Tests Failed", true);
188 static void test_fetch(String url_s, boolean positiveTest, String context) {
190 URL url = new URL(url_s);
191 HttpURLConnection httpConn = HttpURLConnectionFactoryGet(url);
193 Assert.assertEquals(context, 200, httpConn.getResponseCode());
195 Assert.assertEquals(context, 404, httpConn.getResponseCode());
197 } catch (Exception e) {
198 e.printStackTrace(); // temporary, remove me
199 Assert.assertFalse("E2E Tests Failed", true);
203 static void test_delete(String url_s, String context) {
205 URL url = new URL(url_s);
206 HttpURLConnection httpConn = HttpURLConnectionFactoryDelete(url);
207 Assert.assertEquals(context, 204, httpConn.getResponseCode());
208 } catch (Exception e) {
209 e.printStackTrace(); // temporary, remove me
210 Assert.assertFalse("E2E Tests Failed", true);