/api/src/test/java/org/jboss/shrinkwrap/api/asset/StringAssetTestCase.java

https://github.com/maschmid/shrinkwrap · Java · 78 lines · 27 code · 12 blank · 39 comment · 2 complexity · afb94a415dec733d6b83b295b1fc2f60 MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2010, Red Hat Middleware LLC, and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. * http://www.apache.org/licenses/LICENSE-2.0
  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.jboss.shrinkwrap.api.asset;
  18. import java.io.ByteArrayOutputStream;
  19. import java.io.InputStream;
  20. import java.util.logging.Logger;
  21. import junit.framework.Assert;
  22. import org.junit.Test;
  23. /**
  24. * Test Cases for the {@link StringAsset}
  25. *
  26. * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
  27. * @author <a href="mailto:dan.j.allen@gmail.com">Dan Allen</a>
  28. * @version $Revision: $
  29. */
  30. public class StringAssetTestCase
  31. {
  32. //-------------------------------------------------------------------------------------||
  33. // Class Members ----------------------------------------------------------------------||
  34. //-------------------------------------------------------------------------------------||
  35. /**
  36. * Logger
  37. */
  38. private static final Logger log = Logger.getLogger(StringAssetTestCase.class.getName());
  39. //-------------------------------------------------------------------------------------||
  40. // Tests ------------------------------------------------------------------------------||
  41. //-------------------------------------------------------------------------------------||
  42. /**
  43. * Ensures that the contents of the asset match that which was passed in.
  44. */
  45. @Test
  46. public void testRoundtrip() throws Exception
  47. {
  48. // Log
  49. log.info("testRoundtrip");
  50. // Make contents
  51. String contents = StringAsset.class.getSimpleName();
  52. // Make Asset
  53. final StringAsset asset = new StringAsset(contents);
  54. // Get the contents back out of the asset
  55. final InputStream stream = asset.openStream();
  56. final ByteArrayOutputStream out = new ByteArrayOutputStream(contents.length());
  57. int read;
  58. while ((read = stream.read()) != -1)
  59. {
  60. out.write(read);
  61. }
  62. String roundtrip = new String(out.toByteArray());
  63. log.info("Roundtrip contents: " + roundtrip);
  64. Assert.assertEquals("Roundtrip did not equal passed in contents", contents, roundtrip);
  65. }
  66. }