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