You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2007/10/17 03:48:17 UTC

svn commit: r585321 - in /maven/components/branches/maven-model-mng2025/src/test: ./ java/ java/org/ java/org/apache/ java/org/apache/maven/ java/org/apache/maven/model/ java/org/apache/maven/model/io/ java/org/apache/maven/model/io/xpp3/ resources/

Author: brianf
Date: Tue Oct 16 18:48:14 2007
New Revision: 585321

URL: http://svn.apache.org/viewvc?rev=585321&view=rev
Log:
MNG2025 patch to add encoding unit tests

Added:
    maven/components/branches/maven-model-mng2025/src/test/
    maven/components/branches/maven-model-mng2025/src/test/java/
    maven/components/branches/maven-model-mng2025/src/test/java/org/
    maven/components/branches/maven-model-mng2025/src/test/java/org/apache/
    maven/components/branches/maven-model-mng2025/src/test/java/org/apache/maven/
    maven/components/branches/maven-model-mng2025/src/test/java/org/apache/maven/model/
    maven/components/branches/maven-model-mng2025/src/test/java/org/apache/maven/model/io/
    maven/components/branches/maven-model-mng2025/src/test/java/org/apache/maven/model/io/xpp3/
    maven/components/branches/maven-model-mng2025/src/test/java/org/apache/maven/model/io/xpp3/AbstractMavenModelTestCase.java
    maven/components/branches/maven-model-mng2025/src/test/java/org/apache/maven/model/io/xpp3/MavenXpp3ReaderTest.java
    maven/components/branches/maven-model-mng2025/src/test/resources/
    maven/components/branches/maven-model-mng2025/src/test/resources/iso-8859-15-encoded-pom.xml
    maven/components/branches/maven-model-mng2025/src/test/resources/utf-8-encoded-pom.xml

Added: maven/components/branches/maven-model-mng2025/src/test/java/org/apache/maven/model/io/xpp3/AbstractMavenModelTestCase.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-model-mng2025/src/test/java/org/apache/maven/model/io/xpp3/AbstractMavenModelTestCase.java?rev=585321&view=auto
==============================================================================
--- maven/components/branches/maven-model-mng2025/src/test/java/org/apache/maven/model/io/xpp3/AbstractMavenModelTestCase.java (added)
+++ maven/components/branches/maven-model-mng2025/src/test/java/org/apache/maven/model/io/xpp3/AbstractMavenModelTestCase.java Tue Oct 16 18:48:14 2007
@@ -0,0 +1,47 @@
+package org.apache.maven.model.io.xpp3;
+
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+public abstract class AbstractMavenModelTestCase extends TestCase
+{
+    protected File getFileForClasspathResource( String resource )
+        throws FileNotFoundException
+    {
+        ClassLoader cloader = Thread.currentThread().getContextClassLoader();
+
+        URL resourceUrl = cloader.getResource( resource );
+
+        File resourceFile = null;
+        if ( resourceUrl != null )
+        {
+            resourceFile = new File( resourceUrl.getPath() );
+        }
+        else
+        {
+            throw new FileNotFoundException( "Unable to find: " + resource );
+        }
+
+        return resourceFile;
+    }
+}

Added: maven/components/branches/maven-model-mng2025/src/test/java/org/apache/maven/model/io/xpp3/MavenXpp3ReaderTest.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-model-mng2025/src/test/java/org/apache/maven/model/io/xpp3/MavenXpp3ReaderTest.java?rev=585321&view=auto
==============================================================================
--- maven/components/branches/maven-model-mng2025/src/test/java/org/apache/maven/model/io/xpp3/MavenXpp3ReaderTest.java (added)
+++ maven/components/branches/maven-model-mng2025/src/test/java/org/apache/maven/model/io/xpp3/MavenXpp3ReaderTest.java Tue Oct 16 18:48:14 2007
@@ -0,0 +1,44 @@
+package org.apache.maven.model.io.xpp3;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.InputStreamReader;
+
+import org.apache.maven.model.Model;
+
+public class MavenXpp3ReaderTest extends AbstractMavenModelTestCase {
+
+	/**
+	 * This test case will not fail, because 8bit encodings won't corrupt the parser.
+	 * @throws Exception
+	 */
+	public void testISOEncodedModel() throws Exception {
+		File f = getFileForClasspathResource( "iso-8859-15-encoded-pom.xml" );
+		MavenXpp3Reader reader = new MavenXpp3Reader();
+		
+		Model model = reader.read( new InputStreamReader( new FileInputStream( f ), "ISO-8859-15" ) );
+		assertEquals( "öäüß", model.getDescription() );
+		
+		model = reader.read( new FileReader( f ) );
+		assertEquals( "öäüß", model.getDescription() );
+	}
+
+	/**
+	 * This test case WILL FAIL, because FileReader-instances cannot cope with UTF-8 encoded files.
+	 * Maven uses FileReaders by default to read POMs. 
+	 * @throws Exception
+	 */
+	public void testUTFEncodedModel() throws Exception {
+		File f = getFileForClasspathResource( "utf-8-encoded-pom.xml" );
+		MavenXpp3Reader reader = new MavenXpp3Reader();
+		
+		// Here's how to read the POM the right way, by telling the InputStream to use a certain encoding.
+		Model model = reader.read( new InputStreamReader( new FileInputStream( f ), "UTF-8" ) );
+		assertEquals( "öäüß", model.getDescription() );
+		
+		// Here's how Maven reads POMs: THIS TEST WILL FAIL
+		model = reader.read( new FileReader( f ) );
+		assertEquals( "öäüß", model.getDescription() );
+	}
+}

Added: maven/components/branches/maven-model-mng2025/src/test/resources/iso-8859-15-encoded-pom.xml
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-model-mng2025/src/test/resources/iso-8859-15-encoded-pom.xml?rev=585321&view=auto
==============================================================================
--- maven/components/branches/maven-model-mng2025/src/test/resources/iso-8859-15-encoded-pom.xml (added)
+++ maven/components/branches/maven-model-mng2025/src/test/resources/iso-8859-15-encoded-pom.xml Tue Oct 16 18:48:14 2007
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="ISO-8859-15"?>
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>maven</groupId>
+  <artifactId>maven-core</artifactId>
+  <name>Maven</name>
+  <version>2.0-SNAPSHOT</version>
+  <description>öäüß</description>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-plexus-plugin</artifactId>
+        <version>1.0</version>
+        <configuration>
+          <plexusConfiguration>src/conf/plexus.conf</plexusConfiguration>
+          <plexusConfigurationPropertiesFile>src/conf/plexus.properties</plexusConfigurationPropertiesFile>
+          <plexusApplicationName>Continuum</plexusApplicationName>
+        </configuration>
+        <executions>
+          <execution>
+            <goals>
+              <goal>plexus:runtime</goal>
+            </goals>
+            <configuration>
+              <plexusApplicationName>ContinuumPro</plexusApplicationName>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: maven/components/branches/maven-model-mng2025/src/test/resources/utf-8-encoded-pom.xml
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-model-mng2025/src/test/resources/utf-8-encoded-pom.xml?rev=585321&view=auto
==============================================================================
--- maven/components/branches/maven-model-mng2025/src/test/resources/utf-8-encoded-pom.xml (added)
+++ maven/components/branches/maven-model-mng2025/src/test/resources/utf-8-encoded-pom.xml Tue Oct 16 18:48:14 2007
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>maven</groupId>
+  <artifactId>maven-core</artifactId>
+  <name>Maven</name>
+  <version>2.0-SNAPSHOT</version>
+  <description>öäüß</description>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-plexus-plugin</artifactId>
+        <version>1.0</version>
+        <configuration>
+          <plexusConfiguration>src/conf/plexus.conf</plexusConfiguration>
+          <plexusConfigurationPropertiesFile>src/conf/plexus.properties</plexusConfigurationPropertiesFile>
+          <plexusApplicationName>Continuum</plexusApplicationName>
+        </configuration>
+        <executions>
+          <execution>
+            <goals>
+              <goal>plexus:runtime</goal>
+            </goals>
+            <configuration>
+              <plexusApplicationName>ContinuumPro</plexusApplicationName>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>