From ca3c2622ff18a0d6bcbe2c4c46e244eeeed6e815 Mon Sep 17 00:00:00 2001 From: Zack Shoylev Date: Tue, 14 Jul 2015 18:43:32 -0500 Subject: [PATCH] Adds missing floating-ip-pool expect test Fixes broken namespace for the ip pool extension --- .../v2_0/extensions/ExtensionNamespaces.java | 2 +- .../FloatingIPPoolApiExpectTest.java | 95 +++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPPoolApiExpectTest.java diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ExtensionNamespaces.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ExtensionNamespaces.java index 21de36f7e0..888ab7a6ba 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ExtensionNamespaces.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/ExtensionNamespaces.java @@ -116,7 +116,7 @@ public final class ExtensionNamespaces { /** * Floating IP pools support */ - public static final String FLOATING_IP_POOLS = "http://docs.openstack.org/ext/floating_ip_pools/api/v1.1"; + public static final String FLOATING_IP_POOLS = "http://docs.openstack.org/compute/ext/floating_ip_pools/api/v1.1"; /** * Attach interfaces extension */ diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPPoolApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPPoolApiExpectTest.java new file mode 100644 index 0000000000..200e1d7b98 --- /dev/null +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPPoolApiExpectTest.java @@ -0,0 +1,95 @@ +/* + * 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.nova.v2_0.extensions; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.nova.v2_0.NovaApi; +import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest; +import org.jclouds.openstack.nova.v2_0.parse.ParseFloatingIPPoolListTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Tests annotation parsing of {@code FloatingIPPoolApi} + */ +@Test(groups = "unit", testName = "FloatingIPPoolApiExpectTest") +public class FloatingIPPoolApiExpectTest extends BaseNovaApiExpectTest { + public void testWhenNamespaceInExtensionsListFloatingIpPoolPresent() throws Exception { + + NovaApi apiWhenExtensionNotInList = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse); + + assertEquals(apiWhenExtensionNotInList.getConfiguredRegions(), + ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1")); + + assertTrue(apiWhenExtensionNotInList.getFloatingIPPoolApi("az-1.region-a.geo-1").isPresent()); + + } + + public void testWhenNamespaceNotInExtensionsListFloatingIpPoolNotPresent() throws Exception { + + NovaApi apiWhenExtensionNotInList = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, extensionsOfNovaRequest, unmatchedExtensionsOfNovaResponse); + + assertEquals(apiWhenExtensionNotInList.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1")); + + assertFalse(apiWhenExtensionNotInList.getFloatingIPPoolApi("az-1.region-a.geo-1").isPresent()); + + } + + public void testListFloatingIPPoolWhenResponseIs2xx() throws Exception { + HttpRequest list = HttpRequest + .builder() + .method("GET") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/os-floating-ip-pools") + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken).build(); + + HttpResponse listResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/floatingippool_list.json")).build(); + + NovaApi apiWhenFloatingIPPoolExists = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse); + + assertEquals(apiWhenFloatingIPPoolExists.getConfiguredRegions(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1")); + + assertEquals(apiWhenFloatingIPPoolExists.getFloatingIPPoolApi("az-1.region-a.geo-1").get().list() + .toString(), new ParseFloatingIPPoolListTest().expected().toString()); + } + + public void testListFloatingIPsWhenResponseIs404() throws Exception { + HttpRequest list = HttpRequest + .builder() + .method("GET") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/os-floating-ip-pools") + .addHeader("Accept", "application/json") + .addHeader("X-Auth-Token", authToken).build(); + + HttpResponse listResponse = HttpResponse.builder().statusCode(404).build(); + + NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, + responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse); + + assertTrue(apiWhenNoServersExist.getFloatingIPPoolApi("az-1.region-a.geo-1").get().list().isEmpty()); + } +}