You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2016/04/06 21:21:36 UTC
jclouds-labs git commit: Profitbricks REST - LAN API
Repository: jclouds-labs
Updated Branches:
refs/heads/master 313819534 -> ff028de1e
Profitbricks REST - LAN API
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/ff028de1
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/ff028de1
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/ff028de1
Branch: refs/heads/master
Commit: ff028de1e3f8f7be9059e3ed69a20d8d1659165f
Parents: 3138195
Author: mirza-spc <mi...@stackpointcloud.com>
Authored: Tue Mar 29 09:58:08 2016 +0200
Committer: Ignasi Barrera <na...@apache.org>
Committed: Wed Apr 6 21:14:56 2016 +0200
----------------------------------------------------------------------
.../profitbricks/rest/ProfitBricksApi.java | 4 +
.../rest/binder/lan/CreateLanRequestBinder.java | 68 ++++
.../rest/binder/lan/UpdateLanRequestBinder.java | 55 ++++
.../rest/binder/nic/CreateNicRequestBinder.java | 5 +-
.../rest/binder/nic/UpdateNicRequestBinder.java | 3 +-
.../jclouds/profitbricks/rest/domain/Lan.java | 77 ++++-
.../profitbricks/rest/features/LanApi.java | 123 +++++++
.../binder/lan/CreateLanRequestBinderTest.java | 63 ++++
.../binder/lan/UpdateLanRequestBinderTest.java | 61 ++++
.../binder/nic/CreateNicRequestBinderTest.java | 66 ++++
.../binder/nic/UpdateNicRequestBinderTest.java | 62 ++++
.../rest/features/LanApiLiveTest.java | 141 ++++++++
.../rest/features/LanApiMockTest.java | 202 ++++++++++++
.../rest/features/NicApiMockTest.java | 4 +-
.../src/test/resources/lan/get.json | 57 ++++
.../src/test/resources/lan/list.json | 328 +++++++++++++++++++
16 files changed, 1309 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff028de1/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/ProfitBricksApi.java
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/ProfitBricksApi.java b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/ProfitBricksApi.java
index a0ab0c0..881a087 100644
--- a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/ProfitBricksApi.java
+++ b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/ProfitBricksApi.java
@@ -21,6 +21,7 @@ import com.google.common.annotations.Beta;
import java.io.Closeable;
import org.apache.jclouds.profitbricks.rest.features.DataCenterApi;
import org.apache.jclouds.profitbricks.rest.features.ImageApi;
+import org.apache.jclouds.profitbricks.rest.features.LanApi;
import org.apache.jclouds.profitbricks.rest.features.NicApi;
import org.apache.jclouds.profitbricks.rest.features.ServerApi;
import org.apache.jclouds.profitbricks.rest.features.SnapshotApi;
@@ -47,5 +48,8 @@ public interface ProfitBricksApi extends Closeable {
@Delegate
NicApi nicApi();
+
+ @Delegate
+ LanApi lanApi();
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff028de1/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/lan/CreateLanRequestBinder.java
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/lan/CreateLanRequestBinder.java b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/lan/CreateLanRequestBinder.java
new file mode 100644
index 0000000..2c0cfbe
--- /dev/null
+++ b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/lan/CreateLanRequestBinder.java
@@ -0,0 +1,68 @@
+/*
+ * 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.binder.lan;
+
+import com.google.common.base.Supplier;
+import com.google.inject.Inject;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.jclouds.profitbricks.rest.binder.BaseProfitBricksRequestBinder;
+import org.apache.jclouds.profitbricks.rest.domain.Lan;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.json.Json;
+import org.jclouds.location.Provider;
+
+public class CreateLanRequestBinder extends BaseProfitBricksRequestBinder<Lan.Request.CreatePayload> {
+
+ private String dataCenterId;
+
+ @Inject
+ CreateLanRequestBinder(Json jsonBinder, @Provider Supplier<URI> endpointSupplier) {
+ super("lan", jsonBinder, endpointSupplier);
+ }
+
+ @Override
+ protected String createPayload(Lan.Request.CreatePayload payload) {
+
+ dataCenterId = payload.dataCenterId();
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+
+ if (payload.name() != null)
+ properties.put("name", payload.name());
+
+ if (payload.isPublic() != null)
+ properties.put("public", payload.isPublic());
+
+ requestBuilder.put("properties", properties);
+
+ if (payload.nics() != null) {
+ Map<String, Object> entities = new HashMap<String, Object>();
+ entities.put("nics", payload.nics());
+ properties.put("entities", entities);
+ }
+
+ return jsonBinder.toJson(requestBuilder);
+ }
+
+ @Override
+ protected <R extends HttpRequest> R createRequest(R fromRequest, String payload) {
+ return super.createRequest(genRequest(String.format("datacenters/%s/lans", dataCenterId), fromRequest), payload);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff028de1/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/lan/UpdateLanRequestBinder.java
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/lan/UpdateLanRequestBinder.java b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/lan/UpdateLanRequestBinder.java
new file mode 100644
index 0000000..1614f30
--- /dev/null
+++ b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/lan/UpdateLanRequestBinder.java
@@ -0,0 +1,55 @@
+/*
+ * 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.binder.lan;
+
+import com.google.common.base.Supplier;
+import com.google.inject.Inject;
+import java.net.URI;
+import org.apache.jclouds.profitbricks.rest.binder.BaseProfitBricksRequestBinder;
+import org.apache.jclouds.profitbricks.rest.domain.Lan;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.json.Json;
+import org.jclouds.location.Provider;
+
+public class UpdateLanRequestBinder extends BaseProfitBricksRequestBinder<Lan.Request.UpdatePayload> {
+
+ private String dataCenterId;
+ private String lanId;
+
+ @Inject
+ UpdateLanRequestBinder(Json jsonBinder, @Provider Supplier<URI> endpointSupplier) {
+ super("lan", jsonBinder, endpointSupplier);
+ }
+
+ @Override
+ protected String createPayload(Lan.Request.UpdatePayload payload) {
+
+ dataCenterId = payload.dataCenterId();
+ lanId = payload.id();
+
+ if (payload.isPublic() != null)
+ requestBuilder.put("public", payload.isPublic());
+
+ return jsonBinder.toJson(requestBuilder);
+ }
+
+ @Override
+ protected <R extends HttpRequest> R createRequest(R fromRequest, String payload) {
+ return super.createRequest(genRequest(String.format("datacenters/%s/lans/%s", dataCenterId, lanId), fromRequest), payload);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff028de1/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/nic/CreateNicRequestBinder.java
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/nic/CreateNicRequestBinder.java b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/nic/CreateNicRequestBinder.java
index 3a432a5..e0842ab 100644
--- a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/nic/CreateNicRequestBinder.java
+++ b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/nic/CreateNicRequestBinder.java
@@ -76,9 +76,8 @@ public class CreateNicRequestBinder extends BaseProfitBricksRequestBinder<Nic.Re
}
@Override
- protected <R extends HttpRequest> R createRequest(R fromRequest, String payload) {
- R request = (R) fromRequest.toBuilder().replacePath(String.format("/rest/datacenters/%s/servers/%s/nics", dataCenterId, serverId)).build();
- return super.createRequest(request, payload);
+ protected <R extends HttpRequest> R createRequest(R fromRequest, String payload) {
+ return super.createRequest(genRequest(String.format("datacenters/%s/servers/%s/nics", dataCenterId, serverId), fromRequest), payload);
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff028de1/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/nic/UpdateNicRequestBinder.java
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/nic/UpdateNicRequestBinder.java b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/nic/UpdateNicRequestBinder.java
index 7bb92fc..cb8482d 100644
--- a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/nic/UpdateNicRequestBinder.java
+++ b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/binder/nic/UpdateNicRequestBinder.java
@@ -65,8 +65,7 @@ public class UpdateNicRequestBinder extends BaseProfitBricksRequestBinder<Nic.Re
@Override
protected <R extends HttpRequest> R createRequest(R fromRequest, String payload) {
- R request = (R) fromRequest.toBuilder().replacePath(String.format("/rest/datacenters/%s/servers/%s/nics/%s", dataCenterId, serverId, nicId)).build();
- return super.createRequest(request, payload);
+ return super.createRequest(genRequest(String.format("datacenters/%s/servers/%s/nics/%s", dataCenterId, serverId, nicId), fromRequest), payload);
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff028de1/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/domain/Lan.java
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/domain/Lan.java b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/domain/Lan.java
index b7b9fb3..eea8afe 100644
--- a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/domain/Lan.java
+++ b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/domain/Lan.java
@@ -17,6 +17,7 @@
package org.apache.jclouds.profitbricks.rest.domain;
import com.google.auto.value.AutoValue;
+import java.util.List;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
@@ -24,6 +25,9 @@ import org.jclouds.json.SerializedNames;
public abstract class Lan {
public abstract String id();
+
+ @Nullable
+ public abstract String dataCenterId();
public abstract String type();
@@ -38,9 +42,9 @@ public abstract class Lan {
@Nullable
public abstract Entities entities();
- @SerializedNames({"id", "type", "href", "metadata", "properties", "entities"})
- public static Lan create(String id, String type, String href, Metadata metadata, Properties properties, Entities entities) {
- return new AutoValue_Lan(id, type, href, metadata, properties, entities);
+ @SerializedNames({"id", "dataCenterId", "type", "href", "metadata", "properties", "entities"})
+ public static Lan create(String id, String dataCenterId, String type, String href, Metadata metadata, Properties properties, Entities entities) {
+ return new AutoValue_Lan(id, dataCenterId, type, href, metadata, properties, entities);
}
@AutoValue
@@ -67,4 +71,71 @@ public abstract class Lan {
}
}
+
+
+ public static final class Request {
+
+ public static CreatePayload.Builder creatingBuilder() {
+ return new AutoValue_Lan_Request_CreatePayload.Builder();
+ }
+
+ public static UpdatePayload.Builder updatingBuilder() {
+ return new AutoValue_Lan_Request_UpdatePayload.Builder();
+ }
+
+ @AutoValue
+ public abstract static class CreatePayload {
+
+ @Nullable
+ public abstract String name();
+
+ @Nullable
+ public abstract Boolean isPublic();
+
+ @Nullable
+ public abstract List<Nic> nics();
+
+ public abstract String dataCenterId();
+
+ @AutoValue.Builder
+ public abstract static class Builder {
+
+ public abstract Builder name(String name);
+ public abstract Builder isPublic(Boolean isPublic);
+ public abstract Builder nics(List<Nic> nics);
+ public abstract Builder dataCenterId(String dataCenterId);
+
+ abstract CreatePayload autoBuild();
+
+ public CreatePayload build() {
+ return autoBuild();
+ }
+ }
+
+ }
+
+ @AutoValue
+ public abstract static class UpdatePayload {
+
+ public abstract Boolean isPublic();
+ public abstract String dataCenterId();
+ public abstract String id();
+
+ @AutoValue.Builder
+ public abstract static class Builder {
+
+ public abstract Builder isPublic(Boolean isPublic);
+ public abstract Builder dataCenterId(String dataCenterId);
+ public abstract Builder id(String id);
+
+ abstract UpdatePayload autoBuild();
+
+ public UpdatePayload build() {
+ return autoBuild();
+ }
+ }
+ }
+
+ }
+
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff028de1/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/features/LanApi.java
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/features/LanApi.java b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/features/LanApi.java
new file mode 100644
index 0000000..3adec5b
--- /dev/null
+++ b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/features/LanApi.java
@@ -0,0 +1,123 @@
+/*
+ * 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.inject.Inject;
+import com.google.inject.TypeLiteral;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Type;
+import java.util.List;
+import javax.inject.Named;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import org.apache.jclouds.profitbricks.rest.binder.lan.CreateLanRequestBinder;
+import org.apache.jclouds.profitbricks.rest.binder.lan.UpdateLanRequestBinder;
+import org.apache.jclouds.profitbricks.rest.domain.Lan;
+import org.apache.jclouds.profitbricks.rest.domain.options.DepthOptions;
+import org.apache.jclouds.profitbricks.rest.util.ParseId;
+import org.jclouds.Fallbacks;
+import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404;
+import org.jclouds.http.filters.BasicAuthentication;
+import org.jclouds.http.functions.ParseJson;
+import org.jclouds.json.Json;
+import org.jclouds.rest.annotations.Fallback;
+import org.jclouds.rest.annotations.MapBinder;
+import org.jclouds.rest.annotations.PATCH;
+import org.jclouds.rest.annotations.PayloadParam;
+import org.jclouds.rest.annotations.RequestFilters;
+import org.jclouds.rest.annotations.ResponseParser;
+import org.jclouds.rest.annotations.SelectJson;
+import org.jclouds.util.Strings2;
+
+@Path("/datacenters/{dataCenterId}/lans")
+@RequestFilters(BasicAuthentication.class)
+public interface LanApi extends Closeable {
+
+ @Named("lan:list")
+ @GET
+ @SelectJson("items")
+ @Fallback(EmptyListOnNotFoundOr404.class)
+ List<Lan> list(@PathParam("dataCenterId") String dataCenterId);
+
+ @Named("lan:list")
+ @GET
+ @SelectJson("items")
+ @Fallback(EmptyListOnNotFoundOr404.class)
+ List<Lan> list(@PathParam("dataCenterId") String dataCenterId, DepthOptions options);
+
+ @Named("lan:get")
+ @GET
+ @Path("/{lanId}")
+ @ResponseParser(LanApi.LanParser.class)
+ @Fallback(Fallbacks.NullOnNotFoundOr404.class)
+ Lan get(@PathParam("dataCenterId") String dataCenterId, @PathParam("lanId") String lanId);
+
+ @Named("lan:get")
+ @GET
+ @Path("/{lanId}")
+ @ResponseParser(LanApi.LanParser.class)
+ @Fallback(Fallbacks.NullOnNotFoundOr404.class)
+ Lan get(@PathParam("dataCenterId") String dataCenterId, @PathParam("lanId") String lanId, DepthOptions options);
+
+ @Named("lan:create")
+ @POST
+ @MapBinder(CreateLanRequestBinder.class)
+ @ResponseParser(LanApi.LanParser.class)
+ Lan create(@PayloadParam("lan") Lan.Request.CreatePayload payload);
+
+ @Named("lan:update")
+ @PATCH
+ @Path("/{lanId}")
+ @MapBinder(UpdateLanRequestBinder.class)
+ @ResponseParser(LanApi.LanParser.class)
+ @Produces("application/vnd.profitbricks.partial-properties+json")
+ Lan update(@PayloadParam("lan") Lan.Request.UpdatePayload payload);
+
+ @Named("lan:delete")
+ @DELETE
+ @Path("/{lanId}")
+ @Fallback(Fallbacks.VoidOnNotFoundOr404.class)
+ void delete(@PathParam("dataCenterId") String dataCenterId, @PathParam("lanId") String lanId);
+
+ static final class LanParser extends ParseJson<Lan> {
+
+ final ParseId parseService;
+
+ @Inject LanParser(Json json, ParseId parseId) {
+ super(json, TypeLiteral.get(Lan.class));
+ this.parseService = parseId;
+ }
+
+ @Override
+ public <V> V apply(InputStream stream, Type type) throws IOException {
+ try {
+ return (V) json.fromJson(this.parseService.parseId(Strings2.toStringAndClose(stream), "datacenters", "dataCenterId"), type);
+ } finally {
+ if (stream != null)
+ stream.close();
+ }
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff028de1/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/binder/lan/CreateLanRequestBinderTest.java
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/binder/lan/CreateLanRequestBinderTest.java b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/binder/lan/CreateLanRequestBinderTest.java
new file mode 100644
index 0000000..bfde777
--- /dev/null
+++ b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/binder/lan/CreateLanRequestBinderTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.binder.lan;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.jclouds.profitbricks.rest.binder.BinderTestBase;
+import org.apache.jclouds.profitbricks.rest.domain.Lan;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.json.Json;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "CreateLanRequestBinderTest")
+public class CreateLanRequestBinderTest extends BinderTestBase {
+
+ @Test
+ public void testUpdatePayload() {
+
+ CreateLanRequestBinder binder = injector.getInstance(CreateLanRequestBinder.class);
+
+ Lan.Request.CreatePayload payload = Lan.Request.creatingBuilder()
+ .dataCenterId("datacenter-id")
+ .name("jclouds-lan")
+ .build();
+
+ String actual = binder.createPayload(payload);
+
+ HttpRequest request = binder.createRequest(
+ HttpRequest.builder().method("POST").endpoint("http://test.com").build(),
+ actual
+ );
+
+ assertEquals(request.getEndpoint().getPath(), "/rest/v2/datacenters/datacenter-id/lans");
+ assertNotNull(actual, "Binder returned null payload");
+
+ Json json = injector.getInstance(Json.class);
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put("name", "jclouds-lan");
+
+ HashMap<String, Object> expectedPayload = new HashMap<String, Object>();
+ expectedPayload.put("properties", properties);
+
+ assertEquals(actual, json.toJson(expectedPayload));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff028de1/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/binder/lan/UpdateLanRequestBinderTest.java
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/binder/lan/UpdateLanRequestBinderTest.java b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/binder/lan/UpdateLanRequestBinderTest.java
new file mode 100644
index 0000000..75dbce7
--- /dev/null
+++ b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/binder/lan/UpdateLanRequestBinderTest.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.apache.jclouds.profitbricks.rest.binder.lan;
+
+import java.util.HashMap;
+import org.apache.jclouds.profitbricks.rest.binder.BinderTestBase;
+import org.apache.jclouds.profitbricks.rest.domain.Lan;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.json.Json;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "UpdateLanRequestBinderTest")
+public class UpdateLanRequestBinderTest extends BinderTestBase {
+
+ @Test
+ public void testUpdatePayload() {
+
+ UpdateLanRequestBinder binder = injector.getInstance(UpdateLanRequestBinder.class);
+
+ Lan.Request.UpdatePayload payload = Lan.Request.updatingBuilder()
+ .dataCenterId("datacenter-id")
+ .id("lan-id")
+ .isPublic(false)
+ .build();
+
+ String actual = binder.createPayload(payload);
+
+ HttpRequest request = binder.createRequest(
+ HttpRequest.builder().method("POST").endpoint("http://test.com").build(),
+ actual
+ );
+
+ assertEquals(request.getEndpoint().getPath(), "/rest/v2/datacenters/datacenter-id/lans/lan-id");
+ assertNotNull(actual, "Binder returned null payload");
+
+ Json json = injector.getInstance(Json.class);
+
+ HashMap<String, Object> expectedPayload = new HashMap<String, Object>();
+
+ expectedPayload.put("public", false);
+
+ assertEquals(actual, json.toJson(expectedPayload));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff028de1/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/binder/nic/CreateNicRequestBinderTest.java
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/binder/nic/CreateNicRequestBinderTest.java b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/binder/nic/CreateNicRequestBinderTest.java
new file mode 100644
index 0000000..0c47e0f
--- /dev/null
+++ b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/binder/nic/CreateNicRequestBinderTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.binder.nic;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.jclouds.profitbricks.rest.binder.BinderTestBase;
+import org.apache.jclouds.profitbricks.rest.domain.Nic;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.json.Json;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "CreateNicRequestBinderTest")
+public class CreateNicRequestBinderTest extends BinderTestBase {
+
+ @Test
+ public void testUpdatePayload() {
+
+ CreateNicRequestBinder binder = injector.getInstance(CreateNicRequestBinder.class);
+
+ Nic.Request.CreatePayload payload = Nic.Request.creatingBuilder()
+ .dataCenterId("datacenter-id")
+ .serverId("server-id")
+ .name("jclouds-nic")
+ .lan(1)
+ .build();
+
+ String actual = binder.createPayload(payload);
+
+ HttpRequest request = binder.createRequest(
+ HttpRequest.builder().method("POST").endpoint("http://test.com").build(),
+ actual
+ );
+
+ assertEquals(request.getEndpoint().getPath(), "/rest/v2/datacenters/datacenter-id/servers/server-id/nics");
+ assertNotNull(actual, "Binder returned null payload");
+
+ Json json = injector.getInstance(Json.class);
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put("lan", 1);
+ properties.put("name", "jclouds-nic");
+
+ HashMap<String, Object> expectedPayload = new HashMap<String, Object>();
+ expectedPayload.put("properties", properties);
+
+ assertEquals(actual, json.toJson(expectedPayload));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff028de1/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/binder/nic/UpdateNicRequestBinderTest.java
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/binder/nic/UpdateNicRequestBinderTest.java b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/binder/nic/UpdateNicRequestBinderTest.java
new file mode 100644
index 0000000..9f6a906
--- /dev/null
+++ b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/binder/nic/UpdateNicRequestBinderTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.binder.nic;
+
+import java.util.HashMap;
+import org.apache.jclouds.profitbricks.rest.binder.BinderTestBase;
+import org.apache.jclouds.profitbricks.rest.domain.Nic;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.json.Json;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "UpdateNicRequestBinderTest")
+public class UpdateNicRequestBinderTest extends BinderTestBase {
+
+ @Test
+ public void testUpdatePayload() {
+
+ UpdateNicRequestBinder binder = injector.getInstance(UpdateNicRequestBinder.class);
+
+ Nic.Request.UpdatePayload payload = Nic.Request.updatingBuilder()
+ .dataCenterId("datacenter-id")
+ .serverId("server-id")
+ .id("nic-id")
+ .name("apache-nic")
+ .build();
+
+ String actual = binder.createPayload(payload);
+
+ HttpRequest request = binder.createRequest(
+ HttpRequest.builder().method("POST").endpoint("http://test.com").build(),
+ actual
+ );
+
+ assertEquals(request.getEndpoint().getPath(), "/rest/v2/datacenters/datacenter-id/servers/server-id/nics/nic-id");
+ assertNotNull(actual, "Binder returned null payload");
+
+ Json json = injector.getInstance(Json.class);
+
+ HashMap<String, Object> expectedPayload = new HashMap<String, Object>();
+
+ expectedPayload.put("name", "apache-nic");
+
+ assertEquals(actual, json.toJson(expectedPayload));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff028de1/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/LanApiLiveTest.java
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/LanApiLiveTest.java b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/LanApiLiveTest.java
new file mode 100644
index 0000000..44b260c
--- /dev/null
+++ b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/LanApiLiveTest.java
@@ -0,0 +1,141 @@
+/*
+ * 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 com.google.common.collect.Iterables;
+import java.util.List;
+import org.apache.jclouds.profitbricks.rest.domain.DataCenter;
+import org.apache.jclouds.profitbricks.rest.domain.Snapshot;
+import org.apache.jclouds.profitbricks.rest.domain.State;
+import org.apache.jclouds.profitbricks.rest.domain.Lan;
+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;
+import static org.testng.Assert.assertTrue;
+
+@Test(groups = "live", testName = "LanApiLiveTest")
+public class LanApiLiveTest extends BaseProfitBricksLiveTest {
+
+ private DataCenter dataCenter;
+ private Lan testLan;
+ private Snapshot testSnapshot;
+
+ @BeforeClass
+ public void setupTest() {
+ dataCenter = createDataCenter();
+ }
+
+ @AfterClass(alwaysRun = true)
+ public void teardownTest() {
+ if (dataCenter != null)
+ deleteDataCenter(dataCenter.id());
+ }
+
+ @Test
+ public void testCreateLan() {
+ assertNotNull(dataCenter);
+
+ testLan = lanApi().create(
+ Lan.Request.creatingBuilder()
+ .dataCenterId(dataCenter.id())
+ .name("jclouds-lan")
+ .build());
+
+ assertNotNull(testLan);
+ assertEquals(testLan.properties().name(), "jclouds-lan");
+ assertLanAvailable(testLan);
+ }
+
+
+ @Test(dependsOnMethods = "testCreateLan")
+ public void testGetLan() {
+ Lan lan = lanApi().get(dataCenter.id(), testLan.id());
+
+ assertNotNull(lan);
+ assertEquals(lan.id(), testLan.id());
+ }
+
+ @Test(dependsOnMethods = "testCreateLan")
+ public void testList() {
+ List<Lan> lans = lanApi().list(dataCenter.id());
+
+ assertNotNull(lans);
+ assertFalse(lans.isEmpty());
+ assertTrue(Iterables.any(lans, new Predicate<Lan>() {
+ @Override public boolean apply(Lan input) {
+ return input.id().equals(testLan.id());
+ }
+ }));
+ }
+
+ @Test(dependsOnMethods = "testCreateLan")
+ public void testUpdateLan() {
+ assertDataCenterAvailable(dataCenter);
+
+ api.lanApi().update(
+ Lan.Request.updatingBuilder()
+ .dataCenterId(testLan.dataCenterId())
+ .id(testLan.id())
+ .isPublic(false)
+ .build());
+
+ assertLanAvailable(testLan);
+
+ Lan lan = lanApi().get(dataCenter.id(), testLan.id());
+
+ assertEquals(lan.properties().isPublic(), false);
+ }
+
+ @Test(dependsOnMethods = "testUpdateLan")
+ public void testDeleteLan() {
+ lanApi().delete(testLan.dataCenterId(), testLan.id());
+ assertLanRemoved(testLan);
+ }
+
+ private void assertLanAvailable(Lan lan) {
+ assertPredicate(new Predicate<Lan>() {
+ @Override
+ public boolean apply(Lan testLan) {
+ Lan lan = lanApi().get(testLan.dataCenterId(), testLan.id());
+
+ if (lan == null || lan.metadata() == null)
+ return false;
+
+ return lan.metadata().state() == State.AVAILABLE;
+ }
+ }, lan);
+ }
+
+ private void assertLanRemoved(Lan lan) {
+ assertPredicate(new Predicate<Lan>() {
+ @Override
+ public boolean apply(Lan testLan) {
+ return lanApi().get(testLan.dataCenterId(), testLan.id()) == null;
+ }
+ }, lan);
+ }
+
+ private LanApi lanApi() {
+ return api.lanApi();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff028de1/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/LanApiMockTest.java
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/LanApiMockTest.java b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/LanApiMockTest.java
new file mode 100644
index 0000000..9c11d4f
--- /dev/null
+++ b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/LanApiMockTest.java
@@ -0,0 +1,202 @@
+/*
+ * 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.Lan;
+import org.apache.jclouds.profitbricks.rest.domain.options.DepthOptions;
+import org.apache.jclouds.profitbricks.rest.internal.BaseProfitBricksApiMockTest;
+import org.testng.annotations.Test;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+@Test(groups = "unit", testName = "LanApiMockTest", singleThreaded = true)
+public class LanApiMockTest extends BaseProfitBricksApiMockTest {
+
+ @Test
+ public void testList() throws InterruptedException {
+ server.enqueue(
+ new MockResponse().setBody(stringFromResource("/lan/list.json"))
+ );
+
+ List<Lan> list = lanApi().list("datacenter-id");
+
+ assertNotNull(list);
+ assertEquals(list.size(), 4);
+ assertEquals(list.get(0).properties().name(), "Ex lan 1");
+
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "GET", "/datacenters/datacenter-id/lans");
+ }
+
+
+ @Test
+ public void testListWithDepth() throws InterruptedException {
+ server.enqueue(
+ new MockResponse().setBody(stringFromResource("/lan/list.json"))
+ );
+
+ List<Lan> list = lanApi().list("datacenter-id", new DepthOptions().depth(2));
+
+ assertNotNull(list);
+ assertEquals(list.size(), 4);
+ assertEquals(list.get(0).properties().name(), "Ex lan 1");
+
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "GET", "/datacenters/datacenter-id/lans?depth=2");
+ }
+
+ @Test
+ public void testListWith404() throws InterruptedException {
+ server.enqueue(response404());
+ List<Lan> list = lanApi().list("datacenter-id");
+ assertTrue(list.isEmpty());
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "GET", "/datacenters/datacenter-id/lans");
+ }
+
+ @Test
+ public void testListWith404WithDepth() throws InterruptedException {
+ server.enqueue(response404());
+ List<Lan> list = lanApi().list("datacenter-id", new DepthOptions().depth(1));
+ assertTrue(list.isEmpty());
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "GET", "/datacenters/datacenter-id/lans?depth=1");
+ }
+
+ @Test
+ public void testGetLan() throws InterruptedException {
+ MockResponse response = new MockResponse();
+ response.setBody(stringFromResource("/lan/get.json"));
+ response.setHeader("Content-Type", "application/vnd.profitbricks.resource+json");
+
+ server.enqueue(response);
+
+ Lan lan = lanApi().get("datacenter-id", "some-id");
+
+ assertNotNull(lan);
+ assertEquals(lan.properties().name(), "Ex lan");
+
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "GET", "/datacenters/datacenter-id/lans/some-id");
+ }
+
+ public void testGetLanWith404() throws InterruptedException {
+ server.enqueue(response404());
+
+ Lan lan = lanApi().get("datacenter-id", "some-id");
+
+ assertEquals(lan, null);
+
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "GET", "/datacenters/datacenter-id/lans/some-id");
+ }
+
+ @Test
+ public void testGetLanWithDepth() throws InterruptedException {
+ MockResponse response = new MockResponse();
+ response.setBody(stringFromResource("/lan/get.json"));
+ response.setHeader("Content-Type", "application/vnd.profitbricks.resource+json");
+
+ server.enqueue(response);
+
+ Lan lan = lanApi().get("datacenter-id", "some-id", new DepthOptions().depth(2));
+
+ assertNotNull(lan);
+ assertEquals(lan.properties().name(), "Ex lan");
+
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "GET", "/datacenters/datacenter-id/lans/some-id?depth=2");
+ }
+
+ public void testGetLanWith404WithDepth() throws InterruptedException {
+ server.enqueue(response404());
+
+ Lan lan = lanApi().get("datacenter-id", "some-id", new DepthOptions().depth(2));
+
+ assertEquals(lan, null);
+
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "GET", "/datacenters/datacenter-id/lans/some-id?depth=2");
+ }
+
+ @Test
+ public void testCreate() throws InterruptedException {
+ server.enqueue(
+ new MockResponse().setBody(stringFromResource("/lan/get.json"))
+ );
+
+ Lan lan = lanApi().create(
+ Lan.Request.creatingBuilder()
+ .dataCenterId("datacenter-id")
+ .name("jclouds-lan")
+ .build());
+
+ assertNotNull(lan);
+ assertNotNull(lan.id());
+
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "POST", "/datacenters/datacenter-id/lans",
+ "{\"properties\": {\"name\": \"jclouds-lan\"}}"
+ );
+ }
+
+ @Test
+ public void testUpdate() throws InterruptedException {
+ server.enqueue(
+ new MockResponse().setBody(stringFromResource("/lan/get.json"))
+ );
+
+ api.lanApi().update(
+ Lan.Request.updatingBuilder()
+ .id("some-id")
+ .dataCenterId("datacenter-id")
+ .isPublic(false)
+ .build());
+
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "PATCH", "/datacenters/datacenter-id/lans/some-id", "{\"public\": false}");
+ }
+
+ @Test
+ public void testDelete() throws InterruptedException {
+ server.enqueue(
+ new MockResponse().setBody("")
+ );
+
+ lanApi().delete("datacenter-id", "some-id");
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "DELETE", "/datacenters/datacenter-id/lans/some-id");
+ }
+
+ @Test
+ public void testDeleteWith404() throws InterruptedException {
+ server.enqueue(response404());
+
+ lanApi().delete("datacenter-id", "some-id");
+
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "DELETE", "/datacenters/datacenter-id/lans/some-id");
+ }
+
+ private LanApi lanApi() {
+ return api.lanApi();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff028de1/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/NicApiMockTest.java
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/NicApiMockTest.java b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/NicApiMockTest.java
index 1ba8c76..1827f67 100644
--- a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/NicApiMockTest.java
+++ b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/features/NicApiMockTest.java
@@ -100,7 +100,7 @@ public class NicApiMockTest extends BaseProfitBricksApiMockTest {
assertNotNull(nic.id());
assertEquals(server.getRequestCount(), 1);
- assertSent(server, "POST", "/rest/datacenters/datacenter-id/servers/server-id/nics",
+ assertSent(server, "POST", "/datacenters/datacenter-id/servers/server-id/nics",
"{\"properties\": {\"name\": \"jclouds-nic\", \"lan\": 1}}"
);
}
@@ -120,7 +120,7 @@ public class NicApiMockTest extends BaseProfitBricksApiMockTest {
.build());
assertEquals(server.getRequestCount(), 1);
- assertSent(server, "PATCH", "/rest/datacenters/datacenter-id/servers/server-id/nics/some-id", "{\"name\": \"apache-nic\"}");
+ assertSent(server, "PATCH", "/datacenters/datacenter-id/servers/server-id/nics/some-id", "{\"name\": \"apache-nic\"}");
}
@Test
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff028de1/profitbricks-rest/src/test/resources/lan/get.json
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/test/resources/lan/get.json b/profitbricks-rest/src/test/resources/lan/get.json
new file mode 100644
index 0000000..8fdd36f
--- /dev/null
+++ b/profitbricks-rest/src/test/resources/lan/get.json
@@ -0,0 +1,57 @@
+{
+ "id": "4",
+ "type": "lan",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/lans/4",
+ "metadata": {
+ "createdDate": "2015-05-12T17:20:17Z",
+ "createdBy": "vendors@stackpointcloud.com",
+ "etag": "bd1f0344e29ef82d0c2b0e47e386e6bf",
+ "lastModifiedDate": "2015-05-12T17:20:17Z",
+ "lastModifiedBy": "vendors@stackpointcloud.com",
+ "state": "AVAILABLE"
+ },
+ "properties": {
+ "name": "Ex lan",
+ "public": true
+ },
+ "entities": {
+ "nics": {
+ "id": "4/nics",
+ "type": "collection",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/lans/4/nics",
+ "items": [
+ {
+ "id": "bf15f10d-c451-4bd9-b519-62a4bbe02a7b",
+ "type": "nic",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/servers/97bd33ed-b97e-4312-acc1-96f44c6e4465/nics/bf15f10d-c451-4bd9-b519-62a4bbe02a7b",
+ "metadata": {
+ "createdDate": "2015-05-12T17:21:54Z",
+ "createdBy": "vendors@stackpointcloud.com",
+ "etag": "4e256e4cd927eea2337cf9b1b189c71a",
+ "lastModifiedDate": "2015-05-12T17:21:54Z",
+ "lastModifiedBy": "vendors@stackpointcloud.com",
+ "state": "AVAILABLE"
+ },
+ "properties": {
+ "name": null,
+ "mac": "02:01:d9:e0:5c:b8",
+ "ips": [
+ "208.94.38.136"
+ ],
+ "dhcp": true,
+ "lan": 4,
+ "firewallActive": false
+ },
+ "entities": {
+ "firewallrules": {
+ "id": "bf15f10d-c451-4bd9-b519-62a4bbe02a7b/firewallrules",
+ "type": "collection",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/servers/97bd33ed-b97e-4312-acc1-96f44c6e4465/nics/bf15f10d-c451-4bd9-b519-62a4bbe02a7b/firewallrules",
+ "items": []
+ }
+ }
+ }
+ ]
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff028de1/profitbricks-rest/src/test/resources/lan/list.json
----------------------------------------------------------------------
diff --git a/profitbricks-rest/src/test/resources/lan/list.json b/profitbricks-rest/src/test/resources/lan/list.json
new file mode 100644
index 0000000..ea5bbb8
--- /dev/null
+++ b/profitbricks-rest/src/test/resources/lan/list.json
@@ -0,0 +1,328 @@
+{
+ "id": "b0ac144e-e294-415f-ba39-6737d5a9d419/lans",
+ "type": "collection",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/lans",
+ "items": [
+ {
+ "id": "4",
+ "type": "lan",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/lans/4",
+ "metadata": {
+ "createdDate": "2015-05-12T17:20:17Z",
+ "createdBy": "vendors@stackpointcloud.com",
+ "etag": "bd1f0344e29ef82d0c2b0e47e386e6bf",
+ "lastModifiedDate": "2015-05-12T17:20:17Z",
+ "lastModifiedBy": "vendors@stackpointcloud.com",
+ "state": "AVAILABLE"
+ },
+ "properties": {
+ "name": "Ex lan 1",
+ "public": true
+ },
+ "entities": {
+ "nics": {
+ "id": "4/nics",
+ "type": "collection",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/lans/4/nics",
+ "items": [
+ {
+ "id": "bf15f10d-c451-4bd9-b519-62a4bbe02a7b",
+ "type": "nic",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/servers/97bd33ed-b97e-4312-acc1-96f44c6e4465/nics/bf15f10d-c451-4bd9-b519-62a4bbe02a7b",
+ "metadata": {
+ "createdDate": "2015-05-12T17:21:54Z",
+ "createdBy": "vendors@stackpointcloud.com",
+ "etag": "4e256e4cd927eea2337cf9b1b189c71a",
+ "lastModifiedDate": "2015-05-12T17:21:54Z",
+ "lastModifiedBy": "vendors@stackpointcloud.com",
+ "state": "AVAILABLE"
+ },
+ "properties": {
+ "name": null,
+ "mac": "02:01:d9:e0:5c:b8",
+ "ips": [
+ "208.94.38.136"
+ ],
+ "dhcp": true,
+ "lan": 4,
+ "firewallActive": false
+ },
+ "entities": {
+ "firewallrules": {
+ "id": "bf15f10d-c451-4bd9-b519-62a4bbe02a7b/firewallrules",
+ "type": "collection",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/servers/97bd33ed-b97e-4312-acc1-96f44c6e4465/nics/bf15f10d-c451-4bd9-b519-62a4bbe02a7b/firewallrules",
+ "items": []
+ }
+ }
+ }
+ ]
+ }
+ }
+ },
+ {
+ "id": "3",
+ "type": "lan",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/lans/3",
+ "metadata": {
+ "createdDate": "2015-04-28T13:19:38Z",
+ "createdBy": "vendors@stackpointcloud.com",
+ "etag": "666b40a32993814acfce73e897a3075d",
+ "lastModifiedDate": "2015-04-28T13:19:38Z",
+ "lastModifiedBy": "vendors@stackpointcloud.com",
+ "state": "AVAILABLE"
+ },
+ "properties": {
+ "name": null,
+ "public": true
+ },
+ "entities": {
+ "nics": {
+ "id": "3/nics",
+ "type": "collection",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/lans/3/nics",
+ "items": [
+ {
+ "id": "a41611d4-3605-4367-84aa-a7593e1ce108",
+ "type": "nic",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/servers/430ccbff-e67b-43de-bfce-097e068e57ba/nics/a41611d4-3605-4367-84aa-a7593e1ce108",
+ "metadata": {
+ "createdDate": "2015-04-28T13:19:42Z",
+ "createdBy": "vendors@stackpointcloud.com",
+ "etag": "1c542f43914756144e950e37f1a6f3ad",
+ "lastModifiedDate": "2015-04-28T13:19:42Z",
+ "lastModifiedBy": "vendors@stackpointcloud.com",
+ "state": "AVAILABLE"
+ },
+ "properties": {
+ "name": null,
+ "mac": "02:01:be:98:e8:0b",
+ "ips": [
+ "162.254.25.206"
+ ],
+ "dhcp": true,
+ "lan": 3,
+ "firewallActive": false
+ },
+ "entities": {
+ "firewallrules": {
+ "id": "a41611d4-3605-4367-84aa-a7593e1ce108/firewallrules",
+ "type": "collection",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/servers/430ccbff-e67b-43de-bfce-097e068e57ba/nics/a41611d4-3605-4367-84aa-a7593e1ce108/firewallrules",
+ "items": []
+ }
+ }
+ }
+ ]
+ }
+ }
+ },
+ {
+ "id": "2",
+ "type": "lan",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/lans/2",
+ "metadata": {
+ "createdDate": "2015-03-18T19:00:51Z",
+ "createdBy": "vendors@stackpointcloud.com",
+ "etag": "c4a2fde6ba91a038ff953b939cc21efe",
+ "lastModifiedDate": "2015-03-18T19:00:51Z",
+ "lastModifiedBy": "vendors@stackpointcloud.com",
+ "state": "AVAILABLE"
+ },
+ "properties": {
+ "name": "Switch for LAN 2",
+ "public": false
+ },
+ "entities": {
+ "nics": {
+ "id": "2/nics",
+ "type": "collection",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/lans/2/nics",
+ "items": [
+ {
+ "id": "3f0f69c0-5a09-4d0a-8737-24c1dc67e9b2",
+ "type": "nic",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/servers/8345c895-727f-496c-80af-1e7224b2f34e/nics/3f0f69c0-5a09-4d0a-8737-24c1dc67e9b2",
+ "metadata": {
+ "createdDate": "2015-03-18T19:00:51Z",
+ "createdBy": "vendors@stackpointcloud.com",
+ "etag": "fe5f7398133ba0859b034b8dfe3688f2",
+ "lastModifiedDate": "2015-03-18T19:00:51Z",
+ "lastModifiedBy": "vendors@stackpointcloud.com",
+ "state": "AVAILABLE"
+ },
+ "properties": {
+ "name": null,
+ "mac": "02:01:f8:1f:46:fc",
+ "ips": [
+ "10.9.194.11"
+ ],
+ "dhcp": true,
+ "lan": 2,
+ "firewallActive": false
+ },
+ "entities": {
+ "firewallrules": {
+ "id": "3f0f69c0-5a09-4d0a-8737-24c1dc67e9b2/firewallrules",
+ "type": "collection",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/servers/8345c895-727f-496c-80af-1e7224b2f34e/nics/3f0f69c0-5a09-4d0a-8737-24c1dc67e9b2/firewallrules",
+ "items": []
+ }
+ }
+ },
+ {
+ "id": "f5dd8afa-2438-4270-83b4-0e55994f1e8c",
+ "type": "nic",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/servers/93e2efc3-752c-4c08-8997-e688891e53bf/nics/f5dd8afa-2438-4270-83b4-0e55994f1e8c",
+ "metadata": {
+ "createdDate": "2015-03-18T19:00:51Z",
+ "createdBy": "vendors@stackpointcloud.com",
+ "etag": "faa67fbacb1c0e2e02cf9650657251f1",
+ "lastModifiedDate": "2015-03-18T19:00:51Z",
+ "lastModifiedBy": "vendors@stackpointcloud.com",
+ "state": "AVAILABLE"
+ },
+ "properties": {
+ "name": null,
+ "mac": "02:01:37:5f:09:dc",
+ "ips": [
+ "10.9.194.12"
+ ],
+ "dhcp": true,
+ "lan": 2,
+ "firewallActive": false
+ },
+ "entities": {
+ "firewallrules": {
+ "id": "f5dd8afa-2438-4270-83b4-0e55994f1e8c/firewallrules",
+ "type": "collection",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/servers/93e2efc3-752c-4c08-8997-e688891e53bf/nics/f5dd8afa-2438-4270-83b4-0e55994f1e8c/firewallrules",
+ "items": []
+ }
+ }
+ }
+ ]
+ }
+ }
+ },
+ {
+ "id": "1",
+ "type": "lan",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/lans/1",
+ "metadata": {
+ "createdDate": "2014-10-20T21:20:46Z",
+ "createdBy": "vendors@stackpointcloud.com",
+ "etag": "7a539b539d8ca9e08c5ac5e63c9c4c8f",
+ "lastModifiedDate": "2014-10-20T21:20:46Z",
+ "lastModifiedBy": "vendors@stackpointcloud.com",
+ "state": "AVAILABLE"
+ },
+ "properties": {
+ "name": "Switch for LAN 1",
+ "public": true
+ },
+ "entities": {
+ "nics": {
+ "id": "1/nics",
+ "type": "collection",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/lans/1/nics",
+ "items": [
+ {
+ "id": "cf6d01d3-295d-48bd-8d07-568cce63cbbc",
+ "type": "nic",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/servers/93e2efc3-752c-4c08-8997-e688891e53bf/nics/cf6d01d3-295d-48bd-8d07-568cce63cbbc",
+ "metadata": {
+ "createdDate": "2015-03-18T19:00:51Z",
+ "createdBy": "vendors@stackpointcloud.com",
+ "etag": "faa67fbacb1c0e2e02cf9650657251f1",
+ "lastModifiedDate": "2015-03-18T19:00:51Z",
+ "lastModifiedBy": "vendors@stackpointcloud.com",
+ "state": "AVAILABLE"
+ },
+ "properties": {
+ "name": null,
+ "mac": "02:01:70:bf:d4:8e",
+ "ips": [
+ "192.96.159.188"
+ ],
+ "dhcp": true,
+ "lan": 1,
+ "firewallActive": false
+ },
+ "entities": {
+ "firewallrules": {
+ "id": "cf6d01d3-295d-48bd-8d07-568cce63cbbc/firewallrules",
+ "type": "collection",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/servers/93e2efc3-752c-4c08-8997-e688891e53bf/nics/cf6d01d3-295d-48bd-8d07-568cce63cbbc/firewallrules",
+ "items": []
+ }
+ }
+ },
+ {
+ "id": "18e45eaa-3d48-4fa6-8bc9-c07c173a27fe",
+ "type": "nic",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/servers/8345c895-727f-496c-80af-1e7224b2f34e/nics/18e45eaa-3d48-4fa6-8bc9-c07c173a27fe",
+ "metadata": {
+ "createdDate": "2015-03-18T19:00:51Z",
+ "createdBy": "vendors@stackpointcloud.com",
+ "etag": "fe5f7398133ba0859b034b8dfe3688f2",
+ "lastModifiedDate": "2015-03-18T19:00:51Z",
+ "lastModifiedBy": "vendors@stackpointcloud.com",
+ "state": "AVAILABLE"
+ },
+ "properties": {
+ "name": null,
+ "mac": "02:01:61:b7:59:8a",
+ "ips": [
+ "192.96.159.187"
+ ],
+ "dhcp": true,
+ "lan": 1,
+ "firewallActive": false
+ },
+ "entities": {
+ "firewallrules": {
+ "id": "18e45eaa-3d48-4fa6-8bc9-c07c173a27fe/firewallrules",
+ "type": "collection",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/servers/8345c895-727f-496c-80af-1e7224b2f34e/nics/18e45eaa-3d48-4fa6-8bc9-c07c173a27fe/firewallrules",
+ "items": []
+ }
+ }
+ },
+ {
+ "id": "01ea3bd9-047c-4941-85cf-ed6b7a2d1d7d",
+ "type": "nic",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/servers/364f0f1c-7384-462b-8f0c-cfc4c3f6e2b2/nics/01ea3bd9-047c-4941-85cf-ed6b7a2d1d7d",
+ "metadata": {
+ "createdDate": "2015-02-09T22:46:38Z",
+ "createdBy": "vendors@stackpointcloud.com",
+ "etag": "b4854a82738079d2c7f43b5324bd92e3",
+ "lastModifiedDate": "2015-02-09T22:46:38Z",
+ "lastModifiedBy": "vendors@stackpointcloud.com",
+ "state": "AVAILABLE"
+ },
+ "properties": {
+ "name": null,
+ "mac": "02:01:94:9e:f4:a9",
+ "ips": [
+ "208.94.39.76"
+ ],
+ "dhcp": true,
+ "lan": 1,
+ "firewallActive": false
+ },
+ "entities": {
+ "firewallrules": {
+ "id": "01ea3bd9-047c-4941-85cf-ed6b7a2d1d7d/firewallrules",
+ "type": "collection",
+ "href": "https://api.profitbricks.com/rest/datacenters/b0ac144e-e294-415f-ba39-6737d5a9d419/servers/364f0f1c-7384-462b-8f0c-cfc4c3f6e2b2/nics/01ea3bd9-047c-4941-85cf-ed6b7a2d1d7d/firewallrules",
+ "items": []
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ ]
+}
\ No newline at end of file