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

https://github.com/regularfry/jclouds · Java · 78 lines · 42 code · 13 blank · 23 comment · 0 complexity · 14f28cc2efcd1f43fa768f0731932485 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.inject.Guice;
  22. import com.google.inject.Injector;
  23. import com.google.inject.Key;
  24. import com.google.inject.TypeLiteral;
  25. import org.jclouds.http.HttpResponse;
  26. import org.jclouds.http.functions.UnwrapOnlyJsonValue;
  27. import org.jclouds.io.Payloads;
  28. import org.jclouds.json.config.GsonModule;
  29. import org.jclouds.openstack.nova.domain.Address;
  30. import org.testng.annotations.Test;
  31. import java.io.InputStream;
  32. import java.net.UnknownHostException;
  33. import java.util.List;
  34. import static org.testng.Assert.assertEquals;
  35. /**
  36. * Tests behavior of {@code ParseInetAddressListFromJsonResponse}
  37. *
  38. * @author Adrian Cole
  39. */
  40. @Test(groups = "unit")
  41. public class ParseInetAddressListFromJsonResponseTest {
  42. Injector i = Guice.createInjector(new GsonModule());
  43. @Test
  44. public void testPublic() throws UnknownHostException {
  45. InputStream is = getClass().getResourceAsStream("/test_list_addresses_public.json");
  46. UnwrapOnlyJsonValue<List<Address>> parser = i.getInstance(Key
  47. .get(new TypeLiteral<UnwrapOnlyJsonValue<List<Address>>>() {
  48. }));
  49. List<Address> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
  50. assertEquals(response, ImmutableList.of(Address.valueOf("67.23.10.132"),
  51. Address.valueOf("::babe:67.23.10.132"),
  52. Address.valueOf("67.23.10.131"), Address.valueOf("::babe:4317:0A83")));
  53. }
  54. @Test
  55. public void testPrivate() throws UnknownHostException {
  56. InputStream is = getClass().getResourceAsStream("/test_list_addresses_private.json");
  57. UnwrapOnlyJsonValue<List<Address>> parser = i.getInstance(Key
  58. .get(new TypeLiteral<UnwrapOnlyJsonValue<List<Address>>>() {
  59. }));
  60. List<Address> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
  61. assertEquals(response, ImmutableList.of(Address.valueOf("67.23.10.132"),
  62. Address.valueOf("::babe:67.23.10.132"),
  63. Address.valueOf("67.23.10.131"), Address.valueOf("::babe:4317:0A83")));
  64. }
  65. }