http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/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 new file mode 100644 index 0000000..f5f7a20 --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/domain/ServerBuilderTest.java @@ -0,0 +1,164 @@ +/* + * 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.domain; + +import java.util.Date; +import static org.testng.Assert.assertEquals; +import org.testng.annotations.Test; + +@Test( groups = "unit", testName = "ServerBuilderTest" ) +public class ServerBuilderTest { + + private final Boolean _isCpuHotPlug = true; + private final Boolean _isRamHotPlug = false; + private final Boolean _isNicHotPlug = true; + private final Boolean _isNicHotUnPlug = false; + private final Boolean _isDiscVirtioHotPlug = true; + private final Boolean _isDiscVirtioHotUnPlug = false; + private final int _cores = 8; + private final int _ram = 8 * 1024; + private final String _id = "some-random-server-id"; + private final String _name = "jclouds-node"; + private final Boolean _hasInternetAccess = true; + private final ProvisioningState _state = ProvisioningState.INACTIVE; + private final Server.Status _status = Server.Status.SHUTOFF; + private final OsType _osType = OsType.LINUX; + private final AvailabilityZone _availabilityZone = AvailabilityZone.ZONE_1; + private final Date _creationTime = new Date(); + private final Date _lastModificationTime = new Date(); + + private final Integer _lanId = 5; + private final String _dataCenterId = "some-random-datacenter-id"; + 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 ) + .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 ); + } + + @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 ) + .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 ); + } + + @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 ) + .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 ); + } +}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/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 a9c093e..5c05e4d 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 @@ -51,7 +51,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { try { List<DataCenter> dataCenters = api.getAllDataCenters(); - assertRequestHasCommonProperties(server.takeRequest()); + assertRequestHasCommonProperties(server.takeRequest(), "<ws:getAllDataCenters/>"); assertNotNull(dataCenters); assertEquals(dataCenters.size(), 2); } finally { @@ -87,9 +87,10 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { DataCenterApi api = pbApi.dataCenterApi(); String id = "12345678-abcd-efgh-ijkl-987654321000"; + String content = "<ws:getDataCenter><dataCenterId>" + id + "</dataCenterId></ws:getDataCenter>"; try { DataCenter dataCenter = api.getDataCenter(id); - assertRequestHasCommonProperties(server.takeRequest()); + assertRequestHasCommonProperties(server.takeRequest(), content ); assertNotNull(dataCenter); assertEquals(dataCenter.id(), id); } finally { @@ -101,7 +102,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { @Test public void testGetNonExistingDataCenter() throws Exception { MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setResponseCode(500).setBody(payloadFromResource("/fault-404.xml"))); + server.enqueue(new MockResponse().setResponseCode(404)); ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); DataCenterApi api = pbApi.dataCenterApi(); @@ -126,9 +127,10 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { DataCenterApi api = pbApi.dataCenterApi(); String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; + String content = "<ws:getDataCenterState><dataCenterId>" + id + "</dataCenterId></ws:getDataCenterState>"; try { ProvisioningState state = api.getDataCenterState(id); - assertRequestHasCommonProperties(server.takeRequest()); + assertRequestHasCommonProperties(server.takeRequest(), content ); assertNotNull(state); assertEquals(state, ProvisioningState.AVAILABLE); } finally { @@ -145,11 +147,15 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); DataCenterApi api = pbApi.dataCenterApi(); + String content = "<ws:createDataCenter><request>" + + "<dataCenterName>JClouds-DC</dataCenterName>" + + "<location>de/fra</location>" + + "</request></ws:createDataCenter>"; try { DataCenter dataCenter = api.createDataCenter( DataCenter.Request.CreatePayload.create("JClouds-DC", Location.DE_FRA) ); - assertRequestHasCommonProperties(server.takeRequest()); + assertRequestHasCommonProperties(server.takeRequest(), content ); assertNotNull(dataCenter); assertEquals(dataCenter.id(), "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"); assertEquals(dataCenter.version(), 1); @@ -179,13 +185,19 @@ 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>" + + "</request></ws:updateDataCenter>"; try { DataCenter dataCenter = api.updateDataCenter( - DataCenter.Request.UpdatePayload.create(id, "Apache") + DataCenter.Request.UpdatePayload.create(id, newName) ); - assertRequestHasCommonProperties(server.takeRequest()); + assertRequestHasCommonProperties(server.takeRequest(), content); assertNotNull(dataCenter); assertEquals(dataCenter.id(), id); assertEquals(dataCenter.version(), 2); @@ -204,10 +216,12 @@ 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); - assertRequestHasCommonProperties(server.takeRequest()); + assertRequestHasCommonProperties(server.takeRequest(), content); assertNotNull(dataCenter); assertEquals(dataCenter.id(), id); assertEquals(dataCenter.version(), 3); @@ -225,9 +239,12 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); 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("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"); - assertRequestHasCommonProperties(server.takeRequest()); + boolean result = api.deleteDataCenter(id); + assertRequestHasCommonProperties(server.takeRequest(), content); assertTrue(result); } finally { pbApi.close(); @@ -238,7 +255,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { @Test public void testDeleteNonExistingDataCenter() throws Exception { MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setResponseCode(500).setBody(payloadFromResource("/fault-404.xml"))); + 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/ee24ddb2/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiLiveTest.java ---------------------------------------------------------------------- diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiLiveTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiLiveTest.java new file mode 100644 index 0000000..2299a0c --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiLiveTest.java @@ -0,0 +1,58 @@ +/* + * 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 com.google.common.collect.Iterables; +import java.util.List; +import org.jclouds.profitbricks.BaseProfitBricksLiveTest; +import org.jclouds.profitbricks.domain.Image; +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 org.testng.annotations.Test; + +@Test(groups = "live", testName = "ImageApiLiveTest", singleThreaded = true) +public class ImageApiLiveTest extends BaseProfitBricksLiveTest { + + private String imageId; + + @Test + public void testGetAllImages() { + List<Image> images = api.imageApi().getAllImages(); + + assertNotNull(images); + assertFalse(images.isEmpty(), "No images found."); + imageId = Iterables.getFirst(images, null).id(); + } + + @Test(dependsOnMethods = "testGetAllImages") + public void testGetImage() { + Image image = api.imageApi().getImage(imageId); + + assertNotNull(image); + assertEquals(image.id(), imageId); + } + + @Test + public void testGetNonExistingImage() { + String id = "random-non-existing-id"; + Image image = api.imageApi().getImage(id); + + assertNull(image, "Should've just returned null"); + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/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 new file mode 100644 index 0000000..f1229ae --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiMockTest.java @@ -0,0 +1,116 @@ +/* + * 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 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.Image; +import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest; +import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; + +/** + * Mock tests for the {@link org.jclouds.profitbricks.features.ImageApi} class + */ +@Test(groups = "unit", testName = "ImageApiMockTest") +public class ImageApiMockTest extends BaseProfitBricksMockTest { + + @Test + public void testGetAllImages() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setBody(payloadFromResource("/image/images.xml"))); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ImageApi api = pbApi.imageApi(); + + try { + List<Image> images = api.getAllImages(); + assertRequestHasCommonProperties(server.takeRequest(), "<ws:getAllImages/>"); + assertNotNull(images); + assertTrue(images.size() == 7); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testGetAllImagesReturning404() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ImageApi api = pbApi.imageApi(); + + try { + List<Image> images = api.getAllImages(); + assertRequestHasCommonProperties(server.takeRequest()); + assertTrue(images.isEmpty()); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testGetImage() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setBody(payloadFromResource("/image/image.xml"))); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + 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); + assertRequestHasCommonProperties(server.takeRequest(), content); + assertNotNull(image); + assertEquals(image.id(), id); + } finally { + pbApi.close(); + server.shutdown(); + } + + } + + @Test + public void testGetNonExistingImage() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + + ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ImageApi api = pbApi.imageApi(); + + String id = "random-non-existing-id"; + try { + Image image = api.getImage(id); + assertRequestHasCommonProperties(server.takeRequest()); + assertNull(image); + } finally { + pbApi.close(); + server.shutdown(); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/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 new file mode 100644 index 0000000..3237e9c --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiLiveTest.java @@ -0,0 +1,139 @@ +/* + * 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 com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +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.util.Predicates2; +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 org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +@Test( groups = "live", testName = "ServerApiLiveTest", singleThreaded = true ) +public class ServerApiLiveTest extends BaseProfitBricksLiveTest { + + private Predicate<String> waitUntilAvailable; + private DataCenter dataCenter; + private String createdServerId; + + @Override + protected void initialize() { + super.initialize(); + List<DataCenter> dataCenters = api.dataCenterApi().getAllDataCenters(); + assertFalse( dataCenters.isEmpty(), "Must atleast have 1 datacenter available for server testing." ); + + this.dataCenter = Iterables.getFirst( dataCenters, null ); + + this.waitUntilAvailable = Predicates2.retry( + 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 ) ); + + assertNotNull( serverId ); + this.createdServerId = serverId; + } + + @Test( dependsOnMethods = "testCreateServer" ) + public void testGetServer() { + Server server = api.serverApi().getServer( createdServerId ); + + assertNotNull( server ); + assertEquals( server.id(), createdServerId ); + } + + @Test( dependsOnMethods = "testCreateServer" ) + public void testGetAllServers() { + List<Server> servers = api.serverApi().getAllServers(); + + assertNotNull( servers ); + assertFalse( servers.isEmpty() ); + } + + @Test( dependsOnMethods = "testCreateServer" ) + public void testWaitUntilAvailable() { + boolean available = waitUntilAvailable.apply( createdServerId ); + + assertTrue( available ); + } + + @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() ); + + assertNotNull( requestId ); + waitUntilAvailable.apply( createdServerId ); + + Server server = api.serverApi().getServer( createdServerId ); + assertEquals( server.state(), ProvisioningState.AVAILABLE ); + } + + @Test( dependsOnMethods = "testUpdateServer" ) + public void testStopServer() { + 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 ); + + waitUntilInactive.apply( createdServerId ); + Server server = api.serverApi().getServer( createdServerId ); + assertEquals( server.status(), Server.Status.SHUTOFF ); + } + + @Test( dependsOnMethods = "testStopServer" ) + public void testStartServer() { + String requestId = api.serverApi().startServer( createdServerId ); + assertNotNull( requestId ); + + waitUntilAvailable.apply( createdServerId ); + + Server server = api.serverApi().getServer( createdServerId ); + assertEquals( server.status(), Server.Status.RUNNING ); + } + + @AfterClass( alwaysRun = true ) + public void testDeleteServer() { + if ( createdServerId != null ) { + boolean result = api.serverApi().deleteServer( createdServerId ); + + assertTrue( result, "Created test server was not deleted." ); + } + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/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 new file mode 100644 index 0000000..d9fd478 --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiMockTest.java @@ -0,0 +1,338 @@ +/* + * 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 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.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" ) +public class ServerApiMockTest extends BaseProfitBricksMockTest { + + @Test + public void testGetAllServers() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/servers.xml" ) ) ); + + 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 ); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testGetAllServersReturning404() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue( new MockResponse().setResponseCode( 404 ) ); + + ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) ); + ServerApi api = pbApi.serverApi(); + + try { + List<Server> servers = api.getAllServers(); + assertRequestHasCommonProperties( server.takeRequest() ); + assertTrue( servers.isEmpty() ); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testGetServer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server.xml" ) ) ); + + 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 ); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testGetNonExistingServer() 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 { + Server srvr = api.getServer( id ); + assertRequestHasCommonProperties( server.takeRequest() ); + assertNull( srvr ); + + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testStartServer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-start.xml" ) ) ); + + 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" ); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testStartNonExistingServer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue( new MockResponse().setResponseCode( 500 ).setBody( payloadFromResource( "/fault-404.xml" ) ) ); + + 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 ) { + // expected exception + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testStopServer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-stop.xml" ) ) ); + + 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" ); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testResetServer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-reset.xml" ) ) ); + + 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" ); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testCreateServer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-create.xml" ) ) ); + + ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) ); + ServerApi api = pbApi.serverApi(); + + String dataCenterId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; + String name = "jclouds-node"; + String imageId = "some-random-image-id"; + + String content = "<ws:createServer>" + + "<request>" + + "<dataCenterId>" + dataCenterId + "</dataCenterId>" + + "<cores>4</cores>" + + "<ram>4096</ram>" + + "<serverName>" + name + "</serverName>" + // + "<bootFromStorageId></bootFromStorageId>" + + "<bootFromImageId>" + imageId + "</bootFromImageId>" + + "<internetAccess>true</internetAccess>" + + "<lanId>2</lanId>" + + "<osType>LINUX</osType>" + + "<availabilityZone>ZONE_1</availabilityZone>" + + "<cpuHotPlug>true</cpuHotPlug>" + + "<ramHotPlug>false</ramHotPlug>" + + "<nicHotPlug>true</nicHotPlug>" + + "<nicHotUnPlug>false</nicHotUnPlug>" + + "<discVirtioHotPlug>true</discVirtioHotPlug>" + + "<discVirtioHotUnPlug>false</discVirtioHotUnPlug>" + + "</request>" + + "</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" ); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testUpdateServer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-update.xml" ) ) ); + + ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) ); + ServerApi api = pbApi.serverApi(); + + String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; + String newName = "apache-node"; + String storageId = "some-random-storage-id"; + + String content = "<ws:updateServer>" + + "<request>" + + "<serverId>" + serverId + "</serverId>" + + "<cores>8</cores>" + + "<ram>8192</ram>" + + "<serverName>" + newName + "</serverName>" + + "<bootFromStorageId>" + storageId + "</bootFromStorageId>" +// + "<bootFromImageId>?</bootFromImageId>" + + "<osType>OTHER</osType>" + + "<availabilityZone>AUTO</availabilityZone>" + + "<cpuHotPlug>false</cpuHotPlug>" + + "<ramHotPlug>true</ramHotPlug>" + + "<nicHotPlug>false</nicHotPlug>" + + "<nicHotUnPlug>true</nicHotUnPlug>" + + "<discVirtioHotPlug>false</discVirtioHotPlug>" + + "<discVirtioHotUnPlug>true</discVirtioHotUnPlug>" + + "</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" ); + } finally { + pbApi.close(); + server.shutdown(); + } + } + + @Test + public void testDeleteServer() throws Exception { + MockWebServer server = mockWebServer(); + server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-delete.xml" ) ) ); + + 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 ); + } finally { + pbApi.close(); + server.shutdown(); + } + + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/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 new file mode 100644 index 0000000..d32b656 --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/RequestIdOnlyResponseHandlerTest.java @@ -0,0 +1,76 @@ +/* + * 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.http.parser; + +import org.jclouds.http.functions.ParseSax; +import static org.testng.Assert.assertEquals; +import org.testng.annotations.Test; + +@Test( groups = "unit", testName = "RequestIdOnlyResponseHandlerTest" ) +public class RequestIdOnlyResponseHandlerTest extends BaseResponseHandlerTest<String> { + + @Override + protected ParseSax<String> createParser() { + return factory.create( injector.getInstance( RequestIdOnlyResponseHandler.class ) ); + } + + @Test + public void testParseResponseFromStartServer() { + ParseSax<String> parser = createParser(); + + String requestId = parser.parse( payloadFromResource( "/server/server-start.xml" ) ); + + assertEquals( requestId, "123456" ); + } + + @Test + public void testParseResponseFromStopServer() { + ParseSax<String> parser = createParser(); + + String requestId = parser.parse( payloadFromResource( "/server/server-stop.xml" ) ); + + assertEquals( requestId, "123456" ); + } + + @Test + public void testParseResponseFromResetServer() { + ParseSax<String> parser = createParser(); + + String requestId = parser.parse( payloadFromResource( "/server/server-reset.xml" ) ); + + assertEquals( requestId, "123456" ); + } + + @Test + public void testParseResponseFromUpdateServer() { + ParseSax<String> parser = createParser(); + + String requestId = parser.parse( payloadFromResource( "/server/server-update.xml" ) ); + + assertEquals( requestId, "102458" ); + } + + @Test + public void testParseResponseFromDeleteServer() { + ParseSax<String> parser = createParser(); + + String requestId = parser.parse( payloadFromResource( "/server/server-delete.xml" ) ); + + assertEquals( requestId, "102459" ); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/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 66259ab..cb84841 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 @@ -40,8 +40,8 @@ public class ServiceFaultResponseHandlerTest extends BaseResponseHandlerTest<Ser 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 : 11122416. [VDC-6-404] The requested data center does not exist or already deleted by the users. ResourceId random-non-existing-id") - .requestId(11122416) + .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/ee24ddb2/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 f4222fb..0a3a570 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,7 +19,6 @@ package org.jclouds.profitbricks.http.parser.datacenter; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import javax.xml.parsers.ParserConfigurationException; import org.jclouds.http.functions.ParseSax; import org.jclouds.profitbricks.domain.DataCenter; @@ -37,7 +36,7 @@ public class DataCenterInfoResponseHandlerTest extends BaseResponseHandlerTest<D } @Test - public void testParseResponseFromGetDataCenter() throws ParserConfigurationException { + public void testParseResponseFromGetDataCenter() { ParseSax<DataCenter> parser = createParser(); DataCenter actual = parser.parse(payloadFromResource("/datacenter/datacenter.xml")); assertNotNull(actual, "Parsed content returned null"); http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/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 new file mode 100644 index 0000000..d09f362 --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageInfoResponseHandlerTest.java @@ -0,0 +1,65 @@ +/* + * 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.http.parser.image; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.profitbricks.domain.Image; +import org.jclouds.profitbricks.domain.Location; +import org.jclouds.profitbricks.domain.OsType; +import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import org.testng.annotations.Test; + +@Test( groups = "unit", testName = "ImageInfoResponseHandlerTest" ) +public class ImageInfoResponseHandlerTest extends BaseResponseHandlerTest<Image> { + + @Override + protected ParseSax<Image> createParser() { + 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 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 ) + .build(); + + assertEquals( expected, actual ); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandlerTest.java ---------------------------------------------------------------------- diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandlerTest.java new file mode 100644 index 0000000..0aa8f58 --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/image/ImageListResponseHandlerTest.java @@ -0,0 +1,183 @@ +/* + * 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.http.parser.image; + +import com.google.common.collect.ImmutableList; +import java.util.List; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.profitbricks.domain.Image; +import org.jclouds.profitbricks.domain.Location; +import org.jclouds.profitbricks.domain.OsType; +import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import org.testng.annotations.Test; + +@Test( groups = "unit", testName = "ImageListResponseHandlerTest" ) +public class ImageListResponseHandlerTest extends BaseResponseHandlerTest<List<Image>> { + + @Override + protected ParseSax<List<Image>> createParser() { + return factory.create( injector.getInstance( ImageListResponseHandler.class ) ); + } + + @Test + public void testParseResponseFromGetAllImages() { + ParseSax<List<Image>> parser = createParser(); + + List<Image> actual = parser.parse( payloadFromResource( "/image/images.xml" ) ); + assertNotNull( actual, "Parsed content returned null" ); + + List<Image> expected = ImmutableList.<Image>of( + Image.builder() + .isBootable( true ) + .isCpuHotPlug( true ) + .isCpuHotUnPlug( false ) + .isDiscVirtioHotPlug( true ) + .isDiscVirtioHotUnPlug( true ) + .id( "e4f73936-9161-11e4-9d74-52540066fee9" ) + .name( "Ubuntu-12.04-LTS-server-2015-01-01" ) + .size( 2048f ) + .type( Image.Type.HDD ) + .location( Location.DE_FRA ) + .isNicHotPlug( true ) + .isNicHotUnPlug( true ) + .osType( OsType.LINUX ) + .isPublic( true ) + .isRamHotPlug( true ) + .isRamHotUnPlug( false ) + .isWriteable( true ) + .build(), + Image.builder() + .isBootable( true ) + .isCpuHotPlug( true ) + .isCpuHotUnPlug( false ) + .isDiscVirtioHotPlug( true ) + .isDiscVirtioHotUnPlug( true ) + .id( "a984a5d3-9163-11e4-9d74-52540066fee9" ) + .name( "Ubuntu-14.04-LTS-server-2015-01-01" ) + .size( 2048f ) + .type( Image.Type.HDD ) + .location( Location.DE_FRA ) + .isNicHotPlug( true ) + .isNicHotUnPlug( true ) + .osType( OsType.LINUX ) + .isPublic( true ) + .isRamHotPlug( true ) + .isRamHotUnPlug( false ) + .isWriteable( true ) + .build(), + Image.builder() + .isBootable( true ) + .isCpuHotPlug( true ) + .isCpuHotUnPlug( false ) + .isDiscVirtioHotPlug( true ) + .isDiscVirtioHotUnPlug( true ) + .id( "5f3cac96-915f-11e4-9d74-52540066fee9" ) + .name( "Debian-jessie-prerelease-server-2015-01-01" ) + .size( 2048f ) + .type( Image.Type.HDD ) + .location( Location.UNRECOGNIZED ) + .isNicHotPlug( true ) + .isNicHotUnPlug( true ) + .osType( OsType.LINUX ) + .isPublic( true ) + .isRamHotPlug( true ) + .isRamHotUnPlug( false ) + .isWriteable( true ) + .build(), + Image.builder() + .isBootable( true ) + .isCpuHotPlug( true ) + .isCpuHotUnPlug( false ) + .isDiscVirtioHotPlug( true ) + .isDiscVirtioHotUnPlug( true ) + .id( "f4742db0-9160-11e4-9d74-52540066fee9" ) + .name( "Fedora-19-server-2015-01-01" ) + .size( 2048f ) + .type( Image.Type.HDD ) + .location( Location.UNRECOGNIZED ) + .isNicHotPlug( true ) + .isNicHotUnPlug( true ) + .osType( OsType.LINUX ) + .isPublic( true ) + .isRamHotPlug( true ) + .isRamHotUnPlug( false ) + .isWriteable( true ) + .build(), + Image.builder() + .isBootable( true ) + .isCpuHotPlug( true ) + .isCpuHotUnPlug( false ) + .isDiscVirtioHotPlug( true ) + .isDiscVirtioHotUnPlug( true ) + .id( "86902c18-9164-11e4-9d74-52540066fee9" ) + .name( "Ubuntu-12.04-LTS-server-2015-01-01" ) + .size( 2048f ) + .type( Image.Type.HDD ) + .location( Location.UNRECOGNIZED ) + .isNicHotPlug( true ) + .isNicHotUnPlug( true ) + .osType( OsType.LINUX ) + .isPublic( true ) + .isRamHotPlug( true ) + .isRamHotUnPlug( false ) + .isWriteable( true ) + .build(), + Image.builder() + .isBootable( true ) + .isCpuHotPlug( true ) + .isCpuHotUnPlug( false ) + .isDiscVirtioHotPlug( true ) + .isDiscVirtioHotUnPlug( true ) + .id( "3b48e3ff-9163-11e4-9d74-52540066fee9" ) + .name( "Ubuntu-14.04-LTS-server-2015-01-01" ) + .size( 2048f ) + .type( Image.Type.HDD ) + .location( Location.DE_FKB ) + .isNicHotPlug( true ) + .isNicHotUnPlug( true ) + .osType( OsType.LINUX ) + .isPublic( true ) + .isRamHotPlug( true ) + .isRamHotUnPlug( false ) + .isWriteable( true ) + .build(), + Image.builder() + .isBootable( true ) + .isCpuHotPlug( true ) + .isCpuHotUnPlug( false ) + .isDiscVirtioHotPlug( true ) + .isDiscVirtioHotUnPlug( true ) + .id( "6ce17716-9164-11e4-9d74-52540066fee9" ) + .name( "Ubuntu-12.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 ); + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerIdOnlyResponseHandlerTest.java ---------------------------------------------------------------------- diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerIdOnlyResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerIdOnlyResponseHandlerTest.java new file mode 100644 index 0000000..700b1e5 --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerIdOnlyResponseHandlerTest.java @@ -0,0 +1,40 @@ +/* + * 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.http.parser.server; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest; +import static org.testng.Assert.assertEquals; +import org.testng.annotations.Test; + +@Test( groups = "unit", testName = "ServerIdOnlyResponseHandlerTest" ) +public class ServerIdOnlyResponseHandlerTest extends BaseResponseHandlerTest<String> { + + @Override + protected ParseSax<String> createParser() { + return factory.create( injector.getInstance( ServerIdOnlyResponseHandler.class ) ); + } + + @Test + public void testParseResponseFromCreateServer() { + ParseSax<String> parser = createParser(); + + String serverId = parser.parse( payloadFromResource( "/server/server-create.xml" ) ); + + assertEquals( "qwertyui-qwer-qwer-qwer-qwertyyuiiop", serverId ); + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandlerTest.java ---------------------------------------------------------------------- diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandlerTest.java new file mode 100644 index 0000000..734e169 --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerInfoResponseHandlerTest.java @@ -0,0 +1,76 @@ +/* + * 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.http.parser.server; + +import java.text.ParseException; +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.OsType; +import org.jclouds.profitbricks.domain.ProvisioningState; +import org.jclouds.profitbricks.domain.Server; +import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import org.testng.annotations.Test; + +@Test( groups = "unit", testName = "ServerInfoResponseHandlerTest" ) +public class ServerInfoResponseHandlerTest extends BaseResponseHandlerTest<Server> { + + @Override + protected ParseSax<Server> createParser() { + return factory.create( injector.getInstance( ServerInfoResponseHandler.class ) ); + } + + protected DateCodecFactory createDateParser() { + return injector.getInstance( DateCodecFactory.class ); + } + + @Test + public void testParseResponseFromGetServer() throws ParseException { + ParseSax<Server> parser = createParser(); + + Server actual = parser.parse( payloadFromResource( "/server/server.xml" ) ); + assertNotNull( actual, "Parsed content returned null" ); + + DateCodec dateParser = createDateParser().iso8601(); + + Server expected = Server.builder() + .id( "qwertyui-qwer-qwer-qwer-qwertyyuiiop" ) + .name( "facebook-node" ) + .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(); + + assertEquals( actual, expected ); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandlerTest.java ---------------------------------------------------------------------- diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandlerTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandlerTest.java new file mode 100644 index 0000000..c9c01c6 --- /dev/null +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/server/ServerListResponseHandlerTest.java @@ -0,0 +1,97 @@ +/* + * 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.http.parser.server; + +import com.google.common.collect.ImmutableList; +import java.util.List; +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.OsType; +import org.jclouds.profitbricks.domain.ProvisioningState; +import org.jclouds.profitbricks.domain.Server; +import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import org.testng.annotations.Test; + +@Test( groups = "unit", testName = "ServerListResponseHandlerTest" ) +public class ServerListResponseHandlerTest extends BaseResponseHandlerTest<List<Server>> { + + @Override + protected ParseSax<List<Server>> createParser() { + return factory.create( injector.getInstance( ServerListResponseHandler.class ) ); + } + + protected DateCodecFactory createDateParser() { + return injector.getInstance( DateCodecFactory.class ); + } + + @Test + public void testParseResponseFromGetAllServers() { + ParseSax<List<Server>> parser = createParser(); + + List<Server> actual = parser.parse( payloadFromResource( "/server/servers.xml" ) ); + assertNotNull( actual, "Parsed content returned null" ); + + DateCodec dateParser = createDateParser().iso8601(); + + List<Server> expected = ImmutableList.<Server>of( + Server.builder() + .id( "qwertyui-qwer-qwer-qwer-qwertyyuiiop" ) + .name( "facebook-node" ) + .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(), + Server.builder() + .id( "asdfghjk-asdf-asdf-asdf-asdfghjklkjl" ) + .name( "google-node" ) + .cores( 1 ) + .ram( 1024 ) + .hasInternetAccess( false ) + .state( ProvisioningState.AVAILABLE ) + .status( Server.Status.RUNNING ) + .creationTime( dateParser.toDate( "2014-11-12T07:01:00.441Z" ) ) + .lastModificationTime( dateParser.toDate( "2014-11-12T07:01:00.441Z" ) ) + .osType( OsType.LINUX ) + .availabilityZone( AvailabilityZone.AUTO ) + .isCpuHotPlug( true ) + .isRamHotPlug( true ) + .isNicHotPlug( true ) + .isNicHotUnPlug( true ) + .isDiscVirtioHotPlug( true ) + .isDiscVirtioHotUnPlug( true ) + .build() + ); + + assertEquals( actual, expected ); + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/test/java/org/jclouds/profitbricks/internal/BaseProfitBricksMockTest.java ---------------------------------------------------------------------- diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/internal/BaseProfitBricksMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/internal/BaseProfitBricksMockTest.java index 665f1bd..3e5d19a 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/internal/BaseProfitBricksMockTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/internal/BaseProfitBricksMockTest.java @@ -46,6 +46,13 @@ public class BaseProfitBricksMockTest { protected static final String authHeader = BasicAuthentication.basic("username", "password"); protected static final String provider = "profitbricks"; protected static final String rootUrl = "/1.3"; + + private static 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>"; + + private static final String SOAP_SUFFIX = "</soapenv:Body></soapenv:Envelope>"; private final Set<Module> modules = ImmutableSet.<Module>of(); @@ -70,7 +77,7 @@ public class BaseProfitBricksMockTest { server.play(); return server; } - + public byte[] payloadFromResource(String resource) { try { return toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8); @@ -78,6 +85,10 @@ public class BaseProfitBricksMockTest { throw Throwables.propagate(e); } } + + protected static String payloadSoapWithBody(String body){ + return SOAP_PREFIX.concat( body ).concat( SOAP_SUFFIX ); + } protected static void assertRequestHasCommonProperties(final RecordedRequest request) { assertEquals(request.getMethod(), "POST"); @@ -85,4 +96,9 @@ public class BaseProfitBricksMockTest { assertEquals(request.getHeader(HttpHeaders.AUTHORIZATION), authHeader); assertEquals(request.getHeader(HttpHeaders.ACCEPT), MediaType.TEXT_XML); } + + protected static void assertRequestHasCommonProperties(final RecordedRequest request, String content ){ + assertEquals( new String( request.getBody() ), payloadSoapWithBody( content ) ); + assertRequestHasCommonProperties( request ); + } } http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/test/resources/datacenter/datacenter-not-found.xml ---------------------------------------------------------------------- diff --git a/providers/profitbricks/src/test/resources/datacenter/datacenter-not-found.xml b/providers/profitbricks/src/test/resources/datacenter/datacenter-not-found.xml new file mode 100644 index 0000000..486706d --- /dev/null +++ b/providers/profitbricks/src/test/resources/datacenter/datacenter-not-found.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"> + <faultcode>S:Server</faultcode> + <faultstring>The requested resource could not be found. Please refer to Request Id : 11122416. [VDC-6-404] The requested data center does not exist or already deleted by the users. ResourceId random-non-existing-id</faultstring> + <detail> + <ns2:ProfitbricksServiceFault xmlns:ns2="http://ws.api.profitbricks.com/"> + <faultCode>RESOURCE_NOT_FOUND</faultCode> + <httpCode>404</httpCode> + <message>The requested resource could not be found. Please refer to Request Id : 11122416. [VDC-6-404] The requested data center does not exist or already deleted by the users. ResourceId random-non-existing-id</message> + <requestId>11122416</requestId> + </ns2:ProfitbricksServiceFault> + </detail> + </S:Fault> + </S:Body> +</S:Envelope> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/test/resources/fault-404.xml ---------------------------------------------------------------------- diff --git a/providers/profitbricks/src/test/resources/fault-404.xml b/providers/profitbricks/src/test/resources/fault-404.xml index 486706d..430be82 100644 --- a/providers/profitbricks/src/test/resources/fault-404.xml +++ b/providers/profitbricks/src/test/resources/fault-404.xml @@ -1,17 +1,17 @@ <?xml version="1.0" encoding="UTF-8"?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> - <S:Body> - <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"> - <faultcode>S:Server</faultcode> - <faultstring>The requested resource could not be found. Please refer to Request Id : 11122416. [VDC-6-404] The requested data center does not exist or already deleted by the users. ResourceId random-non-existing-id</faultstring> - <detail> - <ns2:ProfitbricksServiceFault xmlns:ns2="http://ws.api.profitbricks.com/"> - <faultCode>RESOURCE_NOT_FOUND</faultCode> - <httpCode>404</httpCode> - <message>The requested resource could not be found. Please refer to Request Id : 11122416. [VDC-6-404] The requested data center does not exist or already deleted by the users. ResourceId random-non-existing-id</message> - <requestId>11122416</requestId> - </ns2:ProfitbricksServiceFault> - </detail> - </S:Fault> - </S:Body> -</S:Envelope> \ No newline at end of file + <S:Body> + <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"> + <faultcode>S:Server</faultcode> + <faultstring>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</faultstring> + <detail> + <ns2:ProfitbricksServiceFault xmlns:ns2="http://ws.api.profitbricks.com/"> + <faultCode>RESOURCE_NOT_FOUND</faultCode> + <httpCode>404</httpCode> + <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</message> + <requestId>16370720</requestId> + </ns2:ProfitbricksServiceFault> + </detail> + </S:Fault> + </S:Body> +</S:Envelope> http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/test/resources/image/image-not-found.xml ---------------------------------------------------------------------- diff --git a/providers/profitbricks/src/test/resources/image/image-not-found.xml b/providers/profitbricks/src/test/resources/image/image-not-found.xml new file mode 100644 index 0000000..98c9f3e --- /dev/null +++ b/providers/profitbricks/src/test/resources/image/image-not-found.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"> + <faultcode>S:Server</faultcode> + <faultstring>The requested resource could not be found. Please refer to Request Id : 16361390. [VDC-6-404] The requested image does not exist or already deleted by the users. ResourceId random-non-existing-id</faultstring> + <detail> + <ns2:ProfitbricksServiceFault xmlns:ns2="http://ws.api.profitbricks.com/"> + <faultCode>RESOURCE_NOT_FOUND</faultCode> + <httpCode>404</httpCode> + <message>The requested resource could not be found. Please refer to Request Id : 16361390. [VDC-6-404] The requested image does not exist or already deleted by the users. ResourceId random-non-existing-id</message> + <requestId>16361390</requestId> + </ns2:ProfitbricksServiceFault> + </detail> + </S:Fault> + </S:Body> +</S:Envelope> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/test/resources/image/image.xml ---------------------------------------------------------------------- diff --git a/providers/profitbricks/src/test/resources/image/image.xml b/providers/profitbricks/src/test/resources/image/image.xml new file mode 100644 index 0000000..0e56bad --- /dev/null +++ b/providers/profitbricks/src/test/resources/image/image.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns2:getImageResponse xmlns:ns2="http://ws.api.profitbricks.com/"> + <return> + <bootable>true</bootable> + <cpuHotPlug>true</cpuHotPlug> + <cpuHotUnPlug>false</cpuHotUnPlug> + <discVirtioHotPlug>true</discVirtioHotPlug> + <discVirtioHotUnPlug>true</discVirtioHotUnPlug> + <imageId>5ad99c9e-9166-11e4-9d74-52540066fee9</imageId> + <imageName>Ubuntu-14.04-LTS-server-2015-01-01</imageName> + <imageSize>2048</imageSize> + <imageType>HDD</imageType> + <location>us/las</location> + <nicHotPlug>true</nicHotPlug> + <nicHotUnPlug>true</nicHotUnPlug> + <osType>LINUX</osType> + <public>true</public> + <ramHotPlug>true</ramHotPlug> + <ramHotUnPlug>false</ramHotUnPlug> + <writeable>true</writeable> + </return> + </ns2:getImageResponse> + </S:Body> +</S:Envelope> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/test/resources/image/images.xml ---------------------------------------------------------------------- diff --git a/providers/profitbricks/src/test/resources/image/images.xml b/providers/profitbricks/src/test/resources/image/images.xml new file mode 100644 index 0000000..5e09a1d --- /dev/null +++ b/providers/profitbricks/src/test/resources/image/images.xml @@ -0,0 +1,140 @@ +<?xml version="1.0" encoding="UTF-8"?> +<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> + <S:Body> + <ns2:getAllImagesResponse xmlns:ns2="http://ws.api.profitbricks.com/"> + <return> + <bootable>true</bootable> + <cpuHotPlug>true</cpuHotPlug> + <cpuHotUnPlug>false</cpuHotUnPlug> + <discVirtioHotPlug>true</discVirtioHotPlug> + <discVirtioHotUnPlug>true</discVirtioHotUnPlug> + <imageId>e4f73936-9161-11e4-9d74-52540066fee9</imageId> + <imageName>Ubuntu-12.04-LTS-server-2015-01-01</imageName> + <imageSize>2048</imageSize> + <imageType>HDD</imageType> + <location>de/fra</location> + <nicHotPlug>true</nicHotPlug> + <nicHotUnPlug>true</nicHotUnPlug> + <osType>LINUX</osType> + <public>true</public> + <ramHotPlug>true</ramHotPlug> + <ramHotUnPlug>false</ramHotUnPlug> + <writeable>true</writeable> + </return> + <return> + <bootable>true</bootable> + <cpuHotPlug>true</cpuHotPlug> + <cpuHotUnPlug>false</cpuHotUnPlug> + <discVirtioHotPlug>true</discVirtioHotPlug> + <discVirtioHotUnPlug>true</discVirtioHotUnPlug> + <imageId>a984a5d3-9163-11e4-9d74-52540066fee9</imageId> + <imageName>Ubuntu-14.04-LTS-server-2015-01-01</imageName> + <imageSize>2048</imageSize> + <imageType>HDD</imageType> + <location>de/fra</location> + <nicHotPlug>true</nicHotPlug> + <nicHotUnPlug>true</nicHotUnPlug> + <osType>LINUX</osType> + <public>true</public> + <ramHotPlug>true</ramHotPlug> + <ramHotUnPlug>false</ramHotUnPlug> + <writeable>true</writeable> + </return> + <return> + <bootable>true</bootable> + <cpuHotPlug>true</cpuHotPlug> + <cpuHotUnPlug>false</cpuHotUnPlug> + <discVirtioHotPlug>true</discVirtioHotPlug> + <discVirtioHotUnPlug>true</discVirtioHotUnPlug> + <imageId>5f3cac96-915f-11e4-9d74-52540066fee9</imageId> + <imageName>Debian-jessie-prerelease-server-2015-01-01</imageName> + <imageSize>2048</imageSize> + <imageType>HDD</imageType> + <location>us/lasdev</location> + <nicHotPlug>true</nicHotPlug> + <nicHotUnPlug>true</nicHotUnPlug> + <osType>LINUX</osType> + <public>true</public> + <ramHotPlug>true</ramHotPlug> + <ramHotUnPlug>false</ramHotUnPlug> + <writeable>true</writeable> + </return> + <return> + <bootable>true</bootable> + <cpuHotPlug>true</cpuHotPlug> + <cpuHotUnPlug>false</cpuHotUnPlug> + <discVirtioHotPlug>true</discVirtioHotPlug> + <discVirtioHotUnPlug>true</discVirtioHotUnPlug> + <imageId>f4742db0-9160-11e4-9d74-52540066fee9</imageId> + <imageName>Fedora-19-server-2015-01-01</imageName> + <imageSize>2048</imageSize> + <imageType>HDD</imageType> + <location>us/lasdev</location> + <nicHotPlug>true</nicHotPlug> + <nicHotUnPlug>true</nicHotUnPlug> + <osType>LINUX</osType> + <public>true</public> + <ramHotPlug>true</ramHotPlug> + <ramHotUnPlug>false</ramHotUnPlug> + <writeable>true</writeable> + </return> + <return> + <bootable>true</bootable> + <cpuHotPlug>true</cpuHotPlug> + <cpuHotUnPlug>false</cpuHotUnPlug> + <discVirtioHotPlug>true</discVirtioHotPlug> + <discVirtioHotUnPlug>true</discVirtioHotUnPlug> + <imageId>86902c18-9164-11e4-9d74-52540066fee9</imageId> + <imageName>Ubuntu-12.04-LTS-server-2015-01-01</imageName> + <imageSize>2048</imageSize> + <imageType>HDD</imageType> + <location>us/lasdev</location> + <nicHotPlug>true</nicHotPlug> + <nicHotUnPlug>true</nicHotUnPlug> + <osType>LINUX</osType> + <public>true</public> + <ramHotPlug>true</ramHotPlug> + <ramHotUnPlug>false</ramHotUnPlug> + <writeable>true</writeable> + </return> + <return> + <bootable>true</bootable> + <cpuHotPlug>true</cpuHotPlug> + <cpuHotUnPlug>false</cpuHotUnPlug> + <discVirtioHotPlug>true</discVirtioHotPlug> + <discVirtioHotUnPlug>true</discVirtioHotUnPlug> + <imageId>3b48e3ff-9163-11e4-9d74-52540066fee9</imageId> + <imageName>Ubuntu-14.04-LTS-server-2015-01-01</imageName> + <imageSize>2048</imageSize> + <imageType>HDD</imageType> + <location>de/fkb</location> + <nicHotPlug>true</nicHotPlug> + <nicHotUnPlug>true</nicHotUnPlug> + <osType>LINUX</osType> + <public>true</public> + <ramHotPlug>true</ramHotPlug> + <ramHotUnPlug>false</ramHotUnPlug> + <writeable>true</writeable> + </return> + <return> + <bootable>true</bootable> + <cpuHotPlug>true</cpuHotPlug> + <cpuHotUnPlug>false</cpuHotUnPlug> + <discVirtioHotPlug>true</discVirtioHotPlug> + <discVirtioHotUnPlug>true</discVirtioHotUnPlug> + <imageId>6ce17716-9164-11e4-9d74-52540066fee9</imageId> + <imageName>Ubuntu-12.04-LTS-server-2015-01-01</imageName> + <imageSize>2048</imageSize> + <imageType>HDD</imageType> + <location>us/las</location> + <nicHotPlug>true</nicHotPlug> + <nicHotUnPlug>true</nicHotUnPlug> + <osType>LINUX</osType> + <public>true</public> + <ramHotPlug>true</ramHotPlug> + <ramHotUnPlug>false</ramHotUnPlug> + <writeable>true</writeable> + </return> + </ns2:getAllImagesResponse> + </S:Body> +</S:Envelope> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds/blob/ee24ddb2/providers/profitbricks/src/test/resources/server/server-create.xml ---------------------------------------------------------------------- diff --git a/providers/profitbricks/src/test/resources/server/server-create.xml b/providers/profitbricks/src/test/resources/server/server-create.xml new file mode 100644 index 0000000..b0392d6 --- /dev/null +++ b/providers/profitbricks/src/test/resources/server/server-create.xml @@ -0,0 +1,13 @@ +<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.api.profitbricks.com/"> + <soapenv:Header/> + <soapenv:Body> + <ws:createServerReturn> + <return> + <requestId>102457</requestId> + <dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId> + <dataCenterVersion>2</dataCenterVersion> + <serverId>qwertyui-qwer-qwer-qwer-qwertyyuiiop</serverId> + </return> + </ws:createServerReturn> + </soapenv:Body> +</soapenv:Envelope> \ No newline at end of file
