You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/08/20 11:36:07 UTC
[21/51] [abbrv] [partial] stratos git commit: Revert "Upgrading to
jclouds 1.9.1"
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2/internal/BaseNeutronApiMockTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2/internal/BaseNeutronApiMockTest.java b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2/internal/BaseNeutronApiMockTest.java
new file mode 100644
index 0000000..fd4a50e
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2/internal/BaseNeutronApiMockTest.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.openstack.neutron.v2.internal;
+
+import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE;
+
+import java.util.Properties;
+
+import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
+import org.jclouds.openstack.neutron.v2.NeutronApi;
+import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest;
+
+/**
+ * Base class for writing Neutron Mock tests
+ *
+ */
+public class BaseNeutronApiMockTest extends BaseOpenStackMockTest<NeutronApi> {
+ protected Properties overrides;
+ /**
+ * Base Mock Test
+ */
+ public BaseNeutronApiMockTest() {
+ overrides = new Properties();
+ //overrides.setProperty(SERVICE_TYPE, "neutron");
+ overrides.setProperty(CREDENTIAL_TYPE, CredentialTypes.PASSWORD_CREDENTIALS);
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2/util/ClassUtil.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2/util/ClassUtil.java b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2/util/ClassUtil.java
new file mode 100644
index 0000000..b9ba915
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2/util/ClassUtil.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jclouds.openstack.neutron.v2.util;
+
+import java.lang.reflect.Field;
+
+public class ClassUtil {
+
+ public static Field findField(Class clazz, String fieldName) {
+ Field fieldToFind = null;
+ if (clazz.getSuperclass() != null)
+ fieldToFind = findField(clazz.getSuperclass(), fieldName);
+
+ if (fieldToFind != null)
+ return fieldToFind;
+
+ for (Field field : clazz.getDeclaredFields()) {
+ if (field.getName().equals(fieldName))
+ return field;
+ }
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2/util/PredicateUtil.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2/util/PredicateUtil.java b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2/util/PredicateUtil.java
new file mode 100644
index 0000000..a3c39ce
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2/util/PredicateUtil.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jclouds.openstack.neutron.v2.util;
+
+import com.google.common.base.Predicate;
+import org.jclouds.javax.annotation.Nullable;
+
+import java.lang.reflect.Field;
+
+public class PredicateUtil {
+
+ public static <T> Predicate<T> createIdEqualsPredicate(final String id) {
+ return new Predicate<T>() {
+ @Override
+ public boolean apply(@Nullable T input) {
+ if (input == null) return false;
+
+ try {
+ Class clazz = input.getClass();
+ Field field = ClassUtil.findField(clazz, "id");
+ field.setAccessible(true);
+ String value = (String) field.get(input);
+ field.setAccessible(false);
+ return value != null && value.equals(id);
+ } catch (IllegalAccessException iae) {
+ return false;
+ }
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/NeutronApiMetadataTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/NeutronApiMetadataTest.java b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/NeutronApiMetadataTest.java
new file mode 100644
index 0000000..db3019c
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/NeutronApiMetadataTest.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jclouds.openstack.neutron.v2_0;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.reflect.TypeToken;
+import org.jclouds.View;
+import org.jclouds.apis.internal.BaseApiMetadataTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "NeutronApiMetadataTest")
+public class NeutronApiMetadataTest extends BaseApiMetadataTest {
+ public NeutronApiMetadataTest() {
+ super(new NeutronApiMetadata(), ImmutableSet.<TypeToken<? extends View>>of());
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/extensions/RouterApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/extensions/RouterApiExpectTest.java b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/extensions/RouterApiExpectTest.java
new file mode 100644
index 0000000..c3f04cc
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/extensions/RouterApiExpectTest.java
@@ -0,0 +1,295 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jclouds.openstack.neutron.v2_0.extensions;
+
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Set;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.neutron.v2_0.domain.ExternalGatewayInfo;
+import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
+import org.jclouds.openstack.neutron.v2_0.domain.Router;
+import org.jclouds.openstack.neutron.v2_0.domain.RouterInterface;
+import org.jclouds.openstack.neutron.v2_0.domain.State;
+import org.jclouds.openstack.neutron.v2_0.internal.BaseNeutronApiExpectTest;
+import org.jclouds.openstack.neutron.v2_0.options.CreateRouterOptions;
+import org.jclouds.openstack.neutron.v2_0.options.UpdateRouterOptions;
+import org.jclouds.openstack.neutron.v2_0.parse.ParseRouterTest;
+import org.jclouds.rest.AuthorizationException;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests parsing and Guice wiring of RouterApi
+ *
+ */
+@Test(groups = "unit", testName = "RouterApiExpectTest")
+public class RouterApiExpectTest extends BaseNeutronApiExpectTest {
+
+ private static final String ZONE = "region-a.geo-1";
+
+ public void testListReferencesReturns2xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers").addQueryParam("fields", "id", "tenant_id", "name").build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/list_routers.json", APPLICATION_JSON)).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ Set<? extends ReferenceWithName> references = api.list().concat().toSet();
+ assertEquals(references, listOfReferencesWithNames());
+ }
+
+ public void testListReferencesReturns4xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers").addQueryParam("fields", "id", "tenant_id", "name").build(),
+ HttpResponse.builder().statusCode(404).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ assertTrue(api.list().concat().isEmpty());
+ }
+
+ public void testListReturns2xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers").build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/list_routers.json", APPLICATION_JSON)).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ Set<? extends Router> routers = api.listInDetail().concat().toSet();
+ assertEquals(routers, listOfRouters());
+ }
+
+ public void testListReturns4xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers").build(),
+ HttpResponse.builder().statusCode(404).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ assertTrue(api.listInDetail().concat().isEmpty());
+ }
+
+ public void testGetReturns2xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers/16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/router.json", APPLICATION_JSON)).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ Router router = api.get("16dba3bc-f3fa-4775-afdc-237e12c72f6a");
+ assertEquals(router, new ParseRouterTest().expected());
+ }
+
+ public void testGetReturns4xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers/16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
+ HttpResponse.builder().statusCode(404).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ assertNull(api.get("16dba3bc-f3fa-4775-afdc-237e12c72f6a"));
+ }
+
+ public void testCreateReturns2xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers").method("POST")
+ .payload(payloadFromStringWithContentType("{\"router\":{\"name\":\"test\",\"external_gateway_info\":{\"network_id\":\"1234567890\"}}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"router\":{\"id\":\"12345\",\"tenant_id\":\"6789\",\"external_gateway_info\":{\"network_id\":\"1234567890\"}}}", APPLICATION_JSON)).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ Router router = api.create(CreateRouterOptions.builder().name("test").externalGatewayInfo(ExternalGatewayInfo.builder().networkId("1234567890").build()).build());
+ assertEquals(router, Router.builder().id("12345").tenantId("6789").externalGatewayInfo(ExternalGatewayInfo.builder().networkId("1234567890").build()).build());
+ }
+
+ @Test(expectedExceptions = AuthorizationException.class)
+ public void testCreateReturns4xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers").method("POST")
+ .payload(payloadFromStringWithContentType("{\"router\":{\"name\":\"another-test\",\"external_gateway_info\":{\"network_id\":\"1234567890\"}}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(401).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ api.create(CreateRouterOptions.builder().name("another-test").externalGatewayInfo(ExternalGatewayInfo.builder().networkId("1234567890").build()).build());
+ }
+
+ public void testUpdateReturns2xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers/12345").method("PUT")
+ .payload(payloadFromStringWithContentType("{\"router\":{\"name\":\"another-test\",\"admin_state_up\":true}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ assertTrue(api.update("12345", UpdateRouterOptions.builder().name("another-test").adminStateUp(true).build()));
+ }
+
+ public void testUpdateReturns4xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers/12345").method("PUT")
+ .payload(payloadFromStringWithContentType("{\"router\":{\"name\":\"another-test\",\"admin_state_up\":true}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(404).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ assertFalse(api.update("12345", UpdateRouterOptions.builder().name("another-test").adminStateUp(true).build()));
+ }
+
+ public void testDeleteReturns2xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers/12345").method("DELETE").build(),
+ HttpResponse.builder().statusCode(200).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ assertTrue(api.delete("12345"));
+ }
+
+ @Test(expectedExceptions = AuthorizationException.class)
+ public void testDeleteReturns4xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers/12345").method("DELETE").build(),
+ HttpResponse.builder().statusCode(403).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ api.delete("12345");
+ }
+
+ public void testAddInterfaceForSubnetReturns2xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers/12345/add_router_interface").method("PUT")
+ .payload(payloadFromStringWithContentType("{\"subnet_id\":\"1234567890\"}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"subnet_id\":\"1234567890\",\"port_id\":\"987654321\"}", MediaType.APPLICATION_JSON)).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ RouterInterface routerInterface = api.addInterfaceForSubnet("12345", "1234567890");
+ assertEquals(routerInterface, RouterInterface.builder().subnetId("1234567890").portId("987654321").build());
+ }
+
+ @Test(expectedExceptions = AuthorizationException.class)
+ public void testAddInterfaceForSubnetReturns4xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers/12345/add_router_interface").method("PUT")
+ .payload(payloadFromStringWithContentType("{\"subnet_id\":\"1234567890\"}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(403).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ api.addInterfaceForSubnet("12345", "1234567890");
+ }
+
+ public void testAddInterfaceForPortReturns2xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers/12345/add_router_interface").method("PUT")
+ .payload(payloadFromStringWithContentType("{\"port_id\":\"987654321\"}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"subnet_id\":\"1234567890\",\"port_id\":\"987654321\"}", MediaType.APPLICATION_JSON)).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ RouterInterface routerInterface = api.addInterfaceForPort("12345", "987654321");
+ assertEquals(routerInterface, RouterInterface.builder().subnetId("1234567890").portId("987654321").build());
+ }
+
+ @Test(expectedExceptions = AuthorizationException.class)
+ public void testAddInterfaceForPortReturns4xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers/12345/add_router_interface").method("PUT")
+ .payload(payloadFromStringWithContentType("{\"port_id\":\"1234567890\"}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(403).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ api.addInterfaceForPort("12345", "1234567890");
+ }
+
+ public void testRemoveInterfaceForSubnetReturns2xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers/12345/remove_router_interface").method("PUT")
+ .payload(payloadFromStringWithContentType("{\"subnet_id\":\"1234567890\"}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ api.removeInterfaceForSubnet("12345", "1234567890");
+ }
+
+ @Test(expectedExceptions = AuthorizationException.class)
+ public void testRemoveInterfaceForSubnetReturns4xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers/12345/remove_router_interface").method("PUT")
+ .payload(payloadFromStringWithContentType("{\"subnet_id\":\"1234567890\"}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(403).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ api.removeInterfaceForSubnet("12345", "1234567890");
+ }
+
+ public void testRemoveInterfaceForPortReturns2xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers/12345/remove_router_interface").method("PUT")
+ .payload(payloadFromStringWithContentType("{\"port_id\":\"1234567890\"}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ api.removeInterfaceForPort("12345", "1234567890");
+ }
+
+ @Test(expectedExceptions = AuthorizationException.class)
+ public void testRemoveInterfaceForPortReturns4xx() {
+ RouterApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/routers/12345/remove_router_interface").method("PUT")
+ .payload(payloadFromStringWithContentType("{\"port_id\":\"1234567890\"}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(403).build())
+ .getRouterExtensionForZone(ZONE).get();
+
+ api.removeInterfaceForPort("12345", "1234567890");
+ }
+
+ protected Set<Router> listOfRouters() {
+ return ImmutableSet.of(
+ Router.builder().state(State.ACTIVE).name("jclouds-test").tenantId("1234567890").id("16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
+ Router.builder().state(State.ACTIVE).name("wibble").tenantId("1234567890").id("1a104cf5-cb18-4d35-9407-2fd2646d9d0b").build(),
+ Router.builder().state(State.ACTIVE).name("jclouds-test").tenantId("1234567890").id("31083ae2-420d-48b2-ac98-9f7a4fd8dbdc").build(),
+ Router.builder().state(State.ACTIVE).name("jclouds-test").tenantId("1234567890").id("49c6d6fa-ff2a-459d-b975-75a8d31c9a89").build(),
+ Router.builder().state(State.ACTIVE).name("wibble").tenantId("1234567890").id("5cb3d6f4-62cb-41c9-b964-ba7d9df79e4e").build(),
+ Router.builder().state(State.ACTIVE).name("jclouds-test").tenantId("1234567890").id("5d51d012-3491-4db7-b1b5-6f254015015d").build(),
+ Router.builder().state(State.ACTIVE).name("wibble").tenantId("1234567890").id("5f9cf7dc-22ca-4097-8e49-1cc8b23faf17").build(),
+ Router.builder().state(State.ACTIVE).name("jclouds-test").tenantId("1234567890").id("6319ecad-6bff-48b2-9b53-02ede8cb7588").build(),
+ Router.builder().state(State.ACTIVE).name("jclouds-test").tenantId("1234567890").id("6ba4c788-661f-49ab-9bf8-5f10cbbb2f57").build(),
+ Router.builder().state(State.ACTIVE).name("jclouds-test").tenantId("1234567890").id("74ed170b-5069-4353-ab38-9719766dc57e").build(),
+ Router.builder().state(State.ACTIVE).name("wibble").tenantId("1234567890").id("b71fcac1-e864-4031-8c5b-edbecd9ece36").build(),
+ Router.builder().state(State.ACTIVE).name("jclouds-test").tenantId("1234567890").id("c7681895-d84d-4650-9ca0-82c72036b855").build()
+ );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/extensions/RouterApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/extensions/RouterApiLiveTest.java b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/extensions/RouterApiLiveTest.java
new file mode 100644
index 0000000..e51a8c4
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/extensions/RouterApiLiveTest.java
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jclouds.openstack.neutron.v2_0.extensions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.jclouds.openstack.neutron.v2_0.domain.ExternalGatewayInfo;
+import org.jclouds.openstack.neutron.v2_0.domain.Network;
+import org.jclouds.openstack.neutron.v2_0.domain.NetworkType;
+import org.jclouds.openstack.neutron.v2_0.domain.Port;
+import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
+import org.jclouds.openstack.neutron.v2_0.domain.Router;
+import org.jclouds.openstack.neutron.v2_0.domain.RouterInterface;
+import org.jclouds.openstack.neutron.v2_0.domain.Subnet;
+import org.jclouds.openstack.neutron.v2_0.features.NetworkApi;
+import org.jclouds.openstack.neutron.v2_0.features.PortApi;
+import org.jclouds.openstack.neutron.v2_0.features.SubnetApi;
+import org.jclouds.openstack.neutron.v2_0.internal.BaseNeutronApiLiveTest;
+import org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions;
+import org.jclouds.openstack.neutron.v2_0.options.CreateRouterOptions;
+import org.jclouds.openstack.neutron.v2_0.options.UpdateRouterOptions;
+import org.testng.annotations.Test;
+
+/**
+ * Tests parsing and Guice wiring of RouterApi
+ *
+ */
+@Test(groups = "live", testName = "RouterApiLiveTest")
+public class RouterApiLiveTest extends BaseNeutronApiLiveTest {
+
+ public void testGetAndListRouters() {
+ for (String zone : api.getConfiguredZones()) {
+ Set<? extends ReferenceWithName> references = api.getRouterExtensionForZone(zone).get().list().concat().toSet();
+ Set<? extends Router> routers = api.getRouterExtensionForZone(zone).get().listInDetail().concat().toSet();
+
+ assertNotNull(references);
+ assertNotNull(routers);
+ assertEquals(references.size(), routers.size());
+
+ for (Router router : routers) {
+ assertNotNull(router.getName());
+ assertTrue(references.contains(ReferenceWithName.builder().id(router.getId()).tenantId(router.getTenantId()).name(router.getName()).build()));
+
+ Router retrievedRouter = api.getRouterExtensionForZone(zone).get().get(router.getId());
+ assertEquals(router, retrievedRouter);
+ }
+ }
+ }
+
+ public void testCreateUpdateAndDeleteRouter() {
+ for (String zone : api.getConfiguredZones()) {
+ RouterApi routerApi = api.getRouterExtensionForZone(zone).get();
+ NetworkApi networkApi = api.getNetworkApiForZone(zone);
+ SubnetApi subnetApi = api.getSubnetApiForZone(zone);
+
+ Network network = networkApi.create(CreateNetworkOptions.builder().name("jclouds-network-test").external(true).networkType(NetworkType.LOCAL).build());
+ assertNotNull(network);
+
+ Subnet subnet = subnetApi.create(network.getId(), 4, "192.168.0.0/16");
+ assertNotNull(subnet);
+
+ Router ref = routerApi.create(CreateRouterOptions.builder().name("jclouds-router-test")
+ .externalGatewayInfo(ExternalGatewayInfo.builder().networkId(network.getId()).build()).build());
+ assertNotNull(ref);
+
+ Router router = routerApi.get(ref.getId());
+
+ assertEquals(router.getId(), ref.getId());
+ assertEquals(router.getName(), "jclouds-router-test");
+ assertEquals(router.getExternalGatewayInfo().getNetworkId(), network.getId());
+ assertTrue(routerApi.update(router.getId(), UpdateRouterOptions.builder().name("jclouds-router-test-rename").build()));
+
+ router = routerApi.get(ref.getId());
+
+ assertEquals(router.getId(), ref.getId());
+ assertEquals(router.getName(), "jclouds-router-test-rename");
+
+ ReferenceWithName ref2 = routerApi.create(CreateRouterOptions.builder().name("jclouds-router-test2")
+ .externalGatewayInfo(ExternalGatewayInfo.builder().networkId(network.getId()).build()).build());
+ assertNotNull(ref2);
+
+ assertTrue(routerApi.delete(ref.getId()));
+ assertTrue(routerApi.delete(ref2.getId()));
+ assertTrue(subnetApi.delete(subnet.getId()));
+ assertTrue(networkApi.delete(network.getId()));
+ }
+ }
+
+ public void testCreateAndDeleteRouterInterfaceForSubnet() {
+ for (String zone : api.getConfiguredZones()) {
+ RouterApi routerApi = api.getRouterExtensionForZone(zone).get();
+ NetworkApi networkApi = api.getNetworkApiForZone(zone);
+ SubnetApi subnetApi = api.getSubnetApiForZone(zone);
+
+ Network network = networkApi.create(CreateNetworkOptions.builder().name("jclouds-network-test").external(true).networkType(NetworkType.LOCAL).build());
+ assertNotNull(network);
+
+ Subnet subnet = subnetApi.create(network.getId(), 4, "192.168.0.0/16");
+ assertNotNull(subnet);
+
+ Network network2 = networkApi.create(CreateNetworkOptions.builder().name("jclouds-network-test2").external(true).networkType(NetworkType.LOCAL).build());
+ assertNotNull(network2);
+
+ Subnet subnet2 = subnetApi.create(network2.getId(), 4, "192.169.0.0/16");
+ assertNotNull(subnet2);
+
+ Router router = routerApi.create(CreateRouterOptions.builder().name("jclouds-router-test").build());
+ assertNotNull(router);
+
+ RouterInterface routerInterface = routerApi.addInterfaceForSubnet(router.getId(), subnet.getId());
+ assertNotNull(routerInterface);
+
+ RouterInterface routerInterface2 = routerApi.addInterfaceForSubnet(router.getId(), subnet2.getId());
+ assertNotNull(routerInterface2);
+
+ assertTrue(routerApi.removeInterfaceForSubnet(router.getId(), subnet.getId()));
+ assertTrue(routerApi.removeInterfaceForSubnet(router.getId(), subnet2.getId()));
+ assertTrue(routerApi.delete(router.getId()));
+ assertTrue(subnetApi.delete(subnet.getId()));
+ assertTrue(networkApi.delete(network.getId()));
+ assertTrue(subnetApi.delete(subnet2.getId()));
+ assertTrue(networkApi.delete(network2.getId()));
+ }
+ }
+
+ public void testCreateAndDeleteRouterInterfaceForPort() {
+ for (String zone : api.getConfiguredZones()) {
+ RouterApi routerApi = api.getRouterExtensionForZone(zone).get();
+ NetworkApi networkApi = api.getNetworkApiForZone(zone);
+ SubnetApi subnetApi = api.getSubnetApiForZone(zone);
+ PortApi portApi = api.getPortApiForZone(zone);
+
+ Network network = networkApi.create(CreateNetworkOptions.builder().name("jclouds-network-test").external(true).networkType(NetworkType.LOCAL).build());
+ assertNotNull(network);
+
+ Subnet subnet = subnetApi.create(network.getId(), 4, "192.168.0.0/16");
+ assertNotNull(subnet);
+
+ Network network2 = networkApi.create(CreateNetworkOptions.builder().name("jclouds-network-test2").external(true).networkType(NetworkType.LOCAL).build());
+ assertNotNull(network2);
+
+ Subnet subnet2 = subnetApi.create(network2.getId(), 4, "192.169.0.0/16");
+ assertNotNull(subnet2);
+
+ Port port = portApi.create(network.getId());
+ assertNotNull(port);
+
+ Port port2 = portApi.create(network2.getId());
+ assertNotNull(port2);
+
+ Router router = routerApi.create(CreateRouterOptions.builder().name("jclouds-router-test").build());
+ assertNotNull(router);
+
+ RouterInterface routerInterface = routerApi.addInterfaceForPort(router.getId(), port.getId());
+ assertNotNull(routerInterface);
+
+ RouterInterface routerInterface2 = routerApi.addInterfaceForPort(router.getId(), port2.getId());
+ assertNotNull(routerInterface2);
+
+ assertTrue(routerApi.removeInterfaceForPort(router.getId(), port.getId()));
+ assertTrue(routerApi.removeInterfaceForPort(router.getId(), port2.getId()));
+ assertTrue(routerApi.delete(router.getId()));
+ assertTrue(subnetApi.delete(subnet.getId()));
+ assertTrue(networkApi.delete(network.getId()));
+ assertTrue(subnetApi.delete(subnet2.getId()));
+ assertTrue(networkApi.delete(network2.getId()));
+
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/features/NetworkApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/features/NetworkApiExpectTest.java b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/features/NetworkApiExpectTest.java
new file mode 100644
index 0000000..2d2b09c
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/features/NetworkApiExpectTest.java
@@ -0,0 +1,245 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.openstack.neutron.v2_0.features;
+
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Set;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.neutron.v2_0.domain.BulkNetwork;
+import org.jclouds.openstack.neutron.v2_0.domain.Network;
+import org.jclouds.openstack.neutron.v2_0.domain.NetworkType;
+import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
+import org.jclouds.openstack.neutron.v2_0.internal.BaseNeutronApiExpectTest;
+import org.jclouds.openstack.neutron.v2_0.options.CreateNetworkBulkOptions;
+import org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions;
+import org.jclouds.openstack.neutron.v2_0.options.UpdateNetworkOptions;
+import org.jclouds.openstack.neutron.v2_0.parse.ParseNetworkTest;
+import org.jclouds.rest.AuthorizationException;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests parsing and Guice wiring of NetworkApi
+ *
+ */
+@Test(groups = "unit", testName = "NetworkApiExpectTest")
+public class NetworkApiExpectTest extends BaseNeutronApiExpectTest {
+
+ private static final String ZONE = "region-a.geo-1";
+
+ public void testListReferencesReturns2xx() {
+ NetworkApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/networks").addQueryParam("fields", "id", "tenant_id", "name").build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/list_networks.json", APPLICATION_JSON)).build())
+ .getNetworkApiForZone(ZONE);
+
+ Set<? extends ReferenceWithName> references = api.list().concat().toSet();
+ assertEquals(references, listOfReferencesWithNames());
+ }
+
+ public void testListReferencesReturns4xx() {
+ NetworkApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/networks").addQueryParam("fields", "id", "tenant_id", "name").build(),
+ HttpResponse.builder().statusCode(404).build())
+ .getNetworkApiForZone(ZONE);
+
+ assertTrue(api.list().concat().isEmpty());
+ }
+
+ public void testListReturns2xx() {
+ NetworkApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/networks").build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/list_networks.json", APPLICATION_JSON)).build())
+ .getNetworkApiForZone(ZONE);
+
+ Set<? extends Network> nets = api.listInDetail().concat().toSet();
+ assertEquals(nets, listOfNetworks());
+ }
+
+ public void testListReturns4xx() {
+ NetworkApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/networks").build(),
+ HttpResponse.builder().statusCode(404).build())
+ .getNetworkApiForZone(ZONE);
+
+ assertTrue(api.listInDetail().concat().isEmpty());
+ }
+
+ public void testGetReturns2xx() {
+ NetworkApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/network.json", APPLICATION_JSON)).build())
+ .getNetworkApiForZone(ZONE);
+
+ Network net = api.get("16dba3bc-f3fa-4775-afdc-237e12c72f6a");
+ assertEquals(net, new ParseNetworkTest().expected());
+ }
+
+ public void testGetReturns4xx() {
+ NetworkApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
+ HttpResponse.builder().statusCode(404).build())
+ .getNetworkApiForZone(ZONE);
+
+ assertNull(api.get("16dba3bc-f3fa-4775-afdc-237e12c72f6a"));
+ }
+
+ public void testCreateReturns2xx() {
+ NetworkApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/networks").method("POST")
+ .payload(payloadFromStringWithContentType("{\"network\":{\"name\":\"another-test\",\"router:external\":true,\"provider:network_type\":\"local\"}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"network\":{\"id\":\"12345\",\"tenant_id\":\"6789\",\"router:external\":true,\"provider:network_type\":\"local\"}}", APPLICATION_JSON)).build())
+ .getNetworkApiForZone(ZONE);
+
+ Network net = api.create(CreateNetworkOptions.builder().name("another-test").external(true).networkType(NetworkType.LOCAL).build());
+ assertEquals(net, Network.builder().id("12345").tenantId("6789").external(true).networkType(NetworkType.LOCAL).build());
+ }
+
+ @Test(expectedExceptions = AuthorizationException.class)
+ public void testCreateReturns4xx() {
+ NetworkApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/networks").method("POST")
+ .payload(payloadFromStringWithContentType("{\"network\":{\"name\":\"another-test\",\"provider:network_type\":\"local\"}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(401).build())
+ .getNetworkApiForZone(ZONE);
+
+ api.create(CreateNetworkOptions.builder().name("another-test").networkType(NetworkType.LOCAL).build());
+ }
+
+ public void testCreateBulkReturns2xx() {
+ NetworkApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/networks").method("POST")
+ .payload(payloadFromStringWithContentType("{\"networks\":[{\"name\":\"test\",\"provider:network_type\":\"local\"},{\"name\":\"test-2\",\"provider:network_type\":\"local\"}]}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"networks\":[{\"id\":\"1\",\"tenant_id\":\"1\",\"name\":\"test\",\"provider:network_type\":\"local\"},{\"id\":\"2\",\"tenant_id\":\"1\",\"name\":\"test-2\",\"provider:network_type\":\"local\"}]}", APPLICATION_JSON)).build())
+ .getNetworkApiForZone(ZONE);
+
+ Set<? extends ReferenceWithName> nets = api.createBulk(
+ CreateNetworkBulkOptions.builder().networks(
+ ImmutableList.of(
+ BulkNetwork.builder().networkType(NetworkType.LOCAL).name("test").build(),
+ BulkNetwork.builder().networkType(NetworkType.LOCAL).name("test-2").build()
+ )
+ ).build()
+ ).toSet();
+ assertEquals(nets, createBulkReturns2xxResponse());
+ }
+
+ @Test(expectedExceptions = AuthorizationException.class)
+ public void testCreateBulkReturns4xx() {
+ NetworkApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/networks").method("POST")
+ .payload(payloadFromStringWithContentType("{\"networks\":[{\"name\":\"test\",\"provider:network_type\":\"local\"},{\"name\":\"test-2\",\"provider:network_type\":\"local\"}]}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(401).build())
+ .getNetworkApiForZone(ZONE);
+
+ api.createBulk(
+ CreateNetworkBulkOptions.builder().networks(
+ ImmutableList.of(
+ BulkNetwork.builder().networkType(NetworkType.LOCAL).name("test").build(),
+ BulkNetwork.builder().networkType(NetworkType.LOCAL).name("test-2").build()
+ )
+ ).build()
+ );
+ }
+
+ public void testUpdateReturns2xx() {
+ NetworkApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/networks/12345").method("PUT")
+ .payload(payloadFromStringWithContentType("{\"network\":{\"name\":\"another-test\",\"admin_state_up\":true}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).build())
+ .getNetworkApiForZone(ZONE);
+
+ assertTrue(api.update("12345", UpdateNetworkOptions.builder().name("another-test").adminStateUp(true).build()));
+ }
+
+ public void testUpdateReturns4xx() {
+ NetworkApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/networks/12345").method("PUT")
+ .payload(payloadFromStringWithContentType("{\"network\":{\"name\":\"another-test\",\"admin_state_up\":true}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(404).build())
+ .getNetworkApiForZone(ZONE);
+
+ assertFalse(api.update("12345", UpdateNetworkOptions.builder().name("another-test").adminStateUp(true).build()));
+ }
+
+ public void testDeleteReturns2xx() {
+ NetworkApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/networks/12345").method("DELETE").build(),
+ HttpResponse.builder().statusCode(200).build())
+ .getNetworkApiForZone(ZONE);
+
+ assertTrue(api.delete("12345"));
+ }
+
+ @Test(expectedExceptions = AuthorizationException.class)
+ public void testDeleteReturns4xx() {
+ NetworkApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/networks/12345").method("DELETE").build(),
+ HttpResponse.builder().statusCode(403).build())
+ .getNetworkApiForZone(ZONE);
+
+ api.delete("12345");
+ }
+
+ protected Set<Network> listOfNetworks() {
+ return ImmutableSet.of(
+ Network.builder().name("jclouds-test").tenantId("1234567890").id("16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
+ Network.builder().name("wibble").tenantId("1234567890").id("1a104cf5-cb18-4d35-9407-2fd2646d9d0b").build(),
+ Network.builder().name("jclouds-test").tenantId("1234567890").id("31083ae2-420d-48b2-ac98-9f7a4fd8dbdc").build(),
+ Network.builder().name("jclouds-test").tenantId("1234567890").id("49c6d6fa-ff2a-459d-b975-75a8d31c9a89").build(),
+ Network.builder().name("wibble").tenantId("1234567890").id("5cb3d6f4-62cb-41c9-b964-ba7d9df79e4e").build(),
+ Network.builder().name("jclouds-test").tenantId("1234567890").id("5d51d012-3491-4db7-b1b5-6f254015015d").build(),
+ Network.builder().name("wibble").tenantId("1234567890").id("5f9cf7dc-22ca-4097-8e49-1cc8b23faf17").build(),
+ Network.builder().name("jclouds-test").tenantId("1234567890").id("6319ecad-6bff-48b2-9b53-02ede8cb7588").build(),
+ Network.builder().name("jclouds-test").tenantId("1234567890").id("6ba4c788-661f-49ab-9bf8-5f10cbbb2f57").build(),
+ Network.builder().name("jclouds-test").tenantId("1234567890").id("74ed170b-5069-4353-ab38-9719766dc57e").build(),
+ Network.builder().name("wibble").tenantId("1234567890").id("b71fcac1-e864-4031-8c5b-edbecd9ece36").build(),
+ Network.builder().name("jclouds-test").tenantId("1234567890").id("c7681895-d84d-4650-9ca0-82c72036b855").build()
+ );
+ }
+
+ protected Set<Network> createBulkReturns2xxResponse() {
+ return ImmutableSet.of(
+ Network.builder().id("1").tenantId("1").name("test").networkType(NetworkType.LOCAL).build(),
+ Network.builder().id("2").tenantId("1").name("test-2").networkType(NetworkType.LOCAL).build()
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/features/NetworkApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/features/NetworkApiLiveTest.java b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/features/NetworkApiLiveTest.java
new file mode 100644
index 0000000..cc72b1c
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/features/NetworkApiLiveTest.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.openstack.neutron.v2_0.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.jclouds.openstack.neutron.v2_0.domain.BulkNetwork;
+import org.jclouds.openstack.neutron.v2_0.domain.Network;
+import org.jclouds.openstack.neutron.v2_0.domain.NetworkType;
+import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
+import org.jclouds.openstack.neutron.v2_0.internal.BaseNeutronApiLiveTest;
+import org.jclouds.openstack.neutron.v2_0.options.CreateNetworkBulkOptions;
+import org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions;
+import org.jclouds.openstack.neutron.v2_0.options.UpdateNetworkOptions;
+import org.jclouds.openstack.neutron.v2_0.util.PredicateUtil;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Sets;
+
+/**
+ * Tests parsing and Guice wiring of NetworkApi
+ *
+ */
+@Test(groups = "live", testName = "NetworkApiLiveTest")
+public class NetworkApiLiveTest extends BaseNeutronApiLiveTest {
+
+ public void testGetAndListNetworks() {
+ for (String zone : api.getConfiguredZones()) {
+ Set<? extends ReferenceWithName> references = api.getNetworkApiForZone(zone).list().concat().toSet();
+ Set<? extends Network> networks = api.getNetworkApiForZone(zone).listInDetail().concat().toSet();
+
+ assertNotNull(references);
+ assertNotNull(networks);
+ assertEquals(references.size(), networks.size());
+
+ for (Network network : networks) {
+ assertNotNull(network.getName());
+ assertTrue(references.contains(ReferenceWithName.builder().id(network.getId()).tenantId(network.getTenantId()).name(network.getName()).build()));
+
+ Network retrievedNetwork = api.getNetworkApiForZone(zone).get(network.getId());
+ assertEquals(network, retrievedNetwork);
+ }
+ }
+ }
+
+ public void testCreateUpdateAndDeleteNetwork() {
+ for (String zone : api.getConfiguredZones()) {
+ NetworkApi networkApi = api.getNetworkApiForZone(zone);
+ Network net = networkApi.create(CreateNetworkOptions.builder().name("jclouds-test").networkType(NetworkType.LOCAL).build());
+ Network test = networkApi.create();
+ assertNotNull(net);
+
+ Network network = networkApi.get(net.getId());
+
+ assertEquals(network.getId(), net.getId());
+ assertEquals(network.getName(), "jclouds-test");
+ assertEquals(network.getNetworkType(), NetworkType.LOCAL);
+ assertTrue(network.getSubnets().isEmpty());
+ assertTrue(networkApi.update(net.getId(), UpdateNetworkOptions.builder().name("jclouds-live-test").build()));
+
+ network = networkApi.get(net.getId());
+
+ assertEquals(network.getId(), net.getId());
+ assertEquals(network.getName(), "jclouds-live-test");
+ assertTrue(network.getSubnets().isEmpty());
+
+ Network net2 = networkApi.create(CreateNetworkOptions.builder().name("jclouds-test2").networkType(NetworkType.LOCAL).build());
+ assertNotNull(net2);
+
+ assertTrue(networkApi.delete(net.getId()));
+ assertTrue(networkApi.delete(net2.getId()));
+ assertTrue(networkApi.delete(test.getId()));
+ }
+ }
+
+ public void testBulkCreateNetwork() {
+ for (String zone : api.getConfiguredZones()) {
+ NetworkApi networkApi = api.getNetworkApiForZone(zone);
+ Set<? extends Network> nets = networkApi.createBulk(
+ CreateNetworkBulkOptions.builder().networks(
+ ImmutableList.of(
+ BulkNetwork.builder().networkType(NetworkType.LOCAL).name("jclouds-live-test-1").adminStateUp(true).build(),
+ BulkNetwork.builder().networkType(NetworkType.LOCAL).name("jclouds-live-test-2").adminStateUp(false).build(),
+ BulkNetwork.builder().networkType(NetworkType.LOCAL).name("jclouds-live-test-3").adminStateUp(false).build()
+ )
+ ).build()
+ ).toSet();
+ Set<? extends Network> existingNets = networkApi.listInDetail().concat().toSet();
+
+ assertNotNull(nets);
+ assertTrue(!nets.isEmpty());
+ assertEquals(nets.size(), 3);
+
+ for (Network net : nets) {
+ Predicate<Network> idEqualsPredicate = PredicateUtil.createIdEqualsPredicate(net.getId());
+ assertEquals(1, Sets.filter(existingNets, idEqualsPredicate).size());
+ assertTrue(networkApi.delete(net.getId()));
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/features/PortApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/features/PortApiExpectTest.java b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/features/PortApiExpectTest.java
new file mode 100644
index 0000000..7f5338d
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/features/PortApiExpectTest.java
@@ -0,0 +1,245 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.openstack.neutron.v2_0.features;
+
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.neutron.v2_0.domain.BulkPort;
+import org.jclouds.openstack.neutron.v2_0.domain.Port;
+import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
+import org.jclouds.openstack.neutron.v2_0.domain.State;
+import org.jclouds.openstack.neutron.v2_0.internal.BaseNeutronApiExpectTest;
+import org.jclouds.openstack.neutron.v2_0.options.CreatePortBulkOptions;
+import org.jclouds.openstack.neutron.v2_0.options.CreatePortOptions;
+import org.jclouds.openstack.neutron.v2_0.options.UpdatePortOptions;
+import org.jclouds.openstack.neutron.v2_0.parse.ParsePortTest;
+import org.jclouds.rest.AuthorizationException;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests parsing and Guice wiring of PortApi
+ *
+ */
+@Test(groups = "unit", testName = "PortApiExpectTest")
+public class PortApiExpectTest extends BaseNeutronApiExpectTest {
+
+ private static final String ZONE = "region-a.geo-1";
+
+ public void testListReferencesReturns2xx() {
+ PortApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/ports").addQueryParam("fields", "id", "tenant_id", "name").build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/list_ports.json", APPLICATION_JSON)).build())
+ .getPortApiForZone(ZONE);
+
+ Set<? extends ReferenceWithName> references = api.list().concat().toSet();
+ assertEquals(references, listOfReferencesWithNames());
+ }
+
+ public void testListReferencesReturns4xx() {
+ PortApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/ports").addQueryParam("fields", "id", "tenant_id", "name").build(),
+ HttpResponse.builder().statusCode(404).build())
+ .getPortApiForZone(ZONE);
+
+ assertTrue(api.list().concat().isEmpty());
+ }
+
+ public void testListReturns2xx() {
+ PortApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/ports").build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/list_ports.json", APPLICATION_JSON)).build())
+ .getPortApiForZone(ZONE);
+
+ Set<? extends Port> ports = api.listInDetail().concat().toSet();
+ assertEquals(ports, listOfPorts());
+ }
+
+ public void testListReturns4xx() {
+ PortApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/ports").build(),
+ HttpResponse.builder().statusCode(404).build())
+ .getPortApiForZone(ZONE);
+
+ assertTrue(api.listInDetail().concat().isEmpty());
+ }
+
+ public void testGetReturns2xx() {
+ PortApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/ports/624312ff-d14b-4ba3-9834-1c78d23d574d").build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/port.json", APPLICATION_JSON)).build())
+ .getPortApiForZone(ZONE);
+
+ Port port = api.get("624312ff-d14b-4ba3-9834-1c78d23d574d");
+ assertEquals(port, new ParsePortTest().expected());
+ }
+
+ public void testGetReturns4xx() {
+ PortApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/ports/624312ff-d14b-4ba3-9834-1c78d23d574d").build(),
+ HttpResponse.builder().statusCode(404).build())
+ .getPortApiForZone(ZONE);
+
+ assertNull(api.get("624312ff-d14b-4ba3-9834-1c78d23d574d"));
+ }
+
+ public void testCreateReturns2xx() {
+ PortApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/ports").method("POST")
+ .payload(payloadFromStringWithContentType("{\"port\":{\"network_id\":\"1\",\"name\":\"test-port\"}}", APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"port\":{\"id\":\"1\",\"tenant_id\":\"1\",\"network_id\":\"1\",\"name\":\"test-port\"}}", APPLICATION_JSON)).build())
+ .getPortApiForZone(ZONE);
+
+ Port port = api.create("1", CreatePortOptions.builder().name("test-port").build());
+ assertEquals(port, Port.builder().id("1").tenantId("1").name("test-port").networkId("1").build());
+ }
+
+ @Test(expectedExceptions = AuthorizationException.class)
+ public void testCreateReturns4xx() {
+ PortApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/ports").method("POST")
+ .payload(payloadFromStringWithContentType("{\"port\":{\"network_id\":\"1\",\"name\":\"test-port\"}}", APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(401).build())
+ .getPortApiForZone(ZONE);
+
+ api.create("1", CreatePortOptions.builder().name("test-port").build());
+ }
+
+ public void testCreateBulkReturns2xx() {
+ PortApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/ports").method("POST")
+ .payload(payloadFromStringWithContentType("{\"ports\":[{\"network_id\":\"1\",\"name\":\"test-port-1\"},{\"network_id\":\"2\",\"name\":\"test-port-2\"}]}", APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200)
+ .payload(payloadFromStringWithContentType("{\"ports\":[{\"id\":\"1\",\"tenant_id\":\"1\",\"network_id\":\"1\",\"name\":\"test-port-1\"},{\"id\":\"2\",\"tenant_id\":\"1\",\"network_id\":\"2\",\"name\":\"test-port-2\"}]}", APPLICATION_JSON)).build())
+ .getPortApiForZone(ZONE);
+
+ Set<? extends ReferenceWithName> ports = api.createBulk(
+ CreatePortBulkOptions.builder().ports(
+ ImmutableList.of(
+ BulkPort.builder().networkId("1").name("test-port-1").build(),
+ BulkPort.builder().networkId("2").name("test-port-2").build()
+ )
+ ).build()
+ ).toSet();
+ assertEquals(ports, createBulkReturns2xxResponse());
+ }
+
+ @Test(expectedExceptions = AuthorizationException.class)
+ public void testCreateBulkReturns4xx() {
+ PortApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/ports").method("POST")
+ .payload(payloadFromStringWithContentType("{\"ports\":[{\"network_id\":\"1\",\"name\":\"test-port-1\"},{\"network_id\":\"2\",\"name\":\"test-port-2\"}]}", APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(401).build())
+ .getPortApiForZone(ZONE);
+
+ api.createBulk(
+ CreatePortBulkOptions.builder().ports(
+ ImmutableList.of(
+ BulkPort.builder().networkId("1").name("test-port-1").build(),
+ BulkPort.builder().networkId("2").name("test-port-2").build()
+ )
+ ).build()
+ );
+ }
+
+ public void testUpdateReturns2xx() {
+ PortApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/ports/12345").method("PUT")
+ .payload(payloadFromStringWithContentType("{\"port\":{\"name\":\"another-test\",\"admin_state_up\":true}}", APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).build())
+ .getPortApiForZone(ZONE);
+
+ assertTrue(api.update("12345", UpdatePortOptions.builder().name("another-test").adminStateUp(true).build()));
+ }
+
+ public void testUpdateReturns4xx() {
+ PortApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/ports/12345").method("PUT")
+ .payload(payloadFromStringWithContentType("{\"port\":{\"name\":\"another-test\",\"admin_state_up\":true}}", APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(404).build())
+ .getPortApiForZone(ZONE);
+
+ assertFalse(api.update("12345", UpdatePortOptions.builder().name("another-test").adminStateUp(true).build()));
+ }
+
+ public void testDeleteReturns2xx() {
+ PortApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/ports/12345").method("DELETE").build(),
+ HttpResponse.builder().statusCode(200).build())
+ .getPortApiForZone(ZONE);
+
+ assertTrue(api.delete("12345"));
+ }
+
+ @Test(expectedExceptions = AuthorizationException.class)
+ public void testDeleteReturns4xx() {
+ PortApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
+ authenticatedGET().endpoint(endpoint + "/ports/12345").method("DELETE").build(),
+ HttpResponse.builder().statusCode(403).build())
+ .getPortApiForZone(ZONE);
+
+ api.delete("12345");
+ }
+
+ protected Set<Port> listOfPorts() {
+ return ImmutableSet.of(
+ Port.builder().state(State.ACTIVE).networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
+ Port.builder().state(State.ACTIVE).networkId("1234567890").name("wibble").tenantId("1234567890").id("1a104cf5-cb18-4d35-9407-2fd2646d9d0b").build(),
+ Port.builder().state(State.ACTIVE).networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("31083ae2-420d-48b2-ac98-9f7a4fd8dbdc").build(),
+ Port.builder().state(State.ACTIVE).networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("49c6d6fa-ff2a-459d-b975-75a8d31c9a89").build(),
+ Port.builder().state(State.ACTIVE).networkId("1234567890").name("wibble").tenantId("1234567890").id("5cb3d6f4-62cb-41c9-b964-ba7d9df79e4e").build(),
+ Port.builder().state(State.ACTIVE).networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("5d51d012-3491-4db7-b1b5-6f254015015d").build(),
+ Port.builder().state(State.ACTIVE).networkId("1234567890").name("wibble").tenantId("1234567890").id("5f9cf7dc-22ca-4097-8e49-1cc8b23faf17").build(),
+ Port.builder().state(State.ACTIVE).networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("6319ecad-6bff-48b2-9b53-02ede8cb7588").build(),
+ Port.builder().state(State.ACTIVE).networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("6ba4c788-661f-49ab-9bf8-5f10cbbb2f57").build(),
+ Port.builder().state(State.ACTIVE).networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("74ed170b-5069-4353-ab38-9719766dc57e").build(),
+ Port.builder().state(State.ACTIVE).networkId("1234567890").name("wibble").tenantId("1234567890").id("b71fcac1-e864-4031-8c5b-edbecd9ece36").build(),
+ Port.builder().state(State.ACTIVE).networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("c7681895-d84d-4650-9ca0-82c72036b855").build()
+ );
+ }
+
+ protected Set<Port> createBulkReturns2xxResponse() {
+ return ImmutableSet.of(
+ Port.builder().id("1").tenantId("1").name("test-port-1").networkId("1").build(),
+ Port.builder().id("2").tenantId("1").name("test-port-2").networkId("2").build()
+ );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/features/PortApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/features/PortApiLiveTest.java b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/features/PortApiLiveTest.java
new file mode 100644
index 0000000..76f3734
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-neutron/1.8.1-stratos/src/test/java/org/jclouds/openstack/neutron/v2_0/features/PortApiLiveTest.java
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.openstack.neutron.v2_0.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.jclouds.openstack.neutron.v2_0.domain.BulkPort;
+import org.jclouds.openstack.neutron.v2_0.domain.IP;
+import org.jclouds.openstack.neutron.v2_0.domain.NetworkType;
+import org.jclouds.openstack.neutron.v2_0.domain.Port;
+import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
+import org.jclouds.openstack.neutron.v2_0.internal.BaseNeutronApiLiveTest;
+import org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions;
+import org.jclouds.openstack.neutron.v2_0.options.CreatePortBulkOptions;
+import org.jclouds.openstack.neutron.v2_0.options.CreatePortOptions;
+import org.jclouds.openstack.neutron.v2_0.options.CreateSubnetOptions;
+import org.jclouds.openstack.neutron.v2_0.options.UpdatePortOptions;
+import org.jclouds.openstack.neutron.v2_0.util.PredicateUtil;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+
+/**
+ * Tests PortApi in combination with the Network & SubnetApi
+ *
+ */
+@Test(groups = "live", testName = "PortApiLiveTest")
+public class PortApiLiveTest extends BaseNeutronApiLiveTest {
+
+ public void testGetAndListPorts() {
+ for (String zone : api.getConfiguredZones()) {
+ Set<? extends ReferenceWithName> references = api.getPortApiForZone(zone).list().concat().toSet();
+ Set<? extends Port> ports = api.getPortApiForZone(zone).listInDetail().concat().toSet();
+
+ assertNotNull(references);
+ assertNotNull(ports);
+ assertEquals(references.size(), ports.size());
+
+ for (Port port : ports) {
+ assertNotNull(port.getName());
+ assertTrue(references.contains(ReferenceWithName.builder().id(port.getId()).tenantId(port.getTenantId()).name(port.getName()).build()));
+
+ Port retrievedPort = api.getPortApiForZone(zone).get(port.getId());
+ assertEquals(port, retrievedPort);
+ }
+ }
+ }
+
+ public void testCreateUpdateAndDeletePort() {
+ for (String zone : api.getConfiguredZones()) {
+ NetworkApi networkApi = api.getNetworkApiForZone(zone);
+ SubnetApi subnetApi = api.getSubnetApiForZone(zone);
+ PortApi portApi = api.getPortApiForZone(zone);
+ String networkId = networkApi.create(CreateNetworkOptions.builder().name("JClouds-Live-Network").networkType(NetworkType.LOCAL).build()).getId();
+ String ipv4SubnetId = subnetApi.create(networkId, 4, "198.51.100.0/24", CreateSubnetOptions.builder().name("JClouds-Live-IPv4-Subnet").build()).getId();
+ String ipv6SubnetId = subnetApi.create(networkId, 6, "a1ca:1e1:c:107d::/96", CreateSubnetOptions.builder().name("JClouds-Live-IPv6-Subnet").build()).getId();
+
+ assertNotNull(networkId);
+ assertNotNull(ipv4SubnetId);
+ assertNotNull(ipv6SubnetId);
+
+ String ipv4PortId = portApi.create(networkId, CreatePortOptions.builder().name("JClouds-Live-IPv4-Port").fixedIps(getFixedAddresses(ipv4SubnetId)).build()).getId();
+ String ipv6PortId = portApi.create(networkId, CreatePortOptions.builder().name("JClouds-Live-IPv6-Port").fixedIps(getFixedAddresses(ipv6SubnetId)).build()).getId();
+
+ assertNotNull(ipv4PortId);
+ assertNotNull(ipv6PortId);
+
+ Port ipv4Port = portApi.get(ipv4PortId);
+ assertNotNull(ipv4Port);
+ assertEquals(ipv4Port.getId(), ipv4PortId);
+ assertEquals(ipv4Port.getName(), "JClouds-Live-IPv4-Port");
+
+ Port ipv6Port = portApi.get(ipv6PortId);
+ assertNotNull(ipv6Port);
+ assertEquals(ipv6Port.getId(), ipv6PortId);
+ assertEquals(ipv6Port.getName(), "JClouds-Live-IPv6-Port");
+
+ assertTrue(portApi.update(ipv4PortId, UpdatePortOptions.builder().name("Updated").build()));
+ Port updatedIpv4Port = portApi.get(ipv4PortId);
+ assertEquals(updatedIpv4Port.getName(), "Updated");
+
+ assertTrue(portApi.delete(ipv4PortId));
+ assertTrue(portApi.delete(ipv6PortId));
+ assertTrue(subnetApi.delete(ipv4SubnetId));
+ assertTrue(subnetApi.delete(ipv6SubnetId));
+ assertTrue(networkApi.delete(networkId));
+ }
+ }
+
+ public void testBulkCreatePort() {
+ for (String zone : api.getConfiguredZones()) {
+ NetworkApi networkApi = api.getNetworkApiForZone(zone);
+ SubnetApi subnetApi = api.getSubnetApiForZone(zone);
+ PortApi portApi = api.getPortApiForZone(zone);
+
+ String networkId = networkApi.create(CreateNetworkOptions.builder().name("JClouds-Live-Network").networkType(NetworkType.LOCAL).build()).getId();
+ String ipv4SubnetId = subnetApi.create(networkId, 4, "198.51.100.0/24", CreateSubnetOptions.builder().name("JClouds-Live-IPv4-Subnet").build()).getId();
+ String ipv6SubnetId = subnetApi.create(networkId, 6, "a1ca:1e1:c:107d::/96", CreateSubnetOptions.builder().name("JClouds-Live-IPv6-Subnet").build()).getId();
+
+ assertNotNull(networkId);
+ assertNotNull(ipv4SubnetId);
+ assertNotNull(ipv6SubnetId);
+
+ Set<? extends Port> ports = portApi.createBulk(
+ CreatePortBulkOptions.builder().ports(
+ ImmutableSet.of(
+ BulkPort.builder().networkId(networkId).name("JClouds-Live-IPv4-Subnet-1").fixedIps(getFixedAddresses(ipv4SubnetId)).build(),
+ BulkPort.builder().networkId(networkId).name("JClouds-Live-IPv4-Subnet-2").fixedIps(getFixedAddresses(ipv4SubnetId)).build(),
+ BulkPort.builder().networkId(networkId).name("JClouds-Live-IPv6-Subnet-1").fixedIps(getFixedAddresses(ipv6SubnetId)).build(),
+ BulkPort.builder().networkId(networkId).name("JClouds-Live-IPv6-Subnet-2").fixedIps(getFixedAddresses(ipv6SubnetId)).build()
+ )
+ ).build()
+ ).toSet();
+ Set<? extends Port> existingPorts = portApi.listInDetail().concat().toSet();
+
+ assertNotNull(ports);
+ assertFalse(ports.isEmpty());
+ assertEquals(ports.size(), 4);
+
+ for (Port port : ports) {
+ Predicate<Port> idEqualsPredicate = PredicateUtil.createIdEqualsPredicate(port.getId());
+ assertEquals(1, Sets.filter(existingPorts, idEqualsPredicate).size());
+ assertTrue(portApi.delete(port.getId()));
+ }
+ assertTrue(subnetApi.delete(ipv4SubnetId));
+ assertTrue(subnetApi.delete(ipv6SubnetId));
+ assertTrue(networkApi.delete(networkId));
+ }
+ }
+
+ public Set<IP> getFixedAddresses(String subnetId) {
+ return ImmutableSet.of(
+ IP.builder().subnetId(subnetId).build()
+ );
+ }
+}