Add IT case for Bug 4027
[neutron.git] / integration / test / src / test / java / org / opendaylight / neutron / e2etest / ITNeutronE2E.java
1 /*
2  * Copyright (C) 2015 IBM, Inc.
3  *
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
7  */
8
9 package org.opendaylight.neutron.e2etest;
10
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;
20
21 import java.io.File;
22 import java.io.OutputStreamWriter;
23
24 import java.net.HttpURLConnection;
25 import java.net.URL;
26
27 import javax.inject.Inject;
28
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32
33 import org.ops4j.pax.exam.Option;
34 import org.ops4j.pax.exam.Configuration;
35 import org.ops4j.pax.exam.junit.PaxExam;
36
37 import org.osgi.framework.BundleContext;
38 import org.osgi.service.cm.ConfigurationAdmin;
39
40 @RunWith(PaxExam.class)
41 public class ITNeutronE2E {
42
43     @Inject
44     private BundleContext bundleContext;
45
46     @Inject
47     private ConfigurationAdmin configurationAdmin;
48
49     @Configuration
50     public Option[] config() {
51         return new Option[] {
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
54             // version bumps
55             karafDistributionConfiguration()
56                 .frameworkUrl(
57                     maven()
58                         .groupId("org.opendaylight.neutron")
59                         .artifactId("neutron-karaf")
60                         .type("zip")
61                         .versionAsInProject())
62                 .karafVersion("3.0.3")
63                 .name("Neutron")
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"),
69             keepRuntimeFolder(),
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),
81        };
82     }
83
84     final String base = "http://127.0.0.1:8080/controller/nb/v2/neutron";
85
86     @Test
87     public void test() {
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);
106
107     // tests related to bugs
108         Neutron_Bug3812_Tests.runTests(base);
109         Tempest_PortsIpV6TestJSON.runTests(base);
110         Neutron_Bug4027_Tests.runTests(base);
111     }
112
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=");
118         return(httpConn);
119     }
120
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=");
126         return(httpConn);
127     }
128
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());
137         out.write(content);
138         out.close();
139         return(httpConn);
140     }
141
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());
150         out.write(content);
151         out.close();
152         return(httpConn);
153     }
154
155     static void test_create(String url_s, String content, String context) {
156         try {
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);
163         }
164     }
165
166     static void test_modify(String url_s, String content, String context) {
167         try {
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);
174         }
175     }
176
177     static void test_fetch(String url_s, String context) {
178         try {
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);
185         }
186     }
187
188     static void test_fetch(String url_s, boolean positiveTest, String context) {
189         try {
190             URL url = new URL(url_s);
191             HttpURLConnection httpConn = HttpURLConnectionFactoryGet(url);
192             if (positiveTest) {
193                 Assert.assertEquals(context, 200, httpConn.getResponseCode());
194             } else {
195                 Assert.assertEquals(context, 404, httpConn.getResponseCode());
196             }
197         } catch (Exception e) {
198             e.printStackTrace(); // temporary, remove me
199             Assert.assertFalse("E2E Tests Failed", true);
200         }
201     }
202
203     static void test_delete(String url_s, String context) {
204         try {
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);
211         }
212     }
213 }