You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AFPResourceUtilTestCase.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. /* $Id$ */
  18. package org.apache.fop.afp;
  19. import java.io.ByteArrayOutputStream;
  20. import java.io.InputStream;
  21. import java.util.Arrays;
  22. import junit.framework.TestCase;
  23. import org.apache.commons.io.IOUtils;
  24. import org.apache.fop.afp.util.AFPResourceUtil;
  25. /**
  26. * Tests the {@link AFPResourceUtil} class.
  27. */
  28. public class AFPResourceUtilTestCase extends TestCase {
  29. private static final String RESOURCE_FILENAME = "expected_resource.afp";
  30. private static final String NAMED_RESOURCE_FILENAME = "expected_named_resource.afp";
  31. private static final String PSEG = "XFEATHER";
  32. /**
  33. * Tests copyResourceFile()
  34. * @throws Exception -
  35. */
  36. public void testCopyResourceFile() throws Exception {
  37. final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  38. InputStream in = null;
  39. try {
  40. in = getClass().getResourceAsStream(RESOURCE_FILENAME);
  41. AFPResourceUtil.copyResourceFile(in, baos);
  42. } finally {
  43. in.close();
  44. }
  45. byte[] expectedBytes = null;
  46. try {
  47. in = getClass().getResourceAsStream(RESOURCE_FILENAME);
  48. expectedBytes = IOUtils.toByteArray(in);
  49. } finally {
  50. in.close();
  51. }
  52. assertTrue(Arrays.equals(expectedBytes, baos.toByteArray()));
  53. }
  54. /**
  55. * Tests copyNamedResource()
  56. * @throws Exception -
  57. */
  58. public void testCopyNamedResource() throws Exception {
  59. final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  60. InputStream in = null;
  61. try {
  62. in = getClass().getResourceAsStream(RESOURCE_FILENAME);
  63. AFPResourceUtil.copyNamedResource(PSEG, in, baos);
  64. } finally {
  65. in.close();
  66. }
  67. byte[] expectedBytes = null;
  68. try {
  69. in = getClass().getResourceAsStream(NAMED_RESOURCE_FILENAME);
  70. expectedBytes = IOUtils.toByteArray(in);
  71. } finally {
  72. in.close();
  73. }
  74. assertTrue(Arrays.equals(expectedBytes, baos.toByteArray()));
  75. }
  76. }