PageRenderTime 51ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java

https://github.com/regularfry/jclouds
Java | 66 lines | 35 code | 8 blank | 23 comment | 0 complexity | 9423c1e6ca262eb0bd2750aefcc0155b 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.cloudfiles.functions;
  20. import static org.testng.Assert.assertEquals;
  21. import java.io.InputStream;
  22. import java.net.URI;
  23. import java.util.Set;
  24. import java.util.SortedSet;
  25. import org.jclouds.cloudfiles.domain.ContainerCDNMetadata;
  26. import org.jclouds.http.HttpResponse;
  27. import org.jclouds.http.functions.ParseJson;
  28. import org.jclouds.io.Payloads;
  29. import org.jclouds.json.config.GsonModule;
  30. import org.testng.annotations.Test;
  31. import com.google.common.collect.ImmutableSortedSet;
  32. import com.google.inject.Guice;
  33. import com.google.inject.Injector;
  34. import com.google.inject.Key;
  35. import com.google.inject.TypeLiteral;
  36. /**
  37. * Tests behavior of {@code ParseContainerCDNMetadataListFromJsonResponse}
  38. *
  39. * @author Adrian Cole
  40. */
  41. @Test(groups = "unit")
  42. public class ParseContainerCDNMetadataListFromJsonResponseTest {
  43. Injector i = Guice.createInjector(new GsonModule());
  44. @Test
  45. public void testApplyInputStream() {
  46. InputStream is = getClass().getResourceAsStream("/test_list_cdn.json");
  47. Set<ContainerCDNMetadata> expects = ImmutableSortedSet.of(
  48. new ContainerCDNMetadata("adriancole-blobstore.testCDNOperationsContainerWithCDN", false, 3600, URI
  49. .create("http://c0354712.cdn.cloudfiles.rackspacecloud.com")), new ContainerCDNMetadata(
  50. "adriancole-blobstore5", true, 28800, URI.create("http://c0404671.cdn.cloudfiles.rackspacecloud.com")),
  51. new ContainerCDNMetadata("adriancole-cfcdnint.testCDNOperationsContainerWithCDN", false, 3600, URI
  52. .create("http://c0320431.cdn.cloudfiles.rackspacecloud.com")));
  53. ParseJson<SortedSet<ContainerCDNMetadata>> parser = i.getInstance(Key
  54. .get(new TypeLiteral<ParseJson<SortedSet<ContainerCDNMetadata>>>() {
  55. }));
  56. assertEquals(parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is))), expects);
  57. }
  58. }