/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseAddressesFromJsonResponseTest.java

https://github.com/regularfry/jclouds · Java · 70 lines · 38 code · 9 blank · 23 comment · 0 complexity · e793db4e3af2b2bde3de5080d1f0b580 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.nova.functions;
  20. import com.google.common.collect.ImmutableList;
  21. import com.google.common.collect.Iterables;
  22. import com.google.common.collect.Sets;
  23. import com.google.inject.Guice;
  24. import com.google.inject.Injector;
  25. import com.google.inject.Key;
  26. import com.google.inject.TypeLiteral;
  27. import org.jclouds.http.HttpResponse;
  28. import org.jclouds.http.functions.UnwrapOnlyJsonValue;
  29. import org.jclouds.io.Payloads;
  30. import org.jclouds.json.config.GsonModule;
  31. import org.jclouds.openstack.nova.domain.Address;
  32. import org.jclouds.openstack.nova.domain.Addresses;
  33. import org.testng.annotations.Test;
  34. import java.io.InputStream;
  35. import java.net.UnknownHostException;
  36. import java.util.List;
  37. import static org.testng.Assert.assertTrue;
  38. /**
  39. * Tests behavior of {@code ParseAddressesFromJsonResponse}
  40. *
  41. * @author Adrian Cole
  42. */
  43. @Test(groups = "unit")
  44. public class ParseAddressesFromJsonResponseTest {
  45. Injector i = Guice.createInjector(new GsonModule());
  46. @Test
  47. public void testApplyInputStreamDetails() throws UnknownHostException {
  48. InputStream is = getClass().getResourceAsStream("/test_list_addresses.json");
  49. UnwrapOnlyJsonValue<Addresses> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Addresses>>() {
  50. }));
  51. Addresses response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
  52. List<Address> publicAddresses = ImmutableList.copyOf(
  53. Iterables.transform(ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
  54. Address.newString2AddressFunction()));
  55. List<Address> privateAddresses = ImmutableList.copyOf(
  56. Iterables.transform(ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"),
  57. Address.newString2AddressFunction()));
  58. assertTrue(response.getPublicAddresses().equals(Sets.newHashSet(publicAddresses)));
  59. assertTrue(response.getPrivateAddresses().equals(Sets.newHashSet(privateAddresses)));
  60. }
  61. }