/apis/cloudservers/src/test/java/org/jclouds/cloudservers/functions/ParseInetAddressListFromJsonResponseTest.java

https://github.com/regularfry/jclouds · Java · 70 lines · 35 code · 12 blank · 23 comment · 0 complexity · 91a8e5984d69f31613289dd4e8dcc725 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.cloudservers.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.io.Payloads;
  27. import org.jclouds.json.config.GsonModule;
  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. public void testPublic() throws UnknownHostException {
  43. InputStream is = getClass().getResourceAsStream("/test_list_addresses_public.json");
  44. UnwrapOnlyJsonValue<List<String>> parser = i.getInstance(Key
  45. .get(new TypeLiteral<UnwrapOnlyJsonValue<List<String>>>() {
  46. }));
  47. List<String> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
  48. assertEquals(response, ImmutableList.of("67.23.10.132", "67.23.10.131"));
  49. }
  50. public void testPrivate() throws UnknownHostException {
  51. InputStream is = getClass().getResourceAsStream("/test_list_addresses_private.json");
  52. UnwrapOnlyJsonValue<List<String>> parser = i.getInstance(Key
  53. .get(new TypeLiteral<UnwrapOnlyJsonValue<List<String>>>() {
  54. }));
  55. List<String> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
  56. assertEquals(response, ImmutableList.of("10.176.42.16"));
  57. }
  58. }