PageRenderTime 33ms CodeModel.GetById 28ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 0ms

/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java

https://github.com/edwardt/jclouds
Java | 80 lines | 48 code | 10 blank | 22 comment | 0 complexity | 286b4d95f64a5c386d602c31c5dca988 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.elasticstack.functions;
20
21import static org.testng.Assert.assertEquals;
22
23import java.util.List;
24import java.util.Map;
25
26import org.jclouds.elasticstack.domain.Device;
27import org.jclouds.elasticstack.domain.DriveMetrics;
28import org.jclouds.elasticstack.domain.NIC;
29import org.jclouds.elasticstack.domain.ServerInfo;
30import org.jclouds.elasticstack.domain.ServerMetrics;
31import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId;
32import org.jclouds.http.HttpResponse;
33import org.jclouds.io.Payloads;
34import org.testng.annotations.Test;
35
36import com.google.common.base.Function;
37import com.google.common.collect.ImmutableSet;
38import com.google.inject.AbstractModule;
39import com.google.inject.Guice;
40import com.google.inject.TypeLiteral;
41
42/**
43 * 
44 * @author Adrian Cole
45 */
46@Test(groups = { "unit" })
47public class ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest {
48
49   private static final ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet FN = Guice.createInjector(
50         new AbstractModule() {
51
52            @Override
53            protected void configure() {
54               bind(new TypeLiteral<Function<Map<String, String>, List<NIC>>>() {
55               }).to(MapToNICs.class);
56               bind(new TypeLiteral<Function<Map<String, String>, Map<String, ? extends Device>>>() {
57               }).to(MapToDevices.class);
58               bind(new TypeLiteral<Function<Map<String, String>, Map<String, ? extends DriveMetrics>>>() {
59               }).to(MapToDriveMetrics.class);
60               bind(new TypeLiteral<Function<Map<String, String>, ServerMetrics>>() {
61               }).to(MapToServerMetrics.class);
62               bind(new TypeLiteral<Function<Device, String>>() {
63               }).to(DeviceToId.class);
64            }
65
66         }).getInstance(ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.class);
67
68   public void testNone() {
69      assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newStringPayload(""))), ImmutableSet.<ServerInfo> of());
70      assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newStringPayload("\n\n"))),
71            ImmutableSet.<ServerInfo> of());
72      assertEquals(FN.apply(new HttpResponse(200, "", null)), ImmutableSet.<ServerInfo> of());
73   }
74
75   public void testOne() {
76      assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToServerInfoTest.class
77            .getResourceAsStream("/servers.txt")))), ImmutableSet.<ServerInfo> of(MapToServerInfoTest.ONE,
78            MapToServerInfoTest.TWO));
79   }
80}