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