[Lutinutil-commits] r1174 - maven-license-switcher-plugin/trunk/src/test/java/org/codelutin/license
Author: tchemit Date: 2008-10-12 21:43:43 +0000 (Sun, 12 Oct 2008) New Revision: 1174 Added: maven-license-switcher-plugin/trunk/src/test/java/org/codelutin/license/BaseLicenseTestCase.java Log: base test class Added: maven-license-switcher-plugin/trunk/src/test/java/org/codelutin/license/BaseLicenseTestCase.java =================================================================== --- maven-license-switcher-plugin/trunk/src/test/java/org/codelutin/license/BaseLicenseTestCase.java (rev 0) +++ maven-license-switcher-plugin/trunk/src/test/java/org/codelutin/license/BaseLicenseTestCase.java 2008-10-12 21:43:43 UTC (rev 1174) @@ -0,0 +1,60 @@ +package org.codelutin.license; + +import junit.framework.TestCase; +import org.codelutin.util.FileUtil; + +import java.io.File; +import java.io.IOException; + +/** @author chemit */ +public abstract class BaseLicenseTestCase extends TestCase { + + protected static final String encoding = "utf-8"; + + protected File getBaseDir() { + String path = System.getenv("basedir"); + if (path == null) { + path = new File("").getAbsolutePath(); + } + return new File(path); + } + + protected void assertLicenseFound(String name, License license) throws IOException { + assertNotNull(license); + assertEquals(name, license.getName()); + assertNotNull(license.getLicenseContent(encoding)); + assertNotNull(license.getHeaderContent(encoding)); + } + + protected File createLicenseRepository(boolean createLicene) throws IOException { + long timestamp = System.currentTimeMillis(); + + File repo = new File(getBaseDir(), "target" + File.separator + "licenses_" + timestamp); + + if (createLicene) { + + String licenseName = "dummy_" + timestamp; + addLicenseToRepository(repo, licenseName); + } + return repo; + } + + protected void addLicenseToRepository(File repo, String licenseName) throws IOException { + + File defFile = new File(repo, "licenses.properties"); + + String content = ""; + if (defFile.exists()) { + content = FileUtil.readAsString(defFile, encoding) + "\n"; + } + + FileUtil.writeString(defFile, content + licenseName + "=My dummy license\n", encoding); + // create dummy licenses + File file = new File(repo, licenseName); + file.mkdirs(); + FileUtil.writeString(new File(file, "license.txt"), "license:" + licenseName, encoding); + FileUtil.writeString(new File(file, "header.txt"), "header:" + licenseName, encoding); + + } +} +
participants (1)
-
tchemit@users.labs.libre-entreprise.org