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