Add more tests to improve code coverage
[neutron.git] / integration / test / src / test / java / org / opendaylight / neutron / e2etest / NeutronSecurityRuleTests.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 java.io.OutputStreamWriter;
12
13 import java.lang.Thread;
14
15 import java.net.HttpURLConnection;
16 import java.net.URL;
17
18 import org.junit.Assert;
19
20 public class NeutronSecurityRuleTests {
21     String base;
22
23     public NeutronSecurityRuleTests(String base) {
24         this.base = base;
25     }
26
27     public void securityRule_collection_get_test() {
28         String url = base + "/security-group-rules";
29         ITNeutronE2E.test_fetch(url, "Security Rule Collection GET failed");
30     }
31
32     public void singleton_sr_create_test() {
33         String url = base + "/security-group-rules";
34         String content = " {\"security_group_rule\": " +
35             "{\"remote_group_id\": null, \"direction\": \"ingress\", " +
36             "\"remote_ip_prefix\": null, \"protocol\": \"tcp\", " +
37             "\"ethertype\": \"IPv6\", \"tenant_id\": " +
38             "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " +
39             "\"port_range_min\": 77, " +
40             "\"id\": \"9b4be7fa-e56e-40fb-9516-1f0fa9185669\", " +
41             "\"security_group_id\": " +
42             "\"b60490fe-60a5-40be-af63-1d641381b784\"}}";
43         ITNeutronE2E.test_create(url, content, "Security Rule Singleton Post Failed");
44     }
45
46     public void multiple_sr_create_test() {
47         String url = base + "/security-group-rules";
48         String content = " {\"security_group_rules\": [" +
49                 "{" +
50                 "  \"id\": \"35fb0f34-c8d3-416d-a205-a2c75f7b8e22\"," +
51                 "  \"direction\": \"egress\"," +
52                 "  \"ethertype\": \"IPv6\"," +
53                 "  \"security_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
54                 "  \"tenant_id\": \"2640ee2ac2474bf3906e482047204fcb\"" +
55                 "}," +
56                 "{" +
57                 "  \"id\": \"63814eed-bc12-4fe4-8b17-2af178224c71\"," +
58                 "  \"direction\": \"egress\"," +
59                 "  \"ethertype\": \"IPv4\"," +
60                 "  \"security_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
61                 "  \"tenant_id\": \"2640ee2ac2474bf3906e482047204fcb\"" +
62                 "}," +
63                 "{" +
64                 "  \"id\": \"ccb9823e-559b-4d84-b656-2739f8e56d89\"," +
65                 "  \"direction\": \"ingress\"," +
66                 "  \"ethertype\": \"IPv6\"," +
67                 "  \"remote_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
68                 "  \"security_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
69                 "  \"tenant_id\": \"2640ee2ac2474bf3906e482047204fcb\"" +
70                 "}," +
71                 "{" +
72                 "  \"id\": \"fbc3f809-7378-40a4-822f-7a70f6ccba98\"," +
73                 "  \"direction\": \"ingress\"," +
74                 "  \"ethertype\": \"IPv4\"," +
75                 "  \"remote_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
76                 "  \"security_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
77                 "  \"tenant_id\": \"2640ee2ac2474bf3906e482047204fcb\"" +
78                 "}" +
79                 "]}";
80         ITNeutronE2E.test_create(url, content, "Security Rule Multiple Post Failed");
81     }
82
83     public void singleton_sr_modify_test() {
84         String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
85         String content = " {\"security_group_rule\": " +
86             "{\"remote_group_id\": null, \"direction\": \"egress\", " +
87             "\"remote_ip_prefix\": null, \"protocol\": \"tcp\", " +
88             "\"ethertype\": \"IPv6\", \"tenant_id\": " +
89             "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " +
90             "\"port_range_min\": 77, " +
91             "\"id\": \"9b4be7fa-e56e-40fb-9516-1f0fa9185669\", " +
92             "\"security_group_id\": " +
93             "\"b60490fe-60a5-40be-af63-1d641381b784\"}}";
94         ITNeutronE2E.test_modify(url, content, "Security Rule Singleton Put Failed");
95     }
96
97     public void sr_element_get_test() {
98         String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
99         ITNeutronE2E.test_fetch(url, true, "Security Rule Element Get Failed");
100     }
101
102     public void sr_element_get_with_query_test() {
103         String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669" +
104             "?fields=id&fields=direction&fields=protocol&fields=port_range_min" +
105             "&fields=port_range_max&fields=ethertype&fields=remote_ip_prefix" +
106             "&fields=remote_group_id&fields=security_group_id&fields=tenant_id" +
107             "&fields=limit&fields=marker&fields=page_reverse";
108         ITNeutronE2E.test_fetch(url, true, "Security Rule Element Get With Query Failed");
109     }
110
111     public void sr_delete_test() {
112         String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
113         ITNeutronE2E.test_delete(url, "Security Rule Delete Failed");
114     }
115
116     public void sr_element_negative_get_test() {
117         String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
118         ITNeutronE2E.test_fetch(url, false, "Security Rule Element Negative Get Failed");
119     }
120
121     public void bug4043_ipv4_test() {
122         String url = base + "/security-group-rules";
123         String content = " {\"security_group_rule\": " +
124             "{\"remote_group_id\": null, \"direction\": \"ingress\", " +
125             "\"remote_ip_prefix\": \"10.10.10.10/16\", \"protocol\": \"tcp\", " +
126             "\"ethertype\": \"IPv4\", \"tenant_id\": " +
127             "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " +
128             "\"port_range_min\": 77, " +
129             "\"id\": \"01234567-0123-0123-0123-01234567890a\", " +
130             "\"security_group_id\": " +
131             "\"b60490fe-60a5-40be-af63-1d641381b784\"}}";
132         ITNeutronE2E.test_create(url, content, "Security Rule bug4043 IPv4 Failed");
133
134         url = url + "/01234567-0123-0123-0123-01234567890a";
135         ITNeutronE2E.test_delete(url, "Security Rule Delete Failed");
136     }
137
138     public void bug4043_ipv6_test() {
139         String url = base + "/security-group-rules";
140         String content = " {\"security_group_rule\": " +
141             "{\"remote_group_id\": null, \"direction\": \"ingress\", " +
142             "\"remote_ip_prefix\": \"fe80::1/10\", \"protocol\": \"tcp\", " +
143             "\"ethertype\": \"IPv6\", \"tenant_id\": " +
144             "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " +
145             "\"port_range_min\": 77, " +
146             "\"id\": \"01234567-0123-0123-0123-01234567890a\", " +
147             "\"security_group_id\": " +
148             "\"b60490fe-60a5-40be-af63-1d641381b784\"}}";
149         ITNeutronE2E.test_create(url, content, "Security Rule Bug4043 IPv6 Failed");
150
151         url = url + "/01234567-0123-0123-0123-01234567890a";
152         ITNeutronE2E.test_delete(url, "Security Rule Delete Failed");
153     }
154
155     public static void runTests(String base) {
156         NeutronSecurityRuleTests securityRule_tester = new NeutronSecurityRuleTests(base);
157         securityRule_tester.singleton_sr_create_test();
158         securityRule_tester.multiple_sr_create_test();
159         securityRule_tester.singleton_sr_modify_test();
160         securityRule_tester.sr_element_get_test();
161         securityRule_tester.sr_element_get_with_query_test();
162         securityRule_tester.securityRule_collection_get_test();
163         securityRule_tester.sr_delete_test();
164         securityRule_tester.sr_element_negative_get_test();
165         securityRule_tester.bug4043_ipv4_test();
166         securityRule_tester.bug4043_ipv6_test();
167     }
168 }