You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by de...@apache.org on 2016/02/19 16:33:18 UTC
[08/35] jclouds git commit: JCLOUDS-702: JClouds ProfitBricks
provider - Storage API
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a219a99/providers/profitbricks/src/test/java/org/jclouds/profitbricks/domain/ServerBuilderTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/domain/ServerBuilderTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/domain/ServerBuilderTest.java
index f5f7a20..c04f65c 100644
--- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/domain/ServerBuilderTest.java
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/domain/ServerBuilderTest.java
@@ -20,7 +20,7 @@ import java.util.Date;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
-@Test( groups = "unit", testName = "ServerBuilderTest" )
+@Test(groups = "unit", testName = "ServerBuilderTest")
public class ServerBuilderTest {
private final Boolean _isCpuHotPlug = true;
@@ -46,119 +46,117 @@ public class ServerBuilderTest {
private final String _bootFromStorageId = "some-random-storage-id";
private final String _bootFromImageId = "some-random-image-id";
- private final String _serverId = "some-random-server-id";
-
@Test
public void testAutoValueServerPropertiesSettingCorrectly() {
Server actual = Server.builder()
- .availabilityZone( _availabilityZone )
- .creationTime( _creationTime )
- .cores( _cores )
- .hasInternetAccess( _hasInternetAccess )
- .id( _id )
- .name( _name )
- .isCpuHotPlug( _isCpuHotPlug )
- .isDiscVirtioHotPlug( _isDiscVirtioHotPlug )
- .isDiscVirtioHotUnPlug( _isDiscVirtioHotUnPlug )
- .isNicHotPlug( _isNicHotPlug )
- .isNicHotUnPlug( _isNicHotUnPlug )
- .isRamHotPlug( _isRamHotPlug )
- .lastModificationTime( _lastModificationTime )
- .ram( _ram )
- .osType( _osType )
- .state( _state )
- .status( _status )
+ .availabilityZone(_availabilityZone)
+ .creationTime(_creationTime)
+ .cores(_cores)
+ .hasInternetAccess(_hasInternetAccess)
+ .id(_id)
+ .name(_name)
+ .isCpuHotPlug(_isCpuHotPlug)
+ .isDiscVirtioHotPlug(_isDiscVirtioHotPlug)
+ .isDiscVirtioHotUnPlug(_isDiscVirtioHotUnPlug)
+ .isNicHotPlug(_isNicHotPlug)
+ .isNicHotUnPlug(_isNicHotUnPlug)
+ .isRamHotPlug(_isRamHotPlug)
+ .lastModificationTime(_lastModificationTime)
+ .ram(_ram)
+ .osType(_osType)
+ .state(_state)
+ .status(_status)
.build();
- assertEquals( actual.availabilityZone(), _availabilityZone );
- assertEquals( actual.cores(), _cores );
- assertEquals( actual.creationTime(), _creationTime );
- assertEquals( actual.hasInternetAccess(), _hasInternetAccess );
- assertEquals( actual.id(), _id );
- assertEquals( actual.name(), _name );
- assertEquals( actual.isCpuHotPlug(), _isCpuHotPlug );
- assertEquals( actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug );
- assertEquals( actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug );
- assertEquals( actual.isNicHotPlug(), _isNicHotPlug );
- assertEquals( actual.isNicHotUnPlug(), _isNicHotUnPlug );
- assertEquals( actual.isRamHotPlug(), _isRamHotPlug );
- assertEquals( actual.lastModificationTime(), _lastModificationTime );
- assertEquals( actual.ram(), _ram );
- assertEquals( actual.osType(), _osType );
- assertEquals( actual.state(), _state );
+ assertEquals(actual.availabilityZone(), _availabilityZone);
+ assertEquals(actual.cores(), _cores);
+ assertEquals(actual.creationTime(), _creationTime);
+ assertEquals(actual.hasInternetAccess(), _hasInternetAccess);
+ assertEquals(actual.id(), _id);
+ assertEquals(actual.name(), _name);
+ assertEquals(actual.isCpuHotPlug(), _isCpuHotPlug);
+ assertEquals(actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug);
+ assertEquals(actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug);
+ assertEquals(actual.isNicHotPlug(), _isNicHotPlug);
+ assertEquals(actual.isNicHotUnPlug(), _isNicHotUnPlug);
+ assertEquals(actual.isRamHotPlug(), _isRamHotPlug);
+ assertEquals(actual.lastModificationTime(), _lastModificationTime);
+ assertEquals(actual.ram(), _ram);
+ assertEquals(actual.osType(), _osType);
+ assertEquals(actual.state(), _state);
}
@Test
public void testAutoValueServerRequestCreatePayloadPropertiesSettingCorrectly() {
Server.Request.CreatePayload actual = Server.Request.creatingBuilder()
- .availabilityZone( _availabilityZone )
- .bootFromImageId( _bootFromImageId )
- .bootFromStorageId( _bootFromStorageId )
- .cores( _cores )
- .dataCenterId( _dataCenterId )
- .hasInternetAccess( _hasInternetAccess )
- .name( _name )
- .isCpuHotPlug( _isCpuHotPlug )
- .isDiscVirtioHotPlug( _isDiscVirtioHotPlug )
- .isDiscVirtioHotUnPlug( _isDiscVirtioHotUnPlug )
- .isNicHotPlug( _isNicHotPlug )
- .isNicHotUnPlug( _isNicHotUnPlug )
- .isRamHotPlug( _isRamHotPlug )
- .lanId( _lanId )
- .ram( _ram )
- .osType( _osType )
+ .availabilityZone(_availabilityZone)
+ .bootFromImageId(_bootFromImageId)
+ .bootFromStorageId(_bootFromStorageId)
+ .cores(_cores)
+ .dataCenterId(_dataCenterId)
+ .hasInternetAccess(_hasInternetAccess)
+ .name(_name)
+ .isCpuHotPlug(_isCpuHotPlug)
+ .isDiscVirtioHotPlug(_isDiscVirtioHotPlug)
+ .isDiscVirtioHotUnPlug(_isDiscVirtioHotUnPlug)
+ .isNicHotPlug(_isNicHotPlug)
+ .isNicHotUnPlug(_isNicHotUnPlug)
+ .isRamHotPlug(_isRamHotPlug)
+ .lanId(_lanId)
+ .ram(_ram)
+ .osType(_osType)
.build();
- assertEquals( actual.availabilityZone(), _availabilityZone );
- assertEquals( actual.bootFromImageId(), _bootFromImageId );
- assertEquals( actual.bootFromStorageId(), _bootFromStorageId );
- assertEquals( actual.cores(), _cores );
- assertEquals( actual.dataCenterId(), _dataCenterId );
- assertEquals( actual.hasInternetAccess(), _hasInternetAccess );
- assertEquals( actual.name(), _name );
- assertEquals( actual.isCpuHotPlug(), _isCpuHotPlug );
- assertEquals( actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug );
- assertEquals( actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug );
- assertEquals( actual.isNicHotPlug(), _isNicHotPlug );
- assertEquals( actual.isNicHotUnPlug(), _isNicHotUnPlug );
- assertEquals( actual.isRamHotPlug(), _isRamHotPlug );
- assertEquals( actual.lanId(), _lanId );
- assertEquals( actual.ram(), _ram );
- assertEquals( actual.osType(), _osType );
+ assertEquals(actual.availabilityZone(), _availabilityZone);
+ assertEquals(actual.bootFromImageId(), _bootFromImageId);
+ assertEquals(actual.bootFromStorageId(), _bootFromStorageId);
+ assertEquals(actual.cores(), _cores);
+ assertEquals(actual.dataCenterId(), _dataCenterId);
+ assertEquals(actual.hasInternetAccess(), _hasInternetAccess);
+ assertEquals(actual.name(), _name);
+ assertEquals(actual.isCpuHotPlug(), _isCpuHotPlug);
+ assertEquals(actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug);
+ assertEquals(actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug);
+ assertEquals(actual.isNicHotPlug(), _isNicHotPlug);
+ assertEquals(actual.isNicHotUnPlug(), _isNicHotUnPlug);
+ assertEquals(actual.isRamHotPlug(), _isRamHotPlug);
+ assertEquals(actual.lanId(), _lanId);
+ assertEquals(actual.ram(), _ram);
+ assertEquals(actual.osType(), _osType);
}
@Test
public void testAutoValueServerRequestUpdatePayloadPropertiesSettingCorrectly() {
Server.Request.UpdatePayload actual = Server.Request.updatingBuilder()
- .availabilityZone( _availabilityZone )
- .bootFromImageId( _bootFromImageId )
- .bootFromStorageId( _bootFromStorageId )
- .cores( _cores )
- .name( _name )
- .id( _id )
- .isCpuHotPlug( _isCpuHotPlug )
- .isDiscVirtioHotPlug( _isDiscVirtioHotPlug )
- .isDiscVirtioHotUnPlug( _isDiscVirtioHotUnPlug )
- .isNicHotPlug( _isNicHotPlug )
- .isNicHotUnPlug( _isNicHotUnPlug )
- .isRamHotPlug( _isRamHotPlug )
- .ram( _ram )
- .osType( _osType )
+ .availabilityZone(_availabilityZone)
+ .bootFromImageId(_bootFromImageId)
+ .bootFromStorageId(_bootFromStorageId)
+ .cores(_cores)
+ .name(_name)
+ .id(_id)
+ .isCpuHotPlug(_isCpuHotPlug)
+ .isDiscVirtioHotPlug(_isDiscVirtioHotPlug)
+ .isDiscVirtioHotUnPlug(_isDiscVirtioHotUnPlug)
+ .isNicHotPlug(_isNicHotPlug)
+ .isNicHotUnPlug(_isNicHotUnPlug)
+ .isRamHotPlug(_isRamHotPlug)
+ .ram(_ram)
+ .osType(_osType)
.build();
- assertEquals( actual.availabilityZone(), _availabilityZone );
- assertEquals( actual.bootFromImageId(), _bootFromImageId );
- assertEquals( actual.bootFromStorageId(), _bootFromStorageId );
- assertEquals( actual.cores(), _cores );
- assertEquals( actual.name(), _name );
- assertEquals( actual.id(), _id );
- assertEquals( actual.isCpuHotPlug(), _isCpuHotPlug );
- assertEquals( actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug );
- assertEquals( actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug );
- assertEquals( actual.isNicHotPlug(), _isNicHotPlug );
- assertEquals( actual.isNicHotUnPlug(), _isNicHotUnPlug );
- assertEquals( actual.isRamHotPlug(), _isRamHotPlug );
- assertEquals( actual.ram(), _ram );
- assertEquals( actual.osType(), _osType );
+ assertEquals(actual.availabilityZone(), _availabilityZone);
+ assertEquals(actual.bootFromImageId(), _bootFromImageId);
+ assertEquals(actual.bootFromStorageId(), _bootFromStorageId);
+ assertEquals(actual.cores(), _cores);
+ assertEquals(actual.name(), _name);
+ assertEquals(actual.id(), _id);
+ assertEquals(actual.isCpuHotPlug(), _isCpuHotPlug);
+ assertEquals(actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug);
+ assertEquals(actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug);
+ assertEquals(actual.isNicHotPlug(), _isNicHotPlug);
+ assertEquals(actual.isNicHotUnPlug(), _isNicHotUnPlug);
+ assertEquals(actual.isRamHotPlug(), _isRamHotPlug);
+ assertEquals(actual.ram(), _ram);
+ assertEquals(actual.osType(), _osType);
}
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a219a99/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java
index 5c05e4d..586487b 100644
--- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java
@@ -90,7 +90,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
String content = "<ws:getDataCenter><dataCenterId>" + id + "</dataCenterId></ws:getDataCenter>";
try {
DataCenter dataCenter = api.getDataCenter(id);
- assertRequestHasCommonProperties(server.takeRequest(), content );
+ assertRequestHasCommonProperties(server.takeRequest(), content);
assertNotNull(dataCenter);
assertEquals(dataCenter.id(), id);
} finally {
@@ -130,7 +130,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
String content = "<ws:getDataCenterState><dataCenterId>" + id + "</dataCenterId></ws:getDataCenterState>";
try {
ProvisioningState state = api.getDataCenterState(id);
- assertRequestHasCommonProperties(server.takeRequest(), content );
+ assertRequestHasCommonProperties(server.takeRequest(), content);
assertNotNull(state);
assertEquals(state, ProvisioningState.AVAILABLE);
} finally {
@@ -155,7 +155,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
DataCenter dataCenter = api.createDataCenter(
DataCenter.Request.CreatePayload.create("JClouds-DC", Location.DE_FRA)
);
- assertRequestHasCommonProperties(server.takeRequest(), content );
+ assertRequestHasCommonProperties(server.takeRequest(), content);
assertNotNull(dataCenter);
assertEquals(dataCenter.id(), "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
assertEquals(dataCenter.version(), 1);
@@ -168,14 +168,13 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
@Test
public void testCreateDataCenterWithIllegalArguments() throws Exception {
String[] names = {"JCl@ouds", "JC|ouds", "^clouds", ""};
- for (String name : names) {
+ for (String name : names)
try {
DataCenter.Request.CreatePayload.create(name, Location.US_LAS);
fail("Should have failed for name: ".concat(name));
} catch (IllegalArgumentException ex) {
// expected exception
}
- }
}
@Test
@@ -185,10 +184,10 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
DataCenterApi api = pbApi.dataCenterApi();
-
+
String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
String newName = "Apache";
-
+
String content = "<ws:updateDataCenter><request>"
+ "<dataCenterId>" + id + "</dataCenterId>"
+ "<dataCenterName>" + newName + "</dataCenterName>"
@@ -216,7 +215,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
DataCenterApi api = pbApi.dataCenterApi();
String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
-
+
String content = "<ws:clearDataCenter><dataCenterId>" + id + "</dataCenterId></ws:clearDataCenter>";
try {
DataCenter dataCenter = api.clearDataCenter(id);
@@ -240,7 +239,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
DataCenterApi api = pbApi.dataCenterApi();
String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
-
+
String content = "<ws:deleteDataCenter><dataCenterId>" + id + "</dataCenterId></ws:deleteDataCenter>";
try {
boolean result = api.deleteDataCenter(id);
@@ -255,7 +254,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
@Test
public void testDeleteNonExistingDataCenter() throws Exception {
MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode( 404 ));
+ server.enqueue(new MockResponse().setResponseCode(404));
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
DataCenterApi api = pbApi.dataCenterApi();
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a219a99/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiMockTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiMockTest.java
index f1229ae..6e97541 100644
--- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiMockTest.java
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiMockTest.java
@@ -81,7 +81,7 @@ public class ImageApiMockTest extends BaseProfitBricksMockTest {
ImageApi api = pbApi.imageApi();
String id = "5ad99c9e-9166-11e4-9d74-52540066fee9";
-
+
String content = "<ws:getImage><imageId>" + id + "</imageId></ws:getImage>";
try {
Image image = api.getImage(id);
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a219a99/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiLiveTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiLiveTest.java
index 3237e9c..e7b1b9c 100644
--- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiLiveTest.java
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiLiveTest.java
@@ -34,7 +34,7 @@ import static org.testng.Assert.assertTrue;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
-@Test( groups = "live", testName = "ServerApiLiveTest", singleThreaded = true )
+@Test(groups = "live", testName = "ServerApiLiveTest", singleThreaded = true)
public class ServerApiLiveTest extends BaseProfitBricksLiveTest {
private Predicate<String> waitUntilAvailable;
@@ -45,94 +45,94 @@ public class ServerApiLiveTest extends BaseProfitBricksLiveTest {
protected void initialize() {
super.initialize();
List<DataCenter> dataCenters = api.dataCenterApi().getAllDataCenters();
- assertFalse( dataCenters.isEmpty(), "Must atleast have 1 datacenter available for server testing." );
+ assertFalse(dataCenters.isEmpty(), "Must atleast have 1 datacenter available for server testing.");
- this.dataCenter = Iterables.getFirst( dataCenters, null );
+ this.dataCenter = Iterables.getFirst(dataCenters, null);
this.waitUntilAvailable = Predicates2.retry(
- new ProvisioningStatusPollingPredicate( api, ProvisioningStatusAware.SERVER, ProvisioningState.AVAILABLE ),
- 2l * 60l, 2l, TimeUnit.SECONDS );
+ new ProvisioningStatusPollingPredicate(api, ProvisioningStatusAware.SERVER, ProvisioningState.AVAILABLE),
+ 2l * 60l, 2l, TimeUnit.SECONDS);
}
@Test
public void testCreateServer() {
String serverId = api.serverApi().createServer(
- Server.Request.CreatePayload.create( dataCenter.id(), "jclouds-node", 1, 1024 ) );
+ Server.Request.CreatePayload.create(dataCenter.id(), "jclouds-node", 1, 1024));
- assertNotNull( serverId );
+ assertNotNull(serverId);
this.createdServerId = serverId;
}
- @Test( dependsOnMethods = "testCreateServer" )
+ @Test(dependsOnMethods = "testCreateServer")
public void testGetServer() {
- Server server = api.serverApi().getServer( createdServerId );
+ Server server = api.serverApi().getServer(createdServerId);
- assertNotNull( server );
- assertEquals( server.id(), createdServerId );
+ assertNotNull(server);
+ assertEquals(server.id(), createdServerId);
}
- @Test( dependsOnMethods = "testCreateServer" )
+ @Test(dependsOnMethods = "testCreateServer")
public void testGetAllServers() {
List<Server> servers = api.serverApi().getAllServers();
- assertNotNull( servers );
- assertFalse( servers.isEmpty() );
+ assertNotNull(servers);
+ assertFalse(servers.isEmpty());
}
- @Test( dependsOnMethods = "testCreateServer" )
+ @Test(dependsOnMethods = "testCreateServer")
public void testWaitUntilAvailable() {
- boolean available = waitUntilAvailable.apply( createdServerId );
+ boolean available = waitUntilAvailable.apply(createdServerId);
- assertTrue( available );
+ assertTrue(available);
}
- @Test( dependsOnMethods = "testWaitUntilAvailable" )
+ @Test(dependsOnMethods = "testWaitUntilAvailable")
public void testUpdateServer() {
String requestId = api.serverApi().updateServer(
Server.Request.updatingBuilder()
- .id( createdServerId )
- .name( "apache-node" )
- .cores( 2 )
- .ram( 2 * 1024 )
- .build() );
+ .id(createdServerId)
+ .name("apache-node")
+ .cores(2)
+ .ram(2 * 1024)
+ .build());
- assertNotNull( requestId );
- waitUntilAvailable.apply( createdServerId );
+ assertNotNull(requestId);
+ waitUntilAvailable.apply(createdServerId);
- Server server = api.serverApi().getServer( createdServerId );
- assertEquals( server.state(), ProvisioningState.AVAILABLE );
+ Server server = api.serverApi().getServer(createdServerId);
+ assertEquals(server.state(), ProvisioningState.AVAILABLE);
}
- @Test( dependsOnMethods = "testUpdateServer" )
+ @Test(dependsOnMethods = "testUpdateServer")
public void testStopServer() {
- String requestId = api.serverApi().stopServer( createdServerId );
- assertNotNull( requestId );
+ String requestId = api.serverApi().stopServer(createdServerId);
+ assertNotNull(requestId);
- Predicate<String> waitUntilInactive = Predicates2.retry( new ProvisioningStatusPollingPredicate(
- api, ProvisioningStatusAware.SERVER, ProvisioningState.INACTIVE ), 2l * 60l, 2l, TimeUnit.SECONDS );
+ Predicate<String> waitUntilInactive = Predicates2.retry(new ProvisioningStatusPollingPredicate(
+ api, ProvisioningStatusAware.SERVER, ProvisioningState.INACTIVE), 2l * 60l, 2l, TimeUnit.SECONDS);
- waitUntilInactive.apply( createdServerId );
- Server server = api.serverApi().getServer( createdServerId );
- assertEquals( server.status(), Server.Status.SHUTOFF );
+ waitUntilInactive.apply(createdServerId);
+ Server server = api.serverApi().getServer(createdServerId);
+ assertEquals(server.status(), Server.Status.SHUTOFF);
}
- @Test( dependsOnMethods = "testStopServer" )
+ @Test(dependsOnMethods = "testStopServer")
public void testStartServer() {
- String requestId = api.serverApi().startServer( createdServerId );
- assertNotNull( requestId );
+ String requestId = api.serverApi().startServer(createdServerId);
+ assertNotNull(requestId);
- waitUntilAvailable.apply( createdServerId );
+ waitUntilAvailable.apply(createdServerId);
- Server server = api.serverApi().getServer( createdServerId );
- assertEquals( server.status(), Server.Status.RUNNING );
+ Server server = api.serverApi().getServer(createdServerId);
+ assertEquals(server.status(), Server.Status.RUNNING);
}
- @AfterClass( alwaysRun = true )
+ @AfterClass(alwaysRun = true)
public void testDeleteServer() {
- if ( createdServerId != null ) {
- boolean result = api.serverApi().deleteServer( createdServerId );
+ if (createdServerId != null) {
+ boolean result = api.serverApi().deleteServer(createdServerId);
- assertTrue( result, "Created test server was not deleted." );
+ assertTrue(result, "Created test server was not deleted.");
}
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a219a99/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiMockTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiMockTest.java
index d9fd478..47738b8 100644
--- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiMockTest.java
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiMockTest.java
@@ -16,39 +16,45 @@
*/
package org.jclouds.profitbricks.features;
+import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer;
+
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
+
import java.util.List;
+
import org.jclouds.profitbricks.ProfitBricksApi;
import org.jclouds.profitbricks.domain.AvailabilityZone;
import org.jclouds.profitbricks.domain.OsType;
import org.jclouds.profitbricks.domain.Server;
import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
-import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer;
import org.jclouds.rest.ResourceNotFoundException;
+
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
+
import org.testng.annotations.Test;
-@Test( groups = "unit", testName = "ServerApiMockTest" )
+@Test(groups = "unit", testName = "ServerApiMockTest")
public class ServerApiMockTest extends BaseProfitBricksMockTest {
@Test
public void testGetAllServers() throws Exception {
MockWebServer server = mockWebServer();
- server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/servers.xml" ) ) );
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/server/servers.xml")));
- ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
ServerApi api = pbApi.serverApi();
try {
List<Server> servers = api.getAllServers();
- assertRequestHasCommonProperties( server.takeRequest(), "<ws:getAllServers/>" );
- assertNotNull( servers );
- assertTrue( servers.size() == 2 );
+ assertRequestHasCommonProperties(server.takeRequest(), "<ws:getAllServers/>");
+ assertNotNull(servers);
+ assertTrue(servers.size() == 2);
} finally {
pbApi.close();
server.shutdown();
@@ -58,15 +64,15 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
@Test
public void testGetAllServersReturning404() throws Exception {
MockWebServer server = mockWebServer();
- server.enqueue( new MockResponse().setResponseCode( 404 ) );
+ server.enqueue(new MockResponse().setResponseCode(404));
- ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
ServerApi api = pbApi.serverApi();
try {
List<Server> servers = api.getAllServers();
- assertRequestHasCommonProperties( server.takeRequest() );
- assertTrue( servers.isEmpty() );
+ assertRequestHasCommonProperties(server.takeRequest());
+ assertTrue(servers.isEmpty());
} finally {
pbApi.close();
server.shutdown();
@@ -76,19 +82,19 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
@Test
public void testGetServer() throws Exception {
MockWebServer server = mockWebServer();
- server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server.xml" ) ) );
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server.xml")));
- ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
ServerApi api = pbApi.serverApi();
String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
String content = "<ws:getServer><serverId>" + id + "</serverId></ws:getServer>";
try {
- Server svr = api.getServer( id );
- assertRequestHasCommonProperties( server.takeRequest(), content );
- assertNotNull( svr );
- assertEquals( svr.id(), id );
+ Server svr = api.getServer(id);
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(svr);
+ assertEquals(svr.id(), id);
} finally {
pbApi.close();
server.shutdown();
@@ -98,16 +104,16 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
@Test
public void testGetNonExistingServer() throws Exception {
MockWebServer server = mockWebServer();
- server.enqueue( new MockResponse().setResponseCode( 404 ) );
+ server.enqueue(new MockResponse().setResponseCode(404));
- ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
ServerApi api = pbApi.serverApi();
String id = "random-non-existing-id";
try {
- Server srvr = api.getServer( id );
- assertRequestHasCommonProperties( server.takeRequest() );
- assertNull( srvr );
+ Server srvr = api.getServer(id);
+ assertRequestHasCommonProperties(server.takeRequest());
+ assertNull(srvr);
} finally {
pbApi.close();
@@ -118,18 +124,18 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
@Test
public void testStartServer() throws Exception {
MockWebServer server = mockWebServer();
- server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-start.xml" ) ) );
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-start.xml")));
- ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
ServerApi api = pbApi.serverApi();
String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
String content = "<ws:startServer><serverId>" + id + "</serverId></ws:startServer>";
try {
- String requestId = api.startServer( id );
- assertRequestHasCommonProperties( server.takeRequest(), content );
- assertEquals( requestId, "123456" );
+ String requestId = api.startServer(id);
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertEquals(requestId, "123456");
} finally {
pbApi.close();
server.shutdown();
@@ -139,17 +145,17 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
@Test
public void testStartNonExistingServer() throws Exception {
MockWebServer server = mockWebServer();
- server.enqueue( new MockResponse().setResponseCode( 500 ).setBody( payloadFromResource( "/fault-404.xml" ) ) );
+ server.enqueue(new MockResponse().setResponseCode(500).setBody(payloadFromResource("/fault-404.xml")));
- ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
ServerApi api = pbApi.serverApi();
String id = "random-non-existing-id";
try {
- String requestId = api.startServer( id );
- assertRequestHasCommonProperties( server.takeRequest() );
- fail( "Should've failed." );
- } catch ( ResourceNotFoundException ex ) {
+ String requestId = api.startServer(id);
+ assertRequestHasCommonProperties(server.takeRequest());
+ fail("Should've failed.");
+ } catch (ResourceNotFoundException ex) {
// expected exception
} finally {
pbApi.close();
@@ -160,18 +166,18 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
@Test
public void testStopServer() throws Exception {
MockWebServer server = mockWebServer();
- server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-stop.xml" ) ) );
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-stop.xml")));
- ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
ServerApi api = pbApi.serverApi();
String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
String content = "<ws:stopServer><serverId>" + id + "</serverId></ws:stopServer>";
try {
- String requestId = api.stopServer( id );
- assertRequestHasCommonProperties( server.takeRequest(), content );
- assertEquals( requestId, "123456" );
+ String requestId = api.stopServer(id);
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertEquals(requestId, "123456");
} finally {
pbApi.close();
server.shutdown();
@@ -181,18 +187,18 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
@Test
public void testResetServer() throws Exception {
MockWebServer server = mockWebServer();
- server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-reset.xml" ) ) );
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-reset.xml")));
- ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
ServerApi api = pbApi.serverApi();
String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
String content = "<ws:resetServer><serverId>" + id + "</serverId></ws:resetServer>";
try {
- String requestId = api.resetServer( id );
- assertRequestHasCommonProperties( server.takeRequest(), content );
- assertEquals( requestId, "123456" );
+ String requestId = api.resetServer(id);
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertEquals(requestId, "123456");
} finally {
pbApi.close();
server.shutdown();
@@ -202,9 +208,9 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
@Test
public void testCreateServer() throws Exception {
MockWebServer server = mockWebServer();
- server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-create.xml" ) ) );
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-create.xml")));
- ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
ServerApi api = pbApi.serverApi();
String dataCenterId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
@@ -233,26 +239,26 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
+ "</ws:createServer>";
try {
- String serverId = api.createServer( Server.Request.creatingBuilder()
- .dataCenterId( dataCenterId )
- .name( name )
- .cores( 4 )
- .ram( 4 * 1024 )
- .bootFromImageId( imageId )
- .hasInternetAccess( Boolean.TRUE )
- .lanId( 2 )
- .osType( OsType.LINUX )
- .availabilityZone( AvailabilityZone.ZONE_1 )
- .isCpuHotPlug( Boolean.TRUE )
- .isRamHotPlug( Boolean.FALSE )
- .isNicHotPlug( Boolean.TRUE )
- .isNicHotUnPlug( Boolean.FALSE )
- .isDiscVirtioHotPlug( Boolean.TRUE )
- .isDiscVirtioHotUnPlug( Boolean.FALSE )
- .build() );
- assertRequestHasCommonProperties( server.takeRequest(), content );
- assertNotNull( serverId );
- assertEquals( serverId, "qwertyui-qwer-qwer-qwer-qwertyyuiiop" );
+ String serverId = api.createServer(Server.Request.creatingBuilder()
+ .dataCenterId(dataCenterId)
+ .name(name)
+ .cores(4)
+ .ram(4 * 1024)
+ .bootFromImageId(imageId)
+ .hasInternetAccess(Boolean.TRUE)
+ .lanId(2)
+ .osType(OsType.LINUX)
+ .availabilityZone(AvailabilityZone.ZONE_1)
+ .isCpuHotPlug(Boolean.TRUE)
+ .isRamHotPlug(Boolean.FALSE)
+ .isNicHotPlug(Boolean.TRUE)
+ .isNicHotUnPlug(Boolean.FALSE)
+ .isDiscVirtioHotPlug(Boolean.TRUE)
+ .isDiscVirtioHotUnPlug(Boolean.FALSE)
+ .build());
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(serverId);
+ assertEquals(serverId, "qwertyui-qwer-qwer-qwer-qwertyyuiiop");
} finally {
pbApi.close();
server.shutdown();
@@ -262,9 +268,9 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
@Test
public void testUpdateServer() throws Exception {
MockWebServer server = mockWebServer();
- server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-update.xml" ) ) );
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-update.xml")));
- ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
ServerApi api = pbApi.serverApi();
String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
@@ -278,7 +284,7 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
+ "<ram>8192</ram>"
+ "<serverName>" + newName + "</serverName>"
+ "<bootFromStorageId>" + storageId + "</bootFromStorageId>"
-// + "<bootFromImageId>?</bootFromImageId>"
+ // + "<bootFromImageId>?</bootFromImageId>"
+ "<osType>OTHER</osType>"
+ "<availabilityZone>AUTO</availabilityZone>"
+ "<cpuHotPlug>false</cpuHotPlug>"
@@ -290,24 +296,24 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
+ "</request>"
+ "</ws:updateServer>";
try {
- String requestId = api.updateServer( Server.Request.updatingBuilder()
- .id( serverId )
- .name( newName )
- .cores( 8 )
- .ram( 8 * 1024 )
- .bootFromStorageId( storageId )
- .osType( OsType.OTHER )
- .availabilityZone( AvailabilityZone.AUTO )
- .isCpuHotPlug( false )
- .isRamHotPlug( true )
- .isNicHotPlug( false )
- .isNicHotUnPlug( true )
- .isDiscVirtioHotPlug( false )
- .isDiscVirtioHotUnPlug( true )
- .build() );
- assertRequestHasCommonProperties( server.takeRequest(), content );
- assertNotNull( requestId );
- assertEquals( requestId, "102458" );
+ String requestId = api.updateServer(Server.Request.updatingBuilder()
+ .id(serverId)
+ .name(newName)
+ .cores(8)
+ .ram(8 * 1024)
+ .bootFromStorageId(storageId)
+ .osType(OsType.OTHER)
+ .availabilityZone(AvailabilityZone.AUTO)
+ .isCpuHotPlug(false)
+ .isRamHotPlug(true)
+ .isNicHotPlug(false)
+ .isNicHotUnPlug(true)
+ .isDiscVirtioHotPlug(false)
+ .isDiscVirtioHotUnPlug(true)
+ .build());
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(requestId);
+ assertEquals(requestId, "102458");
} finally {
pbApi.close();
server.shutdown();
@@ -317,22 +323,41 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest {
@Test
public void testDeleteServer() throws Exception {
MockWebServer server = mockWebServer();
- server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-delete.xml" ) ) );
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-delete.xml")));
- ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
ServerApi api = pbApi.serverApi();
String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
-
+
String content = "<ws:deleteServer><serverId>" + serverId + "</serverId></ws:deleteServer>";
try {
- boolean result = api.deleteServer( serverId );
- assertRequestHasCommonProperties( server.takeRequest(), content );
- assertTrue( result );
+ boolean result = api.deleteServer(serverId);
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertTrue(result);
} finally {
pbApi.close();
server.shutdown();
}
}
+
+ @Test
+ public void testDeleteNonExistingServer() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(404));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ ServerApi api = pbApi.serverApi();
+
+ String id = "random-non-existing-id";
+ try {
+ boolean result = api.deleteServer(id);
+ assertRequestHasCommonProperties(server.takeRequest());
+ assertFalse(result);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a219a99/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiLiveTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiLiveTest.java
new file mode 100644
index 0000000..6295701
--- /dev/null
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiLiveTest.java
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.profitbricks.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.jclouds.profitbricks.BaseProfitBricksLiveTest;
+import org.jclouds.profitbricks.compute.internal.ProvisioningStatusAware;
+import org.jclouds.profitbricks.compute.internal.ProvisioningStatusPollingPredicate;
+import org.jclouds.profitbricks.domain.DataCenter;
+import org.jclouds.profitbricks.domain.ProvisioningState;
+import org.jclouds.profitbricks.domain.Server;
+import org.jclouds.profitbricks.domain.Storage;
+import org.jclouds.rest.InsufficientResourcesException;
+import org.jclouds.util.Predicates2;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+@Test(groups = "live", testName = "StorageApiLiveTest", singleThreaded = true)
+public class StorageApiLiveTest extends BaseProfitBricksLiveTest {
+
+ private Predicate<String> waitUntilAvailable;
+ private DataCenter dataCenter;
+ private Server server;
+ private String createdStorageId;
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+ List<DataCenter> dataCenters = api.dataCenterApi().getAllDataCenters();
+ assertFalse(dataCenters.isEmpty(), "Must atleast have 1 datacenter available for storage testing.");
+
+ dataCenter = Iterables.getFirst(dataCenters, null);
+ if (dataCenter != null)
+ dataCenter = api.dataCenterApi().getDataCenter(dataCenter.id()); // fetch individual to load more properties
+
+ this.waitUntilAvailable = Predicates2.retry(
+ new ProvisioningStatusPollingPredicate(api, ProvisioningStatusAware.STORAGE, ProvisioningState.AVAILABLE),
+ 6l * 60l, 2l, TimeUnit.SECONDS);
+ }
+
+ @Test(expectedExceptions = InsufficientResourcesException.class)
+ public void testUberStorage() {
+ api.storageApi().createStorage(
+ Storage.Request.creatingBuilder()
+ .dataCenterId(dataCenter)
+ .name("Uber Storage")
+ .size(9999999f)
+ .build());
+ }
+
+ @Test
+ public void testCreateStorage() {
+ String storageId = api.storageApi().createStorage(
+ Storage.Request.creatingBuilder()
+ .dataCenterId(dataCenter)
+ .name("hdd-1")
+ .size(2f)
+ .build());
+
+ assertNotNull(storageId);
+ createdStorageId = storageId;
+ }
+
+ @Test(dependsOnMethods = "testCreateStorage")
+ public void testGetStorage() {
+ Storage storage = api.storageApi().getStorage(createdStorageId);
+
+ assertNotNull(storage);
+ assertEquals(storage.id(), createdStorageId);
+ }
+
+ @Test(dependsOnMethods = "testCreateStorage")
+ public void testGetAllStorages() {
+ List<Storage> storages = api.storageApi().getAllStorages();
+
+ assertNotNull(storages);
+ assertFalse(storages.isEmpty());
+ }
+
+ @Test(dependsOnMethods = "testCreateStorage")
+ public void testWaitUntilAvailable() {
+ boolean available = waitUntilAvailable.apply(createdStorageId);
+
+ assertTrue(available);
+ }
+
+ @Test(dependsOnMethods = "testWaitUntilAvailable")
+ public void testUpdateStorage() {
+ String requestId = api.storageApi().updateStorage(
+ Storage.Request.updatingBuilder()
+ .id(createdStorageId)
+ .name("hdd-2")
+ .size(5l)
+ .build());
+
+ assertNotNull(requestId);
+ waitUntilAvailable.apply(createdStorageId);
+
+ Storage storage = api.storageApi().getStorage(createdStorageId);
+ assertEquals(storage.size(), 5f);
+ assertEquals(storage.name(), "hdd-2");
+ }
+
+ @Test(dependsOnMethods = "testUpdateStorage")
+ public void testConnectStorage() {
+ server = Iterables.getFirst(dataCenter.servers(), null);
+ assertNotNull(server, "No server to attach to.");
+
+ String requestId = api.storageApi().connectStorageToServer(
+ Storage.Request.connectingBuilder()
+ .storageId(createdStorageId)
+ .serverId(server.id())
+ .build()
+ );
+
+ assertNotNull(requestId);
+ waitUntilAvailable.apply(createdStorageId);
+
+ Storage storage = api.storageApi().getStorage(createdStorageId);
+ assertTrue(storage.serverIds().contains(server.id()));
+ }
+
+ @Test(dependsOnMethods = "testConnectStorage")
+ public void testDisconnectStorage() {
+ String requestId = api.storageApi()
+ .disconnectStorageFromServer(createdStorageId, server.id());
+
+ assertNotNull(requestId);
+ waitUntilAvailable.apply(createdStorageId);
+
+ Storage storage = api.storageApi().getStorage(createdStorageId);
+ assertFalse(storage.serverIds().contains(server.id()));
+ }
+
+ @AfterClass(alwaysRun = true)
+ public void testDeleteStorage() {
+ if (createdStorageId != null) {
+ boolean result = api.storageApi().deleteStorage(createdStorageId);
+
+ assertTrue(result, "Created test storage was not delete.");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a219a99/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiMockTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiMockTest.java
new file mode 100644
index 0000000..10a4a49
--- /dev/null
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiMockTest.java
@@ -0,0 +1,285 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.profitbricks.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.List;
+
+import org.jclouds.profitbricks.ProfitBricksApi;
+import org.jclouds.profitbricks.domain.Storage;
+import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
+import org.testng.annotations.Test;
+
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
+
+@Test(groups = "unit", testName = "StorageApiMockTest")
+public class StorageApiMockTest extends BaseProfitBricksMockTest {
+
+ @Test
+ public void testGetAllStorages() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storages.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ StorageApi api = pbApi.storageApi();
+
+ try {
+ List<Storage> storages = api.getAllStorages();
+ assertRequestHasCommonProperties(server.takeRequest(), "<ws:getAllStorages/>");
+ assertNotNull(storages);
+ assertTrue(storages.size() == 2);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testGetAllStoragesReturning404() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(404));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ StorageApi api = pbApi.storageApi();
+
+ try {
+ List<Storage> storages = api.getAllStorages();
+ assertRequestHasCommonProperties(server.takeRequest());
+ assertTrue(storages.isEmpty());
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testGetStorage() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ StorageApi api = pbApi.storageApi();
+
+ String id = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh";
+
+ String content = "<ws:getStorage><storageId>" + id + "</storageId></ws:getStorage>";
+ try {
+ Storage storage = api.getStorage(id);
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(storage);
+ assertEquals(storage.id(), id);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testGetNonExistingStorage() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(404));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ StorageApi api = pbApi.storageApi();
+
+ String id = "random-non-existing-id";
+ try {
+ Storage storage = api.getStorage(id);
+ assertRequestHasCommonProperties(server.takeRequest());
+ assertNull(storage);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testConnectStorageToServer() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-connect.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ StorageApi api = pbApi.storageApi();
+
+ String storageId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh";
+ String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
+
+ String content = "<ws:connectStorageToServer><request>"
+ + "<storageId>" + storageId + "</storageId>"
+ + "<serverId>" + serverId + "</serverId>"
+ + "<busType>VIRTIO</busType>"
+ + "<deviceNumber>2</deviceNumber>"
+ + "</request></ws:connectStorageToServer>";
+ try {
+ String requestId = api.connectStorageToServer(
+ Storage.Request.connectingBuilder()
+ .serverId(serverId)
+ .storageId(storageId)
+ .busType(Storage.BusType.VIRTIO)
+ .deviceNumber(2)
+ .build()
+ );
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertEquals(requestId, "16463317");
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testDisconnectStorageFromServer() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-disconnect.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ StorageApi api = pbApi.storageApi();
+
+ String storageId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh";
+ String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
+
+ String content = "<ws:disconnectStorageFromServer>"
+ + "<storageId>" + storageId + "</storageId>"
+ + "<serverId>" + serverId + "</serverId>"
+ + "</ws:disconnectStorageFromServer>";
+
+ try {
+ String requestId = api.disconnectStorageFromServer(storageId, serverId);
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertEquals(requestId, "16463318");
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testCreateStorage() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-create.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ StorageApi api = pbApi.storageApi();
+
+ String dataCenterId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
+ String imageId = "f0a59a5c-7940-11e4-8053-52540066fee9";
+
+ String content = "<ws:createStorage><request>"
+ + "<dataCenterId>" + dataCenterId + "</dataCenterId>"
+ + "<storageName>hdd-1</storageName>" + "<size>80</size>"
+ + "<mountImageId>" + imageId + "</mountImageId>"
+ + "<profitBricksImagePassword>qqqqqqqqq</profitBricksImagePassword>"
+ + "</request></ws:createStorage>";
+ try {
+ String storageId = api.createStorage(
+ Storage.Request.creatingBuilder()
+ .dataCenterId(dataCenterId)
+ .name("hdd-1")
+ .size(80f)
+ .mountImageId(imageId)
+ .imagePassword("qqqqqqqqq")
+ .build());
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(storageId);
+ assertEquals(storageId, "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh");
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testUpdateStorage() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-update.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ StorageApi api = pbApi.storageApi();
+
+ String storageId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh";
+ String imageId = "f4742db0-9160-11e4-9d74-52540066fee9";
+
+ String content = "<ws:updateStorage><request>"
+ + "<storageId>" + storageId + "</storageId>"
+ + "<size>20</size><storageName>hdd-2</storageName>"
+ + "<mountImageId>" + imageId + "</mountImageId>"
+ + "</request></ws:updateStorage>";
+ try {
+ String requestId = api.updateStorage(
+ Storage.Request.updatingBuilder()
+ .id(storageId)
+ .size(20f)
+ .name("hdd-2")
+ .mountImageId(imageId)
+ .build());
+
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertNotNull(requestId);
+ assertEquals(requestId, "1234568");
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testDeleteStorage() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-delete.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ StorageApi api = pbApi.storageApi();
+
+ String storageId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh";
+
+ String content = "<ws:deleteStorage><storageId>" + storageId + "</storageId></ws:deleteStorage>";
+
+ try {
+ boolean result = api.deleteStorage(storageId);
+ assertRequestHasCommonProperties(server.takeRequest(), content);
+ assertTrue(result);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testDeleteNonExistingStorage() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(404));
+
+ ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+ StorageApi api = pbApi.storageApi();
+
+ String id = "random-non-existing-id";
+ try {
+ boolean result = api.deleteStorage(id);
+ assertRequestHasCommonProperties(server.takeRequest());
+ assertFalse(result);
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a219a99/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java
index 9198840..8658e2d 100644
--- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java
@@ -20,12 +20,16 @@ import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWeb
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
+import org.jclouds.http.HttpResponseException;
import org.jclouds.profitbricks.ProfitBricksApi;
import org.jclouds.profitbricks.domain.DataCenter;
import org.jclouds.profitbricks.domain.Location;
+import org.jclouds.profitbricks.domain.Server;
import org.jclouds.profitbricks.features.DataCenterApi;
+import org.jclouds.profitbricks.features.ServerApi;
import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
import org.jclouds.rest.AuthorizationException;
+import org.jclouds.rest.InsufficientResourcesException;
import org.jclouds.rest.ResourceNotFoundException;
import org.testng.annotations.Test;
@@ -38,6 +42,8 @@ import com.squareup.okhttp.mockwebserver.MockWebServer;
@Test(groups = "unit", testName = "ResponseStatusFromPayloadHttpCommandExecutorServiceTest")
public class ResponseStatusFromPayloadHttpCommandExecutorServiceTest extends BaseProfitBricksMockTest {
+ private final int MAX_RETRIES = 5;
+
@Test
public void testNotFound() throws Exception {
MockWebServer server = mockWebServer();
@@ -95,4 +101,43 @@ public class ResponseStatusFromPayloadHttpCommandExecutorServiceTest extends Bas
server.shutdown();
}
}
+
+ @Test
+ public void testOverLimitSettings() throws Exception {
+ MockWebServer server = mockWebServer();
+ server.enqueue(new MockResponse().setResponseCode(503).setBody(payloadFromResource("/fault-413.xml")));
+
+ ProfitBricksApi pbApi = api(server.getUrl("/"));
+ ServerApi api = pbApi.serverApi();
+
+ try {
+ api.createServer(Server.Request.CreatePayload.create("some-datacenter-id", "node1", 99, 12800));
+ fail("Request should have failed.");
+ } catch (Exception ex) {
+ assertTrue(ex instanceof InsufficientResourcesException, "Exception should be InsufficientResourcesException");
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
+
+ @Test
+ public void testServiceUnderMaintenance() throws Exception {
+ MockWebServer server = mockWebServer();
+ for (int i = 0; i <= MAX_RETRIES; i++) // jclouds retries 5 times
+ server.enqueue(new MockResponse().setResponseCode(503).setBody(payloadFromResource("/maintenance-503.html")));
+
+ ProfitBricksApi pbApi = api(server.getUrl("/"));
+ DataCenterApi api = pbApi.dataCenterApi();
+
+ try {
+ api.clearDataCenter("some-datacenter-id");
+ fail("Request should have failed.");
+ } catch (Exception ex) {
+ assertTrue(ex instanceof HttpResponseException, "Exception should be HttpResponseException");
+ } finally {
+ pbApi.close();
+ server.shutdown();
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a219a99/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/filters/ProfitBricksSoapMessageEnvelopeTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/filters/ProfitBricksSoapMessageEnvelopeTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/filters/ProfitBricksSoapMessageEnvelopeTest.java
index e6b692b..7413d01 100644
--- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/filters/ProfitBricksSoapMessageEnvelopeTest.java
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/filters/ProfitBricksSoapMessageEnvelopeTest.java
@@ -28,9 +28,9 @@ import org.testng.annotations.Test;
public class ProfitBricksSoapMessageEnvelopeTest {
private final String SOAP_PREFIX
- = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">"
- + "<soapenv:Header/>"
- + "<soapenv:Body>";
+ = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">"
+ + "<soapenv:Header/>"
+ + "<soapenv:Body>";
private final String SOAP_SUFFIX = "</soapenv:Body></soapenv:Envelope>";
private final String endpoint = "https://api.profitbricks.com/1.3";
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a219a99/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/BaseResponseHandlerTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/BaseResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/BaseResponseHandlerTest.java
index 23bdbc9..d481735 100644
--- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/BaseResponseHandlerTest.java
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/BaseResponseHandlerTest.java
@@ -47,9 +47,9 @@ public abstract class BaseResponseHandlerTest<T> {
protected String payloadFromResource(String resource) {
try {
- return toStringAndClose(getClass().getResourceAsStream(resource));
+ return toStringAndClose(getClass().getResourceAsStream(resource));
} catch (IOException e) {
- throw Throwables.propagate(e);
+ throw Throwables.propagate(e);
}
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a219a99/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/RequestIdOnlyResponseHandlerTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/RequestIdOnlyResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/RequestIdOnlyResponseHandlerTest.java
index d32b656..3ea9ed8 100644
--- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/RequestIdOnlyResponseHandlerTest.java
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/RequestIdOnlyResponseHandlerTest.java
@@ -20,57 +20,57 @@ import org.jclouds.http.functions.ParseSax;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
-@Test( groups = "unit", testName = "RequestIdOnlyResponseHandlerTest" )
+@Test(groups = "unit", testName = "RequestIdOnlyResponseHandlerTest")
public class RequestIdOnlyResponseHandlerTest extends BaseResponseHandlerTest<String> {
@Override
protected ParseSax<String> createParser() {
- return factory.create( injector.getInstance( RequestIdOnlyResponseHandler.class ) );
+ return factory.create(injector.getInstance(RequestIdOnlyResponseHandler.class));
}
@Test
public void testParseResponseFromStartServer() {
ParseSax<String> parser = createParser();
- String requestId = parser.parse( payloadFromResource( "/server/server-start.xml" ) );
+ String requestId = parser.parse(payloadFromResource("/server/server-start.xml"));
- assertEquals( requestId, "123456" );
+ assertEquals(requestId, "123456");
}
@Test
public void testParseResponseFromStopServer() {
ParseSax<String> parser = createParser();
- String requestId = parser.parse( payloadFromResource( "/server/server-stop.xml" ) );
+ String requestId = parser.parse(payloadFromResource("/server/server-stop.xml"));
- assertEquals( requestId, "123456" );
+ assertEquals(requestId, "123456");
}
@Test
public void testParseResponseFromResetServer() {
ParseSax<String> parser = createParser();
- String requestId = parser.parse( payloadFromResource( "/server/server-reset.xml" ) );
+ String requestId = parser.parse(payloadFromResource("/server/server-reset.xml"));
- assertEquals( requestId, "123456" );
+ assertEquals(requestId, "123456");
}
@Test
public void testParseResponseFromUpdateServer() {
ParseSax<String> parser = createParser();
- String requestId = parser.parse( payloadFromResource( "/server/server-update.xml" ) );
+ String requestId = parser.parse(payloadFromResource("/server/server-update.xml"));
- assertEquals( requestId, "102458" );
+ assertEquals(requestId, "102458");
}
@Test
public void testParseResponseFromDeleteServer() {
ParseSax<String> parser = createParser();
- String requestId = parser.parse( payloadFromResource( "/server/server-delete.xml" ) );
+ String requestId = parser.parse(payloadFromResource("/server/server-delete.xml"));
- assertEquals( requestId, "102459" );
+ assertEquals(requestId, "102459");
}
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a219a99/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ServiceFaultResponseHandlerTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ServiceFaultResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ServiceFaultResponseHandlerTest.java
index cb84841..2b54dd5 100644
--- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ServiceFaultResponseHandlerTest.java
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ServiceFaultResponseHandlerTest.java
@@ -38,11 +38,11 @@ public class ServiceFaultResponseHandlerTest extends BaseResponseHandlerTest<Ser
assertNotNull(actual, "Parsed content returned null");
ServiceFault expected = ServiceFault.builder()
- .faultCode(ServiceFault.FaultCode.RESOURCE_NOT_FOUND)
- .httpCode(404)
- .message("The requested resource could not be found. Please refer to Request Id : 16370720. [VDC-6-404] The requested resource does not exist or already deleted by the users. ResourceId random-non-existing-id")
- .requestId(16370720)
- .build();
+ .faultCode(ServiceFault.FaultCode.RESOURCE_NOT_FOUND)
+ .httpCode(404)
+ .message("The requested resource could not be found. Please refer to Request Id : 16370720. [VDC-6-404] The requested resource does not exist or already deleted by the users. ResourceId random-non-existing-id")
+ .requestId(16370720)
+ .build();
assertEquals(expected, actual);
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a219a99/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterInfoResponseHandlerTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterInfoResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterInfoResponseHandlerTest.java
index 0a3a570..f9827b3 100644
--- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterInfoResponseHandlerTest.java
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterInfoResponseHandlerTest.java
@@ -19,14 +19,21 @@ package org.jclouds.profitbricks.http.parser.datacenter;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
-
+import org.jclouds.date.DateCodec;
+import org.jclouds.date.DateCodecFactory;
import org.jclouds.http.functions.ParseSax;
+import org.jclouds.profitbricks.domain.AvailabilityZone;
import org.jclouds.profitbricks.domain.DataCenter;
import org.jclouds.profitbricks.domain.Location;
+import org.jclouds.profitbricks.domain.OsType;
import org.jclouds.profitbricks.domain.ProvisioningState;
+import org.jclouds.profitbricks.domain.Server;
+import org.jclouds.profitbricks.domain.Storage;
import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest;
import org.testng.annotations.Test;
+import com.google.common.collect.ImmutableList;
+
@Test(groups = "unit", testName = "DataCenterInfoResponseHandlerTest")
public class DataCenterInfoResponseHandlerTest extends BaseResponseHandlerTest<DataCenter> {
@@ -35,19 +42,57 @@ public class DataCenterInfoResponseHandlerTest extends BaseResponseHandlerTest<D
return factory.create(injector.getInstance(DataCenterInfoResponseHandler.class));
}
+ protected DateCodecFactory createDateParser() {
+ return injector.getInstance(DateCodecFactory.class);
+ }
+
@Test
public void testParseResponseFromGetDataCenter() {
ParseSax<DataCenter> parser = createParser();
+
DataCenter actual = parser.parse(payloadFromResource("/datacenter/datacenter.xml"));
assertNotNull(actual, "Parsed content returned null");
+ DateCodec dateParser = createDateParser().iso8601();
+
DataCenter expected = DataCenter.builder()
- .id("12345678-abcd-efgh-ijkl-987654321000")
- .version(10)
- .name("JClouds-DC")
- .state(ProvisioningState.AVAILABLE)
- .location(Location.US_LAS)
- .build();
- assertEquals(expected, actual);
+ .id("12345678-abcd-efgh-ijkl-987654321000")
+ .version(10)
+ .name("JClouds-DC")
+ .state(ProvisioningState.AVAILABLE)
+ .location(Location.US_LAS)
+ .servers(ImmutableList.<Server>of(
+ Server.builder()
+ .id("12345678-abcd-efgh-ijkl-987654321000")
+ .name("jnode1")
+ .cores(4)
+ .ram(4096)
+ .hasInternetAccess(true)
+ .state(ProvisioningState.AVAILABLE)
+ .status(Server.Status.RUNNING)
+ .creationTime(dateParser.toDate("2014-12-04T07:09:23.138Z"))
+ .lastModificationTime(dateParser.toDate("2014-12-12T03:08:35.629Z"))
+ .osType(OsType.LINUX)
+ .availabilityZone(AvailabilityZone.AUTO)
+ .isCpuHotPlug(true)
+ .isRamHotPlug(true)
+ .isNicHotPlug(true)
+ .isNicHotUnPlug(true)
+ .isDiscVirtioHotPlug(true)
+ .isDiscVirtioHotUnPlug(true)
+ .build()
+ ))
+ .storages(ImmutableList.<Storage>of(
+ Storage.builder()
+ .id("ssssssss-aaaa-ffff-gggg-hhhhhhhhhhhh")
+ .size(40)
+ .name("jnode1-disk1")
+ .state(ProvisioningState.AVAILABLE)
+ .creationTime(dateParser.toDate("2014-12-04T07:09:23.138Z"))
+ .lastModificationTime(dateParser.toDate("2014-12-12T03:14:48.316Z"))
+ .build()
+ ))
+ .build();
+ assertEquals(actual, expected);
}
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a219a99/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterListResponseHandlerTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterListResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterListResponseHandlerTest.java
index b957b52..7e738ae 100644
--- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterListResponseHandlerTest.java
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterListResponseHandlerTest.java
@@ -45,8 +45,8 @@ public class DataCenterListResponseHandlerTest extends BaseResponseHandlerTest<L
assertNotNull(actual, "Parsed content returned null");
List<DataCenter> expected = ImmutableList.<DataCenter>of(
- DataCenter.builder().id("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee").name("JClouds-DC").version(10).state(ProvisioningState.AVAILABLE).build(),
- DataCenter.builder().id("qqqqqqqq-wwww-rrrr-tttt-yyyyyyyyyyyy").name("Random DC").version(238).state(ProvisioningState.INPROCESS).build()
+ DataCenter.builder().id("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee").name("JClouds-DC").version(10).state(ProvisioningState.AVAILABLE).build(),
+ DataCenter.builder().id("qqqqqqqq-wwww-rrrr-tttt-yyyyyyyyyyyy").name("Random DC").version(238).state(ProvisioningState.INPROCESS).build()
);
assertEquals(expected, actual);
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a219a99/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageInfoResponseHandlerTest.java
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageInfoResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageInfoResponseHandlerTest.java
index d09f362..fb2e33d 100644
--- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageInfoResponseHandlerTest.java
+++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageInfoResponseHandlerTest.java
@@ -25,41 +25,41 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import org.testng.annotations.Test;
-@Test( groups = "unit", testName = "ImageInfoResponseHandlerTest" )
+@Test(groups = "unit", testName = "ImageInfoResponseHandlerTest")
public class ImageInfoResponseHandlerTest extends BaseResponseHandlerTest<Image> {
@Override
protected ParseSax<Image> createParser() {
- return factory.create( injector.getInstance( ImageInfoResponseHandler.class ) );
+ return factory.create(injector.getInstance(ImageInfoResponseHandler.class));
}
@Test
public void testParseResponseFromGetImage() {
ParseSax<Image> parser = createParser();
- Image actual = parser.parse( payloadFromResource( "/image/image.xml" ) );
- assertNotNull( actual, "Parsed content returned null" );
+ Image actual = parser.parse(payloadFromResource("/image/image.xml"));
+ assertNotNull(actual, "Parsed content returned null");
Image expected = Image.builder()
- .isBootable( true )
- .isCpuHotPlug( true )
- .isCpuHotUnPlug( false )
- .isDiscVirtioHotPlug( true )
- .isDiscVirtioHotUnPlug( true )
- .id( "5ad99c9e-9166-11e4-9d74-52540066fee9" )
- .name( "Ubuntu-14.04-LTS-server-2015-01-01" )
- .size( 2048f )
- .type( Image.Type.HDD )
- .location( Location.US_LAS )
- .isNicHotPlug( true )
- .isNicHotUnPlug( true )
- .osType( OsType.LINUX )
- .isPublic( true )
- .isRamHotPlug( true )
- .isRamHotUnPlug( false )
- .isWriteable( true )
+ .isBootable(true)
+ .isCpuHotPlug(true)
+ .isCpuHotUnPlug(false)
+ .isDiscVirtioHotPlug(true)
+ .isDiscVirtioHotUnPlug(true)
+ .id("5ad99c9e-9166-11e4-9d74-52540066fee9")
+ .name("Ubuntu-14.04-LTS-server-2015-01-01")
+ .size(2048f)
+ .type(Image.Type.HDD)
+ .location(Location.US_LAS)
+ .isNicHotPlug(true)
+ .isNicHotUnPlug(true)
+ .osType(OsType.LINUX)
+ .isPublic(true)
+ .isRamHotPlug(true)
+ .isRamHotUnPlug(false)
+ .isWriteable(true)
.build();
- assertEquals( expected, actual );
+ assertEquals(expected, actual);
}
}