adding more tests for security group async client including for security group rules, and fixing a bug found in the delete methods

This commit is contained in:
Mike Arnold 2012-03-15 11:04:49 -05:00
parent 40395d1723
commit 39180e0cc9
4 changed files with 146 additions and 2 deletions

View File

@ -103,7 +103,6 @@ public interface SecurityGroupAsyncClient {
@Path("/os-security-groups/{id}")
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes
@Produces(MediaType.APPLICATION_JSON)
ListenableFuture<Boolean> deleteSecurityGroup(@PathParam("id") String id);
@ -135,7 +134,6 @@ public interface SecurityGroupAsyncClient {
@Path("/os-security-group-rules/{security_group_rule_ID}")
@ExceptionParser(ReturnFalseOnNotFoundOr404.class)
@Consumes
@Produces(MediaType.APPLICATION_JSON)
ListenableFuture<Boolean> deleteSecurityGroupRule(@PathParam("security_group_rule_ID") String security_group_rule_ID);
}

View File

@ -22,9 +22,13 @@ import static org.testng.Assert.assertEquals;
import java.net.URI;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.nova.v1_1.NovaClient;
import org.jclouds.openstack.nova.v1_1.domain.SecurityGroup;
import org.jclouds.openstack.nova.v1_1.domain.SecurityGroupRule;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseSecurityGroupListTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseSecurityGroupTest;
@ -137,4 +141,125 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
assertNull(clientWhenNoSecurityGroupsExist.getSecurityGroupClientForRegion("North").getSecurityGroup("0"));
}
public void testCreateSecurityGroupWhenResponseIs2xx() throws Exception {
HttpRequest createSecurityGroup = HttpRequest
.builder()
.method("POST")
.endpoint(
URI.create("https://compute.north.host/v1.1/3456/os-security-groups"))
.headers(
ImmutableMultimap.<String, String> builder()
.put("Accept", "application/json")
.put("X-Auth-Token", authToken).build())
.payload(payloadFromStringWithContentType("{\"security_group\":{\"name\":\"name\",\"description\":\"description\"}}",
"application/json")).build();
HttpResponse createSecurityGroupResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/securitygroup_created.json")).build();
NovaClient clientWhenSecurityGroupsExist = requestsSendResponses(
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
createSecurityGroup, createSecurityGroupResponse);
assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North")
.createSecurityGroup("name", "description").toString(),
createSecurityGroupExpected().toString());
}
public void testDeleteSecurityGroupWhenResponseIs2xx() throws Exception {
HttpRequest deleteSecurityGroup = HttpRequest
.builder()
.method("DELETE")
.endpoint(
URI.create("https://compute.north.host/v1.1/3456/os-security-groups/160"))
.headers(
ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*")
.put("X-Auth-Token", authToken).build()).build();
HttpResponse deleteSecurityGroupResponse = HttpResponse.builder().statusCode(202).build();
NovaClient clientWhenServersExist = requestsSendResponses(
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
deleteSecurityGroup, deleteSecurityGroupResponse);
assertTrue(clientWhenServersExist.getSecurityGroupClientForRegion("North").deleteSecurityGroup("160"));
}
public void testCreateSecurityGroupRuleWhenResponseIs2xx() throws Exception {
HttpRequest createSecurityGroupRule = HttpRequest
.builder()
.method("POST")
.endpoint(
URI.create("https://compute.north.host/v1.1/3456/os-security-group-rules"))
.headers(
ImmutableMultimap.<String, String>builder()
.put("Accept", "application/json")
.put("X-Auth-Token", authToken).build())
.payload(payloadFromStringWithContentType("{\"security_group_rule\":{\"ip_protocol\":\"tcp\",\"from_port\":\"80\",\"to_port\":\"8080\",\"cidr\":\"0.0.0.0/0\",\"group_id\":\"\",\"parent_group_id\":\"161\"}}",
"application/json")).build();
HttpResponse createSecurityGroupRuleResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/securitygrouprule_created.json")).build();
NovaClient clientWhenSecurityGroupsExist = requestsSendResponses(
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
createSecurityGroupRule, createSecurityGroupRuleResponse);
assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North")
.createSecurityGroupRule("tcp", "80", "8080", "0.0.0.0/0", "", "161").toString(),
createSecurityGroupRuleExpected().toString());
}
public void testDeleteSecurityGroupRuleWhenResponseIs2xx() throws Exception {
HttpRequest deleteSecurityGroupRule = HttpRequest
.builder()
.method("DELETE")
.endpoint(
URI.create("https://compute.north.host/v1.1/3456/os-security-group-rules/161"))
.headers(
ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*")
.put("X-Auth-Token", authToken).build()).build();
HttpResponse deleteSecurityGroupRuleResponse = HttpResponse.builder().statusCode(202).build();
NovaClient clientWhenSecurityGroupsExist = requestsSendResponses(
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
deleteSecurityGroupRule, deleteSecurityGroupRuleResponse);
assertTrue(clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North")
.deleteSecurityGroupRule("161"));
}
private SecurityGroup createSecurityGroupExpected() {
return SecurityGroup
.builder()
.description("description")
.id("160")
.name("name")
.rules(ImmutableSet.<SecurityGroupRule> of())
.tenantId("dev_16767499955063")
.build();
}
private SecurityGroupRule createSecurityGroupRuleExpected() {
return SecurityGroupRule
.builder()
.fromPort(80)
.group(ImmutableMap.<String, String> of())
.id("218")
.ipProtocol(SecurityGroupRule.IpProtocol.TCP)
.ipRange(ImmutableMap.of("cidr","0.0.0.0/0"))
.parentGroupId("161")
.toPort(8080)
.build();
}
}

View File

@ -0,0 +1,9 @@
{
"security_group": {
"rules": [ ],
"tenant_id": "dev_16767499955063",
"id": 160,
"name": "name",
"description": "description"
}
}

View File

@ -0,0 +1,12 @@
{
"security_group_rule": {
"from_port": 80,
"group": {},
"ip_protocol": "tcp",
"to_port": 8080,
"parent_group_id": 161,
"ip_range": {
"cidr": "0.0.0.0/0"
},
"id": 218 }
}