PageRenderTime 3697ms CodeModel.GetById 28ms RepoModel.GetById 8ms app.codeStats 0ms

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

http://github.com/jclouds/jclouds
Java | 68 lines | 41 code | 8 blank | 19 comment | 0 complexity | fdf1bee04c637076181d7769e739a68e 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 org.jclouds.chef.ChefApiMetadata;
  21. import org.jclouds.chef.config.ChefParserModule;
  22. import org.jclouds.http.HttpResponse;
  23. import org.jclouds.json.config.GsonModule;
  24. import org.jclouds.rest.annotations.ApiVersion;
  25. import org.testng.annotations.BeforeTest;
  26. import org.testng.annotations.Test;
  27. import com.google.common.collect.ImmutableSet;
  28. import com.google.inject.AbstractModule;
  29. import com.google.inject.Guice;
  30. import com.google.inject.Injector;
  31. /**
  32. * Tests behavior of {@code ParseCookbookVersionsFromJson}
  33. */
  34. @Test(groups = { "unit" }, singleThreaded = true)
  35. public class ParseCookbookVersionsFromJsonTest
  36. {
  37. private ParseCookbookVersionsFromJson handler;
  38. @BeforeTest
  39. protected void setUpInjector() throws IOException {
  40. Injector injector = Guice.createInjector(new AbstractModule() {
  41. @Override
  42. protected void configure() {
  43. bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION);
  44. }
  45. }, new ChefParserModule(), new GsonModule());
  46. handler = injector.getInstance(ParseCookbookVersionsFromJson.class);
  47. }
  48. public void testRegex() {
  49. assertEquals(handler.apply(HttpResponse
  50. .builder()
  51. .statusCode(200)
  52. .message("ok")
  53. .payload(
  54. "{" + "\"apache2\" => {" + "\"url\" => \"http://localhost:4000/cookbooks/apache2\","
  55. + "\"versions\" => [" + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/5.1.0\","
  56. + "\"version\" => \"5.1.0\"},"
  57. + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/4.2.0\","
  58. + "\"version\" => \"4.2.0\"}" + "]" + "}" + "}").build()), ImmutableSet.of("5.1.0", "4.2.0"));
  59. }
  60. }