Repository: jclouds
Updated Branches:
  refs/heads/master e0ab5d848 -> d05cecc39


http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/datacenter/UpdateDataCenterRequestBinderTest.java
----------------------------------------------------------------------
diff --git 
a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/datacenter/UpdateDataCenterRequestBinderTest.java
 
b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/datacenter/UpdateDataCenterRequestBinderTest.java
new file mode 100644
index 0000000..9e72172
--- /dev/null
+++ 
b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/binder/datacenter/UpdateDataCenterRequestBinderTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.binder.datacenter;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import org.jclouds.profitbricks.domain.DataCenter;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "UpdateDataCenterRequestBinderTest")
+public class UpdateDataCenterRequestBinderTest {
+
+   @Test
+   public void testCreatePayload() {
+      UpdateDataCenterRequestBinder binder = new 
UpdateDataCenterRequestBinder();
+
+      DataCenter.Request.UpdatePayload payload = 
DataCenter.Request.UpdatePayload.create("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", 
"Apache-DC");
+
+      String actual = binder.createPayload(payload);
+      assertNotNull(actual, "Binder returned null payload");
+      assertEquals(expectedPayload, actual);
+   }
+
+   private final String expectedPayload
+          = ("      <ws:updateDataCenter>\n"
+          + "         <request>\n"
+          + "            
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>\n"
+          + "            <dataCenterName>Apache-DC</dataCenterName>\n"
+          + "         </request>\n"
+          + "      </ws:updateDataCenter>").replaceAll("\\s+", "");
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicateTest.java
----------------------------------------------------------------------
diff --git 
a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicateTest.java
 
b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicateTest.java
new file mode 100644
index 0000000..05001f2
--- /dev/null
+++ 
b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/compute/internal/ProvisioningStatusPollingPredicateTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.compute.internal;
+
+import static 
org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer;
+import static org.testng.Assert.assertEquals;
+
+import java.util.concurrent.TimeUnit;
+
+import org.jclouds.profitbricks.ProfitBricksApi;
+import org.jclouds.profitbricks.domain.ProvisioningState;
+import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
+import org.jclouds.util.Predicates2;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicate;
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
+
+/**
+ * Tests for the {@link ProvisioningStatusPollingPredicate} class.
+ * <p>
+ */
+@Test(groups = "unit", testName = "ProvisioningStatusPollingPredicateTest")
+public class ProvisioningStatusPollingPredicateTest extends 
BaseProfitBricksMockTest {
+
+   @Test
+   public void testPredicate() throws Exception {
+      MockWebServer server = mockWebServer();
+
+      byte[] payloadInProcess = 
payloadFromResource("/datacenter/datacenter-state-inprocess.xml");
+      byte[] payloadAvailable = 
payloadFromResource("/datacenter/datacenter-state.xml");
+
+      // wait 3 times
+      server.enqueue(new MockResponse().setBody(payloadInProcess));
+      server.enqueue(new MockResponse().setBody(payloadInProcess));
+      server.enqueue(new MockResponse().setBody(payloadInProcess));
+      server.enqueue(new MockResponse().setBody(payloadAvailable));
+
+      server.enqueue(new MockResponse().setBody(payloadAvailable));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+
+      Predicate<String> waitUntilAvailable = Predicates2.retry(
+              new ProvisioningStatusPollingPredicate(pbApi, 
ProvisioningStatusAware.DATACENTER, ProvisioningState.AVAILABLE),
+              30l, 1l, TimeUnit.SECONDS);
+
+      String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
+      try {
+         waitUntilAvailable.apply(id);
+         ProvisioningState finalState = 
pbApi.dataCenterApi().getDataCenterState(id);
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertEquals(finalState, ProvisioningState.AVAILABLE);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiLiveTest.java
----------------------------------------------------------------------
diff --git 
a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiLiveTest.java
 
b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiLiveTest.java
new file mode 100644
index 0000000..36191ca
--- /dev/null
+++ 
b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiLiveTest.java
@@ -0,0 +1,127 @@
+/*
+ * 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 java.util.List;
+
+import org.jclouds.profitbricks.BaseProfitBricksLiveTest;
+import org.jclouds.profitbricks.domain.DataCenter;
+import org.jclouds.profitbricks.domain.Location;
+import org.jclouds.profitbricks.domain.ProvisioningState;
+
+import static org.testng.Assert.assertTrue;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.Test;
+
+@Test(groups = "live", testName = "DataCenterApiLiveTest", singleThreaded = 
true)
+public class DataCenterApiLiveTest extends BaseProfitBricksLiveTest {
+
+   private String dcId;
+
+   @Test
+   public void testCreateDataCenter() {
+      DataCenter dc = api.dataCenterApi().createDataCenter(
+              DataCenter.Request.CreatePayload.create("JClouds", 
Location.DE_FKB)
+      );
+
+      assertNotNull(dc);
+      dcWaitingPredicate.apply(dc.id());
+
+      dcId = dc.id();
+   }
+
+   @Test(dependsOnMethods = "testCreateDataCenter")
+   public void testGetDataCenter() {
+      assertNotNull(dcId, "No available datacenter found.");
+
+      DataCenter dataCenter = api.dataCenterApi().getDataCenter(dcId);
+
+      assertNotNull(dataCenter);
+      assertEquals(dataCenter.id(), dcId);
+   }
+
+   @Test(dependsOnMethods = "testCreateDataCenter")
+   public void testGetAllDataCenters() {
+      List<DataCenter> dataCenters = api.dataCenterApi().getAllDataCenters();
+
+      assertNotNull(dataCenters);
+      assertFalse(dataCenters.isEmpty(), "No datacenter found.");
+   }
+
+   @Test(dependsOnMethods = "testCreateDataCenter")
+   public void testGetDataCenterState() {
+      assertNotNull(dcId, "No available datacenter found.");
+
+      ProvisioningState state = api.dataCenterApi().getDataCenterState(dcId);
+
+      assertNotNull(state);
+   }
+
+   @Test(dependsOnMethods = "testGetDataCenter")
+   public void testUpdateDataCenter() {
+      assertNotNull(dcId, "No available datacenter found.");
+
+      final String newName = "Apache";
+      DataCenter dataCenter = api.dataCenterApi().updateDataCenter(
+              DataCenter.Request.UpdatePayload.create(dcId, newName)
+      );
+
+      assertNotNull(dataCenter);
+      dcWaitingPredicate.apply(dcId);
+
+      DataCenter fetchedDc = api.dataCenterApi().getDataCenter(dcId);
+
+      assertNotNull(fetchedDc);
+      assertEquals(newName, fetchedDc.name());
+   }
+
+   @Test(dependsOnMethods = "testUpdateDataCenter")
+   public void testClearDataCenter() {
+      DataCenter dataCenter = api.dataCenterApi().clearDataCenter(dcId);
+
+      assertNotNull(dataCenter);
+   }
+
+   @Test
+   public void testGetNonExistingDataCenter() {
+      DataCenter dataCenter = 
api.dataCenterApi().getDataCenter("random-non-existing-id");
+
+      assertNull(dataCenter);
+   }
+
+   @Test
+   public void testDeleteNonExistingDataCenterMustReturnFalse() {
+      boolean result = 
api.dataCenterApi().deleteDataCenter("random-non-existing-id");
+
+      assertFalse(result);
+   }
+
+   @AfterClass(alwaysRun = true)
+   public void testDeleteDataCenter() {
+      if (dcId != null) {
+         boolean result = api.dataCenterApi().deleteDataCenter(dcId);
+
+         assertTrue(result, "Created test data center was not deleted.");
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/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
new file mode 100644
index 0000000..a9c093e
--- /dev/null
+++ 
b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java
@@ -0,0 +1,255 @@
+/*
+ * 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 static org.testng.Assert.fail;
+
+import java.util.List;
+
+import org.jclouds.profitbricks.ProfitBricksApi;
+import org.jclouds.profitbricks.domain.DataCenter;
+import org.jclouds.profitbricks.domain.Location;
+import org.jclouds.profitbricks.domain.ProvisioningState;
+import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
+import org.testng.annotations.Test;
+
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
+
+/**
+ * Mock tests for the {@link org.jclouds.profitbricks.features.DataCenterApi} 
class
+ */
+@Test(groups = "unit", testName = "DataCenterApiMockTest")
+public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
+
+   @Test
+   public void testGetAllDataCenters() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new 
MockResponse().setBody(payloadFromResource("/datacenter/datacenters.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      DataCenterApi api = pbApi.dataCenterApi();
+
+      try {
+         List<DataCenter> dataCenters = api.getAllDataCenters();
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertNotNull(dataCenters);
+         assertEquals(dataCenters.size(), 2);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testGetAllDataCentersReturning404() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new MockResponse().setResponseCode(404));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      DataCenterApi api = pbApi.dataCenterApi();
+
+      try {
+         List<DataCenter> dataCenters = api.getAllDataCenters();
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertTrue(dataCenters.isEmpty());
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testGetDataCenter() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new 
MockResponse().setBody(payloadFromResource("/datacenter/datacenter.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      DataCenterApi api = pbApi.dataCenterApi();
+
+      String id = "12345678-abcd-efgh-ijkl-987654321000";
+      try {
+         DataCenter dataCenter = api.getDataCenter(id);
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertNotNull(dataCenter);
+         assertEquals(dataCenter.id(), id);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testGetNonExistingDataCenter() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new 
MockResponse().setResponseCode(500).setBody(payloadFromResource("/fault-404.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      DataCenterApi api = pbApi.dataCenterApi();
+
+      String id = "random-non-existing-id";
+      try {
+         DataCenter dataCenter = api.getDataCenter(id);
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertNull(dataCenter);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testGetDataCenterState() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new 
MockResponse().setBody(payloadFromResource("/datacenter/datacenter-state.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      DataCenterApi api = pbApi.dataCenterApi();
+
+      String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
+      try {
+         ProvisioningState state = api.getDataCenterState(id);
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertNotNull(state);
+         assertEquals(state, ProvisioningState.AVAILABLE);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testCreateDataCenter() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new 
MockResponse().setBody(payloadFromResource("/datacenter/datacenter-created.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      DataCenterApi api = pbApi.dataCenterApi();
+
+      try {
+         DataCenter dataCenter = api.createDataCenter(
+                 DataCenter.Request.CreatePayload.create("JClouds-DC", 
Location.DE_FRA)
+         );
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertNotNull(dataCenter);
+         assertEquals(dataCenter.id(), "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
+         assertEquals(dataCenter.version(), 1);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testCreateDataCenterWithIllegalArguments() throws Exception {
+      String[] names = {"JCl@ouds", "JC|ouds", "^clouds", ""};
+      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
+   public void testUpdateDataCenter() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new 
MockResponse().setBody(payloadFromResource("/datacenter/datacenter-updated.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      DataCenterApi api = pbApi.dataCenterApi();
+
+      String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
+      try {
+         DataCenter dataCenter = api.updateDataCenter(
+                 DataCenter.Request.UpdatePayload.create(id, "Apache")
+         );
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertNotNull(dataCenter);
+         assertEquals(dataCenter.id(), id);
+         assertEquals(dataCenter.version(), 2);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testClearDataCenter() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new 
MockResponse().setBody(payloadFromResource("/datacenter/datacenter-cleared.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      DataCenterApi api = pbApi.dataCenterApi();
+
+      String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
+      try {
+         DataCenter dataCenter = api.clearDataCenter(id);
+
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertNotNull(dataCenter);
+         assertEquals(dataCenter.id(), id);
+         assertEquals(dataCenter.version(), 3);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testDeleteDataCenter() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new 
MockResponse().setBody(payloadFromResource("/datacenter/datacenter-deleted.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      DataCenterApi api = pbApi.dataCenterApi();
+
+      try {
+         boolean result = 
api.deleteDataCenter("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertTrue(result);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testDeleteNonExistingDataCenter() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new 
MockResponse().setResponseCode(500).setBody(payloadFromResource("/fault-404.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
+      DataCenterApi api = pbApi.dataCenterApi();
+
+      try {
+         boolean result = 
api.deleteDataCenter("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
+         assertRequestHasCommonProperties(server.takeRequest());
+         assertFalse(result);
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/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
new file mode 100644
index 0000000..9198840
--- /dev/null
+++ 
b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java
@@ -0,0 +1,98 @@
+/*
+ * 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;
+
+import static 
org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import org.jclouds.profitbricks.ProfitBricksApi;
+import org.jclouds.profitbricks.domain.DataCenter;
+import org.jclouds.profitbricks.domain.Location;
+import org.jclouds.profitbricks.features.DataCenterApi;
+import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
+import org.jclouds.rest.AuthorizationException;
+import org.jclouds.rest.ResourceNotFoundException;
+import org.testng.annotations.Test;
+
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
+
+/**
+ * Mock tests for the {@link 
ResponseStatusFromPayloadHttpCommandExecutorService} class.
+ */
+@Test(groups = "unit", testName = 
"ResponseStatusFromPayloadHttpCommandExecutorServiceTest")
+public class ResponseStatusFromPayloadHttpCommandExecutorServiceTest extends 
BaseProfitBricksMockTest {
+
+   @Test
+   public void testNotFound() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new 
MockResponse().setResponseCode(500).setBody(payloadFromResource("/fault-404.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl("/"));
+      DataCenterApi api = pbApi.dataCenterApi();
+
+      String id = "random-non-existing-id";
+      try {
+         api.clearDataCenter(id);
+         fail("Request should have failed");
+      } catch (Exception ex) {
+         assertTrue(ex instanceof ResourceNotFoundException, "Exception should 
be an ResourceNotFoundException");
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testBadRequest() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new 
MockResponse().setResponseCode(500).setBody(payloadFromResource("/fault-400.xml")));
+
+      ProfitBricksApi pbApi = api(server.getUrl("/"));
+      DataCenterApi api = pbApi.dataCenterApi();
+
+      try {
+         
api.createDataCenter(DataCenter.Request.CreatePayload.create("D@tacenter", 
Location.DE_FKB));
+         fail("Request should have failed");
+      } catch (Exception ex) {
+         assertTrue(ex instanceof IllegalArgumentException, "Exception should 
be an IllegalArgumentException");
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+
+   @Test
+   public void testUnauthorized() throws Exception {
+      MockWebServer server = mockWebServer();
+      server.enqueue(new 
MockResponse().setResponseCode(401).setBody(payloadFromResource("/fault-401.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 AuthorizationException, "Exception should be 
an AuthorizationException");
+      } finally {
+         pbApi.close();
+         server.shutdown();
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/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
new file mode 100644
index 0000000..e6b692b
--- /dev/null
+++ 
b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/filters/ProfitBricksSoapMessageEnvelopeTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.filters;
+
+import static org.testng.Assert.assertEquals;
+
+import org.jclouds.http.HttpRequest;
+import org.testng.annotations.Test;
+
+/**
+ * Unit tests for the {@link ProfitBricksSoapMessageEnvelope} class.
+ */
+@Test(groups = "unit", testName = "ProfitBricksSoapMessageEnvelopeTest")
+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>";
+   private final String SOAP_SUFFIX = "</soapenv:Body></soapenv:Envelope>";
+   private final String endpoint = "https://api.profitbricks.com/1.3";;
+
+   @Test
+   public void testPayloadEnclosedWithSoapTags() {
+      String requestBody = "<ws:getAllDataCenters/>";
+      String expectedPayload = 
SOAP_PREFIX.concat(requestBody).concat(SOAP_SUFFIX);
+
+      HttpRequest request = 
HttpRequest.builder().method("POST").endpoint(endpoint).payload(requestBody).build();
+
+      ProfitBricksSoapMessageEnvelope soapEnvelope = new 
ProfitBricksSoapMessageEnvelope();
+      HttpRequest filtered = soapEnvelope.filter(request);
+
+      assertEquals(filtered.getPayload().getRawContent(), expectedPayload);
+      
assertEquals(filtered.getPayload().getContentMetadata().getContentLength(), 
Long.valueOf(expectedPayload.length()));
+   }
+
+   @Test(expectedExceptions = NullPointerException.class, 
expectedExceptionsMessageRegExp = ".*must contain payload message.*")
+   public void testNullRequest() {
+      HttpRequest request = 
HttpRequest.builder().method("POST").endpoint(endpoint).build();
+      new ProfitBricksSoapMessageEnvelope().filter(request);
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/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
new file mode 100644
index 0000000..23bdbc9
--- /dev/null
+++ 
b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/BaseResponseHandlerTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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 static org.jclouds.util.Strings2.toStringAndClose;
+
+import java.io.IOException;
+
+import org.jclouds.http.functions.ParseSax;
+import org.jclouds.http.functions.config.SaxParserModule;
+import org.jclouds.rest.internal.GeneratedHttpRequest;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+
+import com.google.common.base.Throwables;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+public abstract class BaseResponseHandlerTest<T> {
+
+   protected Injector injector = null;
+   protected ParseSax.Factory factory;
+   protected GeneratedHttpRequest request;
+
+   protected abstract ParseSax<T> createParser();
+
+   @BeforeTest
+   protected void setUpInjector() {
+      injector = Guice.createInjector(new SaxParserModule());
+      factory = injector.getInstance(ParseSax.Factory.class);
+      assert factory != null;
+   }
+
+   protected String payloadFromResource(String resource) {
+      try {
+        return toStringAndClose(getClass().getResourceAsStream(resource));
+      } catch (IOException e) {
+        throw Throwables.propagate(e);
+      }
+   }
+
+   @AfterTest
+   protected void tearDownInjector() {
+      factory = null;
+      injector = null;
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/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
new file mode 100644
index 0000000..66259ab
--- /dev/null
+++ 
b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/ServiceFaultResponseHandlerTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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 static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import org.jclouds.http.functions.ParseSax;
+import org.jclouds.profitbricks.domain.ServiceFault;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "ServiceFaultResponseHandlerTest")
+public class ServiceFaultResponseHandlerTest extends 
BaseResponseHandlerTest<ServiceFault> {
+
+   @Override
+   protected ParseSax<ServiceFault> createParser() {
+      return 
factory.create(injector.getInstance(ServiceFaultResponseHandler.class));
+   }
+
+   @Test
+   public void testParseSoapServiceFault() {
+      ParseSax<ServiceFault> parser = createParser();
+      ServiceFault actual = 
parser.parse(payloadFromResource("/fault-404.xml"));
+      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 : 11122416. [VDC-6-404] The requested data center does not exist 
or already deleted by the users. ResourceId random-non-existing-id")
+             .requestId(11122416)
+             .build();
+
+      assertEquals(expected, actual);
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/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
new file mode 100644
index 0000000..f4222fb
--- /dev/null
+++ 
b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterInfoResponseHandlerTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.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;
+import org.jclouds.profitbricks.domain.Location;
+import org.jclouds.profitbricks.domain.ProvisioningState;
+import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "DataCenterInfoResponseHandlerTest")
+public class DataCenterInfoResponseHandlerTest extends 
BaseResponseHandlerTest<DataCenter> {
+
+   @Override
+   protected ParseSax<DataCenter> createParser() {
+      return 
factory.create(injector.getInstance(DataCenterInfoResponseHandler.class));
+   }
+
+   @Test
+   public void testParseResponseFromGetDataCenter() throws 
ParserConfigurationException {
+      ParseSax<DataCenter> parser = createParser();
+      DataCenter actual = 
parser.parse(payloadFromResource("/datacenter/datacenter.xml"));
+      assertNotNull(actual, "Parsed content returned null");
+
+      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);
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/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
new file mode 100644
index 0000000..b957b52
--- /dev/null
+++ 
b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/datacenter/DataCenterListResponseHandlerTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.datacenter;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import java.util.List;
+
+import org.jclouds.http.functions.ParseSax;
+import org.jclouds.profitbricks.domain.DataCenter;
+import org.jclouds.profitbricks.domain.ProvisioningState;
+import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "DataCenterListResponseHandlerTest")
+public class DataCenterListResponseHandlerTest extends 
BaseResponseHandlerTest<List<DataCenter>> {
+
+   @Override
+   protected ParseSax<List<DataCenter>> createParser() {
+      return 
factory.create(injector.getInstance(DataCenterListResponseHandler.class));
+   }
+
+   @Test
+   public void testParseResponseFromGetAllDataCenter() {
+      ParseSax<List<DataCenter>> parser = createParser();
+
+      List<DataCenter> actual = 
parser.parse(payloadFromResource("/datacenter/datacenters.xml"));
+      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()
+      );
+      assertEquals(expected, actual);
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/state/GetProvisioningStateResponseHandlerTest.java
----------------------------------------------------------------------
diff --git 
a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/state/GetProvisioningStateResponseHandlerTest.java
 
b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/state/GetProvisioningStateResponseHandlerTest.java
new file mode 100644
index 0000000..0f9822b
--- /dev/null
+++ 
b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/parser/state/GetProvisioningStateResponseHandlerTest.java
@@ -0,0 +1,110 @@
+/*
+ * 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.state;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.jclouds.http.functions.ParseSax;
+import org.jclouds.profitbricks.domain.ProvisioningState;
+import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "GetProvisioningStateResponseHandlerTest")
+public class GetProvisioningStateResponseHandlerTest extends 
BaseResponseHandlerTest<ProvisioningState> {
+
+   @Override
+   protected ParseSax<ProvisioningState> createParser() {
+      return 
factory.create(injector.getInstance(GetProvisioningStateResponseHandler.class));
+   }
+
+   @Test
+   public void testParseResponseFromGetProvisioningState() {
+      ParseSax<ProvisioningState> parser = createParser();
+
+      for (Map.Entry<ProvisioningState, String> pair : 
sampleResponses.entrySet()) {
+        ProvisioningState actual = parser.parse(pair.getValue());
+        assertNotNull(actual, "Parsed content returned null");
+
+        assertEquals(pair.getKey(), actual);
+      }
+
+   }
+
+   private final Map<ProvisioningState, String> sampleResponses = new 
LinkedHashMap<ProvisioningState, String>() {
+      {
+        put(ProvisioningState.INACTIVE,
+                "<soapenv:Envelope 
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"; 
xmlns:ws=\"http://ws.api.profitbricks.com/\";>\n"
+                + "   <soapenv:Header/>\n"
+                + "   <soapenv:Body>\n"
+                + "      <ws:getDataCenterStateResponse>\n"
+                + "         <return>INACTIVE</return>\n"
+                + "      </ws:getDataCenterStateResponse>\n"
+                + "   </soapenv:Body>\n"
+                + "</soapenv:Envelope>");
+        put(ProvisioningState.INPROCESS,
+                "<soapenv:Envelope 
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"; 
xmlns:ws=\"http://ws.api.profitbricks.com/\";>\n"
+                + "   <soapenv:Header/>\n"
+                + "   <soapenv:Body>\n"
+                + "      <ws:getDataCenterStateResponse>\n"
+                + "         <return>INPROCESS</return>\n"
+                + "      </ws:getDataCenterStateResponse>\n"
+                + "   </soapenv:Body>\n"
+                + "</soapenv:Envelope>");
+        put(ProvisioningState.AVAILABLE,
+                "<soapenv:Envelope 
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"; 
xmlns:ws=\"http://ws.api.profitbricks.com/\";>\n"
+                + "   <soapenv:Header/>\n"
+                + "   <soapenv:Body>\n"
+                + "      <ws:getDataCenterStateResponse>\n"
+                + "         <return>AVAILABLE</return>\n"
+                + "      </ws:getDataCenterStateResponse>\n"
+                + "   </soapenv:Body>\n"
+                + "</soapenv:Envelope>");
+        put(ProvisioningState.DELETED,
+                "<soapenv:Envelope 
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"; 
xmlns:ws=\"http://ws.api.profitbricks.com/\";>\n"
+                + "   <soapenv:Header/>\n"
+                + "   <soapenv:Body>\n"
+                + "      <ws:getDataCenterStateResponse>\n"
+                + "         <return>DELETED</return>\n"
+                + "      </ws:getDataCenterStateResponse>\n"
+                + "   </soapenv:Body>\n"
+                + "</soapenv:Envelope>");
+        put(ProvisioningState.ERROR,
+                "<soapenv:Envelope 
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"; 
xmlns:ws=\"http://ws.api.profitbricks.com/\";>\n"
+                + "   <soapenv:Header/>\n"
+                + "   <soapenv:Body>\n"
+                + "      <ws:getDataCenterStateResponse>\n"
+                + "         <return>ERROR</return>\n"
+                + "      </ws:getDataCenterStateResponse>\n"
+                + "   </soapenv:Body>\n"
+                + "</soapenv:Envelope>");
+        put(ProvisioningState.UNRECOGNIZED,
+                "<soapenv:Envelope 
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"; 
xmlns:ws=\"http://ws.api.profitbricks.com/\";>\n"
+                + "   <soapenv:Header/>\n"
+                + "   <soapenv:Body>\n"
+                + "      <ws:getDataCenterStateResponse>\n"
+                + "         <return>MEH</return>\n"
+                + "      </ws:getDataCenterStateResponse>\n"
+                + "   </soapenv:Body>\n"
+                + "</soapenv:Envelope>");
+      }
+   };
+
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/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
new file mode 100644
index 0000000..665f1bd
--- /dev/null
+++ 
b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/internal/BaseProfitBricksMockTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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.internal;
+
+import static org.jclouds.util.Strings2.toStringAndClose;
+import static org.testng.Assert.assertEquals;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.ContextBuilder;
+import org.jclouds.http.filters.BasicAuthentication;
+import org.jclouds.profitbricks.ProfitBricksApi;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Throwables;
+import com.google.common.collect.ImmutableSet;
+import com.google.inject.Module;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
+import com.squareup.okhttp.mockwebserver.RecordedRequest;
+
+/**
+ * Base class for all ProfitBricks mock test
+ */
+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 final Set<Module> modules = ImmutableSet.<Module>of();
+
+   public BaseProfitBricksMockTest() {
+   }
+
+   public ProfitBricksApi api(URL url) {
+      return ContextBuilder.newBuilder(provider)
+              .credentials("username", "password")
+              .endpoint(url.toString())
+              .modules(modules)
+              .overrides(setupProperties())
+              .buildApi(ProfitBricksApi.class);
+   }
+
+   protected Properties setupProperties() {
+      return new Properties();
+   }
+
+   public static MockWebServer mockWebServer() throws IOException {
+      MockWebServer server = new MockWebServer();
+      server.play();
+      return server;
+   }
+
+   public byte[] payloadFromResource(String resource) {
+      try {
+         return 
toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8);
+      } catch (IOException e) {
+         throw Throwables.propagate(e);
+      }
+   }
+
+   protected static void assertRequestHasCommonProperties(final 
RecordedRequest request) {
+      assertEquals(request.getMethod(), "POST");
+      assertEquals(request.getPath(), rootUrl);
+      assertEquals(request.getHeader(HttpHeaders.AUTHORIZATION), authHeader);
+      assertEquals(request.getHeader(HttpHeaders.ACCEPT), MediaType.TEXT_XML);
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/providers/profitbricks/src/test/resources/datacenter/datacenter-cleared.xml
----------------------------------------------------------------------
diff --git 
a/providers/profitbricks/src/test/resources/datacenter/datacenter-cleared.xml 
b/providers/profitbricks/src/test/resources/datacenter/datacenter-cleared.xml
new file mode 100644
index 0000000..5b85c96
--- /dev/null
+++ 
b/providers/profitbricks/src/test/resources/datacenter/datacenter-cleared.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/";>
+    <S:Body>
+        <ns2:clearDataCenterResponse 
xmlns:ns2="http://ws.api.profitbricks.com/";>
+            <return>
+                <requestId>1143191</requestId>
+                
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
+                <dataCenterVersion>3</dataCenterVersion>
+            </return>
+        </ns2:clearDataCenterResponse>
+    </S:Body>
+</S:Envelope>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/providers/profitbricks/src/test/resources/datacenter/datacenter-created.xml
----------------------------------------------------------------------
diff --git 
a/providers/profitbricks/src/test/resources/datacenter/datacenter-created.xml 
b/providers/profitbricks/src/test/resources/datacenter/datacenter-created.xml
new file mode 100644
index 0000000..92ef01d
--- /dev/null
+++ 
b/providers/profitbricks/src/test/resources/datacenter/datacenter-created.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; 
xmlns:ws="http://ws.api.profitbricks.com/";>
+    <soapenv:Body>
+        <ws:createDataCenterResponse>
+            <return>
+                <requestId>102456</requestId>
+                
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
+                <dataCenterVersion>1</dataCenterVersion>
+                <location>de/fra</location>
+            </return>
+        </ws:createDataCenterResponse>
+    </soapenv:Body>
+</soapenv:Envelope>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/providers/profitbricks/src/test/resources/datacenter/datacenter-deleted.xml
----------------------------------------------------------------------
diff --git 
a/providers/profitbricks/src/test/resources/datacenter/datacenter-deleted.xml 
b/providers/profitbricks/src/test/resources/datacenter/datacenter-deleted.xml
new file mode 100644
index 0000000..c09858e
--- /dev/null
+++ 
b/providers/profitbricks/src/test/resources/datacenter/datacenter-deleted.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/";>
+   <S:Body>
+      <ns2:deleteDataCenterResponse 
xmlns:ns2="http://ws.api.profitbricks.com/";>
+         <return>
+            <requestId>11411363</requestId>
+         </return>
+      </ns2:deleteDataCenterResponse>
+   </S:Body>
+</S:Envelope>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/providers/profitbricks/src/test/resources/datacenter/datacenter-state-inprocess.xml
----------------------------------------------------------------------
diff --git 
a/providers/profitbricks/src/test/resources/datacenter/datacenter-state-inprocess.xml
 
b/providers/profitbricks/src/test/resources/datacenter/datacenter-state-inprocess.xml
new file mode 100644
index 0000000..77d41e3
--- /dev/null
+++ 
b/providers/profitbricks/src/test/resources/datacenter/datacenter-state-inprocess.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/";>
+   <S:Body>
+      <ns2:getDataCenterStateResponse 
xmlns:ns2="http://ws.api.profitbricks.com/";>
+         <return>INPROCESS</return>
+      </ns2:getDataCenterStateResponse>
+   </S:Body>
+</S:Envelope>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/providers/profitbricks/src/test/resources/datacenter/datacenter-state.xml
----------------------------------------------------------------------
diff --git 
a/providers/profitbricks/src/test/resources/datacenter/datacenter-state.xml 
b/providers/profitbricks/src/test/resources/datacenter/datacenter-state.xml
new file mode 100644
index 0000000..8bd56e2
--- /dev/null
+++ b/providers/profitbricks/src/test/resources/datacenter/datacenter-state.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/";>
+   <S:Body>
+      <ns2:getDataCenterStateResponse 
xmlns:ns2="http://ws.api.profitbricks.com/";>
+         <return>AVAILABLE</return>
+      </ns2:getDataCenterStateResponse>
+   </S:Body>
+</S:Envelope>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/providers/profitbricks/src/test/resources/datacenter/datacenter-updated.xml
----------------------------------------------------------------------
diff --git 
a/providers/profitbricks/src/test/resources/datacenter/datacenter-updated.xml 
b/providers/profitbricks/src/test/resources/datacenter/datacenter-updated.xml
new file mode 100644
index 0000000..f0c84d4
--- /dev/null
+++ 
b/providers/profitbricks/src/test/resources/datacenter/datacenter-updated.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/";>
+    <S:Body>
+        <ns2:updateDataCenterResponse 
xmlns:ns2="http://ws.api.profitbricks.com/";>
+            <return>
+                <requestId>1143190</requestId>
+                
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
+                <dataCenterVersion>2</dataCenterVersion>
+            </return>
+        </ns2:updateDataCenterResponse>
+    </S:Body>
+</S:Envelope>

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/providers/profitbricks/src/test/resources/datacenter/datacenter.xml
----------------------------------------------------------------------
diff --git 
a/providers/profitbricks/src/test/resources/datacenter/datacenter.xml 
b/providers/profitbricks/src/test/resources/datacenter/datacenter.xml
new file mode 100644
index 0000000..2911c81
--- /dev/null
+++ b/providers/profitbricks/src/test/resources/datacenter/datacenter.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/";>
+    <S:Body>
+        <ns2:getDataCenterResponse xmlns:ns2="http://ws.api.profitbricks.com/";>
+            <return>
+                <requestId>10933055</requestId>
+                
<dataCenterId>12345678-abcd-efgh-ijkl-987654321000</dataCenterId>
+                <dataCenterVersion>10</dataCenterVersion>
+                <dataCenterName>JClouds-DC</dataCenterName>
+                <servers>
+                    
<dataCenterId>12345678-abcd-efgh-ijkl-987654321000</dataCenterId>
+                    <dataCenterVersion>10</dataCenterVersion>
+                    <serverId>qqqqqqqq-wwww-eeee-rrrr-tttttttttttt</serverId>
+                    <serverName>jnode1</serverName>
+                    <cores>4</cores>
+                    <ram>4096</ram>
+                    <internetAccess>true</internetAccess>
+                    <ips>202.94.38.12</ips>
+                    <connectedStorages>
+                        <bootDevice>true</bootDevice>
+                        <busType>VIRTIO</busType>
+                        <deviceNumber>1</deviceNumber>
+                        <size>40</size>
+                        
<storageId>ssssssss-aaaa-ffff-gggg-hhhhhhhhhhhh</storageId>
+                        <storageName>jnode1-disk1</storageName>
+                    </connectedStorages>
+                    <nics>
+                        
<dataCenterId>12345678-abcd-efgh-ijkl-987654321000</dataCenterId>
+                        <dataCenterVersion>10</dataCenterVersion>
+                        <nicId>zzzzzzzz-xxxx-cccc-vvvv-bbbbbbbbbbbb</nicId>
+                        <lanId>1</lanId>
+                        <internetAccess>true</internetAccess>
+                        
<serverId>12345678-abcd-efgh-ijkl-987654321000</serverId>
+                        <ips>202.94.38.12</ips>
+                        <macAddress>02:01:09:cd:f0:b0</macAddress>
+                        <firewall>`
+                            <active>false</active>
+                            
<firewallId>llllllll-kkkk-jjjj-hhhh-gggggggggggg</firewallId>
+                            
<firewallId>62383ec1-38c8-486b-8fa2-a3bb0a5edd97</firewallId>
+                            <nicId>zzzzzzzz-xxxx-cccc-vvvv-bbbbbbbbbbbb</nicId>
+                            <provisioningState>AVAILABLE</provisioningState>
+                        </firewall>
+                        <dhcpActive>true</dhcpActive>
+                        <gatewayIp>202.94.38.1</gatewayIp>
+                        <provisioningState>AVAILABLE</provisioningState>
+                    </nics>
+                    <provisioningState>AVAILABLE</provisioningState>
+                    <virtualMachineState>RUNNING</virtualMachineState>
+                    <creationTime>2014-12-04T07:09:23.138Z</creationTime>
+                    
<lastModificationTime>2014-12-12T03:08:35.629Z</lastModificationTime>
+                    <osType>LINUX</osType>
+                    <availabilityZone>AUTO</availabilityZone>
+                    <cpuHotPlug>true</cpuHotPlug>
+                    <ramHotPlug>true</ramHotPlug>
+                    <nicHotPlug>true</nicHotPlug>
+                    <nicHotUnPlug>true</nicHotUnPlug>
+                    <discVirtioHotPlug>true</discVirtioHotPlug>
+                    <discVirtioHotUnPlug>true</discVirtioHotUnPlug>
+                </servers>
+                <storages>
+                    
<dataCenterId>12345678-abcd-efgh-ijkl-987654321000</dataCenterId>
+                    <dataCenterVersion>10</dataCenterVersion>
+                    <storageId>ssssssss-aaaa-ffff-gggg-hhhhhhhhhhhh</storageId>
+                    <size>40</size>
+                    <storageName>jnode1-disk1</storageName>
+                    <mountImage>
+                        <imageId>f0a59a5c-7940-11e4-8053-52540066fee9</imageId>
+                        
<imageName>Ubuntu-14.04-LTS-server-2014-12-01</imageName>
+                    </mountImage>
+                    <serverIds>qqqqqqqq-wwww-eeee-rrrr-tttttttttttt</serverIds>
+                    <provisioningState>AVAILABLE</provisioningState>
+                    <creationTime>2014-12-04T07:09:23.138Z</creationTime>
+                    
<lastModificationTime>2014-12-12T03:14:48.316Z</lastModificationTime>
+                </storages>
+                <provisioningState>AVAILABLE</provisioningState>
+                <location>us/las</location>
+            </return>
+        </ns2:getDataCenterResponse>
+    </S:Body>
+</S:Envelope>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/providers/profitbricks/src/test/resources/datacenter/datacenters.xml
----------------------------------------------------------------------
diff --git 
a/providers/profitbricks/src/test/resources/datacenter/datacenters.xml 
b/providers/profitbricks/src/test/resources/datacenter/datacenters.xml
new file mode 100644
index 0000000..b3b7bc3
--- /dev/null
+++ b/providers/profitbricks/src/test/resources/datacenter/datacenters.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/";>
+    <S:Body>
+        <ns2:getAllDataCentersResponse 
xmlns:ns2="http://ws.api.profitbricks.com/";>
+            <return>
+                
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
+                <dataCenterName>JClouds-DC</dataCenterName>
+                <dataCenterVersion>10</dataCenterVersion>
+                <provisioningState>AVAILABLE</provisioningState>
+            </return>
+            <return>
+                
<dataCenterId>qqqqqqqq-wwww-rrrr-tttt-yyyyyyyyyyyy</dataCenterId>
+                <dataCenterName>Random DC</dataCenterName>
+                <dataCenterVersion>238</dataCenterVersion>
+                <provisioningState>INPROCESS</provisioningState>
+            </return>
+        </ns2:getAllDataCentersResponse>
+    </S:Body>
+</S:Envelope>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/providers/profitbricks/src/test/resources/fault-400.xml
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/resources/fault-400.xml 
b/providers/profitbricks/src/test/resources/fault-400.xml
new file mode 100644
index 0000000..9648b2a
--- /dev/null
+++ b/providers/profitbricks/src/test/resources/fault-400.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>RAM of requested server too small, 256 Mb is 
minimum</faultstring>
+            <detail>
+                <ns2:ProfitbricksServiceFault 
xmlns:ns2="http://ws.api.profitbricks.com/";>
+                    <faultCode>BAD_REQUEST</faultCode>
+                    <httpCode>400</httpCode>
+                    <message>RAM of requested server too small, 256 Mb is 
minimum</message>
+                    <requestId>1045</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/cb45048a/providers/profitbricks/src/test/resources/fault-401.html
----------------------------------------------------------------------
diff --git a/providers/profitbricks/src/test/resources/fault-401.html 
b/providers/profitbricks/src/test/resources/fault-401.html
new file mode 100644
index 0000000..ecadab1
--- /dev/null
+++ b/providers/profitbricks/src/test/resources/fault-401.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";>
+<html xmlns="http://www.w3.org/1999/xhtml";>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" 
lang="en"/>
+        <title>Profitbricks | 401 Unauthorized</title>
+        <base href="/"/>
+        <link rel="stylesheet" type="text/css" href="css/style.css"/>
+        <link rel="stylesheet" type="text/css" href="css/content.css"/>
+        <link rel="stylesheet" type="text/css" 
href="css/recent_additions.css"/>
+        <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
+    </head>
+    <body>
+        <div class="head1 h_bg"/>
+        <div class="head2 h_bg"/>
+        <div class="head3 h_bg"/>
+        <div id="wrapper">
+            <div class="wrapper_inner">
+                <div id="header">
+                    <a id="logo" href="#">
+                        <img alt="Profitbricks" src="img/logo.png"/>
+                    </a>
+                </div>
+                <div id="main">
+                    <div id="right" style="min-height: 550px;">
+                        <div class="article msg">
+                            <h1>Unauthorized</h1>
+                            <img title="" alt="message error" 
src="img/msg_error.png" class="msg_sign" style="margin: 10px;" height="49" 
width="49"/>
+                            <div class="container" style="margin:20px 80px 
!important;">
+                                <p class="bigmargin">This request requires 
authentication.</p>
+                            </div>
+                        </div>
+                    </div>
+                    <br class="clear"/>
+                </div>
+            </div>
+        </div>
+        <div id="footer">
+            <div class="bottom">
+                <div class="inner"></div>
+            </div>
+        </div>
+    </body>
+</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jclouds/blob/cb45048a/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
new file mode 100644
index 0000000..486706d
--- /dev/null
+++ b/providers/profitbricks/src/test/resources/fault-404.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

Reply via email to