mirror of https://github.com/apache/jclouds.git
unit test fixes
This commit is contained in:
parent
7f02824928
commit
06b99c1cdc
|
@ -28,9 +28,6 @@ import org.jclouds.domain.Credentials;
|
|||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
|
|
|
@ -18,39 +18,32 @@
|
|||
*/
|
||||
package org.jclouds.openstack.nova.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.openstack.nova.domain.Address;
|
||||
import org.jclouds.openstack.nova.domain.Server;
|
||||
import org.jclouds.openstack.nova.domain.ServerStatus;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.domain.*;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationBuilder;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.openstack.nova.domain.Address;
|
||||
import org.jclouds.openstack.nova.domain.Server;
|
||||
import org.jclouds.openstack.nova.domain.ServerStatus;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Iterables;
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
|
@ -113,8 +106,11 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
|||
from.getHostId()).parent(location.get()).build());
|
||||
builder.userMetadata(from.getMetadata());
|
||||
builder.group(parseGroupFromName(from.getName()));
|
||||
builder.imageId(from.getImageRef() + "");
|
||||
builder.operatingSystem(parseOperatingSystem(from));
|
||||
Image image = parseImage(from);
|
||||
if (image != null) {
|
||||
builder.imageId(image.getId());
|
||||
builder.operatingSystem(image.getOperatingSystem());
|
||||
}
|
||||
builder.hardware(parseHardware(from));
|
||||
builder.state(serverToNodeState.get(from.getStatus()));
|
||||
builder.publicAddresses(Iterables.transform(from.getAddresses().getPublicAddresses(), Address.newAddress2StringFunction()));
|
||||
|
@ -133,9 +129,9 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
|||
return null;
|
||||
}
|
||||
|
||||
protected OperatingSystem parseOperatingSystem(Server from) {
|
||||
protected Image parseImage(Server from) {
|
||||
try {
|
||||
return Iterables.find(images.get(), new FindImageForServer(from)).getOperatingSystem();
|
||||
return Iterables.find(images.get(), new FindImageForServer(from));
|
||||
} catch (NoSuchElementException e) {
|
||||
logger.warn("could not find a matching image for server %s in location %s", from, location);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ public class Address {
|
|||
private int version;
|
||||
|
||||
//for de-serialization
|
||||
@SuppressWarnings("unused")
|
||||
private Address() {
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package org.jclouds.openstack.nova.domain;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* @author Dmitri Babaev
|
||||
*/
|
||||
|
@ -17,6 +18,11 @@ public class Resource {
|
|||
public URI getURI() {
|
||||
for (Map<String, String> linkProperties : links) {
|
||||
try {
|
||||
if (!Functions.forMap(linkProperties, "").apply("rel").equals("bookmark"))
|
||||
continue;
|
||||
if (!Functions.forMap(linkProperties, "").apply("type").contains("json"))
|
||||
continue;
|
||||
|
||||
return new URI(linkProperties.get("href"));
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
|
@ -28,6 +28,8 @@ import org.jclouds.openstack.nova.domain.Flavor;
|
|||
import org.jclouds.openstack.nova.functions.ParseFlavorFromJsonResponseTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
@ -40,11 +42,16 @@ public class FlavorToHardwareTest {
|
|||
Location provider = new LocationBuilder().scope(LocationScope.ZONE).id("dallas").description("description").build();
|
||||
|
||||
@Test
|
||||
public void test() throws UnknownHostException {
|
||||
assertEquals(convertFlavor(), new HardwareBuilder().ids("1").name("256 MB Server").processors(
|
||||
ImmutableList.of(new Processor(1.0, 1.0))).ram(256).volumes(
|
||||
ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(10.0f).durable(true).bootDevice(true)
|
||||
.build())).build());
|
||||
public void test() throws UnknownHostException, URISyntaxException {
|
||||
Hardware flavor = convertFlavor();
|
||||
Hardware tempFlavor = new HardwareBuilder().ids("1").name("256 MB Server")
|
||||
.processors(ImmutableList.of(new Processor(1.0, 1.0)))
|
||||
.ram(256)
|
||||
.volumes(ImmutableList.of(
|
||||
new VolumeBuilder().type(Volume.Type.LOCAL).size(10.0f).durable(true).bootDevice(true).build()))
|
||||
.uri(new URI("http://servers.api.openstack.org/1234/flavors/1"))
|
||||
.build();
|
||||
assertEquals(flavor, tempFlavor);
|
||||
}
|
||||
|
||||
public static Hardware convertFlavor() {
|
||||
|
|
|
@ -18,8 +18,12 @@
|
|||
*/
|
||||
package org.jclouds.openstack.nova.compute.functions;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.ImageBuilder;
|
||||
|
@ -28,12 +32,11 @@ import org.jclouds.compute.domain.OsFamily;
|
|||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.openstack.nova.functions.ParseImageFromJsonResponseTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import com.google.inject.Guice;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
|
@ -42,27 +45,23 @@ import static org.testng.Assert.assertEquals;
|
|||
public class NovaImageToImageTest {
|
||||
|
||||
@Test
|
||||
public void testApplyWhereImageNotFound() throws UnknownHostException {
|
||||
assertEquals(
|
||||
convertImage(),
|
||||
new ImageBuilder()
|
||||
public void testApplyWhereImageNotFound() throws UnknownHostException, URISyntaxException {
|
||||
Image image = new ImageBuilder()
|
||||
.name("CentOS 5.2")
|
||||
.operatingSystem(
|
||||
new OperatingSystem.Builder().family(OsFamily.CENTOS).version("5.2").description("CentOS 5.2").is64Bit(true)
|
||||
.build()).description("CentOS 5.2").defaultCredentials(new Credentials("root", null))
|
||||
.ids("2").version("1286712000000").build());
|
||||
.ids("1").version("1286712000000").uri(new URI("http://servers.api.openstack.org/1234/images/1")).build();
|
||||
Image parsedImage = convertImage();
|
||||
|
||||
assertEquals(parsedImage, image);
|
||||
}
|
||||
|
||||
public static Image convertImage() {
|
||||
org.jclouds.openstack.nova.domain.Image image = ParseImageFromJsonResponseTest.parseImage();
|
||||
|
||||
NovaImageToImage parser = new NovaImageToImage(new NovaImageToOperatingSystem(new BaseComputeServiceContextModule() {
|
||||
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
})
|
||||
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
|
||||
.getInstance(Json.class))));
|
||||
|
||||
return parser.apply(image);
|
||||
|
|
|
@ -18,11 +18,25 @@
|
|||
*/
|
||||
package org.jclouds.openstack.nova.compute.functions;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.jclouds.compute.domain.*;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.HardwareBuilder;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.domain.Processor;
|
||||
import org.jclouds.compute.domain.Volume;
|
||||
import org.jclouds.compute.domain.VolumeBuilder;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationBuilder;
|
||||
|
@ -33,11 +47,10 @@ import org.jclouds.openstack.nova.domain.ServerStatus;
|
|||
import org.jclouds.openstack.nova.functions.ParseServerFromJsonResponseTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
|
@ -47,7 +60,7 @@ public class ServerToNodeMetadataTest {
|
|||
Location provider = new LocationBuilder().scope(LocationScope.ZONE).id("dallas").description("description").build();
|
||||
|
||||
@Test
|
||||
public void testApplyWhereImageAndHardwareNotFoundButCredentialsFound() throws UnknownHostException, NoSuchMethodException, ClassNotFoundException {
|
||||
public void testApplyWhereImageAndHardwareNotFoundButCredentialsFound() throws UnknownHostException, NoSuchMethodException, ClassNotFoundException, URISyntaxException {
|
||||
Credentials creds = new Credentials("root", "abdce");
|
||||
|
||||
Map<ServerStatus, NodeState> serverStateToNodeState = NovaComputeServiceDependenciesModule.serverToNodeState;
|
||||
|
@ -61,16 +74,13 @@ public class ServerToNodeMetadataTest {
|
|||
|
||||
NodeMetadata metadata = parser.apply(server);
|
||||
|
||||
assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(
|
||||
ImmutableSet.of("67.23.10.132", "67.23.10.131")).privateAddresses(ImmutableSet.of("10.176.42.16"))
|
||||
.imageId("2").id("1234").providerId("1234").name("sample-server").credentials(creds).location(
|
||||
new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0")
|
||||
.description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build())
|
||||
.userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
||||
NodeMetadata constructedMetadata = newNodeMetadataBuilder()
|
||||
.credentials(creds).build();
|
||||
assertEquals(metadata, constructedMetadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyWhereImageAndHardwareNotFound() throws UnknownHostException, NoSuchMethodException, ClassNotFoundException {
|
||||
public void testApplyWhereImageAndHardwareNotFound() throws UnknownHostException, NoSuchMethodException, ClassNotFoundException, URISyntaxException {
|
||||
Map<ServerStatus, NodeState> serverStateToNodeState = NovaComputeServiceDependenciesModule.serverToNodeState;
|
||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
|
||||
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
||||
|
@ -82,17 +92,31 @@ public class ServerToNodeMetadataTest {
|
|||
|
||||
NodeMetadata metadata = parser.apply(server);
|
||||
|
||||
assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(
|
||||
ImmutableSet.of("67.23.10.132", "67.23.10.131")).privateAddresses(ImmutableSet.of("10.176.42.16"))
|
||||
.imageId("2").id("1234").providerId("1234").name("sample-server").location(
|
||||
new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0")
|
||||
.description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build())
|
||||
.userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
||||
NodeMetadata constructedMetadata = newNodeMetadataBuilder().build();
|
||||
|
||||
assertEquals(metadata, constructedMetadata);
|
||||
|
||||
}
|
||||
|
||||
private NodeMetadataBuilder newNodeMetadataBuilder() throws URISyntaxException {
|
||||
return new NodeMetadataBuilder()
|
||||
.state(NodeState.PENDING)
|
||||
.publicAddresses(ImmutableSet.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"))
|
||||
.privateAddresses(ImmutableSet.of("10.176.42.16", "::babe:10.176.42.16"))
|
||||
.id("1234")
|
||||
.providerId("1234")
|
||||
.name("sample-server")
|
||||
.location(new LocationBuilder()
|
||||
.scope(LocationScope.HOST)
|
||||
.id("e4d909c290d0fb1ca068ffaddf22cbd0")
|
||||
.description("e4d909c290d0fb1ca068ffaddf22cbd0")
|
||||
.parent(provider).build())
|
||||
.userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"))
|
||||
.uri(new URI("http://servers.api.openstack.org/1234/servers/1234"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyWhereImageFoundAndHardwareNotFound() throws UnknownHostException, NoSuchMethodException, ClassNotFoundException {
|
||||
public void testApplyWhereImageFoundAndHardwareNotFound() throws UnknownHostException, NoSuchMethodException, ClassNotFoundException, URISyntaxException {
|
||||
Map<ServerStatus, NodeState> serverStateToNodeState = NovaComputeServiceDependenciesModule.serverToNodeState;
|
||||
org.jclouds.compute.domain.Image jcImage = NovaImageToImageTest.convertImage();
|
||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage);
|
||||
|
@ -105,19 +129,21 @@ public class ServerToNodeMetadataTest {
|
|||
|
||||
NodeMetadata metadata = parser.apply(server);
|
||||
|
||||
assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(
|
||||
ImmutableSet.of("67.23.10.132", "67.23.10.131")).privateAddresses(ImmutableSet.of("10.176.42.16"))
|
||||
.imageId("2").operatingSystem(
|
||||
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2")
|
||||
.is64Bit(true).build()).id("1234").providerId("1234").name("sample-server").location(
|
||||
new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0")
|
||||
.description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build())
|
||||
.userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
||||
NodeMetadata constructedMetadata = newNodeMetadataBuilder()
|
||||
.imageId("1")
|
||||
.operatingSystem(new OperatingSystem.Builder()
|
||||
.family(OsFamily.CENTOS)
|
||||
.description("CentOS 5.2")
|
||||
.version("5.2")
|
||||
.is64Bit(true).build())
|
||||
.build();
|
||||
|
||||
assertEquals(metadata, constructedMetadata);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyWhereImageAndHardwareFound() throws UnknownHostException, NoSuchMethodException, ClassNotFoundException {
|
||||
public void testApplyWhereImageAndHardwareFound() throws UnknownHostException, NoSuchMethodException, ClassNotFoundException, URISyntaxException {
|
||||
Map<ServerStatus, NodeState> serverStateToNodeState = NovaComputeServiceDependenciesModule.serverToNodeState;
|
||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(NovaImageToImageTest.convertImage());
|
||||
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of(FlavorToHardwareTest.convertFlavor());
|
||||
|
@ -129,17 +155,27 @@ public class ServerToNodeMetadataTest {
|
|||
|
||||
NodeMetadata metadata = parser.apply(server);
|
||||
|
||||
assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(
|
||||
ImmutableSet.of("67.23.10.132", "67.23.10.131")).privateAddresses(ImmutableSet.of("10.176.42.16"))
|
||||
.imageId("2").hardware(
|
||||
new HardwareBuilder().ids("1").name("256 MB Server").processors(
|
||||
ImmutableList.of(new Processor(1.0, 1.0))).ram(256).volumes(
|
||||
ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(10.0f).durable(true)
|
||||
.bootDevice(true).build())).build()).operatingSystem(
|
||||
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2")
|
||||
.is64Bit(true).build()).id("1234").providerId("1234").name("sample-server").location(
|
||||
new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0")
|
||||
.description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build())
|
||||
.userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
||||
NodeMetadata constructedMetadata = newNodeMetadataBuilder()
|
||||
.imageId("1")
|
||||
.operatingSystem(new OperatingSystem.Builder()
|
||||
.family(OsFamily.CENTOS)
|
||||
.description("CentOS 5.2")
|
||||
.version("5.2")
|
||||
.is64Bit(true).build())
|
||||
.hardware(new HardwareBuilder()
|
||||
.ids("1")
|
||||
.name("256 MB Server")
|
||||
.processors(ImmutableList.of(new Processor(1.0, 1.0)))
|
||||
.ram(256)
|
||||
.volumes(ImmutableList.of(new VolumeBuilder()
|
||||
.type(Volume.Type.LOCAL)
|
||||
.size(10.0f)
|
||||
.durable(true)
|
||||
.bootDevice(true).build()))
|
||||
.uri(new URI("http://servers.api.openstack.org/1234/flavors/1"))
|
||||
.build())
|
||||
.build();
|
||||
|
||||
assertEquals(metadata, constructedMetadata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,9 @@
|
|||
*/
|
||||
package org.jclouds.openstack.nova.functions;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
@ -33,8 +35,9 @@ import org.testng.annotations.Test;
|
|||
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.testng.Assert.assertEqualsNoOrder;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseAddressesFromJsonResponse}
|
||||
|
@ -53,13 +56,15 @@ public class ParseAddressesFromJsonResponseTest {
|
|||
}));
|
||||
Addresses response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
||||
|
||||
ImmutableSet<Address> publicAddresses = ImmutableSet.of(new Address("67.23.10.132", 4)
|
||||
, new Address("::babe:67.23.10.132", 6), new Address("67.23.10.131", 4), new Address("::babe:4317:0A83", 6));
|
||||
List<Address> publicAddresses = ImmutableList.copyOf(
|
||||
Iterables.transform(ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
|
||||
Address.newString2AddressFunction()));
|
||||
|
||||
ImmutableSet<Address> privateAddresses = ImmutableSet.of(new Address("10.176.42.16", 4),
|
||||
new Address("::babe:10.176.42.16", 6));
|
||||
List<Address> privateAddresses = ImmutableList.copyOf(
|
||||
Iterables.transform(ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"),
|
||||
Address.newString2AddressFunction()));
|
||||
|
||||
assertEqualsNoOrder(response.getPublicAddresses().toArray(), publicAddresses.toArray());
|
||||
assertEqualsNoOrder(response.getPrivateAddresses().toArray(), privateAddresses.toArray());
|
||||
assertTrue(response.getPublicAddresses().equals(Sets.newHashSet(publicAddresses)));
|
||||
assertTrue(response.getPrivateAddresses().equals(Sets.newHashSet(privateAddresses)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import com.google.inject.TypeLiteral;
|
|||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.openstack.nova.domain.Address;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -43,7 +44,7 @@ import static org.testng.Assert.assertEquals;
|
|||
@Test(groups = "unit")
|
||||
public class ParseInetAddressListFromJsonResponseTest {
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule());
|
||||
Injector i = Guice.createInjector(new GsonModule());
|
||||
|
||||
@Test
|
||||
public void testPublic() throws UnknownHostException {
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
package org.jclouds.openstack.nova.functions;
|
||||
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: VGalkin
|
||||
* Date: 4/16/11
|
||||
* Time: 7:47 AM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
class ParserModule extends GsonModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
}
|
||||
}
|
|
@ -18,21 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.openstack.nova.functions;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.openstack.nova.domain.Address;
|
||||
import org.jclouds.openstack.nova.domain.Addresses;
|
||||
import org.jclouds.openstack.nova.domain.Server;
|
||||
import org.jclouds.openstack.nova.domain.ServerStatus;
|
||||
import org.testng.annotations.Test;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
|
@ -43,7 +29,23 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.SimpleTimeZone;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.openstack.nova.domain.Address;
|
||||
import org.jclouds.openstack.nova.domain.Addresses;
|
||||
import org.jclouds.openstack.nova.domain.Server;
|
||||
import org.jclouds.openstack.nova.domain.ServerStatus;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseServerFromJsonResponse}
|
||||
|
@ -72,9 +74,12 @@ public class ParseServerFromJsonResponseTest {
|
|||
assertEquals(response.getUpdated(),
|
||||
dateFormat.parse("2010-10-10T12:00:00Z"));
|
||||
|
||||
|
||||
List<Address> publicAddresses = ImmutableList.copyOf(Iterables.transform(ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"), Address.newString2AddressFunction()));
|
||||
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
|
||||
List<Address> publicAddresses = ImmutableList.copyOf(Iterables.transform(
|
||||
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
|
||||
Address.newString2AddressFunction()));
|
||||
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
|
||||
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"),
|
||||
Address.newString2AddressFunction()));
|
||||
Addresses addresses1 = new Addresses(new HashSet<Address>(publicAddresses), new HashSet<Address>(privateAddresses));
|
||||
assertEquals(response.getAddresses(), addresses1);
|
||||
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
||||
|
@ -84,14 +89,18 @@ public class ParseServerFromJsonResponseTest {
|
|||
|
||||
public static Server parseServer() throws NoSuchMethodException, ClassNotFoundException {
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule());
|
||||
Injector i = Guice.createInjector(new GsonModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
}
|
||||
});
|
||||
|
||||
InputStream is = ParseServerFromJsonResponseTest.class.getResourceAsStream("/test_get_server_detail.json");
|
||||
|
||||
UnwrapOnlyJsonValue<Server> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Server>>() {
|
||||
}));
|
||||
UnwrapOnlyJsonValue<Server> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Server>>() {}));
|
||||
|
||||
//Function<HttpResponse, ?> parser = i.getInstance(getParserOrThrowException(NovaClient.class.getMethod("getServer", int.class)));
|
||||
return (Server) parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,23 @@
|
|||
*/
|
||||
package org.jclouds.openstack.nova.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.openstack.nova.domain.Address;
|
||||
import org.jclouds.openstack.nova.domain.Addresses;
|
||||
import org.jclouds.openstack.nova.domain.Server;
|
||||
import org.jclouds.openstack.nova.domain.ServerStatus;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
@ -25,21 +42,6 @@ import com.google.inject.Guice;
|
|||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.openstack.nova.domain.Address;
|
||||
import org.jclouds.openstack.nova.domain.Addresses;
|
||||
import org.jclouds.openstack.nova.domain.Server;
|
||||
import org.jclouds.openstack.nova.domain.ServerStatus;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseServerListFromJsonResponse}
|
||||
|
@ -49,7 +51,13 @@ import static org.testng.Assert.assertEquals;
|
|||
@Test(groups = "unit")
|
||||
public class ParseServerListFromJsonResponseTest {
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule());
|
||||
Injector i = Guice.createInjector(new GsonModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
}
|
||||
});
|
||||
|
||||
@Test
|
||||
public void testApplyInputStream() {
|
||||
|
@ -82,8 +90,12 @@ public class ParseServerListFromJsonResponseTest {
|
|||
assertEquals(response.get(0).getStatus(), ServerStatus.BUILD);
|
||||
assertEquals(response.get(0).getProgress(), new Integer(60));
|
||||
|
||||
List<Address> publicAddresses = ImmutableList.copyOf(Iterables.transform(ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"), Address.newString2AddressFunction()));
|
||||
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
|
||||
List<Address> publicAddresses = ImmutableList.copyOf(Iterables.transform(
|
||||
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
|
||||
Address.newString2AddressFunction()));
|
||||
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
|
||||
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"),
|
||||
Address.newString2AddressFunction()));
|
||||
Addresses addresses1 = new Addresses(new HashSet<Address>(publicAddresses), new HashSet<Address>(privateAddresses));
|
||||
|
||||
assertEquals(response.get(0).getAddresses(), addresses1);
|
||||
|
@ -97,13 +109,17 @@ public class ParseServerListFromJsonResponseTest {
|
|||
assertEquals(response.get(1).getStatus(), ServerStatus.ACTIVE);
|
||||
assertEquals(response.get(1).getProgress(), null);
|
||||
|
||||
List<Address> publicAddresses2 = ImmutableList.of(new Address("67.23.10.133", 4), new Address("::babe:67.23.10.133", 6));
|
||||
List<Address> privateAddresses2 = ImmutableList.of(new Address("10.176.42.17", 4), new Address("::babe:10.176.42.17", 6));
|
||||
List<Address> publicAddresses2 = ImmutableList.copyOf(Iterables.transform(
|
||||
ImmutableList.of("67.23.10.133", "::babe:67.23.10.133"),
|
||||
Address.newString2AddressFunction()));
|
||||
List<Address> privateAddresses2 = ImmutableList.copyOf(Iterables.transform(
|
||||
ImmutableList.of("10.176.42.17", "::babe:10.176.42.17"),
|
||||
Address.newString2AddressFunction()));
|
||||
Addresses addresses2 = new Addresses(new HashSet<Address>(publicAddresses2), new HashSet<Address>(privateAddresses2));
|
||||
|
||||
assertEquals(response.get(1).getAddresses(), addresses2);
|
||||
assertEquals(response.get(1).getMetadata(), ImmutableMap.of("Server Label", "DB 1"));
|
||||
assertEquals(response.get(1).getURI(), "http://servers.api.openstack.org/1234/servers/56789");
|
||||
assertEquals(response.get(1).getURI().toString(), "http://servers.api.openstack.org/1234/servers/56789");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
{
|
||||
"rel" : "bookmark",
|
||||
"type" : "application/vnd.openstack.computev1.1+json",
|
||||
"href" : "http://servers.api.openstack.org/1234/images/1"
|
||||
"href" : "https://servers.api.rackspacecloud.com/v1.1/1234/images/1"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
"server" : {
|
||||
"id" : 1234,
|
||||
"name" : "sample-server",
|
||||
"imageRef" : "https://servers.api.rackspacecloud.com/v1.1/32278/images/1234",
|
||||
"flavorRef" : "https://servers.api.rackspacecloud.com/v1.1/32278/flavors/1",
|
||||
"imageRef" : "https://servers.api.rackspacecloud.com/v1.1/1234/images/1",
|
||||
"flavorRef" : "http://servers.api.openstack.org/1234/flavors/1",
|
||||
"updated" : "2010-10-10T12:00:00Z",
|
||||
"created" : "2010-08-10T12:00:00Z",
|
||||
"hostId" : "e4d909c290d0fb1ca068ffaddf22cbd0",
|
||||
|
|
Loading…
Reference in New Issue