PageRenderTime 957ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/providers/glesys/src/test/java/org/jclouds/glesys/compute/functions/ParseOsFamilyVersion64BitFromImageNameTest.java

http://github.com/jclouds/jclouds
Java | 74 lines | 46 code | 11 blank | 17 comment | 0 complexity | a175b6ce2d10b8260cc9721057d90d16 MD5 | raw file
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.jclouds.glesys.compute.functions;
  18. import static com.google.common.collect.Iterables.transform;
  19. import static com.google.common.collect.Lists.newArrayList;
  20. import static org.testng.Assert.assertEquals;
  21. import java.io.IOException;
  22. import java.io.InputStream;
  23. import java.util.Map;
  24. import java.util.Map.Entry;
  25. import org.jclouds.compute.config.BaseComputeServiceContextModule;
  26. import org.jclouds.compute.domain.OsFamilyVersion64Bit;
  27. import org.jclouds.compute.reference.ComputeServiceConstants;
  28. import org.jclouds.json.Json;
  29. import org.jclouds.json.config.GsonModule;
  30. import org.jclouds.json.internal.GsonWrapper;
  31. import org.jclouds.util.Strings2;
  32. import org.testng.annotations.DataProvider;
  33. import org.testng.annotations.Test;
  34. import com.google.common.base.Function;
  35. import com.google.gson.Gson;
  36. import com.google.inject.Guice;
  37. import com.google.inject.TypeLiteral;
  38. @Test(groups = "unit", testName = "ParseOsFamilyVersion64BitFromImageNameTest")
  39. public class ParseOsFamilyVersion64BitFromImageNameTest {
  40. Json json = new GsonWrapper(new Gson());
  41. //TODO: update osmatches corresponding with server_templates.json, this may imply an update to ComputeServiceConstants and/or OsFamily
  42. @DataProvider(name = "data")
  43. public Object[][] createData() throws IOException {
  44. InputStream is = ParseOsFamilyVersion64BitFromImageNameTest.class.getResourceAsStream("/osmatches.json");
  45. Map<String, OsFamilyVersion64Bit> values = json.fromJson(Strings2.toStringAndClose(is),
  46. new TypeLiteral<Map<String, OsFamilyVersion64Bit>>() {
  47. }.getType());
  48. return newArrayList(
  49. transform(values.entrySet(), new Function<Map.Entry<String, OsFamilyVersion64Bit>, Object[]>() {
  50. @Override
  51. public Object[] apply(Entry<String, OsFamilyVersion64Bit> input) {
  52. return new Object[] { input.getKey(), input.getValue() };
  53. }
  54. })).toArray(new Object[][] {});
  55. }
  56. ParseOsFamilyVersion64BitFromImageName parser = new ParseOsFamilyVersion64BitFromImageName(new BaseComputeServiceContextModule() {
  57. }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
  58. .getInstance(Json.class)));
  59. @Test(dataProvider = "data")
  60. public void test(String input, OsFamilyVersion64Bit expected) {
  61. assertEquals(parser.apply(input), expected);
  62. }
  63. }