From dac27a045a56e1d307fb85e4f63a5befe990a749 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Wed, 3 Nov 2004 05:16:28 +0000 Subject: [PATCH] Added test for binary resource with non-standard encoding...I'm trying to get a multi-byte character encoding so it might throw off a String-based copy... git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163228 13f79535-47bb-0310-9956-ffa450edef68 --- .../plugin/resources/ResourcesMojoTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/maven-plugins/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/ResourcesMojoTest.java b/maven-plugins/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/ResourcesMojoTest.java index c52827ab68..95c632b0eb 100644 --- a/maven-plugins/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/ResourcesMojoTest.java +++ b/maven-plugins/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/ResourcesMojoTest.java @@ -23,9 +23,14 @@ import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.embed.Embedder; +import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.FileWriter; +import java.io.InputStream; import java.io.PrintWriter; +import java.util.Arrays; import java.util.Collections; import java.util.Map; import java.util.HashMap; @@ -40,6 +45,10 @@ public class ResourcesMojoTest private static final String TEST_DIRECTORY = "target/tests/test-data"; private static final String OUTPUT_DIRECTORY = "target/tests/output"; + private static final String RESOURCE_COPY_TEST_KEYSTORE = "resourceCopyTest.jks"; + + private byte[] testFileData; + public ResourcesMojoTest( String s ) { super( s ); @@ -58,6 +67,12 @@ public class ResourcesMojoTest w.println( ":local:/cvs/root" ); w.close(); + this.testFileData = "This is a test".getBytes("MS949"); + + FileOutputStream outstream = new FileOutputStream( new File( basedir, TEST_DIRECTORY + "/test.bin" ) ); + outstream.write(testFileData); + outstream.close(); + w = new PrintWriter( new FileWriter( new File( basedir, TEST_DIRECTORY + "/test.txt" ) ) ); w.println( "test data" ); w.close(); @@ -68,6 +83,8 @@ public class ResourcesMojoTest f.getParentFile().delete(); f = new File( basedir, OUTPUT_DIRECTORY + "/test.txt" ); f.delete(); + f = new File( basedir, OUTPUT_DIRECTORY + "/test.bin" ); + f.delete(); f.getParentFile().delete(); } @@ -95,6 +112,8 @@ public class ResourcesMojoTest assertTrue( "sanity check creation of CVS file " + f, f.exists() ); f = new File( directory, "test.txt" ); assertTrue( "sanity check creation of file " + f, f.exists() ); + f = new File( directory, "test.bin" ); + assertTrue( "sanity check creation of binary file " + f, f.exists() ); Resource r = new Resource(); r.setDirectory( TEST_DIRECTORY ); @@ -116,5 +135,23 @@ public class ResourcesMojoTest assertFalse( "check no creation of CVS directory " + f, f.getParentFile().exists() ); f = new File( basedir + "/" + OUTPUT_DIRECTORY, "test.txt" ); assertTrue( "check creation of resource " + f, f.exists() ); + + f = new File( basedir + "/" + OUTPUT_DIRECTORY, "test.bin" ); + assertTrue( "check creation of binary resource " + f, f.exists() ); + + FileInputStream testInput = new FileInputStream(f); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + int read = -1; + byte[] buffer = new byte[512]; + + while((read = testInput.read(buffer)) > -1) + { + baos.write(buffer, 0, read); + } + testInput.close(); + + assertTrue(Arrays.equals(testFileData, baos.toByteArray())); + fail("Sanity check!"); } }