From 04f1bb2b499018a539b12c5ef3a991acdce2d61c Mon Sep 17 00:00:00 2001 From: Ignasi Barrera Date: Thu, 21 Apr 2016 18:48:38 +0200 Subject: [PATCH] JCLOUDS-1104: Extension namespaces are deprecated and can be null --- .../openstack/v2_0/domain/Extension.java | 6 ++- .../v2_0/functions/ExtensionToNameSpace.java | 41 ----------------- .../v2_0/predicates/ExtensionPredicates.java | 7 +-- .../functions/ExtensionToNameSpaceTest.java | 44 ------------------- ...EqualsAnyNamespaceInExtensionsSetTest.java | 27 ++++++++++-- .../predicates/ExtensionPredicatesTest.java | 6 +++ .../v2_0/features/ExtensionApiLiveTest.java | 3 +- 7 files changed, 39 insertions(+), 95 deletions(-) delete mode 100644 apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/functions/ExtensionToNameSpace.java delete mode 100644 apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/functions/ExtensionToNameSpaceTest.java diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Extension.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Extension.java index c44b72f8ae..f2c5a3a8fe 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Extension.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Extension.java @@ -122,14 +122,16 @@ public class Extension extends Resource { @ConstructorProperties({ "name", "links", "namespace", "alias", "updated", "description" }) - protected Extension(@Nullable String name, Set links, URI namespace, String alias, @Nullable Date updated, String description) { + protected Extension(@Nullable String name, Set links, @Nullable URI namespace, String alias, + @Nullable Date updated, String description) { super(alias, name, links); - this.namespace = checkNotNull(namespace, "namespace"); + this.namespace = namespace; this.alias = checkNotNull(alias, "alias"); this.updated = updated; this.description = checkNotNull(description, "description"); } + @Nullable public URI getNamespace() { return this.namespace; } diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/functions/ExtensionToNameSpace.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/functions/ExtensionToNameSpace.java deleted file mode 100644 index c9964f336c..0000000000 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/functions/ExtensionToNameSpace.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.v2_0.functions; - -import static org.jclouds.http.Uris.uriBuilder; - -import java.net.URI; - -import javax.inject.Singleton; - -import org.jclouds.openstack.v2_0.domain.Extension; - -import com.google.common.base.Function; - -@Singleton -public class ExtensionToNameSpace implements Function { - - @Override - public URI apply(Extension input) { - return uriBuilder(input.getNamespace()).scheme("http").build(); - } - - public String toString() { - return "changeSchemeToHttp()"; - } - -} diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/predicates/ExtensionPredicates.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/predicates/ExtensionPredicates.java index fdcb37c577..2c4206ac2e 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/predicates/ExtensionPredicates.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/predicates/ExtensionPredicates.java @@ -44,7 +44,8 @@ public class ExtensionPredicates { return new Predicate() { @Override public boolean apply(Extension ext) { - return namespace.toASCIIString().equals(ext.getNamespace().toASCIIString().replace("https", "http")); + return ext.getNamespace() == null ? false : namespace.toASCIIString().equals( + ext.getNamespace().toASCIIString().replace("https", "http")); } @Override @@ -92,8 +93,8 @@ public class ExtensionPredicates { return new Predicate() { @Override public boolean apply(Extension ext) { - return namespace.toASCIIString().equals(ext.getNamespace().toASCIIString().replace("https", "http")) || - namespaceAliases.contains(ext.getNamespace()); + return ext.getNamespace() == null ? false : (namespaceEquals(namespace).apply(ext) || namespaceAliases.contains(ext + .getNamespace())); } @Override diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/functions/ExtensionToNameSpaceTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/functions/ExtensionToNameSpaceTest.java deleted file mode 100644 index 9ce76ef5bb..0000000000 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/functions/ExtensionToNameSpaceTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.v2_0.functions; - -import static org.testng.Assert.assertEquals; - -import java.net.URI; - -import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.jclouds.openstack.v2_0.domain.Extension; -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "ExtensionToNameSpaceTest") -public class ExtensionToNameSpaceTest { - private final ExtensionToNameSpace fn = new ExtensionToNameSpace(); - - public void testReturnsNamespace() { - URI ns = URI.create("http://docs.openstack.org/ext/keypairs/api/v1.1"); - assertEquals(fn.apply(Extension.builder().alias("os-keypairs").name("Keypairs").namespace(ns).updated( - new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-08-08T00:00:00+00:00")).description( - "Keypair Support").build()), ns); - } - - public void testChangesHttpsToHttp() { - assertEquals(fn.apply(Extension.builder().alias("security_groups").name("SecurityGroups").namespace( - URI.create("https://docs.openstack.org/ext/securitygroups/api/v1.1")).updated( - new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-07-21T00:00:00+00:00")).description( - "Security group support").build()), URI.create("http://docs.openstack.org/ext/securitygroups/api/v1.1")); - } -} diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/functions/PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSetTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/functions/PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSetTest.java index 7836140d9f..872315740e 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/functions/PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSetTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/functions/PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSetTest.java @@ -130,20 +130,41 @@ public class PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensio * "fake" /fake namespace), allow matching by name and alias. * */ - public void testPresentWhenNameSpaceIsMissingAndMatchByNameOrAlias() throws SecurityException, NoSuchMethodException { + public void testPresentWhenNameSpaceIsFakeAndMatchByNameOrAlias() throws SecurityException, NoSuchMethodException { // Revert to alias - Extension floatingIpsWithMissingNamespace = floatingIps.toBuilder() + Extension floatingIpsWithFakeNamespace = floatingIps.toBuilder() .namespace(URI.create("http://docs.openstack.org/ext/fake")) .build(); // Revert to name - Extension floatingIpsWithMissingNamespaceAndAlias = floatingIps.toBuilder() + Extension floatingIpsWithFakeNamespaceAndAlias = floatingIps.toBuilder() .namespace(URI.create("http://docs.openstack.org/ext/fake")) .alias("fake") .build(); Multimap aliases = ImmutableMultimap.of(); + assertEquals(whenExtensionsAndAliasesInRegionInclude("region", ImmutableSet.of(floatingIpsWithFakeNamespace), aliases).apply( + getFloatingIPExtension(ImmutableList. of("region"))), Optional.of("foo")); + + assertEquals(whenExtensionsAndAliasesInRegionInclude("region", ImmutableSet.of(floatingIpsWithFakeNamespaceAndAlias), aliases).apply( + getFloatingIPExtension(ImmutableList. of("region"))), Optional.of("foo")); + } + + public void testPresentWhenNameSpaceIsMissingAndMatchByNameOrAlias() throws SecurityException, NoSuchMethodException { + // Revert to alias + Extension floatingIpsWithMissingNamespace = floatingIps.toBuilder() + .namespace(null) + .build(); + + // Revert to name + Extension floatingIpsWithMissingNamespaceAndAlias = floatingIps.toBuilder() + .namespace(null) + .alias("fake") + .build(); + + Multimap aliases = ImmutableMultimap.of(); + assertEquals(whenExtensionsAndAliasesInRegionInclude("region", ImmutableSet.of(floatingIpsWithMissingNamespace), aliases).apply( getFloatingIPExtension(ImmutableList. of("region"))), Optional.of("foo")); diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/predicates/ExtensionPredicatesTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/predicates/ExtensionPredicatesTest.java index f4e15ecc9b..671cb20382 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/predicates/ExtensionPredicatesTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/predicates/ExtensionPredicatesTest.java @@ -46,6 +46,12 @@ public class ExtensionPredicatesTest { public void testNamespaceEqualsWhenEqual() { assert namespaceEquals(URI.create("http://docs.openstack.org/ext/keypairs/api/v1.1")).apply(ref); } + + @Test + public void testNamespaceEqualsWhenNullNamespace() { + Extension withoutNamespace = ref.toBuilder().namespace(null).build(); + assert !namespaceEquals(URI.create("http://docs.openstack.org/ext/keypairs/api/v1.1")).apply(withoutNamespace); + } @Test public void testNamespaceEqualsWhenEqualEvenOnInputHttps() { diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ExtensionApiLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ExtensionApiLiveTest.java index 2db531f2db..393e01d281 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ExtensionApiLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ExtensionApiLiveTest.java @@ -49,9 +49,8 @@ public class ExtensionApiLiveTest extends BaseNovaApiLiveTest { assertNotNull(extension.getId()); assertNotNull(extension.getName()); assertNotNull(extension.getDescription()); - assertNotNull(extension.getNamespace()); - assertNotNull(extension.getUpdated()); assertNotNull(extension.getLinks()); + // Namespace and updated fields are nullable } } }