PageRenderTime 1506ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/jclouds/jclouds
Java | 87 lines | 58 code | 10 blank | 19 comment | 0 complexity | 3fbde0ab9a8dd92a4bbd32d478966c83 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 com.google.common.io.BaseEncoding.base16;
  19. import static com.google.common.primitives.Bytes.asList;
  20. import static org.testng.Assert.assertEquals;
  21. import java.io.IOException;
  22. import java.net.URI;
  23. import org.jclouds.chef.ChefApiMetadata;
  24. import org.jclouds.chef.config.ChefParserModule;
  25. import org.jclouds.chef.domain.ChecksumStatus;
  26. import org.jclouds.chef.domain.UploadSandbox;
  27. import org.jclouds.http.HttpResponse;
  28. import org.jclouds.http.functions.ParseJson;
  29. import org.jclouds.json.config.GsonModule;
  30. import org.jclouds.rest.annotations.ApiVersion;
  31. import org.testng.annotations.BeforeTest;
  32. import org.testng.annotations.Test;
  33. import com.google.inject.AbstractModule;
  34. import com.google.inject.Guice;
  35. import com.google.inject.Injector;
  36. import com.google.inject.Key;
  37. import com.google.inject.TypeLiteral;
  38. /**
  39. * Tests behavior of {@code ParseUploadSiteFromJson}
  40. */
  41. @Test(groups = { "unit" }, singleThreaded = true)
  42. public class ParseUploadSandboxFromJsonTest {
  43. private ParseJson<UploadSandbox> handler;
  44. private Injector injector;
  45. @BeforeTest
  46. protected void setUpInjector() throws IOException {
  47. injector = Guice.createInjector(new AbstractModule() {
  48. @Override
  49. protected void configure() {
  50. bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION);
  51. }
  52. }, new ChefParserModule(), new GsonModule());
  53. handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<UploadSandbox>>() {
  54. }));
  55. }
  56. public void test() {
  57. assertEquals(
  58. handler.apply(HttpResponse.builder().statusCode(200).message("ok")
  59. .payload(ParseUploadSandboxFromJsonTest.class.getResourceAsStream("/upload-site.json")).build()),
  60. UploadSandbox
  61. .builder()
  62. .uri(URI
  63. .create("https://api.opscode.com/organizations/jclouds/sandboxes/d454f71e2a5f400c808d0c5d04c2c88c"))
  64. .checksum(
  65. asList(base16().lowerCase().decode("0c5ecd7788cf4f6c7de2a57193897a6c")),
  66. ChecksumStatus
  67. .builder()
  68. .url(URI
  69. .create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/sandbox-d454f71e2a5f400c808d0c5d04c2c88c/checksum-0c5ecd7788cf4f6c7de2a57193897a6c?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277344702&Signature=FtKyqvYEjhhEKmRY%2B0M8aGPMM7g%3D"))
  70. .needsUpload(true).build())
  71. .checksum(asList(base16().lowerCase().decode("0189e76ccc476701d6b374e5a1a27347")),
  72. ChecksumStatus.builder().build())
  73. .checksum(asList(base16().lowerCase().decode("1dda05ed139664f1f89b9dec482b77c0")),
  74. ChecksumStatus.builder().build()).sandboxId("d454f71e2a5f400c808d0c5d04c2c88c").build()
  75. );
  76. }
  77. }