Author: tchemit Date: 2009-09-27 22:11:26 +0200 (Sun, 27 Sep 2009) New Revision: 274 Added: trunk/nuiton-processor/src/test/ trunk/nuiton-processor/src/test/java/ trunk/nuiton-processor/src/test/java/org/ trunk/nuiton-processor/src/test/java/org/nuiton/ trunk/nuiton-processor/src/test/java/org/nuiton/processor/ trunk/nuiton-processor/src/test/java/org/nuiton/processor/LicenseProcessorTest.java trunk/nuiton-processor/src/test/resources/ trunk/nuiton-processor/src/test/resources/log4j.properties trunk/nuiton-processor/src/test/resources/org/ trunk/nuiton-processor/src/test/resources/org/nuiton/ trunk/nuiton-processor/src/test/resources/org/nuiton/processor/ trunk/nuiton-processor/src/test/resources/org/nuiton/processor/LicenseProcessorTest.java2 trunk/nuiton-processor/src/test/resources/org/nuiton/processor/LicenseProcessorTest_1.java2 Modified: trunk/nuiton-processor/pom.xml Log: first test in this project! Modified: trunk/nuiton-processor/pom.xml =================================================================== --- trunk/nuiton-processor/pom.xml 2009-09-27 19:43:08 UTC (rev 273) +++ trunk/nuiton-processor/pom.xml 2009-09-27 20:11:26 UTC (rev 274) @@ -22,7 +22,23 @@ <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </dependency> - + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-utils</artifactId> + <scope>test</scope> + </dependency> </dependencies> <!-- ************************************************************* --> @@ -44,7 +60,8 @@ <properties> <!-- extra files to include in release --> <redmine.releaseFiles>target/${project.artifactId}-${project.version}-deps.zip, - target/${project.artifactId}-${project.version}-full.zip</redmine.releaseFiles> + target/${project.artifactId}-${project.version}-full.zip + </redmine.releaseFiles> </properties> <!-- ************************************************************* --> Added: trunk/nuiton-processor/src/test/java/org/nuiton/processor/LicenseProcessorTest.java =================================================================== --- trunk/nuiton-processor/src/test/java/org/nuiton/processor/LicenseProcessorTest.java (rev 0) +++ trunk/nuiton-processor/src/test/java/org/nuiton/processor/LicenseProcessorTest.java 2009-09-27 20:11:26 UTC (rev 274) @@ -0,0 +1,138 @@ +package org.nuiton.processor; + +/* + * *##% + * Maven License Plugin + * Copyright (C) 2008 - 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * ##%* + */ +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codehaus.plexus.util.IOUtil; +import org.junit.Before; +import org.junit.BeforeClass; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Test; + +/** + * + * @author chemit + * @since 1.0.1 + */ +public class LicenseProcessorTest { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private final Log log = LogFactory.getLog(LicenseProcessorTest.class); + static File basedir; + static File testdir; + + @BeforeClass + public static void initClass() throws Exception { + basedir = getBasedir(); + testdir = getFile(basedir, "target", "test-classes", "org", "nuiton", "processor", "result"); + testdir.mkdirs(); + } + + @AfterClass + public static void afterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @Test + public void testProcessor() throws IOException { + + File in = getFile(basedir, "target", "test-classes", "org", "nuiton", "processor", "LicenseProcessorTest.java2"); + File out = getFile(testdir, in.getName()); + LicenseProcessor processor = new LicenseProcessor("my license"); + processor.process(in, out); + String content = readAsString(out, "utf-8"); + if (log.isDebugEnabled()) { + log.debug("output : " + out); + log.debug(content); + } + checkPattern("// MUST BE THERE!", true, out); + checkPattern("my license", false, out); + } + + @Test + public void testProcessor2() throws IOException { + + File in = getFile(basedir, "target", "test-classes", "org", "nuiton", "processor", "LicenseProcessorTest_1.java2"); + File out = new File(testdir, in.getName()); + LicenseProcessor processor = new LicenseProcessor("my license"); + processor.process(in, out); + String content = readAsString(out, "utf-8"); + if (log.isDebugEnabled()) { + log.debug("output : " + out); + log.debug(content); + } + checkPattern("// MUST BE THERE!", true, out); + checkPattern("my license", true, out); + } + + protected void checkPattern(String pattern, boolean required, File f) throws IOException { + + if (log.isDebugEnabled()) { + log.debug("check generated file " + f); + } + + Assert.assertTrue("generated file " + f + " was not found...", f.exists()); + String content = readAsString(f, "utf-8"); + + String errorMessage = required ? "could not find the pattern : " : "should not have found pattern :"; + Assert.assertEquals(errorMessage + pattern + " in file " + f, required, content.contains(pattern)); + } + + static public String readAsString(File file, String encoding) throws IOException { + FileInputStream inf = new FileInputStream(file); + BufferedReader in = new BufferedReader(new InputStreamReader(inf, encoding)); + try { + return IOUtil.toString(in); + } finally { + in.close(); + } + } + + public static File getFile(File base, String... paths) { + StringBuilder buffer = new StringBuilder(); + for (String path : paths) { + buffer.append(File.separator).append(path); + } + File f = new File(base, buffer.substring(1)); + return f; + } + + public static File getBasedir() { + String basedirPath = System.getProperty("basedir"); + + if (basedirPath == null) { + basedirPath = new File("").getAbsolutePath(); + } + + return new File(basedirPath); + } +} Property changes on: trunk/nuiton-processor/src/test/java/org/nuiton/processor/LicenseProcessorTest.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/nuiton-processor/src/test/resources/log4j.properties =================================================================== --- trunk/nuiton-processor/src/test/resources/log4j.properties (rev 0) +++ trunk/nuiton-processor/src/test/resources/log4j.properties 2009-09-27 20:11:26 UTC (rev 274) @@ -0,0 +1,11 @@ +# Global logging configuration +log4j.rootLogger=ERROR, stdout +# Console output... +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n + +# package level + +log4j.logger.org.nuiton=INFO +log4j.logger.org.nuiton.processor=INFO Added: trunk/nuiton-processor/src/test/resources/org/nuiton/processor/LicenseProcessorTest.java2 =================================================================== --- trunk/nuiton-processor/src/test/resources/org/nuiton/processor/LicenseProcessorTest.java2 (rev 0) +++ trunk/nuiton-processor/src/test/resources/org/nuiton/processor/LicenseProcessorTest.java2 2009-09-27 20:11:26 UTC (rev 274) @@ -0,0 +1,10 @@ +/** + * *##% YO + * ##% yy + */ + +public class LicenceProcessorTest { + + +// MUST BE THERE! +} \ No newline at end of file Added: trunk/nuiton-processor/src/test/resources/org/nuiton/processor/LicenseProcessorTest_1.java2 =================================================================== --- trunk/nuiton-processor/src/test/resources/org/nuiton/processor/LicenseProcessorTest_1.java2 (rev 0) +++ trunk/nuiton-processor/src/test/resources/org/nuiton/processor/LicenseProcessorTest_1.java2 2009-09-27 20:11:26 UTC (rev 274) @@ -0,0 +1,10 @@ +/** + * *##% YO + * ##%* yy + */ + +public class LicenceProcessorTest { + + +// MUST BE THERE! +} \ No newline at end of file