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