Skip to content

Commit 7b934ed

Browse files
committed
Issue #290, re-enable and fix some LBaaS tests
1 parent 867e7f8 commit 7b934ed

File tree

9 files changed

+107
-30
lines changed

9 files changed

+107
-30
lines changed

connectors/okhttp/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<packaging>jar</packaging>
1212

1313
<properties>
14-
<okhttp.version>2.2.0</okhttp.version>
14+
<okhttp.version>2.3.0</okhttp.version>
1515
</properties>
1616

1717
<dependencies>

connectors/okhttp/src/main/java/org/openstack4j/connectors/okhttp/HttpResponseImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ public String getStatusMessage() {
8989
* @return the input stream
9090
*/
9191
public InputStream getInputStream() {
92-
return response.body().byteStream();
92+
try {
93+
return response.body().byteStream();
94+
} catch (IOException e) {
95+
e.printStackTrace();
96+
}
97+
return null;
9398
}
9499

95100
/**

connectors/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<dependency>
3737
<groupId>com.squareup.okhttp</groupId>
3838
<artifactId>mockwebserver</artifactId>
39-
<version>2.1.0</version>
39+
<version>2.3.0</version>
4040
<scope>test</scope>
4141
</dependency>
4242
<dependency>

core-test/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<dependency>
2222
<groupId>com.squareup.okhttp</groupId>
2323
<artifactId>mockwebserver</artifactId>
24-
<version>2.2.0</version>
24+
<version>2.3.0</version>
2525
<scope>provided</scope>
2626
</dependency>
2727
<dependency>

core-test/src/main/java/org/openstack4j/api/AbstractTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.fasterxml.jackson.databind.DeserializationFeature;
2020
import com.fasterxml.jackson.databind.ObjectMapper;
2121
import com.fasterxml.jackson.databind.SerializationFeature;
22+
import com.google.common.io.ByteStreams;
2223
import com.squareup.okhttp.mockwebserver.MockResponse;
2324
import com.squareup.okhttp.mockwebserver.MockWebServer;
2425

@@ -65,7 +66,7 @@ protected void startServer() throws UnknownHostException {
6566
Logger.getLogger(getClass().getName()).info("Tests using connector: " + HttpExecutor.create().getExecutorName() + " on " + getHost());
6667
try {
6768
Logger.getLogger(getClass().getName()).info("Starting server on port "+service().port);
68-
server.play(service().port);
69+
server.start(service().port);
6970
}
7071
catch (IOException e) {
7172
e.printStackTrace();
@@ -84,7 +85,7 @@ protected void startServer() throws UnknownHostException {
8485
protected void respondWith(String resource) throws IOException {
8586
MockResponse r = new MockResponse();
8687
InputStream is = getClass().getResourceAsStream(resource);
87-
r.setBody(is, is.available());
88+
r.setBody(new String(ByteStreams.toByteArray(is)));
8889
r.setHeader("Content-Type", "application/json");
8990
server.enqueue(r);
9091
}
@@ -146,6 +147,7 @@ protected OSClient os() {
146147

147148
try {
148149
String json = new String(Streams.readAll(getClass().getResourceAsStream(JSON_ACCESS)));
150+
Logger.getLogger(getClass().getName()).info(getClass().getName());
149151
// Logger.getLogger(getClass().getName()).info(getClass().getName() + ", JSON Access = " + json);
150152
json = json.replaceAll("127.0.0.1", getHost());
151153
// Logger.getLogger(getClass().getName()).info("JSON Access = " + json);

core-test/src/main/java/org/openstack4j/api/network/LbPoolTests.java

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import static org.testng.Assert.assertEquals;
44
import static org.testng.Assert.assertFalse;
5+
import static org.testng.Assert.assertNotNull;
56
import static org.testng.Assert.assertTrue;
67

8+
import java.io.IOException;
79
import java.util.HashMap;
810
import java.util.List;
911
import java.util.Map;
@@ -17,38 +19,42 @@
1719
import org.openstack4j.model.network.ext.LbPoolUpdate;
1820
import org.openstack4j.openstack.networking.domain.ext.LbMethod;
1921
import org.openstack4j.openstack.networking.domain.ext.Protocol;
22+
import org.testng.Assert;
2023
import org.testng.annotations.Test;
2124

22-
/**
23-
*
24-
* @author liujunpeng
25-
*
26-
*/
27-
@Test(suiteName="Network/lbpool", enabled=false)
28-
public class LbPoolTests extends AbstractTest{
29-
public void testListPool() {
25+
@Test(suiteName="Network/lbpool", enabled=true)
26+
public class LbPoolTests extends AbstractTest {
27+
28+
private static final String LBPOOLS_JSON = "/network/lbpools.json";
29+
private static final String LBPOOL_JSON = "/network/lbpool.json";
30+
private static final String LBPOOL_UPDATE_JSON = "/network/lbpool_update.json";
31+
32+
public void testListPool() throws IOException {
33+
respondWith(LBPOOLS_JSON);
3034
List<? extends LbPool> list = os().networking().loadbalancers().lbPool().list();
31-
System.out.println("test lb pool List" + list);
3235
assertEquals(1, list.size());
36+
assertEquals(list.get(0).getSubnetId(), "8032909d-47a1-4715-90af-5153ffe39861");
3337
}
3438

35-
public void testListPoolFilter() {
39+
public void testListPoolFilter() throws IOException {
40+
respondWith(LBPOOLS_JSON);
3641
Map<String, String> map = new HashMap<String, String>();
3742
map.put("name", "pool");
3843
List<? extends LbPool> list = os().networking().loadbalancers().lbPool().list(map);
39-
System.out.println("test lb pool List filter" + list);
4044
assertEquals(1, list.size());
4145
}
4246

43-
public void testGetPool() {
44-
String id = "f6f1a5bb-2c5d-4c41-941c-024eb39414a6";
47+
public void testGetPool() throws IOException {
48+
respondWith(LBPOOL_JSON);
49+
String id = "4c0a0a5f-cf8f-44b7-b912-957daa8ce5e5";
4550
LbPool pool = os().networking().loadbalancers().lbPool().get(id);
46-
System.out.println("test get a pool" + pool);
51+
assertNotNull(pool);
4752
assertEquals(id, pool.getId());
4853
}
4954

50-
public void testCreatePool() {
51-
String name = "create";
55+
public void testCreatePool() throws IOException {
56+
respondWith(LBPOOL_JSON);
57+
String name = "pool1";
5258
String protocol = Protocol.HTTP.toString();
5359
LbPool create = Builders.lbPool().adminStateUp(true)
5460
.description("pool").lbMethod(LbMethod.ROUND_ROBIN.toString())
@@ -58,11 +64,11 @@ public void testCreatePool() {
5864
.protocol(protocol).build();
5965
LbPool result = os().networking().loadbalancers().lbPool().create(create);
6066
assertEquals(name, result.getName());
61-
assertEquals(LbMethod.ROUND_ROBIN.toString(), result.getLbMethod());
67+
assertEquals(result.getLbMethod(), LbMethod.ROUND_ROBIN.toString());
6268
assertEquals(protocol, result.getProtocol());
6369
}
64-
65-
public void testUpdatePool() {
70+
public void testUpdatePool() throws IOException {
71+
respondWith(LBPOOL_UPDATE_JSON);
6672
String poolId = "db083bf7-c455-4758-b1ad-203cf441a73a";
6773
String name = "update";
6874
LbPoolUpdate update = Builders.lbPoolUpdate().adminStateUp(false)
@@ -76,28 +82,30 @@ public void testUpdatePool() {
7682
assertFalse(result.isAdminStateUp());
7783
}
7884

85+
@Test(enabled=false)
7986
public void testAssociateHealthMonitor() {
8087
String poolId = "db083bf7-c455-4758-b1ad-203cf441a73a";
8188
String healthId = "8767284a-b542-4db6-8393-0a404a959c1d";
8289
HealthMonitorAssociate associate = Builders.lbPoolAssociateHealthMonitor().id(healthId).build();
8390
HealthMonitor result = os().networking().loadbalancers().lbPool().associateHealthMonitor(poolId, associate);
8491
assertTrue(result != null);
8592
}
86-
93+
94+
@Test(enabled=false)
8795
public void testDisAssociateHealthMonitor() {
8896
String poolId = "db083bf7-c455-4758-b1ad-203cf441a73a";
8997
String healthId = "8767284a-b542-4db6-8393-0a404a959c1d";
9098
ActionResponse result = os().networking().loadbalancers().lbPool()
9199
.disAssociateHealthMonitor(poolId, healthId);
92100
assertTrue(result.isSuccess());
93101
}
94-
102+
95103
public void testDeletePool() {
96-
String id = "02ae87ec-5502-469e-8c41-f2c57d185054";
97-
ActionResponse result = os().networking().loadbalancers().lbPool().delete(id);
98-
System.out.println("delete a pool" + result);
104+
respondWith(200);
105+
ActionResponse result = os().networking().loadbalancers().lbPool().delete("02ae87ec-5502-469e-8c41-f2c57d185054");
99106
assertTrue(result.isSuccess());
100107
}
108+
101109
@Override
102110
protected Service service() {
103111
return Service.NETWORK;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"pool": {
3+
"admin_state_up": true,
4+
"description": "simple pool",
5+
"healthmonitor_id": null,
6+
"id": "4c0a0a5f-cf8f-44b7-b912-957daa8ce5e5",
7+
"lb_method": "ROUND_ROBIN",
8+
"listeners": [
9+
{
10+
"id": "35cb8516-1173-4035-8dae-0dae3453f37f"
11+
}
12+
],
13+
"members": [],
14+
"name": "pool1",
15+
"protocol": "HTTP",
16+
"subnet_id":"7d1dab60-cf8a-4f75-af5c-44aab98b0c42",
17+
"tenant_id":"d7fd03242ffa4933863bc528ed884fb6"
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"pool": {
3+
"admin_state_up": false,
4+
"description": "update",
5+
"healthmonitor_id": null,
6+
"id": "4c0a0a5f-cf8f-44b7-b912-957daa8ce5e5",
7+
"lb_method": "LEAST_CONNECTIONS",
8+
"listeners": [
9+
{
10+
"id": "35cb8516-1173-4035-8dae-0dae3453f37f"
11+
}
12+
],
13+
"members": [],
14+
"name": "update",
15+
"protocol": "HTTP",
16+
"subnet_id":"7d1dab60-cf8a-4f75-af5c-44aab98b0c42",
17+
"tenant_id":"d7fd03242ffa4933863bc528ed884fb6"
18+
}
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"pools":[
3+
{
4+
"status":"ACTIVE",
5+
"lb_method":"ROUND_ROBIN",
6+
"protocol":"HTTP",
7+
"description":"",
8+
"health_monitors":[
9+
"466c8345-28d8-4f84-a246-e04380b0461d",
10+
"5d4b5228-33b0-4e60-b225-9b727c1a20e7"
11+
],
12+
"subnet_id":"8032909d-47a1-4715-90af-5153ffe39861",
13+
"tenant_id":"83657cfcdfe44cd5920adaf26c48ceea",
14+
"admin_state_up":true,
15+
"name":"app_pool",
16+
"members":[
17+
"701b531b-111a-4f21-ad85-4795b7b12af6",
18+
"beb53b4d-230b-4abd-8118-575b8fa006ef"
19+
],
20+
"id":"72741b06-df4d-4715-b142-276b6bce75ab",
21+
"vip_id":"4ec89087-d057-4e2c-911f-60a3b47ee304"
22+
}
23+
]
24+
}

0 commit comments

Comments
 (0)