JCLOUDS-1104: Extension namespaces are deprecated and can be null

This commit is contained in:
Ignasi Barrera 2016-04-21 18:48:38 +02:00
parent 6446627aad
commit 04f1bb2b49
7 changed files with 39 additions and 95 deletions

View File

@ -122,14 +122,16 @@ public class Extension extends Resource {
@ConstructorProperties({
"name", "links", "namespace", "alias", "updated", "description"
})
protected Extension(@Nullable String name, Set<Link> links, URI namespace, String alias, @Nullable Date updated, String description) {
protected Extension(@Nullable String name, Set<Link> 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;
}

View File

@ -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<Extension, URI> {
@Override
public URI apply(Extension input) {
return uriBuilder(input.getNamespace()).scheme("http").build();
}
public String toString() {
return "changeSchemeToHttp()";
}
}

View File

@ -44,7 +44,8 @@ public class ExtensionPredicates {
return new Predicate<Extension>() {
@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<Extension>() {
@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

View File

@ -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"));
}
}

View File

@ -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<URI, URI> aliases = ImmutableMultimap.of();
assertEquals(whenExtensionsAndAliasesInRegionInclude("region", ImmutableSet.of(floatingIpsWithFakeNamespace), aliases).apply(
getFloatingIPExtension(ImmutableList.<Object> of("region"))), Optional.of("foo"));
assertEquals(whenExtensionsAndAliasesInRegionInclude("region", ImmutableSet.of(floatingIpsWithFakeNamespaceAndAlias), aliases).apply(
getFloatingIPExtension(ImmutableList.<Object> 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<URI, URI> aliases = ImmutableMultimap.of();
assertEquals(whenExtensionsAndAliasesInRegionInclude("region", ImmutableSet.of(floatingIpsWithMissingNamespace), aliases).apply(
getFloatingIPExtension(ImmutableList.<Object> of("region"))), Optional.of("foo"));

View File

@ -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() {

View File

@ -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
}
}
}