PageRenderTime 40ms CodeModel.GetById 37ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

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

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