/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java

https://github.com/richardcloudsoft/legacy-jclouds · Java · 68 lines · 34 code · 11 blank · 23 comment · 0 complexity · d5937816b7c29aee9dc1eda244efd58e MD5 · raw file

  1. /**
  2. * Licensed to jclouds, Inc. (jclouds) under one or more
  3. * contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. jclouds licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package org.jclouds.openstack.functions;
  20. import static org.testng.Assert.assertEquals;
  21. import java.net.URI;
  22. import org.jclouds.Constants;
  23. import org.jclouds.blobstore.reference.BlobStoreConstants;
  24. import org.jclouds.http.HttpResponse;
  25. import org.jclouds.openstack.domain.AuthenticationResponse;
  26. import org.testng.annotations.Test;
  27. import com.google.common.collect.ImmutableMap;
  28. import com.google.inject.AbstractModule;
  29. import com.google.inject.Guice;
  30. import com.google.inject.Injector;
  31. import com.google.inject.name.Names;
  32. /**
  33. * Tests behavior of {@code ParseContainerListFromJsonResponse}
  34. *
  35. * @author Adrian Cole
  36. */
  37. @Test(groups = "unit", testName = "ParseAuthenticationResponseFromHeadersTest")
  38. public class ParseAuthenticationResponseFromHeadersTest {
  39. Injector i = Guice.createInjector(new AbstractModule() {
  40. @Override
  41. protected void configure() {
  42. bindConstant().annotatedWith(Names.named(BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX)).to("sdf");
  43. bindConstant().annotatedWith(Names.named(Constants.PROPERTY_API_VERSION)).to("1");
  44. }
  45. });
  46. public void testReplaceLocalhost() {
  47. ParseAuthenticationResponseFromHeaders parser = i.getInstance(ParseAuthenticationResponseFromHeaders.class);
  48. parser = parser.setHostToReplace("fooman");
  49. HttpResponse response = HttpResponse.builder().statusCode(204).message("No Content")
  50. .addHeader("X-Auth-Token", "token")
  51. .addHeader("X-Storage-Token", "token")
  52. .addHeader("X-Storage-Url", "http://127.0.0.1:8080/v1/token").build();
  53. AuthenticationResponse md = parser.apply(response);
  54. assertEquals(md, new AuthenticationResponse("token", ImmutableMap.<String, URI> of("X-Storage-Url", URI
  55. .create("http://fooman:8080/v1/token"))));
  56. }
  57. }