Skip to content

Commit

Permalink
test coverage for loadbalancersv2, listeners, healthmonitorsv2
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleycutalo committed Jul 26, 2016
1 parent 4c7756c commit a03709d
Show file tree
Hide file tree
Showing 13 changed files with 579 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package org.openstack4j.api.network;

import org.openstack4j.api.AbstractTest;
import org.openstack4j.api.Builders;
import org.openstack4j.model.common.ActionResponse;
import org.openstack4j.model.network.ext.HealthMonitorType;
import org.openstack4j.model.network.ext.HealthMonitorV2;
import org.openstack4j.model.network.ext.HealthMonitorV2Update;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

/**
*
* @author ashleykasim
*
*/
@Test(suiteName="Network/healthMonitorV2", enabled = true)
public class HealthMonitorV2Tests extends AbstractTest {
private static final String HEALTHMONITORSV2_JSON = "/network/healthmonitorsv2.json";
private static final String HEALTHMONITORV2_JSON = "/network/healthmonitorv2.json";
private static final String HEALTHMONITORV2_UPDATE_JSON = "/network/healthmonitorv2_update.json";

public void testListHealthMonitorsV2() throws IOException {
respondWith(HEALTHMONITORSV2_JSON);
List<? extends HealthMonitorV2> list = osv3().networking().lbaasV2().healthMonitorV2().list();
assertEquals(list.size(), 3);
assertEquals("350576d8-5015-4d4e-b73f-23df2397e4c4", list.get(0).getId());
}

public void testListHealthMonitorsV2Filter() throws IOException {
respondWith(HEALTHMONITORSV2_JSON);
Map<String, String> map = new HashMap<>();
map.put("tenant_id", "6f759d84e3ca496ab77f8c0ffaa0311e");
List<? extends HealthMonitorV2> list = osv3().networking().lbaasV2().healthMonitorV2().list(map);
assertEquals(list.size(), 3);
}

public void testGetHealthMonitorV2() throws IOException {
respondWith(HEALTHMONITORV2_JSON);
String id = "350576d8-5015-4d4e-b73f-23df2397e4c4";
HealthMonitorV2 hm = osv3().networking().lbaasV2().healthMonitorV2().get(id);
assertNotNull(hm);
assertEquals(hm.getId(), id);
}

public void testCreateHealthMonitorV2() throws IOException {
respondWith(HEALTHMONITORV2_JSON);
Integer delay = 2;
Integer timeout = 3;
HealthMonitorType type = HealthMonitorType.HTTP;
HealthMonitorV2 create = Builders.healthmonitorV2()
.adminStateUp(true)
.delay(delay)
.type(type)
.timeout(timeout)
.build();
HealthMonitorV2 result = osv3().networking().lbaasV2().healthMonitorV2().create(create);
assertEquals(result.getDelay(), delay);
assertEquals(result.getTimeout(), timeout);
assertEquals(result.getType(), type);
assertTrue(result.isAdminStateUp());
}

public void testUpdateHealthMonitorV2() throws IOException {
respondWith(HEALTHMONITORV2_UPDATE_JSON);
Integer delay = 10;
Integer timeout = 5;
String id = "350576d8-5015-4d4e-b73f-23df2397e4c4";
HealthMonitorV2Update update = Builders.healthMonitorV2Update()
.delay(delay)
.timeout(timeout)
.build();
HealthMonitorV2 result = osv3().networking().lbaasV2().healthMonitorV2().update(id, update);
assertEquals(result.getDelay(), delay);
assertEquals(result.getTimeout(), timeout);
}

public void testDeleteHealthMonitorV2() {
respondWith(204);
ActionResponse result = osv3().networking().lbaasV2().healthMonitorV2().delete("350576d8-5015-4d4e-b73f-23df2397e4c4");
assertTrue(result.isSuccess());
}

@Override
protected Service service() {
return Service.NETWORK;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class LbPoolV2Tests extends AbstractTest {
public void testListPoolV2() throws IOException {
respondWith(LBPOOLSV2_JSON);
List<? extends LbPoolV2> list = osv3().networking().lbaasV2().lbPoolV2().list();
assertEquals(2, list.size());
assertEquals(list.size(), 2);
assertEquals(list.get(0).getId(), "b7f6a49f-ebd8-43c5-b792-5748366eff21");
}

Expand All @@ -42,15 +42,15 @@ public void testListPoolV2Filter() throws IOException {
Map<String, String> map = new HashMap<String, String>();
map.put("protocol", "HTTP");
List<? extends LbPoolV2> list = osv3().networking().lbaasV2().lbPoolV2().list(map);
assertEquals(2, list.size());
assertEquals(list.size(), 2);
}

public void testGetPoolV2() throws IOException {
respondWith(LBPOOLV2_JSON);
String id = "b7f6a49f-ebd8-43c5-b792-5748366eff21";
LbPoolV2 pool = osv3().networking().lbaasV2().lbPoolV2().get(id);
assertNotNull(pool);
assertEquals(id, pool.getId());
assertEquals(pool.getId(), id);
}

public void testCreatePoolV2() throws IOException {
Expand All @@ -66,9 +66,9 @@ public void testCreatePoolV2() throws IOException {
.protocol(protocol)
.build();
LbPoolV2 result = osv3().networking().lbaasV2().lbPoolV2().create(create);
assertEquals(name, result.getName());
assertEquals(result.getName(), name);
assertEquals(result.getLbMethod(), LbMethod.LEAST_CONNECTIONS);
assertEquals(protocol, result.getProtocol());
assertEquals(result.getProtocol(), protocol);
}

public void testUpdatePoolV2() throws IOException {
Expand All @@ -82,8 +82,8 @@ public void testUpdatePoolV2() throws IOException {
.name(name)
.build();
LbPoolV2 result = osv3().networking().lbaasV2().lbPoolV2().update(poolId, update);
assertEquals(name, result.getName());
assertEquals(LbMethod.ROUND_ROBIN, result.getLbMethod());
assertEquals(result.getName(), name);
assertEquals(result.getLbMethod(), LbMethod.ROUND_ROBIN);
assertFalse(result.isAdminStateUp());
}

Expand Down
102 changes: 102 additions & 0 deletions core-test/src/main/java/org/openstack4j/api/network/ListenerTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package org.openstack4j.api.network;


import org.openstack4j.api.AbstractTest;
import org.openstack4j.api.Builders;
import org.openstack4j.model.common.ActionResponse;
import org.openstack4j.model.network.ext.Listener;
import org.openstack4j.model.network.ext.ListenerUpdate;
import org.openstack4j.model.network.ext.Protocol;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;

/**
*
* @author ashleykasim
*
*/
@Test(suiteName="Network/listener", enabled = true)
public class ListenerTests extends AbstractTest {
private static final String LISTENERS_JSON = "/network/listeners.json";
private static final String LISTENER_JSON = "/network/listener.json";
private static final String LISTENER_UPDATE_JSON = "/network/listener_update.json";

public void testListListeners() throws IOException {
respondWith(LISTENERS_JSON);
List<? extends Listener> list = osv3().networking().lbaasV2().listener().list();
assertEquals(list.size(), 2);
assertEquals(list.get(0).getName(), "listener1");
}

public void testListListenersFilter() throws IOException {
respondWith(LISTENERS_JSON);
Map<String, String> map = new HashMap<>();
map.put("tenantId", "6f759d84e3ca496ab77f8c0ffaa0311e");
List<? extends Listener> list = osv3().networking().lbaasV2().listener().list(map);
assertEquals(list.size(), 2);
}

public void testGetListener() throws IOException {
respondWith(LISTENER_JSON);
String id = "c07058a9-8d84-4443-b8f5-508d0facfe10";
Listener listener = osv3().networking().lbaasV2().listener().get(id);
assertNotNull(listener);
assertEquals(listener.getId(), id);
}

public void testCreateListener() throws IOException {
respondWith(LISTENER_JSON);
String name = "listener1";
String description = "";
Protocol protocol = Protocol.HTTP;
Listener create = Builders.listenerV2()
.adminStateUp(true)
.name(name)
.description(description)
.protocol(protocol)
.build();
Listener result = osv3().networking().lbaasV2().listener().create(create);
assertEquals(result.getName(), name);
assertEquals(result.getDescription(), description);
assertEquals(result.getProtocol(), protocol);
assertTrue(result.isAdminStateUp());
}

public void testUpdateListener() throws IOException {
respondWith(LISTENER_UPDATE_JSON);
String name = "listener_updated";
String description = "im a good listener";
Integer connectionLimit = 20;
ListenerUpdate update = Builders.listenerV2Update()
.adminStateUp(false)
.description(description)
.name(name)
.connectionLimit(connectionLimit)
.build();
Listener result = osv3().networking().lbaasV2().listener().update("c07058a9-8d84-4443-b8f5-508d0facfe10", update);
assertFalse(result.isAdminStateUp());
assertEquals(result.getName(), name);
assertEquals(result.getDescription(), description);
assertEquals(result.getConnectionLimit(), connectionLimit);
}

public void testDeleteListener() {
respondWith(204);
ActionResponse result = osv3().networking().lbaasV2().listener().delete("c07058a9-8d84-4443-b8f5-508d0facfe10");
assertTrue(result.isSuccess());
}

@Override
protected Service service() {
return Service.NETWORK;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package org.openstack4j.api.network;


import org.openstack4j.api.AbstractTest;
import org.openstack4j.api.Builders;
import org.openstack4j.model.common.ActionResponse;
import org.openstack4j.model.network.ext.LoadBalancerV2;
import org.openstack4j.model.network.ext.LoadBalancerV2Update;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;

/**
*
* @author ashleykasim
*
*/
@Test(suiteName="Network/loadBalancerV2", enabled = true)
public class LoadBalancerV2Tests extends AbstractTest {
private static final String LOADBALANCERSV2_JSON = "/network/loadbalancersv2.json";
private static final String LOADBALANCERV2_JSON = "/network/loadbalancerv2.json";
private static final String LOADBALANCERV2_UPDATE_JSON = "/network/loadbalancerv2_update.json";

public void testListLoadBalancersV2() throws IOException {
respondWith(LOADBALANCERSV2_JSON);
List<? extends LoadBalancerV2> list = osv3().networking().lbaasV2().loadbalancerV2().list();
assertEquals(list.size(), 3);
assertEquals(list.get(0).getName(), "lb1");
}

public void testListLoadBalancersV2Filter() throws IOException {
respondWith(LOADBALANCERSV2_JSON);
Map<String, String> map = new HashMap<>();
map.put("provider", "octavia");
List<? extends LoadBalancerV2> list = osv3().networking().lbaasV2().loadbalancerV2().list(map);
assertEquals(list.size(), 3);
}

public void testGetLoadBalancerV2() throws IOException {
respondWith(LOADBALANCERV2_JSON);
String id = "282b71ea-9ceb-4cd6-8881-cb511af2edb5";
LoadBalancerV2 lb = osv3().networking().lbaasV2().loadbalancerV2().get(id);
assertNotNull(lb);
assertEquals(lb.getId(), id);
}

public void testCreateLoadBalancerV2() throws IOException {
respondWith(LOADBALANCERV2_JSON);
String name = "lb1";
String description = "im a baby lb";
String address = "10.0.0.13";
String subnetId = "388c5684-86b0-49ab-90ef-944b1f7328f8";
LoadBalancerV2 create = Builders.loadbalancerV2()
.adminStateUp(false)
.name(name)
.description(description)
.address(address)
.subnetId(subnetId)
.build();
LoadBalancerV2 result = osv3().networking().lbaasV2().loadbalancerV2().create(create);
assertEquals(result.getName(), name);
assertEquals(result.getDescription(), description);
assertEquals(result.getVIPAddress(), address);
assertEquals(result.getVIPSubnetId(), subnetId);
assertFalse(result.isAdminStateUp());
}

public void testUpdateLoadBalancerV2() throws IOException {
respondWith(LOADBALANCERV2_UPDATE_JSON);
String name = "lb_updated";
String description = "im no longer a baby lb";
LoadBalancerV2Update update = Builders.loadBalancerV2Update()
.adminStateUp(true)
.description(description)
.name(name)
.build();
LoadBalancerV2 result = osv3().networking().lbaasV2().loadbalancerV2().update("282b71ea-9ceb-4cd6-8881-cb511af2edb5", update);
assertTrue(result.isAdminStateUp());
assertEquals(result.getName(), name);
assertEquals(result.getDescription(), description);
}

public void testDeleteLoadbalancerV2() {
respondWith(204);
ActionResponse result = osv3().networking().lbaasV2().loadbalancerV2().delete("282b71ea-9ceb-4cd6-8881-cb511af2edb5");
assertTrue(result.isSuccess());
}

@Override
protected Service service() {
return Service.NETWORK;
}
}
Loading

0 comments on commit a03709d

Please sign in to comment.