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

https://github.com/danikov/jclouds · Java · 71 lines · 36 code · 12 blank · 23 comment · 0 complexity · 15496ebb72288a9481954d4fdfe0d566 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 javax.ws.rs.core.UriBuilder;
  23. import org.jclouds.Constants;
  24. import org.jclouds.blobstore.reference.BlobStoreConstants;
  25. import org.jclouds.http.HttpResponse;
  26. import org.jclouds.openstack.domain.AuthenticationResponse;
  27. import org.testng.annotations.Test;
  28. import com.google.common.collect.ImmutableMap;
  29. import com.google.common.collect.ImmutableMultimap;
  30. import com.google.inject.AbstractModule;
  31. import com.google.inject.Guice;
  32. import com.google.inject.Injector;
  33. import com.google.inject.name.Names;
  34. import com.sun.jersey.api.uri.UriBuilderImpl;
  35. /**
  36. * Tests behavior of {@code ParseContainerListFromJsonResponse}
  37. *
  38. * @author Adrian Cole
  39. */
  40. @Test(groups = "unit")
  41. public class ParseAuthenticationResponseFromHeadersTest {
  42. Injector i = Guice.createInjector(new AbstractModule() {
  43. @Override
  44. protected void configure() {
  45. bindConstant().annotatedWith(Names.named(BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX)).to("sdf");
  46. bindConstant().annotatedWith(Names.named(Constants.PROPERTY_API_VERSION)).to("1");
  47. bind(UriBuilder.class).to(UriBuilderImpl.class);
  48. }
  49. });
  50. public void testReplaceLocalhost() {
  51. ParseAuthenticationResponseFromHeaders parser = i.getInstance(ParseAuthenticationResponseFromHeaders.class);
  52. parser = parser.setHostToReplace("fooman");
  53. HttpResponse response = new HttpResponse(204, "No Content", null, ImmutableMultimap.<String, String> of(
  54. "X-Auth-Token", "token", "X-Storage-Token", "token", "X-Storage-Url", "http://127.0.0.1:8080/v1/token"));
  55. AuthenticationResponse md = parser.apply(response);
  56. assertEquals(md, new AuthenticationResponse("token", ImmutableMap.<String, URI> of("X-Storage-Url", URI
  57. .create("http://fooman:8080/v1/token"))));
  58. }
  59. }