Updated Branches: refs/heads/fix-jclouds-155 ea2feb67c -> d38d1681e
Moving unit ParseAuthenticationResponseFromHeaders unit test into the same artifact as the code Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/commit/d38d1681 Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/tree/d38d1681 Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/diff/d38d1681 Branch: refs/heads/fix-jclouds-155 Commit: d38d1681e31f568dc3792cba0da070a3b2eeaf07 Parents: ea2feb6 Author: Andrew Phillips <[email protected]> Authored: Wed Jul 31 00:26:20 2013 -0400 Committer: Andrew Phillips <[email protected]> Committed: Wed Jul 31 00:26:20 2013 -0400 ---------------------------------------------------------------------- ...seAuthenticationResponseFromHeadersTest.java | 79 -------------------- .../ParseAuthenticationResponseFromHeaders.java | 3 +- ...seAuthenticationResponseFromHeadersTest.java | 77 +++++++++++++++++++ 3 files changed, 78 insertions(+), 81 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/d38d1681/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java b/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java deleted file mode 100644 index 91987a9..0000000 --- a/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java +++ /dev/null @@ -1,79 +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.functions; - -import static org.testng.Assert.assertEquals; - -import java.net.URI; - -import org.jclouds.Constants; -import org.jclouds.blobstore.reference.BlobStoreConstants; -import org.jclouds.http.HttpResponse; -import org.jclouds.openstack.domain.AuthenticationResponse; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.name.Names; - -/** - * Tests behavior of {@code ParseContainerListFromJsonResponse} - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "ParseAuthenticationResponseFromHeadersTest") -public class ParseAuthenticationResponseFromHeadersTest { - - Injector i = Guice.createInjector(new AbstractModule() { - - @Override - protected void configure() { - bindConstant().annotatedWith(Names.named(BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX)).to("sdf"); - bindConstant().annotatedWith(Names.named(Constants.PROPERTY_API_VERSION)).to("1"); - } - - }); - - public void testReplaceLocalhost() { - ParseAuthenticationResponseFromHeaders parser = i.getInstance(ParseAuthenticationResponseFromHeaders.class); - parser = parser.setHostToReplace("fooman"); - - HttpResponse response = HttpResponse.builder().statusCode(204).message("No Content") - .addHeader("X-Auth-Token", "token") - .addHeader("X-Storage-Token", "token") - .addHeader("X-Storage-Url", "http://127.0.0.1:8080/v1/token").build(); - - AuthenticationResponse md = parser.apply(response); - assertEquals(md, new AuthenticationResponse("token", ImmutableMap.<String, URI> of("X-Storage-Url", URI - .create("http://fooman:8080/v1/token")))); - } - - public void testHandleHeadersCaseInsensitively() { - ParseAuthenticationResponseFromHeaders parser = i.getInstance(ParseAuthenticationResponseFromHeaders.class); - parser = parser.setHostToReplace("fooman"); - - HttpResponse response = HttpResponse.builder().statusCode(204).message("No Content") - .addHeader("x-auth-token", "token") - .addHeader("x-storage-token", "token") - .addHeader("x-storage-url", "http://127.0.0.1:8080/v1/token").build(); - AuthenticationResponse md = parser.apply(response); - assertEquals(md, new AuthenticationResponse("token", ImmutableMap.<String, URI> of("x-storage-url".toLowerCase(), URI - .create("http://fooman:8080/v1/token")))); - } -} http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/d38d1681/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java ---------------------------------------------------------------------- diff --git a/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java b/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java index ed033f0..c824d9c 100644 --- a/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java +++ b/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java @@ -54,11 +54,10 @@ public class ParseAuthenticationResponseFromHeaders implements Function<HttpResp /** * parses the http response headers to create a new {@link AuthenticationResponse} object. */ - @SuppressWarnings("unchecked") public AuthenticationResponse apply(HttpResponse from) { releasePayload(from); - // HTTP headers are case in-sensitive (RFC 2616) so we must allow for that when looking an header names for the URL keyword + // HTTP headers are case insensitive (RFC 2616) so we must allow for that when looking an header names for the URL keyword Builder<String, URI> builder = ImmutableMap.builder(); for (Entry<String, String> entry : from.getHeaders().entries()) { if (entry.getKey().toLowerCase().endsWith(URL_SUFFIX.toLowerCase())) http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/d38d1681/common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java ---------------------------------------------------------------------- diff --git a/common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java b/common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java new file mode 100644 index 0000000..ee2b79a --- /dev/null +++ b/common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java @@ -0,0 +1,77 @@ +/* + * 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.functions; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.jclouds.Constants; +import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.domain.AuthenticationResponse; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.name.Names; + +/** + * Tests behavior of {@code ParseAuthenticationResponseFromHeaders} + * + * @author Adrian Cole + */ +@Test(enabled=true,groups = "unit", testName = "ParseAuthenticationResponseFromHeadersTest") +public class ParseAuthenticationResponseFromHeadersTest { + + Injector i = Guice.createInjector(new AbstractModule() { + + @Override + protected void configure() { + bindConstant().annotatedWith(Names.named(Constants.PROPERTY_API_VERSION)).to("1"); + } + + }); + + public void testReplaceLocalhost() { + ParseAuthenticationResponseFromHeaders parser = i.getInstance(ParseAuthenticationResponseFromHeaders.class); + parser = parser.setHostToReplace("fooman"); + + HttpResponse response = HttpResponse.builder().statusCode(204).message("No Content") + .addHeader("X-Auth-Token", "token") + .addHeader("X-Storage-Token", "token") + .addHeader("X-Storage-Url", "http://127.0.0.1:8080/v1/token").build(); + + AuthenticationResponse md = parser.apply(response); + assertEquals(md, new AuthenticationResponse("token", ImmutableMap.<String, URI> of("X-Storage-Url", + URI.create("http://fooman:8080/v1/token")))); + } + + public void testHandleHeadersCaseInsensitively() { + ParseAuthenticationResponseFromHeaders parser = i.getInstance(ParseAuthenticationResponseFromHeaders.class); + parser = parser.setHostToReplace("fooman"); + + HttpResponse response = HttpResponse.builder().statusCode(204).message("No Content") + .addHeader("x-auth-token", "token") + .addHeader("x-storage-token", "token") + .addHeader("x-storage-url", "http://127.0.0.1:8080/v1/token").build(); + AuthenticationResponse md = parser.apply(response); + assertEquals(md, new AuthenticationResponse("token", ImmutableMap.<String, URI> of("x-storage-url", + URI.create("http://fooman:8080/v1/token")))); + } +}
