Repository: jclouds-labs
Updated Branches:
  refs/heads/master 7b3c8788c -> 9a8b346ca


http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9a8b346c/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/ServerApiMockTest.java
----------------------------------------------------------------------
diff --git 
a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/ServerApiMockTest.java
 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/ServerApiMockTest.java
index 13e867e..20bbf0a 100644
--- 
a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/ServerApiMockTest.java
+++ 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/ServerApiMockTest.java
@@ -25,7 +25,6 @@ import 
org.apache.jclouds.profitbricks.rest.domain.options.DepthOptions;
 import 
org.apache.jclouds.profitbricks.rest.internal.BaseProfitBricksApiMockTest;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
 import org.testng.annotations.Test;
 
 @Test(groups = "unit", testName = "ServerApiMockTest", singleThreaded = true)
@@ -62,16 +61,7 @@ public class ServerApiMockTest extends 
BaseProfitBricksApiMockTest {
       assertEquals(server.getRequestCount(), 1);
       assertSent(server, "GET", "/datacenters/datacenter-id/servers?depth=5");
    }
-   
-   @Test
-   public void testGetListWith404() throws InterruptedException {
-      server.enqueue(new MockResponse().setResponseCode(404));
-      List<Server> list = serverApi().getList("datacenter-id", new 
DepthOptions().depth(1));
-      assertTrue(list.isEmpty());
-      assertEquals(server.getRequestCount(), 1);
-      assertSent(server, "GET", "/datacenters/datacenter-id/servers?depth=1");
-   }
-    
+
    @Test
    public void testGetServer() throws InterruptedException {
       MockResponse response = new MockResponse();
@@ -106,17 +96,6 @@ public class ServerApiMockTest extends 
BaseProfitBricksApiMockTest {
       assertSent(this.server, "GET", 
"/datacenters/datacenter-id/servers/some-id?depth=5");
    }
    
-   public void testGetServerWith404() throws InterruptedException {
-      server.enqueue(response404());
-
-      Server server = serverApi().getServer("datacenter-id", "some-id");
-      
-      assertEquals(server, null);
-
-      assertEquals(this.server.getRequestCount(), 1);
-      assertSent(this.server, "GET", 
"/datacenters/datacenter-id/servers/some-id");
-   }
-   
    @Test
    public void testCreate() throws InterruptedException {
       server.enqueue(
@@ -143,7 +122,7 @@ public class ServerApiMockTest extends 
BaseProfitBricksApiMockTest {
    @Test
    public void testUpdate() throws InterruptedException {
       server.enqueue(
-         new MockResponse().setBody(stringFromResource("/datacenter/get.json"))
+         new MockResponse().setBody(stringFromResource("/server/get.json"))
       );
       
       api.serverApi().updateServer(
@@ -167,17 +146,7 @@ public class ServerApiMockTest extends 
BaseProfitBricksApiMockTest {
       assertEquals(server.getRequestCount(), 1);
       assertSent(server, "DELETE", 
"/datacenters/datacenter-id/servers/some-id");
    }
-   
-   @Test
-   public void testDeleteWith404() throws InterruptedException {
-      server.enqueue(response404());
 
-      serverApi().deleteServer("datacenter-id", "some-id");
-      
-      assertEquals(server.getRequestCount(), 1);
-      assertSent(server, "DELETE", 
"/datacenters/datacenter-id/servers/some-id");
-   }
-   
    @Test
    public void testStopServer() throws InterruptedException {
       server.enqueue(response204());
@@ -227,14 +196,14 @@ public class ServerApiMockTest extends 
BaseProfitBricksApiMockTest {
       Volume volume = 
serverApi().attachVolume(Server.Request.attachVolumeBuilder()
               .dataCenterId("datacenter-id")
               .serverId("server-id")
-              .imageId("image-id")
+              .volumeId("volume-id")
               .build()
       );
       
       assertEquals(volume.properties().name(), "Storage");
       
       assertEquals(server.getRequestCount(), 1);
-      assertSent(server, "POST", 
"/rest/datacenters/datacenter-id/servers/server-id/volumes", "{\"id\": 
\"image-id\"}");
+      assertSent(server, "POST", 
"/rest/datacenters/datacenter-id/servers/server-id/volumes", "{\"id\": 
\"volume-id\"}");
    }
    
    @Test

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9a8b346c/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/VolumeApiLiveTest.java
----------------------------------------------------------------------
diff --git 
a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/VolumeApiLiveTest.java
 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/VolumeApiLiveTest.java
new file mode 100644
index 0000000..98a9693
--- /dev/null
+++ 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/VolumeApiLiveTest.java
@@ -0,0 +1,175 @@
+/*
+ * 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.apache.jclouds.profitbricks.rest.features;
+
+import com.google.common.base.Predicate;
+import java.util.List;
+import org.apache.jclouds.profitbricks.rest.domain.DataCenter;
+import org.apache.jclouds.profitbricks.rest.domain.LicenceType;
+import org.apache.jclouds.profitbricks.rest.domain.Snapshot;
+import org.apache.jclouds.profitbricks.rest.domain.State;
+import org.apache.jclouds.profitbricks.rest.domain.Volume;
+import org.apache.jclouds.profitbricks.rest.ids.VolumeRef;
+import org.apache.jclouds.profitbricks.rest.internal.BaseProfitBricksLiveTest;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+
+@Test(groups = "live", testName = "VolumeApiLiveTest")
+public class VolumeApiLiveTest extends BaseProfitBricksLiveTest {
+
+   DataCenter dataCenter;
+   Volume testVolume;
+   Snapshot testSnapshot;
+
+   @BeforeClass
+   public void setupTest() {
+      dataCenter = createDataCenter();
+   }
+
+   @AfterClass(alwaysRun = true)
+   public void teardownTest() {
+      if (dataCenter != null)
+         deleteDataCenter(dataCenter.id());
+   }
+
+   @Test
+   public void testCreateVolume() {
+      assertNotNull(dataCenter);
+
+      testVolume = volumeApi().createVolume(
+              Volume.Request.creatingBuilder()
+              .dataCenterId(dataCenter.id())
+              .name("jclouds-volume")
+              .size(3)
+              .licenceType(LicenceType.LINUX)
+              .build());
+
+      assertNotNull(testVolume);
+      assertEquals(testVolume.properties().name(), "jclouds-volume");
+      assertVolumeAvailable(testVolume);
+   }
+
+
+   @Test(dependsOnMethods = "testCreateVolume")
+   public void testGetVolume() {
+      Volume volume = volumeApi().getVolume(dataCenter.id(), testVolume.id());
+
+      assertNotNull(volume);
+      assertEquals(volume.id(), testVolume.id());
+   }
+
+   @Test(dependsOnMethods = "testCreateVolume")
+   public void testList() {
+      List<Volume> volumes = volumeApi().getList(dataCenter.id());
+
+      assertNotNull(volumes);
+      assertFalse(volumes.isEmpty());
+      assertEquals(volumes.size(), 1);
+   }
+
+   @Test(dependsOnMethods = "testGetVolume")
+   public void testUpdateVolume() {
+      assertDataCenterAvailable(dataCenter);
+
+      Volume volume = api.volumeApi().updateVolume(
+              Volume.Request.updatingBuilder()
+              .dataCenterId(testVolume.dataCenterId())
+              .id(testVolume.id())
+              .name("apache-volume")
+              .build());
+
+      assertVolumeAvailable(testVolume);
+      assertEquals(volume.properties().name(), "apache-volume");
+   }
+
+   @Test(dependsOnMethods = "testUpdateVolume")
+   public void testCreateSnapshot() {
+      testSnapshot = volumeApi().createSnapshot(
+         Volume.Request.createSnapshotBuilder()
+            .dataCenterId(testVolume.dataCenterId())
+            .volumeId(testVolume.id())
+            .name("test-snapshot")
+            .description("snapshot desc...")
+            .build());
+
+      assertSnapshotAvailable(testSnapshot);
+   }
+
+   @Test(dependsOnMethods = "testCreateSnapshot")
+   public void testRestoreSnapshot() {
+      volumeApi().restoreSnapshot(
+         Volume.Request.restoreSnapshotBuilder()
+            .dataCenterId(testVolume.dataCenterId())
+            .volumeId(testVolume.id())
+            .snapshotId(testSnapshot.id())
+            .build()
+      );
+      assertVolumeAvailable(testVolume);
+   }
+
+   @Test(dependsOnMethods = "testRestoreSnapshot")
+   public void testDeleteVolume() {
+      volumeApi().deleteVolume(testVolume.dataCenterId(), testVolume.id());
+      assertVolumeRemoved(testVolume);
+   }
+
+   private void assertVolumeAvailable(Volume volume) {
+      assertRandom(new Predicate<VolumeRef>() {
+         @Override
+         public boolean apply(VolumeRef volumeRef) {
+            Volume volume = volumeApi().getVolume(volumeRef.dataCenterId(), 
volumeRef.volumeId());
+
+            if (volume == null || volume.metadata() == null)
+               return false;
+
+            return volume.metadata().state() == State.AVAILABLE;
+         }
+      }, VolumeRef.create(volume.dataCenterId(), volume.id()));
+   }
+
+   private void assertVolumeRemoved(Volume volume) {
+      assertRandom(new Predicate<VolumeRef>() {
+         @Override
+         public boolean apply(VolumeRef volumeRef) {
+            return volumeApi().getVolume(volumeRef.dataCenterId(), 
volumeRef.volumeId()) == null;
+         }
+      }, VolumeRef.create(volume.dataCenterId(), volume.id()));
+   }
+
+   private void assertSnapshotAvailable(Snapshot snapshot) {
+      assertRandom(new Predicate<String>() {
+         @Override
+         public boolean apply(String id) {
+            Snapshot snapshot = api.snapshotApi().getSnapshot(id);
+
+            if (snapshot == null || snapshot.metadata() == null)
+               return false;
+
+            return snapshot.metadata().state() == State.AVAILABLE;
+         }
+      }, snapshot.id());
+   }
+
+   private VolumeApi volumeApi() {
+      return api.volumeApi();
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9a8b346c/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/VolumeApiMockTest.java
----------------------------------------------------------------------
diff --git 
a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/VolumeApiMockTest.java
 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/VolumeApiMockTest.java
new file mode 100644
index 0000000..433063d
--- /dev/null
+++ 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/VolumeApiMockTest.java
@@ -0,0 +1,154 @@
+/*
+ * 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.apache.jclouds.profitbricks.rest.features;
+
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import java.util.List;
+import org.apache.jclouds.profitbricks.rest.domain.LicenceType;
+import org.apache.jclouds.profitbricks.rest.domain.Volume;
+import 
org.apache.jclouds.profitbricks.rest.internal.BaseProfitBricksApiMockTest;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "VolumeApiMockTest", singleThreaded = true)
+public class VolumeApiMockTest extends BaseProfitBricksApiMockTest {
+   
+   @Test
+   public void testGetList() throws InterruptedException {
+      server.enqueue(
+         new MockResponse().setBody(stringFromResource("/volume/list.json"))
+      );
+      
+      List<Volume> list = volumeApi().getList("datacenter-id");
+      
+      assertNotNull(list);
+      assertEquals(list.size(), 6);
+      assertEquals(list.get(0).properties().name(), "Docker Registry Volume");
+      
+      assertEquals(server.getRequestCount(), 1);
+      assertSent(server, "GET", "/datacenters/datacenter-id/volumes");
+   }
+    
+   @Test
+   public void testGetVolume() throws InterruptedException {
+      MockResponse response = new MockResponse();
+      response.setBody(stringFromResource("/volume/get.json"));
+      response.setHeader("Content-Type", 
"application/vnd.profitbricks.resource+json");
+      
+      server.enqueue(response);
+      
+      Volume volume = volumeApi().getVolume("datacenter-id", "some-id");
+      
+      assertNotNull(volume);
+      assertEquals(volume.properties().name(), "Docker Registry Volume");
+      
+      assertEquals(server.getRequestCount(), 1);
+      assertSent(server, "GET", "/datacenters/datacenter-id/volumes/some-id");
+   }
+      
+   @Test
+   public void testCreate() throws InterruptedException {
+      server.enqueue(
+         new MockResponse().setBody(stringFromResource("/volume/get.json"))
+      );
+      
+      Volume volume = volumeApi().createVolume(
+              Volume.Request.creatingBuilder()
+              .dataCenterId("datacenter-id")
+              .name("jclouds-volume")
+              .size(3)
+              .licenceType(LicenceType.LINUX)
+              .build());
+
+      assertNotNull(volume);
+      assertNotNull(volume.id());
+      
+      assertEquals(server.getRequestCount(), 1);
+      assertSent(server, "POST", "/rest/datacenters/datacenter-id/volumes", 
+              "{\"properties\": {\"name\": \"jclouds-volume\", \"size\": 3, 
\"licenceType\": \"LINUX\"}}"
+      );
+   }
+   
+   @Test
+   public void testUpdate() throws InterruptedException {
+      server.enqueue(
+         new MockResponse().setBody(stringFromResource("/volume/get.json"))
+      );
+      
+      api.volumeApi().updateVolume(
+              Volume.Request.updatingBuilder()
+              .id("some-id")
+              .dataCenterId("datacenter-id")
+              .name("apache-volume")
+              .build());
+            
+      assertEquals(server.getRequestCount(), 1);
+      assertSent(server, "PATCH", 
"/rest/datacenters/datacenter-id/volumes/some-id", "{\"name\": 
\"apache-volume\"}");
+   }
+   
+   @Test
+   public void testDelete() throws InterruptedException {
+      server.enqueue(
+         new MockResponse().setBody("")
+      );
+      
+      volumeApi().deleteVolume("datacenter-id", "some-id");
+      assertEquals(server.getRequestCount(), 1);
+      assertSent(server, "DELETE", 
"/datacenters/datacenter-id/volumes/some-id");
+   }
+   
+   @Test
+   public void testCreateSnapshot() throws InterruptedException {
+      server.enqueue(
+         new 
MockResponse().setBody(stringFromResource("/volume/snapshot.json"))
+      );
+      
+      volumeApi().createSnapshot(
+         Volume.Request.createSnapshotBuilder()
+            .dataCenterId("datacenter-id")
+            .volumeId("volume-id")
+            .name("test snapshot")
+            .build()
+      );
+      
+      assertEquals(server.getRequestCount(), 1);
+      assertSent(server, "POST", 
"/rest/datacenters/datacenter-id/volumes/volume-id/create-snapshot");
+   }
+   
+   @Test
+   public void testRestoreSnapshot() throws InterruptedException {
+      
+      server.enqueue(response204());
+      
+      volumeApi().restoreSnapshot(
+         Volume.Request.restoreSnapshotBuilder()
+            .dataCenterId("datacenter-id")
+            .volumeId("volume-id")
+            .snapshotId("snapshot-id")
+            .build()
+      );
+      
+      assertEquals(server.getRequestCount(), 1);
+      assertSent(server, "POST", 
"/rest/datacenters/datacenter-id/volumes/volume-id/restore-snapshot");
+   }
+        
+   private VolumeApi volumeApi() {
+      return api.volumeApi();
+   }
+   
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9a8b346c/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/internal/BaseProfitBricksApiMockTest.java
----------------------------------------------------------------------
diff --git 
a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/internal/BaseProfitBricksApiMockTest.java
 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/internal/BaseProfitBricksApiMockTest.java
index 58cad1f..5a21eb3 100644
--- 
a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/internal/BaseProfitBricksApiMockTest.java
+++ 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/internal/BaseProfitBricksApiMockTest.java
@@ -85,17 +85,13 @@ public class BaseProfitBricksApiMockTest {
    protected MockResponse response204() {
       return new MockResponse().setStatus("HTTP/1.1 204 No Content");
    }
-
-   protected MockResponse response404() {
-      return new MockResponse().setStatus("HTTP/1.1 404 Not Found");
-   }
-
+   
    protected String stringFromResource(String resourceName) {
       try {
-        return Resources.toString(getClass().getResource(resourceName), 
Charsets.UTF_8)
-                .replace(DEFAULT_ENDPOINT, url(""));
+         return Resources.toString(getClass().getResource(resourceName), 
Charsets.UTF_8)
+            .replace(DEFAULT_ENDPOINT, url(""));
       } catch (IOException e) {
-        throw Throwables.propagate(e);
+         throw Throwables.propagate(e);
       }
    }
 

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9a8b346c/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/internal/BaseProfitBricksLiveTest.java
----------------------------------------------------------------------
diff --git 
a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/internal/BaseProfitBricksLiveTest.java
 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/internal/BaseProfitBricksLiveTest.java
index 7ebb32e..75eefc7 100644
--- 
a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/internal/BaseProfitBricksLiveTest.java
+++ 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/internal/BaseProfitBricksLiveTest.java
@@ -31,10 +31,13 @@ import static 
org.apache.jclouds.profitbricks.rest.config.ProfitBricksComputePro
 import static 
org.apache.jclouds.profitbricks.rest.config.ProfitBricksComputeProperties.TIMEOUT_NODE_RUNNING;
 import static 
org.apache.jclouds.profitbricks.rest.config.ProfitBricksComputeProperties.TIMEOUT_NODE_SUSPENDED;
 import org.apache.jclouds.profitbricks.rest.domain.DataCenter;
+import org.apache.jclouds.profitbricks.rest.domain.LicenceType;
 import org.apache.jclouds.profitbricks.rest.domain.Location;
 import org.apache.jclouds.profitbricks.rest.domain.Server;
 import org.apache.jclouds.profitbricks.rest.domain.State;
+import org.apache.jclouds.profitbricks.rest.domain.Volume;
 import org.apache.jclouds.profitbricks.rest.ids.ServerRef;
+import org.apache.jclouds.profitbricks.rest.ids.VolumeRef;
 import org.jclouds.apis.BaseApiLiveTest;
 import org.jclouds.util.Predicates2;
 import static org.testng.Assert.assertTrue;
@@ -48,6 +51,7 @@ public class BaseProfitBricksLiveTest extends 
BaseApiLiveTest<ProfitBricksApi> {
    private Predicate<ServerRef> serverSuspended;
    private Predicate<ServerRef> serverAvailable;
    private Predicate<ServerRef> serverRemoved;
+   private Predicate<VolumeRef> volumeAvailable;
    
    ComputeConstants computeConstants;
    
@@ -98,13 +102,27 @@ public class BaseProfitBricksLiveTest extends 
BaseApiLiveTest<ProfitBricksApi> {
       };
       
       serverRemoved = Predicates2.retry(serverRemovedPredicate, 
c.pollTimeout(), c.pollPeriod(), c.pollMaxPeriod(), TimeUnit.SECONDS);
+      
+      Predicate<VolumeRef> volumeAvailablePredicate = new 
Predicate<VolumeRef>() {
+         @Override
+         public boolean apply(VolumeRef volumeRef) {
+            Volume volume = 
api.volumeApi().getVolume(volumeRef.dataCenterId(), volumeRef.volumeId());
+            
+            if (volume == null || volume.metadata() == null)
+               return false;
 
+            return volume.metadata().state() == State.AVAILABLE;
+         }
+      };
+      
+      volumeAvailable = Predicates2.retry(volumeAvailablePredicate, 
c.pollTimeout(), c.pollPeriod(), c.pollMaxPeriod(), TimeUnit.SECONDS);
+              
       return injector.getInstance(ProfitBricksApi.class);
    }
    
-   protected void assertRandom(Predicate<String> check, String arguments) {
+   protected <T> void assertRandom(Predicate<T> check, T arguments) {
       ComputeConstants c = computeConstants;
-      Predicate<String> checkPoll = Predicates2.retry(check, c.pollTimeout(), 
c.pollPeriod(), c.pollMaxPeriod(), TimeUnit.SECONDS);
+      Predicate<T>checkPoll = Predicates2.retry(check, c.pollTimeout(), 
c.pollPeriod(), c.pollMaxPeriod(), TimeUnit.SECONDS);
       assertTrue(checkPoll.apply(arguments), "Random check failed in the 
configured timeout");
    }
 
@@ -133,6 +151,11 @@ public class BaseProfitBricksLiveTest extends 
BaseApiLiveTest<ProfitBricksApi> {
       assertTrue(serverAvailable.apply(serverRef), String.format("Server %s is 
not available", serverRef));
    }
    
+   protected void assertVolumeAvailable(VolumeRef volumeRef) {
+      assertTrue(volumeAvailable.apply(volumeRef),
+              String.format("Volume %s wasn't available in the configured 
timeout", volumeRef.volumeId()));
+   }
+   
    protected DataCenter createDataCenter() {
       return api.dataCenterApi().create("test-data-center", "example 
description", TestLocation.value());
    }
@@ -141,6 +164,16 @@ public class BaseProfitBricksLiveTest extends 
BaseApiLiveTest<ProfitBricksApi> {
       api.dataCenterApi().delete(id);
    }
    
+   protected Volume createVolume(DataCenter dataCenter) {
+      return api.volumeApi().createVolume(
+              Volume.Request.creatingBuilder()
+              .dataCenterId(dataCenter.id())
+              .name("jclouds-volume")
+              .size(3)
+              .licenceType(LicenceType.LINUX)
+              .build());
+   }
+   
    protected String complexId(String ... ids) {
       return Joiner.on(",").join(ids);
    }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9a8b346c/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/util/MacAddressesTest.java
----------------------------------------------------------------------
diff --git 
a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/util/MacAddressesTest.java
 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/util/MacAddressesTest.java
new file mode 100644
index 0000000..ec431e1
--- /dev/null
+++ 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/util/MacAddressesTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.apache.jclouds.profitbricks.rest.util;
+
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import static 
org.apache.jclouds.profitbricks.rest.util.MacAddresses.isMacAddress;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "MacAddressesTest")
+public class MacAddressesTest {
+
+   private final List<String> expectedValidAddresses = ImmutableList.of(
+           "aa:bb:cc:dd:ee:ff", "11:22:33:44:55:66"
+   );
+   private final List<String> expectedInvalidAddresses = ImmutableList.of(
+           "AA:BB:CC:DD:EE:FF", "aa-bb-cc-dd-ee-ff", "", "aabbccddeeff",
+           "aa:bb:cc:dd:ff", "gg:aa:bb:cc:dd:ee"
+   );
+
+   @Test
+   public void testIsMacAddress() {
+      for (String addr : expectedValidAddresses)
+         assertTrue(isMacAddress(addr));
+
+      for (String addr : expectedInvalidAddresses)
+         assertFalse(isMacAddress(addr));
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9a8b346c/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/util/ParseIdTest.java
----------------------------------------------------------------------
diff --git 
a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/util/ParseIdTest.java
 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/util/ParseIdTest.java
new file mode 100644
index 0000000..f1e0499
--- /dev/null
+++ 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/util/ParseIdTest.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.apache.jclouds.profitbricks.rest.util;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
+import com.google.common.reflect.TypeToken;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import java.io.IOException;
+import java.lang.reflect.Type;
+import java.util.Map;
+import org.jclouds.json.Json;
+import org.jclouds.json.config.GsonModule;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "ParseIdTest")
+public class ParseIdTest {
+
+   @Test
+   public void testIdExtraction() throws IOException {
+      String serverResult = 
Resources.toString(getClass().getResource("/server/get.json"), Charsets.UTF_8);
+      
+      Injector injector = Guice.createInjector(new GsonModule());
+      ParseId parseService = injector.getInstance(ParseId.class);
+      Json json = injector.getInstance(Json.class);
+      
+      String result = parseService.parseId(serverResult, "datacenters", 
"dataCenterId");
+      
+      Type mapType = new TypeToken<Map<String, Object>>(){}.getType();
+      Map<String, String> jsonMap = json.fromJson(result, mapType);
+      
assertTrue(jsonMap.get("dataCenterId").equals("b0ac144e-e294-415f-ba39-6737d5a9d419"));
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9a8b346c/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/util/PasswordsTest.java
----------------------------------------------------------------------
diff --git 
a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/util/PasswordsTest.java
 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/util/PasswordsTest.java
new file mode 100644
index 0000000..7b470ce
--- /dev/null
+++ 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/util/PasswordsTest.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.apache.jclouds.profitbricks.rest.util;
+
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import static 
org.apache.jclouds.profitbricks.rest.util.Passwords.isValidPassword;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "PasswordsTest")
+public class PasswordsTest {
+
+   private final List<String> validPasswords = ImmutableList.of(
+           "fKVasTnNm", "84625894", "QQQQQQQQ", "qqqqqqqq", "asdfghjk"
+   );
+   private final List<String> invalidPasswords = ImmutableList.of(
+           "", "apachejclouds", "s0merand0mpassw0rd"
+   );
+
+   @Test
+   public void testPasswordValidation() {
+      for (String pwd : validPasswords)
+         assertTrue(isValidPassword(pwd), "Should've been valid: " + pwd);
+
+      for (String pwd : invalidPasswords)
+         assertFalse(isValidPassword(pwd), "Should've been invalid: " + pwd);
+   }
+
+   @Test
+   public void testGeneratorGeneratesValidPassword() {
+      final int times = 50;
+      for (int i = 0; i < times; i++) {
+         String pwd = Passwords.generate();
+         assertTrue(isValidPassword(pwd), "Failed with: " + pwd);
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9a8b346c/profitbricks-rest/src/test/resources/volume/get.json
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/test/resources/volume/get.json 
b/profitbricks-rest/src/test/resources/volume/get.json
new file mode 100644
index 0000000..c5d3ba1
--- /dev/null
+++ b/profitbricks-rest/src/test/resources/volume/get.json
@@ -0,0 +1,33 @@
+{
+  "id": "5c4d37ca-d620-4546-8b24-f92e3c608c2c",
+  "type": "volume",
+  "href": 
"https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/volumes/5c4d37ca-d620-4546-8b24-f92e3c608c2c";,
+  "metadata": {
+    "createdDate": "2015-03-18T21:31:10Z",
+    "createdBy": "[email protected]",
+    "etag": "0018832d7a7ba455db74ac41ae9f11fe",
+    "lastModifiedDate": "2015-03-18T21:31:10Z",
+    "lastModifiedBy": "[email protected]",
+    "state": "AVAILABLE"
+  },
+  "properties": {
+    "name": "Docker Registry Volume",
+    "type": "HDD",
+    "size": 50,
+    "image": null,
+    "imagePassword": null,
+    "bus": "VIRTIO",
+    "licenceType": "OTHER",
+    "cpuHotPlug": false,
+    "cpuHotUnplug": false,
+    "ramHotPlug": false,
+    "ramHotUnplug": false,
+    "nicHotPlug": false,
+    "nicHotUnplug": false,
+    "discVirtioHotPlug": false,
+    "discVirtioHotUnplug": false,
+    "discScsiHotPlug": false,
+    "discScsiHotUnplug": false,
+    "deviceNumber": 2
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9a8b346c/profitbricks-rest/src/test/resources/volume/list.json
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/test/resources/volume/list.json 
b/profitbricks-rest/src/test/resources/volume/list.json
new file mode 100644
index 0000000..faed34e
--- /dev/null
+++ b/profitbricks-rest/src/test/resources/volume/list.json
@@ -0,0 +1,205 @@
+{
+  "id": "b0ac144e-e294-415f-ba39-6737d5a9d419/volumes",
+  "type": "collection",
+  "href": 
"https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/volumes";,
+  "items": [
+    {
+      "id": "5c4d37ca-d620-4546-8b24-f92e3c608c2c",
+      "type": "volume",
+      "href": 
"https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/volumes/5c4d37ca-d620-4546-8b24-f92e3c608c2c";,
+      "metadata": {
+        "createdDate": "2015-03-18T21:31:10Z",
+        "createdBy": "[email protected]",
+        "etag": "0018832d7a7ba455db74ac41ae9f11fe",
+        "lastModifiedDate": "2015-03-18T21:31:10Z",
+        "lastModifiedBy": "[email protected]",
+        "state": "AVAILABLE"
+      },
+      "properties": {
+        "name": "Docker Registry Volume",
+        "type": "HDD",
+        "size": 50,
+        "image": null,
+        "imagePassword": null,
+        "bus": "VIRTIO",
+        "licenceType": "OTHER",
+        "cpuHotPlug": false,
+        "cpuHotUnplug": false,
+        "ramHotPlug": false,
+        "ramHotUnplug": false,
+        "nicHotPlug": false,
+        "nicHotUnplug": false,
+        "discVirtioHotPlug": false,
+        "discVirtioHotUnplug": false,
+        "discScsiHotPlug": false,
+        "discScsiHotUnplug": false,
+        "deviceNumber": 2
+      }
+    },
+    {
+      "id": "f9217444-4711-477f-83d8-24adea5d9557",
+      "type": "volume",
+      "href": 
"https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/volumes/f9217444-4711-477f-83d8-24adea5d9557";,
+      "metadata": {
+        "createdDate": "2015-03-18T19:00:51Z",
+        "createdBy": "[email protected]",
+        "etag": "c4a2fde6ba91a038ff953b939cc21efe",
+        "lastModifiedDate": "2015-03-18T19:00:51Z",
+        "lastModifiedBy": "[email protected]",
+        "state": "AVAILABLE"
+      },
+      "properties": {
+        "name": "master 1 Storage",
+        "type": "HDD",
+        "size": 50,
+        "image": "681673e7-bfc2-11e4-850c-52540066fee9",
+        "imagePassword": null,
+        "bus": "VIRTIO",
+        "licenceType": "OTHER",
+        "cpuHotPlug": true,
+        "cpuHotUnplug": false,
+        "ramHotPlug": false,
+        "ramHotUnplug": false,
+        "nicHotPlug": true,
+        "nicHotUnplug": true,
+        "discVirtioHotPlug": true,
+        "discVirtioHotUnplug": true,
+        "discScsiHotPlug": false,
+        "discScsiHotUnplug": false,
+        "deviceNumber": 1
+      }
+    },
+    {
+      "id": "0eea1824-8079-4c80-8e18-4e1e41a80368",
+      "type": "volume",
+      "href": 
"https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/volumes/0eea1824-8079-4c80-8e18-4e1e41a80368";,
+      "metadata": {
+        "createdDate": "2015-03-18T19:00:51Z",
+        "createdBy": "[email protected]",
+        "etag": "c4a2fde6ba91a038ff953b939cc21efe",
+        "lastModifiedDate": "2015-03-18T19:00:51Z",
+        "lastModifiedBy": "[email protected]",
+        "state": "AVAILABLE"
+      },
+      "properties": {
+        "name": "node Storage",
+        "type": "HDD",
+        "size": 50,
+        "image": "681673e7-bfc2-11e4-850c-52540066fee9",
+        "imagePassword": null,
+        "bus": "VIRTIO",
+        "licenceType": "OTHER",
+        "cpuHotPlug": true,
+        "cpuHotUnplug": false,
+        "ramHotPlug": false,
+        "ramHotUnplug": false,
+        "nicHotPlug": true,
+        "nicHotUnplug": true,
+        "discVirtioHotPlug": true,
+        "discVirtioHotUnplug": true,
+        "discScsiHotPlug": false,
+        "discScsiHotUnplug": false,
+        "deviceNumber": 1
+      }
+    },
+    {
+      "id": "c04a2198-7e60-4bc0-b869-6e9c9dbcb8e1",
+      "type": "volume",
+      "href": 
"https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/volumes/c04a2198-7e60-4bc0-b869-6e9c9dbcb8e1";,
+      "metadata": {
+        "createdDate": "2014-10-20T21:20:46Z",
+        "createdBy": "[email protected]",
+        "etag": "7a539b539d8ca9e08c5ac5e63c9c4c8f",
+        "lastModifiedDate": "2014-10-20T21:20:46Z",
+        "lastModifiedBy": "[email protected]",
+        "state": "AVAILABLE"
+      },
+      "properties": {
+        "name": "Storage",
+        "type": "HDD",
+        "size": 50,
+        "image": "4f363db0-4955-11e4-b362-52540066fee9",
+        "imagePassword": null,
+        "bus": "VIRTIO",
+        "licenceType": "LINUX",
+        "cpuHotPlug": true,
+        "cpuHotUnplug": false,
+        "ramHotPlug": true,
+        "ramHotUnplug": false,
+        "nicHotPlug": true,
+        "nicHotUnplug": true,
+        "discVirtioHotPlug": true,
+        "discVirtioHotUnplug": true,
+        "discScsiHotPlug": false,
+        "discScsiHotUnplug": false,
+        "deviceNumber": 1
+      }
+    },
+    {
+      "id": "dc2f35f4-7335-46f2-b30f-96e31c5ba54d",
+      "type": "volume",
+      "href": 
"https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/volumes/dc2f35f4-7335-46f2-b30f-96e31c5ba54d";,
+      "metadata": {
+        "createdDate": "2015-05-12T17:20:21Z",
+        "createdBy": "[email protected]",
+        "etag": "95c6a09c3aa29672c4baf3c52abb2506",
+        "lastModifiedDate": "2015-05-12T17:20:21Z",
+        "lastModifiedBy": "[email protected]",
+        "state": "AVAILABLE"
+      },
+      "properties": {
+        "name": "default-dockerui002-6386",
+        "type": "HDD",
+        "size": 20,
+        "image": "c1fc45a9-efb2-11e4-9660-52540066fee9",
+        "imagePassword": null,
+        "bus": "VIRTIO",
+        "licenceType": "LINUX",
+        "cpuHotPlug": true,
+        "cpuHotUnplug": false,
+        "ramHotPlug": true,
+        "ramHotUnplug": false,
+        "nicHotPlug": true,
+        "nicHotUnplug": true,
+        "discVirtioHotPlug": true,
+        "discVirtioHotUnplug": true,
+        "discScsiHotPlug": false,
+        "discScsiHotUnplug": false,
+        "deviceNumber": 1
+      }
+    },
+    {
+      "id": "af473785-b791-4724-bb01-242035bf88ef",
+      "type": "volume",
+      "href": 
"https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/volumes/af473785-b791-4724-bb01-242035bf88ef";,
+      "metadata": {
+        "createdDate": "2015-04-28T13:19:42Z",
+        "createdBy": "[email protected]",
+        "etag": "1c542f43914756144e950e37f1a6f3ad",
+        "lastModifiedDate": "2015-04-28T13:19:42Z",
+        "lastModifiedBy": "[email protected]",
+        "state": "AVAILABLE"
+      },
+      "properties": {
+        "name": "default-dockerui001-ul0w",
+        "type": "HDD",
+        "size": 10,
+        "image": "4e4e2f60-d81f-11e4-aea4-52540066fee9",
+        "imagePassword": null,
+        "bus": "VIRTIO",
+        "licenceType": "LINUX",
+        "cpuHotPlug": true,
+        "cpuHotUnplug": false,
+        "ramHotPlug": true,
+        "ramHotUnplug": false,
+        "nicHotPlug": true,
+        "nicHotUnplug": true,
+        "discVirtioHotPlug": true,
+        "discVirtioHotUnplug": true,
+        "discScsiHotPlug": false,
+        "discScsiHotUnplug": false,
+        "deviceNumber": 1
+      }
+    }
+  ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9a8b346c/profitbricks-rest/src/test/resources/volume/snapshot.json
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/test/resources/volume/snapshot.json 
b/profitbricks-rest/src/test/resources/volume/snapshot.json
new file mode 100644
index 0000000..0689031
--- /dev/null
+++ b/profitbricks-rest/src/test/resources/volume/snapshot.json
@@ -0,0 +1,30 @@
+{
+  "id" : "9b5379bb-81f3-4d51-90a9-ca8a3d3a716c",
+  "type" : "snapshot",
+  "href" : 
"https://api.profitbricks.com/rest/snapshots/9b5379bb-81f3-4d51-90a9-ca8a3d3a716c";,
+  "metadata" : {
+    "createdDate" : "2015-12-23T21:01:35Z",
+    "createdBy" : "[email protected]",
+    "etag" : "f5a10eb559a142d2848a6b57b63d2c60",
+    "lastModifiedDate" : "2015-12-23T21:01:35Z",
+    "lastModifiedBy" : "[email protected]",
+    "state" : "BUSY"
+  },
+  "properties" : {
+    "name" : "snapshot desc...",
+    "description" : "Created from \"apache-node\" in Data Center 
\"test-data-center\"",
+    "location" : "us/lasdev",
+    "size" : null,
+    "cpuHotPlug" : false,
+    "cpuHotUnplug" : false,
+    "ramHotPlug" : false,
+    "ramHotUnplug" : false,
+    "nicHotPlug" : false,
+    "nicHotUnplug" : false,
+    "discVirtioHotPlug" : false,
+    "discVirtioHotUnplug" : false,
+    "discScsiHotPlug" : false,
+    "discScsiHotUnplug" : false,
+    "licenceType" : null
+  }
+}

Reply via email to