mirror of
https://github.com/apache/jclouds.git
synced 2025-02-27 21:09:07 +00:00
JCLOUDS-1104: Extension namespaces are deprecated and can be null
This commit is contained in:
parent
6446627aad
commit
04f1bb2b49
@ -122,14 +122,16 @@ public class Extension extends Resource {
|
|||||||
@ConstructorProperties({
|
@ConstructorProperties({
|
||||||
"name", "links", "namespace", "alias", "updated", "description"
|
"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);
|
super(alias, name, links);
|
||||||
this.namespace = checkNotNull(namespace, "namespace");
|
this.namespace = namespace;
|
||||||
this.alias = checkNotNull(alias, "alias");
|
this.alias = checkNotNull(alias, "alias");
|
||||||
this.updated = updated;
|
this.updated = updated;
|
||||||
this.description = checkNotNull(description, "description");
|
this.description = checkNotNull(description, "description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public URI getNamespace() {
|
public URI getNamespace() {
|
||||||
return this.namespace;
|
return this.namespace;
|
||||||
}
|
}
|
||||||
|
@ -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()";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -44,7 +44,8 @@ public class ExtensionPredicates {
|
|||||||
return new Predicate<Extension>() {
|
return new Predicate<Extension>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Extension ext) {
|
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
|
@Override
|
||||||
@ -92,8 +93,8 @@ public class ExtensionPredicates {
|
|||||||
return new Predicate<Extension>() {
|
return new Predicate<Extension>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Extension ext) {
|
public boolean apply(Extension ext) {
|
||||||
return namespace.toASCIIString().equals(ext.getNamespace().toASCIIString().replace("https", "http")) ||
|
return ext.getNamespace() == null ? false : (namespaceEquals(namespace).apply(ext) || namespaceAliases.contains(ext
|
||||||
namespaceAliases.contains(ext.getNamespace());
|
.getNamespace()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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"));
|
|
||||||
}
|
|
||||||
}
|
|
@ -130,20 +130,41 @@ public class PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensio
|
|||||||
* "fake" /fake namespace), allow matching by name and alias.
|
* "fake" /fake namespace), allow matching by name and alias.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void testPresentWhenNameSpaceIsMissingAndMatchByNameOrAlias() throws SecurityException, NoSuchMethodException {
|
public void testPresentWhenNameSpaceIsFakeAndMatchByNameOrAlias() throws SecurityException, NoSuchMethodException {
|
||||||
// Revert to alias
|
// Revert to alias
|
||||||
Extension floatingIpsWithMissingNamespace = floatingIps.toBuilder()
|
Extension floatingIpsWithFakeNamespace = floatingIps.toBuilder()
|
||||||
.namespace(URI.create("http://docs.openstack.org/ext/fake"))
|
.namespace(URI.create("http://docs.openstack.org/ext/fake"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Revert to name
|
// Revert to name
|
||||||
Extension floatingIpsWithMissingNamespaceAndAlias = floatingIps.toBuilder()
|
Extension floatingIpsWithFakeNamespaceAndAlias = floatingIps.toBuilder()
|
||||||
.namespace(URI.create("http://docs.openstack.org/ext/fake"))
|
.namespace(URI.create("http://docs.openstack.org/ext/fake"))
|
||||||
.alias("fake")
|
.alias("fake")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Multimap<URI, URI> aliases = ImmutableMultimap.of();
|
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(
|
assertEquals(whenExtensionsAndAliasesInRegionInclude("region", ImmutableSet.of(floatingIpsWithMissingNamespace), aliases).apply(
|
||||||
getFloatingIPExtension(ImmutableList.<Object> of("region"))), Optional.of("foo"));
|
getFloatingIPExtension(ImmutableList.<Object> of("region"))), Optional.of("foo"));
|
||||||
|
|
||||||
|
@ -46,6 +46,12 @@ public class ExtensionPredicatesTest {
|
|||||||
public void testNamespaceEqualsWhenEqual() {
|
public void testNamespaceEqualsWhenEqual() {
|
||||||
assert namespaceEquals(URI.create("http://docs.openstack.org/ext/keypairs/api/v1.1")).apply(ref);
|
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
|
@Test
|
||||||
public void testNamespaceEqualsWhenEqualEvenOnInputHttps() {
|
public void testNamespaceEqualsWhenEqualEvenOnInputHttps() {
|
||||||
|
@ -49,9 +49,8 @@ public class ExtensionApiLiveTest extends BaseNovaApiLiveTest {
|
|||||||
assertNotNull(extension.getId());
|
assertNotNull(extension.getId());
|
||||||
assertNotNull(extension.getName());
|
assertNotNull(extension.getName());
|
||||||
assertNotNull(extension.getDescription());
|
assertNotNull(extension.getDescription());
|
||||||
assertNotNull(extension.getNamespace());
|
|
||||||
assertNotNull(extension.getUpdated());
|
|
||||||
assertNotNull(extension.getLinks());
|
assertNotNull(extension.getLinks());
|
||||||
|
// Namespace and updated fields are nullable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user