mirror of https://github.com/apache/jclouds.git
Changed expectations for parser tests
This commit is contained in:
parent
5e2bae24e8
commit
8d2d3e8088
|
@ -45,6 +45,7 @@ import static org.testng.Assert.assertEquals;
|
||||||
public class ParseAddressesFromJsonResponseTest {
|
public class ParseAddressesFromJsonResponseTest {
|
||||||
Injector i = Guice.createInjector(new GsonModule());
|
Injector i = Guice.createInjector(new GsonModule());
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_addresses.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_addresses.json");
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,9 @@ import static org.testng.Assert.assertEquals;
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class ParseFlavorFromJsonResponseTest {
|
public class ParseFlavorFromJsonResponseTest {
|
||||||
public void test() throws IOException {
|
|
||||||
|
@Test
|
||||||
|
public void testParseFlavorFromJsonResponseTest() throws IOException {
|
||||||
Flavor response = parseFlavor();
|
Flavor response = parseFlavor();
|
||||||
|
|
||||||
String json = new Gson().toJson(response);
|
String json = new Gson().toJson(response);
|
||||||
|
@ -52,6 +54,11 @@ public class ParseFlavorFromJsonResponseTest {
|
||||||
ParseFlavorFromJsonResponseTest.class.getResourceAsStream("/test_get_flavor_details.json"))
|
ParseFlavorFromJsonResponseTest.class.getResourceAsStream("/test_get_flavor_details.json"))
|
||||||
.replace("\n", "").replace("\t", "").replace("\r", "").replace(" ", "");
|
.replace("\n", "").replace("\t", "").replace("\r", "").replace(" ", "");
|
||||||
|
|
||||||
|
assertEquals(response.getId(), 1);
|
||||||
|
assertEquals(response.getName(), "256 MB Server");
|
||||||
|
assertEquals(response.getDisk().intValue(), 10);
|
||||||
|
assertEquals(response.getRam().intValue(), 256);
|
||||||
|
|
||||||
assertEquals(json, expectedJson);
|
assertEquals(json, expectedJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,24 +18,23 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.functions;
|
package org.jclouds.openstack.nova.functions;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jclouds.openstack.nova.domain.Flavor;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
|
||||||
import org.jclouds.io.Payloads;
|
|
||||||
import org.jclouds.json.config.GsonModule;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
import com.google.inject.TypeLiteral;
|
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.Flavor;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code ParseFlavorListFromJsonResponse}
|
* Tests behavior of {@code ParseFlavorListFromJsonResponse}
|
||||||
|
@ -47,6 +46,7 @@ public class ParseFlavorListFromJsonResponseTest {
|
||||||
|
|
||||||
Injector i = Guice.createInjector(new GsonModule());
|
Injector i = Guice.createInjector(new GsonModule());
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testApplyInputStream() {
|
public void testApplyInputStream() {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_flavors.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_flavors.json");
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ public class ParseFlavorListFromJsonResponseTest {
|
||||||
assertEquals(response, expects);
|
assertEquals(response, expects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_flavors_detail.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_flavors_detail.json");
|
||||||
|
|
||||||
|
|
|
@ -18,13 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.functions;
|
package org.jclouds.openstack.nova.functions;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import com.google.inject.*;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
|
|
||||||
import org.jclouds.openstack.nova.domain.Image;
|
|
||||||
import org.jclouds.openstack.nova.domain.ImageStatus;
|
|
||||||
import org.jclouds.date.DateService;
|
import org.jclouds.date.DateService;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||||
|
@ -32,13 +26,14 @@ import org.jclouds.io.Payloads;
|
||||||
import org.jclouds.json.config.GsonModule;
|
import org.jclouds.json.config.GsonModule;
|
||||||
import org.jclouds.json.config.GsonModule.DateAdapter;
|
import org.jclouds.json.config.GsonModule.DateAdapter;
|
||||||
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
||||||
|
import org.jclouds.openstack.nova.domain.Image;
|
||||||
|
import org.jclouds.openstack.nova.domain.ImageStatus;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import java.io.InputStream;
|
||||||
import com.google.inject.Guice;
|
import java.net.UnknownHostException;
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Key;
|
import static org.testng.Assert.assertEquals;
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code ParseImageFromJsonResponse}
|
* Tests behavior of {@code ParseImageFromJsonResponse}
|
||||||
|
@ -58,17 +53,21 @@ public class ParseImageFromJsonResponseTest {
|
||||||
|
|
||||||
DateService dateService = i.getInstance(DateService.class);
|
DateService dateService = i.getInstance(DateService.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||||
Image response = parseImage();
|
Image response = parseImage();
|
||||||
|
|
||||||
assertEquals(response.getId(), 2);
|
assertEquals(response.getId(), 2);
|
||||||
assertEquals(response.getName(), "CentOS 5.2");
|
assertEquals(response.getName(), "CentOS 5.2");
|
||||||
|
assertEquals(response.getServerId(), new Integer(12));
|
||||||
assertEquals(response.getCreated(), dateService.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
|
assertEquals(response.getCreated(), dateService.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
|
||||||
assertEquals(response.getProgress(), new Integer(80));
|
assertEquals(response.getProgress(), new Integer(80));
|
||||||
assertEquals(response.getServerId(), new Integer(12));
|
|
||||||
assertEquals(response.getStatus(), ImageStatus.SAVING);
|
assertEquals(response.getStatus(), ImageStatus.SAVING);
|
||||||
assertEquals(response.getUpdated(), dateService.iso8601SecondsDateParse(("2010-10-10T12:00:00Z")));
|
assertEquals(response.getUpdated(), dateService.iso8601SecondsDateParse(("2010-10-10T12:00:00Z")));
|
||||||
|
assertEquals(response.getServerId(), "http://servers.api.openstack.org/v1.1/1234/servers/12", "Change serverId to serverRefs");
|
||||||
|
assertEquals(response.getMetadata().get("ImageVersion"), "1.5");
|
||||||
|
assertEquals(response.getMetadata().get("ImageType"), "Gold");
|
||||||
|
assertEquals(response.getMetadata().size(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Image parseImage() {
|
public static Image parseImage() {
|
||||||
|
|
|
@ -18,14 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.functions;
|
package org.jclouds.openstack.nova.functions;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.inject.*;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jclouds.openstack.nova.domain.Image;
|
|
||||||
import org.jclouds.openstack.nova.domain.ImageStatus;
|
|
||||||
import org.jclouds.date.DateService;
|
import org.jclouds.date.DateService;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||||
|
@ -33,14 +27,15 @@ import org.jclouds.io.Payloads;
|
||||||
import org.jclouds.json.config.GsonModule;
|
import org.jclouds.json.config.GsonModule;
|
||||||
import org.jclouds.json.config.GsonModule.DateAdapter;
|
import org.jclouds.json.config.GsonModule.DateAdapter;
|
||||||
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
||||||
|
import org.jclouds.openstack.nova.domain.Image;
|
||||||
|
import org.jclouds.openstack.nova.domain.ImageStatus;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import java.io.InputStream;
|
||||||
import com.google.inject.AbstractModule;
|
import java.net.UnknownHostException;
|
||||||
import com.google.inject.Guice;
|
import java.util.List;
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Key;
|
import static org.testng.Assert.assertEquals;
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code ParseImageListFromJsonResponse}
|
* Tests behavior of {@code ParseImageListFromJsonResponse}
|
||||||
|
@ -59,10 +54,11 @@ public class ParseImageListFromJsonResponseTest {
|
||||||
}, new GsonModule());
|
}, new GsonModule());
|
||||||
DateService dateService = i.getInstance(DateService.class);
|
DateService dateService = i.getInstance(DateService.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testApplyInputStream() {
|
public void testApplyInputStream() {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_images.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_images.json");
|
||||||
|
|
||||||
List<Image> expects = ImmutableList.of(new Image(2, "CentOS 5.2"), new Image(743, "My Server Backup"));
|
List<Image> expects = ImmutableList.of(new Image(1, "CentOS 5.2"), new Image(743, "My Server Backup"));
|
||||||
|
|
||||||
UnwrapOnlyJsonValue<List<Image>> parser = i.getInstance(Key
|
UnwrapOnlyJsonValue<List<Image>> parser = i.getInstance(Key
|
||||||
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {
|
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {
|
||||||
|
@ -72,6 +68,7 @@ public class ParseImageListFromJsonResponseTest {
|
||||||
assertEquals(response, expects);
|
assertEquals(response, expects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_images_detail.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_images_detail.json");
|
||||||
|
|
||||||
|
@ -80,22 +77,30 @@ public class ParseImageListFromJsonResponseTest {
|
||||||
}));
|
}));
|
||||||
List<Image> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
List<Image> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
||||||
|
|
||||||
assertEquals(response.get(0).getId(), 2);
|
assertEquals(response.get(0).getId(), 1);
|
||||||
assertEquals(response.get(0).getName(), "CentOS 5.2");
|
assertEquals(response.get(0).getName(), "CentOS 5.2");
|
||||||
assertEquals(response.get(0).getCreated(), dateService.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
|
assertEquals(response.get(0).getCreated(), dateService.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
|
||||||
assertEquals(response.get(0).getProgress(), null);
|
assertEquals(response.get(0).getProgress(), null);
|
||||||
assertEquals(response.get(0).getServerId(), null);
|
assertEquals(response.get(0).getServerId(), null);
|
||||||
assertEquals(response.get(0).getStatus(), ImageStatus.ACTIVE);
|
assertEquals(response.get(0).getStatus(), ImageStatus.ACTIVE);
|
||||||
assertEquals(response.get(0).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
|
assertEquals(response.get(0).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
|
||||||
|
assertEquals(response.get(0).getMetadata().get("ImageType"), "Gold");
|
||||||
|
assertEquals(response.get(0).getMetadata().get("ImageVersion"), "1.5");
|
||||||
|
assertEquals(response.get(0).getMetadata().size(), 2);
|
||||||
|
assertEquals(response.get(0).getServerId(), null, "Change serverId to serverRef");
|
||||||
|
|
||||||
assertEquals(response.get(1).getId(), 743);
|
assertEquals(response.get(1).getId(), 743);
|
||||||
assertEquals(response.get(1).getName(), "My Server Backup");
|
assertEquals(response.get(1).getName(), "My Server Backup");
|
||||||
assertEquals(response.get(1).getCreated(), dateService.iso8601SecondsDateParse("2009-07-07T09:56:16-05:00"));
|
assertEquals(response.get(1).getCreated(), dateService.iso8601SecondsDateParse("2009-07-07T09:56:16Z"));
|
||||||
;
|
|
||||||
assertEquals(response.get(1).getProgress(), new Integer(80));
|
assertEquals(response.get(1).getProgress(), new Integer(80));
|
||||||
assertEquals(response.get(1).getServerId(), new Integer(12));
|
assertEquals(response.get(1).getServerId(), new Integer(12));
|
||||||
assertEquals(response.get(1).getStatus(), ImageStatus.SAVING);
|
assertEquals(response.get(1).getStatus(), ImageStatus.SAVING);
|
||||||
assertEquals(response.get(1).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
|
assertEquals(response.get(1).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
|
||||||
|
assertEquals(response.get(1).getServerId(), "http://servers.api.openstack.org/v1.1/1234/servers/12", "Change serverId to serverRef");
|
||||||
|
|
||||||
|
//short form of reference
|
||||||
|
assertEquals(response.get(2).getServerId().intValue(), 12, "Change serverId to serverRef");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,23 +18,22 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.functions;
|
package org.jclouds.openstack.nova.functions;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.inject.Guice;
|
||||||
import java.io.InputStream;
|
import com.google.inject.Injector;
|
||||||
import java.net.UnknownHostException;
|
import com.google.inject.Key;
|
||||||
import java.util.List;
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||||
import org.jclouds.io.Payloads;
|
import org.jclouds.io.Payloads;
|
||||||
import org.jclouds.json.config.GsonModule;
|
import org.jclouds.json.config.GsonModule;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import java.io.InputStream;
|
||||||
import com.google.inject.Guice;
|
import java.net.UnknownHostException;
|
||||||
import com.google.inject.Injector;
|
import java.util.List;
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.TypeLiteral;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code ParseInetAddressListFromJsonResponse}
|
* Tests behavior of {@code ParseInetAddressListFromJsonResponse}
|
||||||
|
@ -46,6 +45,7 @@ public class ParseInetAddressListFromJsonResponseTest {
|
||||||
|
|
||||||
Injector i = Guice.createInjector(new GsonModule());
|
Injector i = Guice.createInjector(new GsonModule());
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPublic() throws UnknownHostException {
|
public void testPublic() throws UnknownHostException {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_addresses_public.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_addresses_public.json");
|
||||||
|
|
||||||
|
@ -54,9 +54,10 @@ public class ParseInetAddressListFromJsonResponseTest {
|
||||||
}));
|
}));
|
||||||
List<String> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
List<String> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
||||||
|
|
||||||
assertEquals(response, ImmutableList.of("67.23.10.132", "67.23.10.131"));
|
assertEquals(response, ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPrivate() throws UnknownHostException {
|
public void testPrivate() throws UnknownHostException {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_addresses_private.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_addresses_private.json");
|
||||||
|
|
||||||
|
@ -65,6 +66,6 @@ public class ParseInetAddressListFromJsonResponseTest {
|
||||||
}));
|
}));
|
||||||
List<String> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
List<String> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
||||||
|
|
||||||
assertEquals(response, ImmutableList.of("10.176.42.16"));
|
assertEquals(response, ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,27 +18,27 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.functions;
|
package org.jclouds.openstack.nova.functions;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jclouds.openstack.nova.domain.Addresses;
|
|
||||||
import org.jclouds.openstack.nova.domain.Server;
|
|
||||||
import org.jclouds.openstack.nova.domain.ServerStatus;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
|
||||||
import org.jclouds.io.Payloads;
|
|
||||||
import org.jclouds.json.config.GsonModule;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
import com.google.inject.TypeLiteral;
|
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.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 ParseServerFromJsonResponse}
|
* Tests behavior of {@code ParseServerFromJsonResponse}
|
||||||
|
@ -48,24 +48,27 @@ import com.google.inject.TypeLiteral;
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class ParseServerFromJsonResponseTest {
|
public class ParseServerFromJsonResponseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||||
Server response = parseServer();
|
Server response = parseServer();
|
||||||
|
|
||||||
assertEquals(response.getId(), 1234);
|
assertEquals(response.getId(), 1234);
|
||||||
assertEquals(response.getName(), "sample-server");
|
assertEquals(response.getName(), "sample-server");
|
||||||
assertEquals(response.getImageId(), new Integer(2));
|
assertEquals(response.getImageId().intValue(), 1234);
|
||||||
assertEquals(response.getFlavorId(), new Integer(1));
|
assertEquals(response.getFlavorId().intValue(), 1);
|
||||||
|
assertEquals(response.getImageId(), "https://servers.api.rackspacecloud.com/v1.1/32278/images/1234");
|
||||||
|
assertEquals(response.getFlavorId(), "https://servers.api.rackspacecloud.com/v1.1/32278/flavors/1");
|
||||||
assertEquals(response.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
assertEquals(response.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||||
|
assertEquals(true, false, "Uncomment next line");
|
||||||
|
//assertEquals(response.getAffinityId(), "fc88bcf8394db9c8d0564e08ca6a9724188a84d1");
|
||||||
assertEquals(response.getStatus(), ServerStatus.BUILD);
|
assertEquals(response.getStatus(), ServerStatus.BUILD);
|
||||||
assertEquals(response.getProgress(), new Integer(60));
|
assertEquals(response.getProgress(), new Integer(60));
|
||||||
List<String> publicAddresses = Lists.newArrayList("67.23.10.132", "67.23.10.131");
|
|
||||||
List<String> privateAddresses = Lists.newArrayList("10.176.42.16");
|
List<String> publicAddresses = ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83");
|
||||||
Addresses addresses1 = new Addresses();
|
List<String> privateAddresses = ImmutableList.of("10.176.42.16", "::babe:10.176.42.16");
|
||||||
addresses1.getPrivateAddresses().addAll(privateAddresses);
|
Addresses addresses1 = new Addresses(new HashSet<String>(publicAddresses), new HashSet<String>(privateAddresses));
|
||||||
addresses1.getPublicAddresses().addAll(publicAddresses);
|
|
||||||
assertEquals(response.getAddresses(), addresses1);
|
assertEquals(response.getAddresses(), addresses1);
|
||||||
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Server parseServer() {
|
public static Server parseServer() {
|
||||||
|
|
|
@ -18,28 +18,27 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.functions;
|
package org.jclouds.openstack.nova.functions;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.jclouds.openstack.nova.domain.Addresses;
|
|
||||||
import org.jclouds.openstack.nova.domain.Server;
|
|
||||||
import org.jclouds.openstack.nova.domain.ServerStatus;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
|
||||||
import org.jclouds.io.Payloads;
|
|
||||||
import org.jclouds.json.config.GsonModule;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
import com.google.inject.TypeLiteral;
|
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.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}
|
* Tests behavior of {@code ParseServerListFromJsonResponse}
|
||||||
|
@ -51,6 +50,7 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
|
|
||||||
Injector i = Guice.createInjector(new GsonModule());
|
Injector i = Guice.createInjector(new GsonModule());
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testApplyInputStream() {
|
public void testApplyInputStream() {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_servers.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_servers.json");
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
assertEquals(response, expects);
|
assertEquals(response, expects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_servers_detail.json");
|
InputStream is = getClass().getResourceAsStream("/test_list_servers_detail.json");
|
||||||
|
|
||||||
|
@ -74,32 +75,39 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
|
|
||||||
assertEquals(response.get(0).getId(), 1234);
|
assertEquals(response.get(0).getId(), 1234);
|
||||||
assertEquals(response.get(0).getName(), "sample-server");
|
assertEquals(response.get(0).getName(), "sample-server");
|
||||||
assertEquals(response.get(0).getImageId(), new Integer(2));
|
assertEquals(response.get(0).getImageId().intValue(), 1234);
|
||||||
assertEquals(response.get(0).getFlavorId(), new Integer(1));
|
assertEquals(response.get(0).getFlavorId().intValue(), 1);
|
||||||
|
assertEquals(response.get(0).getImageId(), "https://servers.api.rackspacecloud.com/v1.1/32278/images/1234");
|
||||||
|
assertEquals(response.get(0).getFlavorId(), "https://servers.api.rackspacecloud.com/v1.1/32278/flavors/1");
|
||||||
|
assertEquals(true, false, "Uncomment next line");
|
||||||
|
//assertEquals(response.getAffinityId(), "fc88bcf8394db9c8d0564e08ca6a9724188a84d1");
|
||||||
assertEquals(response.get(0).getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
assertEquals(response.get(0).getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||||
assertEquals(response.get(0).getStatus(), ServerStatus.BUILD);
|
assertEquals(response.get(0).getStatus(), ServerStatus.BUILD);
|
||||||
assertEquals(response.get(0).getProgress(), new Integer(60));
|
assertEquals(response.get(0).getProgress(), new Integer(60));
|
||||||
List<String> publicAddresses = Lists.newArrayList("67.23.10.132", "67.23.10.131");
|
|
||||||
List<String> privateAddresses = Lists.newArrayList("10.176.42.16");
|
List<String> publicAddresses = ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83");
|
||||||
Addresses addresses1 = new Addresses();
|
List<String> privateAddresses = ImmutableList.of("10.176.42.16", "::babe:10.176.42.16");
|
||||||
addresses1.getPrivateAddresses().addAll(privateAddresses);
|
Addresses addresses1 = new Addresses(new HashSet<String>(publicAddresses), new HashSet<String>(privateAddresses));
|
||||||
addresses1.getPublicAddresses().addAll(publicAddresses);
|
|
||||||
assertEquals(response.get(0).getAddresses(), addresses1);
|
assertEquals(response.get(0).getAddresses(), addresses1);
|
||||||
assertEquals(response.get(0).getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
assertEquals(response.get(0).getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
||||||
assertEquals(response.get(1).getId(), 5678);
|
assertEquals(response.get(1).getId(), 5678);
|
||||||
assertEquals(response.get(1).getName(), "sample-server2");
|
assertEquals(response.get(1).getName(), "sample-server2");
|
||||||
assertEquals(response.get(1).getImageId(), new Integer(2));
|
assertEquals(response.get(0).getImageId(), "https://servers.api.rackspacecloud.com/v1.1/32278/images/1");
|
||||||
assertEquals(response.get(1).getFlavorId(), new Integer(1));
|
assertEquals(response.get(0).getFlavorId(), "https://servers.api.rackspacecloud.com/v1.1/32278/flavors/1");
|
||||||
|
assertEquals(true, false, "Uncomment next line");
|
||||||
|
//assertEquals(response.getAffinityId(), "b414fa41cb37b97dcb58d6c76112af1258e9eae2");
|
||||||
assertEquals(response.get(1).getHostId(), "9e107d9d372bb6826bd81d3542a419d6");
|
assertEquals(response.get(1).getHostId(), "9e107d9d372bb6826bd81d3542a419d6");
|
||||||
assertEquals(response.get(1).getStatus(), ServerStatus.ACTIVE);
|
assertEquals(response.get(1).getStatus(), ServerStatus.ACTIVE);
|
||||||
assertEquals(response.get(1).getProgress(), null);
|
assertEquals(response.get(1).getProgress(), null);
|
||||||
List<String> publicAddresses2 = Lists.newArrayList("67.23.10.133");
|
|
||||||
List<String> privateAddresses2 = Lists.newArrayList("10.176.42.17");
|
List<String> publicAddresses2 = ImmutableList.of("67.23.10.133", "::babe:67.23.10.133");
|
||||||
Addresses addresses2 = new Addresses();
|
List<String> privateAddresses2 = ImmutableList.of("10.176.42.17", "::babe:10.176.42.17");
|
||||||
addresses2.getPrivateAddresses().addAll(privateAddresses2);
|
Addresses addresses2 = new Addresses(new HashSet<String>(publicAddresses2), new HashSet<String>(privateAddresses2));
|
||||||
addresses2.getPublicAddresses().addAll(publicAddresses2);
|
|
||||||
assertEquals(response.get(1).getAddresses(), addresses2);
|
assertEquals(response.get(1).getAddresses(), addresses2);
|
||||||
assertEquals(response.get(1).getMetadata(), ImmutableMap.of("Server Label", "DB 1"));
|
assertEquals(response.get(1).getMetadata(), ImmutableMap.of("Server Label", "DB 1"));
|
||||||
|
assertEquals(response.get(1).getURI(), "http://servers.api.openstack.org/1234/servers/56789");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
{
|
{
|
||||||
|
"network" {
|
||||||
"private" : [
|
"id" : "private",
|
||||||
"10.176.42.16"
|
"values" : [
|
||||||
|
{"version" : 4, "addr" : "67.23.10.132"},
|
||||||
|
{"version" : 6, "addr" : "::babe:67.23.10.132"},
|
||||||
|
{"version" : 4, "addr" : "67.23.10.131"},
|
||||||
|
{"version" : 6, "addr" : "::babe:4317:0A83"}
|
||||||
]
|
]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
{
|
{
|
||||||
"public" : [
|
"network" {
|
||||||
"67.23.10.132",
|
"id" : "public",
|
||||||
"67.23.10.131"
|
"values" : [
|
||||||
|
{"version" : 4, "addr" : "67.23.10.132"},
|
||||||
|
{"version" : 6, "addr" : "::babe:67.23.10.132"},
|
||||||
|
{"version" : 4, "addr" : "67.23.10.131"},
|
||||||
|
{"version" : 6, "addr" : "::babe:4317:0A83"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
"name" : "My Server Backup",
|
"name" : "My Server Backup",
|
||||||
"serverRef" : "http://servers.api.openstack.org/v1.1/1234/servers/12",
|
"serverRef" : "http://servers.api.openstack.org/v1.1/1234/servers/12",
|
||||||
"updated" : "2010-10-10T12:00:00Z",
|
"updated" : "2010-10-10T12:00:00Z",
|
||||||
"created" : "2010-08-10T12:00:00Z",
|
"created" : "2009-07-07T09:56:16Z",
|
||||||
"status" : "SAVING",
|
"status" : "SAVING",
|
||||||
"progress" : 80,
|
"progress" : 80,
|
||||||
"links": [
|
"links": [
|
||||||
|
@ -54,6 +54,36 @@
|
||||||
"href" : "http://servers.api.openstack.org/1234/images/743"
|
"href" : "http://servers.api.openstack.org/1234/images/743"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id" : 5,
|
||||||
|
"name" : "CentOS 5.2",
|
||||||
|
"serverRef" : 12,
|
||||||
|
"updated" : "2010-10-10T12:00:00Z",
|
||||||
|
"created" : "2010-08-10T12:00:00Z",
|
||||||
|
"status" : "ACTIVE",
|
||||||
|
"metadata" : {
|
||||||
|
"values" : {
|
||||||
|
"ImageType" : "Gold",
|
||||||
|
"ImageVersion" : "1.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"rel" : "self",
|
||||||
|
"href" : "http://servers.api.openstack.org/v1.1/1234/images/1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"rel" : "bookmark",
|
||||||
|
"type" : "application/vnd.openstack.compute-v1.1+xml",
|
||||||
|
"href" : "http://servers.api.openstack.org/1234/images/1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"rel" : "bookmark",
|
||||||
|
"type" : "application/vnd.openstack.compute-v1.1+json",
|
||||||
|
"href" : "http://servers.api.openstack.org/1234/images/1"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@
|
||||||
{
|
{
|
||||||
"rel" : "bookmark",
|
"rel" : "bookmark",
|
||||||
"type" : "application/vnd.openstack.compute-v1.1+json",
|
"type" : "application/vnd.openstack.compute-v1.1+json",
|
||||||
"href" : "http://servers.api.openstack.org/1234/servers/5678"
|
"href" : "http://servers.api.openstack.org/1234/servers/56789"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue