diff --git a/magnolia-core/src/test/java/info/magnolia/cms/core/PathTest.java b/magnolia-core/src/test/java/info/magnolia/cms/core/PathTest.java index 6bd7172..14bd138 100644 --- a/magnolia-core/src/test/java/info/magnolia/cms/core/PathTest.java +++ b/magnolia-core/src/test/java/info/magnolia/cms/core/PathTest.java @@ -52,6 +52,9 @@ import org.junit.Test; */ public class PathTest { + // @author Tobias Hochg├╝rtel + private static String OS = System.getProperty("os.name").toLowerCase(); + @Before public void setUp() { SystemProperty.setProperty(SystemProperty.MAGNOLIA_APP_ROOTDIR, "./src/test/resources"); @@ -133,11 +136,26 @@ public class PathTest { assertEquals("----", Path.getValidatedLabel(" ", null)); } + /** + * @author Tobias Hochg├╝rtel + */ + public static boolean isWindows() { + return (OS.indexOf("win") >= 0); + } + @Test public void testGetAbsoluteFileSystemPathPrependsApplicationRootDirIfPathIsRelative() throws Exception { - String relPath = "WEB-INF/config"; + // @author Tobias Hochg├╝rtel + String directorySeperatorToken; + if (isWindows()) { + directorySeperatorToken = "\\"; + } else { + directorySeperatorToken = "/"; + } + String relPath = "WEB-INF" + directorySeperatorToken + "config"; + String returnedPath = Path.getAbsoluteFileSystemPath(relPath); - assertEquals(Path.getAppRootDir().getAbsolutePath() + "/" + relPath, returnedPath); + assertEquals(Path.getAppRootDir().getAbsolutePath() + directorySeperatorToken + relPath, returnedPath); } @Test diff --git a/magnolia-core/src/test/java/info/magnolia/cms/util/WorkspaceXmlUtilTest.java b/magnolia-core/src/test/java/info/magnolia/cms/util/WorkspaceXmlUtilTest.java index 55e7505..5729940 100644 --- a/magnolia-core/src/test/java/info/magnolia/cms/util/WorkspaceXmlUtilTest.java +++ b/magnolia-core/src/test/java/info/magnolia/cms/util/WorkspaceXmlUtilTest.java @@ -47,6 +47,31 @@ import org.junit.Test; */ public class WorkspaceXmlUtilTest { + // @author Tobias Hochg├╝rtel + private static String OS = System.getProperty("os.name").toLowerCase(); + + /** + * Check's if we running on an Windows System + * @author Tobias Hochg├╝rtel + * @return boolean If Windows System: return true; + */ + public static boolean isWindows() { + return (OS.indexOf("win") >= 0); + } + + /** + * Returns the System-specific Directory Seperator Token + * + * @author Tobias Hochg├╝rtel + * @return String If Windows System: "\\"; Else "/"; + */ + public static String getDirectorySeperatorToken() { + if (isWindows()) { + return "\\"; + } + return "/"; + } + @Before public void setUp() { SystemProperty.setProperty(SystemProperty.MAGNOLIA_REPOSITORIES_HOME, "src/test/resources/config/repositories"); @@ -56,14 +81,14 @@ public class WorkspaceXmlUtilTest { public void testWorkspaceNamesWithNonNullExpectation() { List names = WorkspaceXmlUtil.getWorkspaceNames("/Workspace/SearchIndex/param[@name='textFilterClasses']/@value", ".*\\.jackrabbit\\.extractor\\..*"); assertEquals("Found incorrect amount of indexers", 1, names.size()); - assertTrue(names.get(0).contains("/outdated/workspace.xml")); + assertTrue(names.get(0).contains(getDirectorySeperatorToken() + "outdated"+ getDirectorySeperatorToken() + "workspace.xml")); } @Test public void testWorkspaceNamesWithNullExpectation() { List names = WorkspaceXmlUtil.getWorkspaceNames("/Workspace/SearchIndex/param[@name='textFilterClasses']/@value", null); assertEquals("Found incorrect amount of indexers", 1, names.size()); - assertTrue(names.get(0).contains("/current/workspace.xml")); + assertTrue(names.get(0).contains(getDirectorySeperatorToken() + "current" + getDirectorySeperatorToken() + "workspace.xml")); } @After diff --git a/magnolia-core/src/test/java/info/magnolia/init/DefaultMagnoliaPropertiesResolverTest.java b/magnolia-core/src/test/java/info/magnolia/init/DefaultMagnoliaPropertiesResolverTest.java index a6e83eb..d3a7f2e 100644 --- a/magnolia-core/src/test/java/info/magnolia/init/DefaultMagnoliaPropertiesResolverTest.java +++ b/magnolia-core/src/test/java/info/magnolia/init/DefaultMagnoliaPropertiesResolverTest.java @@ -151,13 +151,29 @@ public class DefaultMagnoliaPropertiesResolverTest { assertEquals("WEB-INF/hello/magnolia.properties", locations.get(0)); } + // @author Tobias Hochg├╝rtel + private static String OS = System.getProperty("os.name").toLowerCase(); + + /** + * Check's if we running on an Windows System + * @author Tobias Hochg├╝rtel + * @return boolean If Windows System: return true; + */ + public static boolean isWindows() { + return (OS.indexOf("win") >= 0); + } + @Test public void testEnvironmentPropertiesCanBeUsed() { // since we can't add properties to System.env, we just an env property whose value we can know otherwise. // This test will most likely fail on Windows (where the env property seems to be USERNAME), unless someone comes up with a brighter idea. final String user = System.getProperty("user.name"); - expect(ctx.getInitParameter("magnolia.initialization.file")).andReturn("WEB-INF/${env/USER}/magnolia.properties"); + if (isWindows()){ + expect(ctx.getInitParameter("magnolia.initialization.file")).andReturn("WEB-INF/${env/USERNAME}/magnolia.properties"); + } else { + expect(ctx.getInitParameter("magnolia.initialization.file")).andReturn("WEB-INF/${env/USER}/magnolia.properties"); + } replay(ctx); final List locations = new DefaultMagnoliaPropertiesResolver(ctx, initPaths).getLocations(); assertEquals(1, locations.size()); diff --git a/magnolia-core/src/test/java/info/magnolia/module/delta/WorkspaceXmlConditionsUtilTest.java b/magnolia-core/src/test/java/info/magnolia/module/delta/WorkspaceXmlConditionsUtilTest.java index 358a8a3..55f4d8f 100644 --- a/magnolia-core/src/test/java/info/magnolia/module/delta/WorkspaceXmlConditionsUtilTest.java +++ b/magnolia-core/src/test/java/info/magnolia/module/delta/WorkspaceXmlConditionsUtilTest.java @@ -51,6 +51,31 @@ public class WorkspaceXmlConditionsUtilTest { private List conditions; private WorkspaceXmlConditionsUtil util; + // @author Tobias Hochg├╝rtel + private static String OS = System.getProperty("os.name").toLowerCase(); + + /** + * Check's if we running on an Windows System + * @author Tobias Hochg├╝rtel + * @return boolean If Windows System: return true; + */ + public static boolean isWindows() { + return (OS.indexOf("win") >= 0); + } + + /** + * Returns the System-specific Directory Seperator Token + * + * @author Tobias Hochg├╝rtel + * @return String If Windows System: "\\"; Else "/"; + */ + public static String getDirectorySeperatorToken() { + if (isWindows()) { + return "\\"; + } + return "/"; + } + @Before public void setUp() { SystemProperty.setProperty(SystemProperty.MAGNOLIA_REPOSITORIES_HOME, "src/test/resources/config/repositories"); @@ -68,7 +93,7 @@ public class WorkspaceXmlConditionsUtilTest { // THEN assertEquals(1,conditions.size()); assertTrue(conditions.get(0) instanceof WarnCondition); - assertTrue("Received condition was expected to be comming from the outdated config!", conditions.get(0).getDescription().contains("/outdated/workspace.xml")); + assertTrue("Received condition was expected to be comming from the outdated config!", conditions.get(0).getDescription().contains( getDirectorySeperatorToken() + "outdated" + getDirectorySeperatorToken() + "workspace.xml")); } @@ -82,7 +107,7 @@ public class WorkspaceXmlConditionsUtilTest { // THEN assertEquals(1,conditions.size()); assertTrue(conditions.get(0) instanceof FalseCondition); - assertTrue("Received condition was expected to be comming from the outdated config!", conditions.get(0).getDescription().contains("/outdated/workspace.xml")); + assertTrue("Received condition was expected to be comming from the outdated config!", conditions.get(0).getDescription().contains( getDirectorySeperatorToken() + "outdated" + getDirectorySeperatorToken() + "workspace.xml")); } @Test @@ -95,7 +120,7 @@ public class WorkspaceXmlConditionsUtilTest { // THEN assertEquals(1,conditions.size()); assertTrue(conditions.get(0) instanceof FalseCondition); - assertTrue("Received condition was expected to be comming from the outdated config!", conditions.get(0).getDescription().contains("/outdated/workspace.xml")); + assertTrue("Received condition was expected to be comming from the outdated config!", conditions.get(0).getDescription().contains( getDirectorySeperatorToken() +"outdated" + getDirectorySeperatorToken() + "workspace.xml")); } diff --git a/magnolia-core/src/test/java/info/magnolia/module/files/MD5CheckingFileExtractorOperationTest.java b/magnolia-core/src/test/java/info/magnolia/module/files/MD5CheckingFileExtractorOperationTest.java index 130ce5f..daf8967 100644 --- a/magnolia-core/src/test/java/info/magnolia/module/files/MD5CheckingFileExtractorOperationTest.java +++ b/magnolia-core/src/test/java/info/magnolia/module/files/MD5CheckingFileExtractorOperationTest.java @@ -63,14 +63,35 @@ public class MD5CheckingFileExtractorOperationTest extends RepositoryTestCase { private InnerLog log; private Session configSession; + // @author Tobias Hochg├╝rtel + private static String OS = System.getProperty("os.name").toLowerCase(); + private String md5sumExpected; + + /** + * Check's if we running on an Windows System + * @author Tobias Hochg├╝rtel + * @return boolean If Windows System: return true; + */ + public static boolean isWindows() { + return (OS.indexOf("win") >= 0); + } + @Override @Before public void setUp() throws Exception { super.setUp(); configSession = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); + fileInfoNode = NodeUtil.createPath(configSession.getRootNode(), fileInfoNodePath, NodeTypes.ContentNode.NAME); assertNotNull(getClass().getResourceAsStream(resourcePath)); + // @author Tobias Hochg├╝rtel + if (isWindows()){ + md5sumExpected = "dff8984527123a3857642b5e4f17f24c"; + } else { + md5sumExpected = "37fcdd006d3c514226f743a95da53622"; + } + // We need a randomly named (to enable test to be run in parallel), not yet physically existing file testOut = File.createTempFile("MD5-temp", null); // remove the file but keep the reference - file will be (re-)created by the class under test @@ -96,7 +117,7 @@ public class MD5CheckingFileExtractorOperationTest extends RepositoryTestCase { assertEquals("File should have been re-extracted", true, testOut.exists()); assertEquals(IOUtils.toString(new FileInputStream(testOut)), IOUtils.toString(getClass().getResourceAsStream(resourcePath))); assertTrue("md5 property was created", fileInfoNode.hasProperty("md5")); - assertEquals("37fcdd006d3c514226f743a95da53622", fileInfoNode.getProperty("md5").getString()); + assertEquals(md5sumExpected, fileInfoNode.getProperty("md5").getString()); } @Test @@ -105,6 +126,7 @@ public class MD5CheckingFileExtractorOperationTest extends RepositoryTestCase { MD5CheckingFileExtractorOperation op = new MD5CheckingFileExtractorOperation(log, configSession, resourcePath, testOut.getAbsolutePath()); // create it op.extract(); + // modify the md5 property fileInfoNode.getProperty("md5").setValue("x"); @@ -112,8 +134,8 @@ public class MD5CheckingFileExtractorOperationTest extends RepositoryTestCase { op.extract(); // THEN - assertEquals("File should have been re-extracted", "Can't extract /info/magnolia/test/mock/testcontent.properties as this file was probably modified locally: expected MD5 [x] but current MD5 is [37fcdd006d3c514226f743a95da53622].", log.getMessage()); - assertEquals(IOUtils.toString(new FileInputStream(testOut)), IOUtils.toString(getClass().getResourceAsStream(resourcePath))); + assertEquals("File should have been re-extracted","Can't extract /info/magnolia/test/mock/testcontent.properties as this file was probably modified locally: expected MD5 [x] but current MD5 is [" + md5sumExpected + "].",log.getMessage()); + assertEquals(IOUtils.toString(new FileInputStream(testOut)),IOUtils.toString(getClass().getResourceAsStream(resourcePath))); } private class InnerLog implements FileExtractionLogger { diff --git a/pom.xml b/pom.xml index 0afd797..6000310 100644 --- a/pom.xml +++ b/pom.xml @@ -85,9 +85,34 @@ for Java Content Repositories (JCR). + + org.apache.maven.plugins + maven-compiler-plugin + + ${javaVersion} + ${javaVersion} + UTF-8 + + + + compile-tests + process-test-sources + + testCompile + + + ${javaVersionForTests} + ${javaVersionForTests} + UTF-8 + + + + + maven-surefire-plugin false + true