Merge pull request #444 from jdaggett/master

openstack-nova changes
This commit is contained in:
Adrian Cole 2012-03-14 17:46:07 -07:00
commit 6df4fd9afa
3 changed files with 157 additions and 2 deletions

View File

@ -19,9 +19,11 @@
package org.jclouds.openstack.nova.v1_1.domain;
import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import org.jclouds.javax.annotation.Nullable;
import com.google.gson.annotations.SerializedName;
@ -98,6 +100,7 @@ public class SecurityGroup {
this.tenantId = tenantId;
this.name = name;
this.description = description;
this.rules = ImmutableSet.copyOf(checkNotNull(rules, "rules"));
}
public String getId() {
@ -117,7 +120,7 @@ public class SecurityGroup {
}
public Set<SecurityGroupRule> getRules() {
return this.rules;
return rules;
}

View File

@ -18,13 +18,51 @@
*/
package org.jclouds.openstack.nova.v1_1.extensions;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
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.internal.BaseNovaRestClientExpectTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseSecurityGroupListTest;
import org.testng.annotations.Test;
import java.net.URI;
import java.util.logging.Logger;
import static org.testng.Assert.assertEquals;
/**
* Tests annotation parsing of {@code SecurityGroupAsyncClient}
*
* @author Michael Arnold
*/
@Test(groups = "unit", testName = "SecurityGroupClientExpectTest")
public class SecurityGroupClientExpectTest {
public class SecurityGroupClientExpectTest extends BaseNovaRestClientExpectTest {
public void testListSecurityGroupsWhenResponseIs2xx() throws Exception {
HttpRequest listSecurityGroups = HttpRequest
.builder()
.method("GET")
.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()).build();
HttpResponse listSecurityGroupsResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/securitygroup_list.json")).build();
NovaClient clientWhenSecurityGroupsExist = requestsSendResponses(
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
listSecurityGroups, listSecurityGroupsResponse);
assertEquals(clientWhenSecurityGroupsExist.getConfiguredRegions(),
ImmutableSet.of("North"));
assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North")
.listSecurityGroups().toString(), new ParseSecurityGroupListTest().expected()
.toString());
}
}

View File

@ -0,0 +1,114 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.nova.v1_1.parse;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.jclouds.json.BaseParserTest;
import org.jclouds.json.BaseSetParserTest;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.domain.Resource;
import org.jclouds.openstack.nova.v1_1.config.NovaParserModule;
import org.jclouds.openstack.nova.v1_1.domain.SecurityGroup;
import org.jclouds.openstack.nova.v1_1.domain.SecurityGroupRule;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import static org.testng.Assert.assertEquals;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ParseSecurityGroupListTest")
public class ParseSecurityGroupListTest extends BaseSetParserTest<SecurityGroup> {
@Override
public String resource() {
return "/securitygroup_list.json";
}
@Override
@SelectJson("security_groups")
@Consumes(MediaType.APPLICATION_JSON)
public Set<SecurityGroup> expected() {
Map<String, String> anyCidr = ImmutableMap.<String, String> of("cidr", "0.0.0.0/0");
Set<SecurityGroupRule> securityGroupRules = ImmutableSet.<SecurityGroupRule> of(
SecurityGroupRule
.builder()
.fromPort(22)
.group(new HashMap<String, String>())
.ipProtocol(SecurityGroupRule.IpProtocol.TCP)
.toPort(22)
.parentGroupId("3")
.ipRange(anyCidr)
.id("107")
.build(),
SecurityGroupRule
.builder()
.fromPort(7600)
.group(new HashMap<String, String>())
.ipProtocol(SecurityGroupRule.IpProtocol.TCP)
.toPort(7600)
.parentGroupId("3")
.ipRange(anyCidr)
.id("118")
.build(),
SecurityGroupRule
.builder()
.fromPort(8084)
.group(new HashMap<String, String>())
.ipProtocol(SecurityGroupRule.IpProtocol.TCP)
.toPort(8084)
.parentGroupId("3")
.ipRange(anyCidr)
.id("119")
.build()
);
return ImmutableSet
.of(
SecurityGroup
.builder()
.description("description1")
.id("1")
.tenantId("tenant1")
.rules(securityGroupRules)
.name("name1")
.build()
);
}
protected Injector injector() {
return Guice.createInjector(new NovaParserModule(), new GsonModule());
}
}