/sandbox-apis/pcs/src/test/java/org/jclouds/mezeo/pcs/binders/BindFileInfoToXmlPayloadTest.java

https://github.com/regularfry/jclouds · Java · 76 lines · 42 code · 11 blank · 23 comment · 0 complexity · c6dfa396731d919fa0cff010ed068e28 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.mezeo.pcs.binders;
  20. import static org.testng.Assert.assertEquals;
  21. import java.net.URI;
  22. import javax.ws.rs.core.HttpHeaders;
  23. import org.jclouds.http.HttpRequest;
  24. import org.jclouds.mezeo.pcs.binders.BindFileInfoToXmlPayload;
  25. import org.jclouds.mezeo.pcs.config.PCSObjectModule;
  26. import org.jclouds.mezeo.pcs.domain.PCSFile;
  27. import org.testng.annotations.Test;
  28. import com.google.inject.Guice;
  29. /**
  30. * Tests behavior of {@code BindFileInfoToXmlPayload}
  31. *
  32. * @author Adrian Cole
  33. */
  34. @Test(groups = "unit", testName = "pcs2.BindFileInfoToXmlPayloadTest")
  35. public class BindFileInfoToXmlPayloadTest {
  36. PCSFile.Factory factory = Guice.createInjector(new PCSObjectModule()).getInstance(PCSFile.Factory.class);
  37. public void test() {
  38. BindFileInfoToXmlPayload binder = new BindFileInfoToXmlPayload();
  39. HttpRequest request = new HttpRequest("GET", URI.create("http://localhost"));
  40. PCSFile file = factory.create(null);
  41. file.getMetadata().setName("foo");
  42. request = binder.bindToRequest(request, file);
  43. assertEquals(request.getPayload().getRawContent(),
  44. "<file><name>foo</name><mime_type>application/octet-stream</mime_type><public>false</public></file>");
  45. assertEquals(
  46. request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH),
  47. "<file><name>foo</name><mime_type>application/octet-stream</mime_type><public>false</public></file>"
  48. .getBytes().length + "");
  49. assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE), "application/vnd.csp.file-info+xml");
  50. }
  51. public void testCompound() {
  52. BindFileInfoToXmlPayload binder = new BindFileInfoToXmlPayload();
  53. HttpRequest request = new HttpRequest("GET", URI.create("http://localhost"));
  54. PCSFile file = factory.create(null);
  55. file.getMetadata().setName("subdir/foo");
  56. request = binder.bindToRequest(request, file);
  57. assertEquals(request.getPayload().getRawContent(),
  58. "<file><name>foo</name><mime_type>application/octet-stream</mime_type><public>false</public></file>");
  59. assertEquals(
  60. request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH),
  61. "<file><name>foo</name><mime_type>application/octet-stream</mime_type><public>false</public></file>"
  62. .getBytes().length + "");
  63. assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE), "application/vnd.csp.file-info+xml");
  64. }
  65. }