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

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