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 java.io.OutputStreamWriter;
13 import java.lang.Thread;
15 import java.net.HttpURLConnection;
18 import org.junit.Assert;
20 import com.google.gson.Gson;
21 import com.google.gson.JsonArray;
22 import com.google.gson.JsonObject;
24 public class NeutronSecurityRuleTests {
27 public NeutronSecurityRuleTests(String base) {
31 public void securityRule_collection_get_test() {
32 String url = base + "/security-group-rules";
33 ITNeutronE2E.test_fetch(url, "Security Rule Collection GET failed");
36 public String singleton_sr_create_test() {
37 String url = base + "/security-group-rules";
38 String content = " {\"security_group_rule\": " +
39 "{\"remote_group_id\": null, \"direction\": \"ingress\", " +
40 "\"remote_ip_prefix\": null, \"protocol\": \"tcp\", " +
41 "\"ethertype\": \"IPv6\", \"tenant_id\": " +
42 "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " +
43 "\"port_range_min\": 77, " +
44 "\"id\": \"9b4be7fa-e56e-40fb-9516-1f0fa9185669\", " +
45 "\"security_group_id\": " +
46 "\"b60490fe-60a5-40be-af63-1d641381b784\"}}";
47 ITNeutronE2E.test_create(url, content, "Security Rule Singleton Post Failed");
51 public void singleton_sr_get_with_one_query_item_test(String createJsonString) {
52 String url = base + "/security-group-rules";
53 ITNeutronE2E.test_fetch_with_one_query_item(url, createJsonString, "security_group_rules");
56 public void multiple_sr_create_test() {
57 String url = base + "/security-group-rules";
58 String content = " {\"security_group_rules\": [" +
60 " \"id\": \"35fb0f34-c8d3-416d-a205-a2c75f7b8e22\"," +
61 " \"direction\": \"egress\"," +
62 " \"ethertype\": \"IPv6\"," +
63 " \"security_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
64 " \"tenant_id\": \"2640ee2ac2474bf3906e482047204fcb\"" +
67 " \"id\": \"63814eed-bc12-4fe4-8b17-2af178224c71\"," +
68 " \"direction\": \"egress\"," +
69 " \"ethertype\": \"IPv4\"," +
70 " \"security_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
71 " \"tenant_id\": \"2640ee2ac2474bf3906e482047204fcb\"" +
74 " \"id\": \"ccb9823e-559b-4d84-b656-2739f8e56d89\"," +
75 " \"direction\": \"ingress\"," +
76 " \"ethertype\": \"IPv6\"," +
77 " \"remote_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
78 " \"security_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
79 " \"tenant_id\": \"2640ee2ac2474bf3906e482047204fcb\"" +
82 " \"id\": \"fbc3f809-7378-40a4-822f-7a70f6ccba98\"," +
83 " \"direction\": \"ingress\"," +
84 " \"ethertype\": \"IPv4\"," +
85 " \"remote_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
86 " \"security_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
87 " \"tenant_id\": \"2640ee2ac2474bf3906e482047204fcb\"" +
90 ITNeutronE2E.test_create(url, content, "Security Rule Multiple Post Failed");
93 public void singleton_sr_modify_test() {
94 String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
95 String content = " {\"security_group_rule\": " +
96 "{\"remote_group_id\": null, \"direction\": \"egress\", " +
97 "\"remote_ip_prefix\": null, \"protocol\": \"tcp\", " +
98 "\"ethertype\": \"IPv6\", \"tenant_id\": " +
99 "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " +
100 "\"port_range_min\": 77, " +
101 "\"id\": \"9b4be7fa-e56e-40fb-9516-1f0fa9185669\", " +
102 "\"security_group_id\": " +
103 "\"b60490fe-60a5-40be-af63-1d641381b784\"}}";
104 ITNeutronE2E.test_modify(url, content, "Security Rule Singleton Put Failed");
107 public void sr_element_get_test() {
108 String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
109 ITNeutronE2E.test_fetch(url, true, "Security Rule Element Get Failed");
112 public void sr_element_get_with_query_test() {
113 String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669" +
114 "?fields=id&fields=direction&fields=protocol&fields=port_range_min" +
115 "&fields=port_range_max&fields=ethertype&fields=remote_ip_prefix" +
116 "&fields=remote_group_id&fields=security_group_id&fields=tenant_id" +
117 "&fields=limit&fields=marker&fields=page_reverse";
118 ITNeutronE2E.test_fetch(url, true, "Security Rule Element Get With Query Failed");
121 public void sr_delete_test() {
122 String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
123 ITNeutronE2E.test_delete(url, "Security Rule Delete Failed");
126 public void sr_element_negative_get_test() {
127 String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
128 ITNeutronE2E.test_fetch(url, false, "Security Rule Element Negative Get Failed");
131 public void bug5478_rule_delete_negative_test() {
132 String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
133 ITNeutronE2E.test_delete_404(url, "Security Rule Delete 404 Failed");
136 public void bug4043_ipv4_test() {
137 String url = base + "/security-group-rules";
138 String content = " {\"security_group_rule\": " +
139 "{\"remote_group_id\": null, \"direction\": \"ingress\", " +
140 "\"remote_ip_prefix\": \"10.10.10.10/16\", \"protocol\": \"tcp\", " +
141 "\"ethertype\": \"IPv4\", \"tenant_id\": " +
142 "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " +
143 "\"port_range_min\": 77, " +
144 "\"id\": \"01234567-0123-0123-0123-01234567890a\", " +
145 "\"security_group_id\": " +
146 "\"b60490fe-60a5-40be-af63-1d641381b784\"}}";
147 ITNeutronE2E.test_create(url, content, "Security Rule bug4043 IPv4 Failed");
149 url = url + "/01234567-0123-0123-0123-01234567890a";
150 ITNeutronE2E.test_delete(url, "Security Rule Delete Failed");
153 public void bug4043_ipv6_test() {
154 String url = base + "/security-group-rules";
155 String content = " {\"security_group_rule\": " +
156 "{\"remote_group_id\": null, \"direction\": \"ingress\", " +
157 "\"remote_ip_prefix\": \"fe80::1/10\", \"protocol\": \"tcp\", " +
158 "\"ethertype\": \"IPv6\", \"tenant_id\": " +
159 "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " +
160 "\"port_range_min\": 77, " +
161 "\"id\": \"01234567-0123-0123-0123-01234567890a\", " +
162 "\"security_group_id\": " +
163 "\"b60490fe-60a5-40be-af63-1d641381b784\"}}";
164 ITNeutronE2E.test_create(url, content, "Security Rule Bug4043 IPv6 Failed");
166 url = url + "/01234567-0123-0123-0123-01234567890a";
167 ITNeutronE2E.test_delete(url, "Security Rule Delete Failed");
170 public static void runTests(String base) {
171 NeutronSecurityRuleTests securityRule_tester = new NeutronSecurityRuleTests(base);
172 String createJsonString = securityRule_tester.singleton_sr_create_test();
173 securityRule_tester.singleton_sr_get_with_one_query_item_test(createJsonString);
174 securityRule_tester.multiple_sr_create_test();
175 securityRule_tester.singleton_sr_modify_test();
176 securityRule_tester.sr_element_get_test();
177 securityRule_tester.sr_element_get_with_query_test();
178 securityRule_tester.securityRule_collection_get_test();
179 securityRule_tester.sr_delete_test();
180 securityRule_tester.sr_element_negative_get_test();
181 securityRule_tester.bug5478_rule_delete_negative_test();
182 securityRule_tester.bug4043_ipv4_test();
183 securityRule_tester.bug4043_ipv6_test();