PageRenderTime 35ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/core/src/test/java/org/jclouds/chef/functions/ParseCookbookDefinitionListFromJsonv10Test.java

https://github.com/jclouds/legacy-jclouds-chef
Java | 85 lines | 58 code | 9 blank | 18 comment | 0 complexity | 4e8374f03f27888da3bfded629cf6ba5 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.chef.functions;
  20. import static org.testng.Assert.assertEquals;
  21. import java.io.IOException;
  22. import java.net.URI;
  23. import java.net.URISyntaxException;
  24. import org.jclouds.chef.ChefApi;
  25. import org.jclouds.chef.config.ChefParserModule;
  26. import org.jclouds.chef.domain.CookbookDefinition;
  27. import org.jclouds.http.HttpResponse;
  28. import org.jclouds.json.config.GsonModule;
  29. import org.jclouds.rest.annotations.ApiVersion;
  30. import org.testng.annotations.BeforeTest;
  31. import org.testng.annotations.Test;
  32. import com.google.common.collect.ImmutableSet;
  33. import com.google.inject.AbstractModule;
  34. import com.google.inject.Guice;
  35. import com.google.inject.Injector;
  36. @Test(groups = {"unit"}, singleThreaded = true)
  37. public class ParseCookbookDefinitionListFromJsonv10Test {
  38. private ParseCookbookDefinitionListFromJsonv10 handler;
  39. @BeforeTest
  40. protected void setUpInjector() throws IOException {
  41. Injector injector = Guice.createInjector(new AbstractModule() {
  42. @Override
  43. protected void configure() {
  44. bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApi.VERSION);
  45. }
  46. }, new ChefParserModule(), new GsonModule());
  47. handler = injector.getInstance(ParseCookbookDefinitionListFromJsonv10.class);
  48. }
  49. public void testCookbokDefinitionListParsing() throws URISyntaxException {
  50. assertEquals(handler.apply(HttpResponse
  51. .builder()
  52. .statusCode(200)
  53. .message("ok")
  54. .payload(
  55. "{" + "\"apache2\" => {" + "\"url\" => \"http://localhost:4000/cookbooks/apache2\","
  56. + "\"versions\" => [" + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/5.1.0\","
  57. + "\"version\" => \"5.1.0\"},"
  58. + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/4.2.0\","
  59. + "\"version\" => \"4.2.0\"}" + "]" + "},"
  60. + "\"nginx\" => {"
  61. + "\"url\" => \"http://localhost:4000/cookbooks/nginx\","
  62. + "\"versions\" => ["
  63. + "{\"url\" => \"http://localhost:4000/cookbooks/nginx/1.0.0\","
  64. + "\"version\" => \"1.0.0\"},"
  65. + "{\"url\" => \"http://localhost:4000/cookbooks/nginx/0.3.0\","
  66. + "\"version\" => \"0.3.0\"}"
  67. + "]}" +
  68. "}").build()),
  69. ImmutableSet.of(new CookbookDefinition(new URI("http://localhost:4000/cookbooks/apache2"),
  70. ImmutableSet.of(new CookbookDefinition.Version(new URI("http://localhost:4000/cookbooks/apache2/5.1.0"), "5.1.0"),
  71. new CookbookDefinition.Version(new URI("http://localhost:4000/cookbooks/apache2/4.2.0"), "4.2.0"))),
  72. new CookbookDefinition(new URI("http://localhost:4000/cookbooks/nginx"),
  73. ImmutableSet.of(new CookbookDefinition.Version(new URI("http://localhost:4000/cookbooks/nginx/1.0.0"), "1.0.0"),
  74. new CookbookDefinition.Version(new URI("http://localhost:4000/cookbooks/nginx/0.3.0"), "0.3.0")))));
  75. }
  76. }