7735270937d3397f8910afedc0dbf2dcf1a4dda6
[neutron.git] / integration / test-standalone / src / main / java / org / opendaylight / neutron / e2etest / NeutronSecurityGroupTests.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 NeutronSecurityGroupTests {
12     String base;
13
14     public NeutronSecurityGroupTests(String base) {
15         this.base = base;
16     }
17
18     public void securityGroup_collection_get_test() {
19         String url = base + "/security-groups";
20         HttpUtils.test_fetch(url, "Security Group Collection GET failed");
21     }
22
23     public String singleton_sg_create_test() {
24         String url = base + "/security-groups";
25         String content = "{\"security_group\": {\"tenant_id\": "
26                 + "\"1dfe7dffa0624ae882cdbda397d1d276\", \"description\": \"\", "
27                 + "\"id\": \"521e29d6-67b8-4b3c-8633-027d21195333\", "
28                 + "\"security_group_rules\": [{\"remote_group_id\": null, "
29                 + "\"direction\": \"egress\", \"remote_ip_prefix\": null, "
30                 + "\"protocol\": null, \"ethertype\": \"IPv4\", "
31                 + "\"tenant_id\": \"1dfe7dffa0624ae882cdbda397d1d276\", "
32                 + "\"port_range_max\": null, \"port_range_min\": null, "
33                 + "\"id\": \"823faaf7-175d-4f01-a271-0bf56fb1e7e6\", "
34                 + "\"security_group_id\": \"d3329053-bae5-4bf4-a2d1-7330f11ba5db\"}, "
35                 + "{\"remote_group_id\": null, \"direction\": \"egress\", "
36                 + "\"remote_ip_prefix\": null, \"protocol\": null, " + "\"ethertype\": \"IPv6\", \"tenant_id\": "
37                 + "\"1dfe7dffa0624ae882cdbda397d1d276\", \"port_range_max\": null, "
38                 + "\"port_range_min\": null, \"id\": " + "\"d3329053-bae5-4bf4-a2d1-7330f11ba5db\", "
39                 + "\"security_group_id\": \"d3329053-bae5-4bf4-a2d1-7330f11ba5db\"}], "
40                 + "\"name\": \"tempest-secgroup-1272206251\"}}";
41         HttpUtils.test_create(url, content, "Security Group Singleton Post Failed");
42         return content;
43     }
44
45     public void singleton_sg_get_with_one_query_item_test(String createJsonString) {
46         String url = base + "/security-groups";
47         HttpUtils.test_fetch_with_one_query_item(url, createJsonString, "security_groups");
48     }
49
50     public void sg_update_test() {
51         String url = base + "/security-groups/521e29d6-67b8-4b3c-8633-027d21195333";
52         String content = "{\"security_group\": {\"tenant_id\": "
53                 + "\"00f340c7c3b34ab7be1fc690c05a0275\", \"description\": "
54                 + "\"tempest-security-description-897433715\", \"id\": " + "\"521e29d6-67b8-4b3c-8633-027d21195333\", "
55                 + "\"security_group_rules\": [{\"remote_group_id\": null, "
56                 + "\"direction\": \"egress\", \"remote_ip_prefix\": null, "
57                 + "\"protocol\": null, \"ethertype\": \"IPv4\", \"tenant_id\": "
58                 + "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": null, "
59                 + "\"port_range_min\": null, \"id\": "
60                 + "\"808bcefb-9917-4640-be68-14157bf33288\", \"security_group_id\": "
61                 + "\"521e29d6-67b8-4b3c-8633-027d21195333\"}, {\"remote_group_id\": "
62                 + "null, \"direction\": \"egress\", \"remote_ip_prefix\": null, "
63                 + "\"protocol\": null, \"ethertype\": \"IPv6\", \"tenant_id\": "
64                 + "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": null, "
65                 + "\"port_range_min\": null, \"id\": " + "\"c376f7b5-a281-40e0-a703-5c832c03aeb3\", "
66                 + "\"security_group_id\": " + "\"521e29d6-67b8-4b3c-8633-027d21195333\"}], \"name\": "
67                 + "\"tempest-security--1135434738\"}}";
68         HttpUtils.test_modify(url, content, "Security Group Put Failed");
69     }
70
71     public void sg_element_get_test() {
72         String url = base + "/security-groups/521e29d6-67b8-4b3c-8633-027d21195333";
73         HttpUtils.test_fetch(url, true, "Security Group Element Get Failed");
74     }
75
76     public void sg_element_get_with_query_test() {
77         String url = base + "/security-groups/521e29d6-67b8-4b3c-8633-027d21195333"
78                 + "?fields=id&fields=name&fields=description&fields=tenant_id"
79                 + "&fields=limit&fields=marker&fields=page_reverse";
80         HttpUtils.test_fetch(url, true, "Security Group Element Get Failed");
81     }
82
83     public void sg_delete_test() {
84         String url = base + "/security-groups/521e29d6-67b8-4b3c-8633-027d21195333";
85         HttpUtils.test_delete(url, "Security Group Delete Failed");
86     }
87
88     public void sg_element_negative_get_test() {
89         String url = base + "/security-groups/521e29d6-67b8-4b3c-8633-027d21195333";
90         HttpUtils.test_fetch(url, false, "Security Group Element Negative Get Failed");
91     }
92
93     public static void runTests(String base) {
94         NeutronSecurityGroupTests securityGroupTester = new NeutronSecurityGroupTests(base);
95         String createJsonString = securityGroupTester.singleton_sg_create_test();
96         securityGroupTester.singleton_sg_get_with_one_query_item_test(createJsonString);
97         securityGroupTester.sg_update_test();
98         securityGroupTester.sg_element_get_test();
99         securityGroupTester.sg_element_get_with_query_test();
100         securityGroupTester.securityGroup_collection_get_test();
101         securityGroupTester.sg_delete_test();
102         securityGroupTester.sg_element_negative_get_test();
103     }
104 }