/providers/cloudsigma-zrh/src/test/java/org/jclouds/cloudsigma/functions/ParseOsFamilyVersion64BitFromImageNameTest.java

https://github.com/regularfry/jclouds · Java · 80 lines · 47 code · 11 blank · 22 comment · 0 complexity · eda00f00b467ee9ec531c8454a7c5a3c 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.cloudsigma.functions;
  20. import static com.google.common.collect.Iterables.transform;
  21. import static com.google.common.collect.Lists.newArrayList;
  22. import static org.testng.Assert.assertEquals;
  23. import java.io.IOException;
  24. import java.io.InputStream;
  25. import java.util.Map;
  26. import java.util.Map.Entry;
  27. import org.jclouds.cloudsigma.compute.functions.ParseOsFamilyVersion64BitFromImageName;
  28. import org.jclouds.compute.config.BaseComputeServiceContextModule;
  29. import org.jclouds.compute.domain.OsFamilyVersion64Bit;
  30. import org.jclouds.compute.reference.ComputeServiceConstants;
  31. import org.jclouds.json.Json;
  32. import org.jclouds.json.config.GsonModule;
  33. import org.jclouds.json.internal.GsonWrapper;
  34. import org.jclouds.util.Strings2;
  35. import org.testng.annotations.DataProvider;
  36. import org.testng.annotations.Test;
  37. import com.google.common.base.Function;
  38. import com.google.gson.Gson;
  39. import com.google.inject.Guice;
  40. import com.google.inject.TypeLiteral;
  41. /**
  42. *
  43. * @author Adrian Cole
  44. */
  45. @Test(groups = "unit")
  46. public class ParseOsFamilyVersion64BitFromImageNameTest {
  47. Json json = new GsonWrapper(new Gson());
  48. @DataProvider(name = "data")
  49. public Object[][] createData() throws IOException {
  50. InputStream is = ParseOsFamilyVersion64BitFromImageNameTest.class.getResourceAsStream("/osmatches.json");
  51. Map<String, OsFamilyVersion64Bit> values = json.fromJson(Strings2.toStringAndClose(is),
  52. new TypeLiteral<Map<String, OsFamilyVersion64Bit>>() {
  53. }.getType());
  54. return newArrayList(
  55. transform(values.entrySet(), new Function<Map.Entry<String, OsFamilyVersion64Bit>, Object[]>() {
  56. @Override
  57. public Object[] apply(Entry<String, OsFamilyVersion64Bit> input) {
  58. return new Object[] { input.getKey(), input.getValue() };
  59. }
  60. })).toArray(new Object[][] {});
  61. }
  62. ParseOsFamilyVersion64BitFromImageName parser = new ParseOsFamilyVersion64BitFromImageName(new BaseComputeServiceContextModule() {
  63. }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
  64. .getInstance(Json.class)));
  65. @Test(dataProvider = "data")
  66. public void test(String input, OsFamilyVersion64Bit expected) {
  67. assertEquals(parser.apply(input), expected);
  68. }
  69. }