You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jo...@apache.org on 2006/10/19 04:23:09 UTC

svn commit: r465447 [2/2] - in /maven/sandbox: maven-shared-license/ maven-shared-license/src/ maven-shared-license/src/main/ maven-shared-license/src/main/java/ maven-shared-license/src/main/java/org/ maven-shared-license/src/main/java/org/apache/ mav...

Added: maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/AbstractFileTypeTestCase.java
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/AbstractFileTypeTestCase.java?view=auto&rev=465447
==============================================================================
--- maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/AbstractFileTypeTestCase.java (added)
+++ maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/AbstractFileTypeTestCase.java Wed Oct 18 19:23:04 2006
@@ -0,0 +1,117 @@
+package org.apache.maven.plugins.license.filetype;
+
+/*
+ * Copyright 2001-2006 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 org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+/**
+ * AbstractFileTypeTestCase 
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public abstract class AbstractFileTypeTestCase
+    extends PlexusTestCase
+{
+    private String roleHint;
+
+    public AbstractFileTypeTestCase( String hint )
+    {
+        super();
+        this.roleHint = hint;
+    }
+
+    protected AbstractFileType filetype;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        filetype = (AbstractFileType) lookup( AbstractFileType.ROLE, this.roleHint );
+        assertNotNull( "Unable to find filetype for role-hint [" + this.roleHint + "]", filetype );
+    }
+
+    public String getFileContents( File file )
+        throws IOException
+    {
+        FileReader freader = null;
+        try
+        {
+            freader = new FileReader( file );
+            String rawContents = IOUtil.toString( freader );
+            return rawContents;
+        }
+        finally
+        {
+            IOUtil.close( freader );
+        }
+    }
+
+    public String getRawLicense()
+        throws IOException
+    {
+        File licenseFile = new File( "src/test/filetypes/LICENSE" );
+        assertTrue( licenseFile.exists() );
+        return getFileContents( licenseFile );
+    }
+
+    public File getSourceFile( String name )
+    {
+        File sourceFile = new File( "src/test/filetypes/" + roleHint + "/" + name );
+
+        assertTrue( "Source test file [" + sourceFile.getAbsolutePath() + "] should exist.", sourceFile.exists() );
+        
+        return sourceFile;
+    }
+
+    public File getTestInjectFile( String name )
+        throws IOException
+    {
+        File sourceFile = getSourceFile( name );
+
+        File destDir = new File( "target/test-filetype-" + roleHint );
+
+        if ( !destDir.exists() )
+        {
+            assertTrue( "Unable to make " + destDir.getAbsolutePath() + " directories.", destDir.mkdirs() );
+        }
+
+        FileUtils.copyFileToDirectory( sourceFile, destDir );
+
+        File testFile = new File( destDir, sourceFile.getName() );
+
+        assertTrue( "Test file [" + testFile.getAbsolutePath() + "] should exist.", testFile.exists() );
+
+        return testFile;
+    }
+
+    public String getTestFileContents( String name )
+        throws IOException
+    {
+        File sourceFile = new File( "src/test/filetypes/" + roleHint + "/" + name );
+
+        assertTrue( "Source test file [" + sourceFile.getAbsolutePath() + "] should exist.", sourceFile.exists() );
+
+        return getFileContents( sourceFile );
+    }
+}

Propchange: maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/AbstractFileTypeTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/AbstractFileTypeTestCase.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/HtmlFileTypeTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/HtmlFileTypeTest.java?view=auto&rev=465447
==============================================================================
--- maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/HtmlFileTypeTest.java (added)
+++ maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/HtmlFileTypeTest.java Wed Oct 18 19:23:04 2006
@@ -0,0 +1,64 @@
+package org.apache.maven.plugins.license.filetype;
+
+/*
+ * Copyright 2001-2006 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 org.apache.maven.plugins.license.LicenseCheckException;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * HtmlFileTypeTest 
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class HtmlFileTypeTest
+    extends AbstractFileTypeTestCase
+{
+    public HtmlFileTypeTest()
+    {
+        super( "html" );
+    }
+
+    public void testCheck()
+        throws IOException, LicenseCheckException
+    {
+        String license = getRawLicense();
+        String licenses[] = new String[] { license };
+
+        File unsetFile = getSourceFile( "inject-1.html" );
+        File expectedFile = getSourceFile( "inject-1-expected.html" );
+
+        assertTrue( filetype.hasLicense( expectedFile, licenses ) );
+        assertFalse( filetype.hasLicense( unsetFile, licenses ) );
+    }
+
+    public void testInject1()
+        throws Exception
+    {
+        File injectFile = getTestInjectFile( "inject-1.html" );
+        String rawLicense = getRawLicense();
+
+        filetype.injectLicense( injectFile, rawLicense );
+
+        String expectedContents = getTestFileContents( "inject-1-expected.html" );
+        String actualContents = getFileContents( injectFile );
+
+        assertEquals( expectedContents, actualContents );
+    }
+}

Propchange: maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/HtmlFileTypeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/HtmlFileTypeTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/JavaFileTypeTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/JavaFileTypeTest.java?view=auto&rev=465447
==============================================================================
--- maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/JavaFileTypeTest.java (added)
+++ maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/JavaFileTypeTest.java Wed Oct 18 19:23:04 2006
@@ -0,0 +1,64 @@
+package org.apache.maven.plugins.license.filetype;
+
+/*
+ * Copyright 2001-2006 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 org.apache.maven.plugins.license.LicenseCheckException;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * JavaFileTypeTest 
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class JavaFileTypeTest
+    extends AbstractFileTypeTestCase
+{
+    public JavaFileTypeTest()
+    {
+        super( "java" );
+    }
+
+    public void testCheck()
+        throws IOException, LicenseCheckException
+    {
+        String license = getRawLicense();
+        String licenses[] = new String[] { license };
+
+        File unsetFile = getSourceFile( "inject-1.java" );
+        File expectedFile = getSourceFile( "inject-1-expected.java" );
+
+        assertTrue( filetype.hasLicense( expectedFile, licenses ) );
+        assertFalse( filetype.hasLicense( unsetFile, licenses ) );
+    }
+
+    public void testInject1()
+        throws Exception
+    {
+        File injectFile = getTestInjectFile( "inject-1.java" );
+        String rawLicense = getRawLicense();
+
+        filetype.injectLicense( injectFile, rawLicense );
+
+        String expectedContents = getTestFileContents( "inject-1-expected.java" );
+        String actualContents = getFileContents( injectFile );
+
+        assertEquals( expectedContents, actualContents );
+    }
+}

Propchange: maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/JavaFileTypeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/JavaFileTypeTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/PropertiesFileTypeTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/PropertiesFileTypeTest.java?view=auto&rev=465447
==============================================================================
--- maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/PropertiesFileTypeTest.java (added)
+++ maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/PropertiesFileTypeTest.java Wed Oct 18 19:23:04 2006
@@ -0,0 +1,65 @@
+package org.apache.maven.plugins.license.filetype;
+
+/*
+ * Copyright 2001-2006 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 org.apache.maven.plugins.license.LicenseCheckException;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * PropertiesFileTypeTest 
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class PropertiesFileTypeTest
+    extends AbstractFileTypeTestCase
+{
+    public PropertiesFileTypeTest()
+    {
+        super( "properties" );
+    }
+
+    public void testCheck()
+        throws IOException, LicenseCheckException
+    {
+        String license = getRawLicense();
+        String licenses[] = new String[] { license };
+
+        File unsetFile = getSourceFile( "inject-1.properties" );
+        File expectedFile = getSourceFile( "inject-1-expected.properties" );
+
+        assertTrue( filetype.hasLicense( expectedFile, licenses ) );
+        assertFalse( filetype.hasLicense( unsetFile, licenses ) );
+    }
+
+    public void testInject1()
+        throws Exception
+    {
+        File injectFile = getTestInjectFile( "inject-1.properties" );
+        String rawLicense = getRawLicense();
+
+        filetype.injectLicense( injectFile, rawLicense );
+
+        String expectedContents = getTestFileContents( "inject-1-expected.properties" );
+        String actualContents = getFileContents( injectFile );
+
+        assertEquals( expectedContents, actualContents );
+    }
+
+}

Propchange: maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/PropertiesFileTypeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/PropertiesFileTypeTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/XmlFileTypeTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/XmlFileTypeTest.java?view=auto&rev=465447
==============================================================================
--- maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/XmlFileTypeTest.java (added)
+++ maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/XmlFileTypeTest.java Wed Oct 18 19:23:04 2006
@@ -0,0 +1,64 @@
+package org.apache.maven.plugins.license.filetype;
+
+/*
+ * Copyright 2001-2006 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 org.apache.maven.plugins.license.LicenseCheckException;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * XmlFileTypeTest 
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class XmlFileTypeTest
+    extends AbstractFileTypeTestCase
+{
+    public XmlFileTypeTest()
+    {
+        super( "xml" );
+    }
+
+    public void testCheck()
+        throws IOException, LicenseCheckException
+    {
+        String license = getRawLicense();
+        String licenses[] = new String[] { license };
+
+        File unsetFile = getSourceFile( "inject-1.xml" );
+        File expectedFile = getSourceFile( "inject-1-expected.xml" );
+
+        assertTrue( filetype.hasLicense( expectedFile, licenses ) );
+        assertFalse( filetype.hasLicense( unsetFile, licenses ) );
+    }
+
+    public void testInject1()
+        throws Exception
+    {
+        File injectFile = getTestInjectFile( "inject-1.xml" );
+        String rawLicense = getRawLicense();
+
+        filetype.injectLicense( injectFile, rawLicense );
+
+        String expectedContents = getTestFileContents( "inject-1-expected.xml" );
+        String actualContents = getFileContents( injectFile );
+
+        assertEquals( expectedContents, actualContents );
+    }
+}

Propchange: maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/XmlFileTypeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/plugins/maven-license-plugin/src/test/java/org/apache/maven/plugins/license/filetype/XmlFileTypeTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"