Test code for Bug #2545
[neutron.git] / integration / test / src / test / java / org / opendaylight / neutron / e2etest / NeutronLoadBalancerTests.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 import java.io.OutputStreamWriter;
12
13 import java.lang.Thread;
14
15 import java.net.HttpURLConnection;
16 import java.net.URL;
17
18 import org.junit.Assert;
19
20 public class NeutronLoadBalancerTests {
21     String base;
22
23     public NeutronLoadBalancerTests(String base) {
24         this.base = base;
25     }
26
27     public void loadBalancer_collection_get_test() {
28         String url_s = base + "/lbaas/loadbalancers";
29         try {
30             URL url = new URL(url_s);
31             HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
32             httpConn.setRequestMethod("GET");
33             httpConn.setRequestProperty("Content-Type", "application/json");
34             httpConn.setRequestProperty("Authorization", "Basic YWRtaW46YWRtaW4=");
35             Assert.assertEquals("Load Balancer Collection GET failed",
36                         200, httpConn.getResponseCode());
37         } catch (Exception e) {
38             Assert.assertFalse("E2E Tests Failed", true);
39         }
40     }
41
42     //TODO handle SB check
43     public void singleton_loadbalancer_create_test() {
44         String url_s = base + "/lbaas/loadbalancers";
45         String content = "{ \"loadbalancer\": { " +
46             "\"admin_state_up\": true, " +
47             "\"description\": \"simple lb\", " +
48             "\"id\": \"a36c20d0-18e9-42ce-88fd-82a35977ee8c\", " +
49             "\"listeners\": [], " +
50             "\"name\": \"loadbalancer1\", " +
51             "\"operating_status\": \"ONLINE\", " +
52             "\"provisioning_status\": \"ACTIVE\", " +
53             "\"tenant_id\": \"b7c1a69e88bf4b21a8148f787aef2081\", " +
54             "\"vip_address\": \"10.0.0.4\", " +
55             "\"vip_subnet_id\": \"013d3059-87a4-45a5-91e9-d721068ae0b2\" } }";
56
57         try {
58             URL url = new URL(url_s);
59             HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
60             httpConn.setRequestMethod("POST");
61             httpConn.setRequestProperty("Content-Type", "application/json");
62             httpConn.setRequestProperty("Authorization", "Basic YWRtaW46YWRtaW4=");
63             httpConn.setDoOutput(true);
64             OutputStreamWriter out = new OutputStreamWriter(
65                 httpConn.getOutputStream());
66             out.write(content);
67             out.close();
68             Assert.assertEquals("Singleton Load Balancer Post Failed NB",
69                 201, httpConn.getResponseCode());
70         } catch (Exception e) {
71             Assert.assertFalse("E2E Tests Failed", true);
72         }
73     }
74 }