PageRenderTime 3503ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/apis/chef/src/test/java/org/jclouds/chef/functions/ParseCookbookDefinitionFromJsonTest.java

http://github.com/jclouds/jclouds
Java | 75 lines | 49 code | 10 blank | 16 comment | 0 complexity | ee75a6fd6c70c97d35a0112fc1c0c3cc 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.chef.functions;
  18. import static org.testng.Assert.assertEquals;
  19. import java.io.IOException;
  20. import java.net.URI;
  21. import java.net.URISyntaxException;
  22. import org.jclouds.chef.ChefApiMetadata;
  23. import org.jclouds.chef.config.ChefParserModule;
  24. import org.jclouds.chef.domain.CookbookDefinition;
  25. import org.jclouds.http.HttpResponse;
  26. import org.jclouds.json.config.GsonModule;
  27. import org.jclouds.rest.annotations.ApiVersion;
  28. import org.testng.annotations.BeforeTest;
  29. import org.testng.annotations.Test;
  30. import com.google.inject.AbstractModule;
  31. import com.google.inject.Guice;
  32. import com.google.inject.Injector;
  33. @Test(groups = { "unit" }, singleThreaded = true)
  34. public class ParseCookbookDefinitionFromJsonTest
  35. {
  36. private ParseCookbookDefinitionFromJson handler;
  37. @BeforeTest
  38. protected void setUpInjector() throws IOException {
  39. Injector injector = Guice.createInjector(new AbstractModule() {
  40. @Override
  41. protected void configure() {
  42. bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION);
  43. }
  44. }, new ChefParserModule(), new GsonModule());
  45. handler = injector.getInstance(ParseCookbookDefinitionFromJson.class);
  46. }
  47. public void testCookbokDefinitionParsing() throws URISyntaxException {
  48. CookbookDefinition.Version v510 = CookbookDefinition.Version.builder()
  49. .url(new URI("http://localhost:4000/cookbooks/apache2/5.1.0")).version("5.1.0").build();
  50. CookbookDefinition.Version v420 = CookbookDefinition.Version.builder()
  51. .url(new URI("http://localhost:4000/cookbooks/apache2/4.2.0")).version("4.2.0").build();
  52. CookbookDefinition definition = CookbookDefinition.builder()
  53. .name("apache2").url(new URI("http://localhost:4000/cookbooks/apache2")).version(v510).version(v420).build();
  54. assertEquals(handler.apply(HttpResponse
  55. .builder()
  56. .statusCode(200)
  57. .message("ok")
  58. .payload(
  59. "{" + "\"apache2\" => {" + "\"url\" => \"http://localhost:4000/cookbooks/apache2\","
  60. + "\"versions\" => [" + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/5.1.0\","
  61. + "\"version\" => \"5.1.0\"},"
  62. + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/4.2.0\","
  63. + "\"version\" => \"4.2.0\"}" + "]" + "}" + "}").build()), definition);
  64. }
  65. }