/apis/deltacloud/src/test/java/org/jclouds/deltacloud/xml/ImageHandlerTest.java

https://github.com/regularfry/jclouds · Java · 64 lines · 32 code · 9 blank · 23 comment · 0 complexity · 063ba980eb1ed921672f48d40372a55e 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.deltacloud.xml;
  20. import static org.testng.Assert.assertEquals;
  21. import java.io.InputStream;
  22. import java.net.URI;
  23. import org.jclouds.deltacloud.domain.Image;
  24. import org.jclouds.deltacloud.xml.ImageHandler;
  25. import org.jclouds.http.functions.ParseSax;
  26. import org.jclouds.http.functions.config.SaxParserModule;
  27. import org.testng.annotations.Test;
  28. import com.google.inject.Guice;
  29. import com.google.inject.Injector;
  30. /**
  31. * Tests behavior of {@code ImageHandler}
  32. *
  33. * @author Adrian Cole
  34. */
  35. @Test(groups = "unit")
  36. public class ImageHandlerTest {
  37. static ParseSax<Image> createParser() {
  38. Injector injector = Guice.createInjector(new SaxParserModule());
  39. ParseSax<Image> parser = (ParseSax<Image>) injector.getInstance(ParseSax.Factory.class).create(
  40. injector.getInstance(ImageHandler.class));
  41. return parser;
  42. }
  43. public static Image parseImage() {
  44. return parseImage("/test_get_image.xml");
  45. }
  46. public static Image parseImage(String resource) {
  47. InputStream is = ImageHandlerTest.class.getResourceAsStream(resource);
  48. return createParser().parse(is);
  49. }
  50. public void test() {
  51. Image expects = new Image(URI.create("http://fancycloudprovider.com/api/images/img1"), "img1", "fedoraproject",
  52. "Fedora 10", "Fedora 10", "x86_64");
  53. assertEquals(parseImage(), expects);
  54. }
  55. }