diff --git a/pom.xml b/pom.xml index 566f14d12874df100323d98aba0ffc7e97420f50..b31e76866afa4433a209d4c394c11aa7621b0709 100644 --- a/pom.xml +++ b/pom.xml @@ -291,6 +291,21 @@ </resource> --> </resources> + <testResources> + <!-- Same comment as for src/main/java also applies to src/test/java --> + <testResource> + <directory>src/test/java</directory> + <excludes> + <exclude>**/*.java</exclude> + </excludes> + </testResource> + <testResource> + <directory>src/test/resources</directory> + <!-- when enabled resources will be searched and variables replaces with + values --> + <filtering>true</filtering> + </testResource> + </testResources> <plugins> <plugin> <artifactId>maven-resources-plugin</artifactId> @@ -426,13 +441,22 @@ <configuration> <testFailureIgnore>true</testFailureIgnore> <skipTests>${skipTests}</skipTests> + <argLine>-XX:MaxPermSize=256m -Xmx1024m -Xms1024m</argLine> + <systemPropertyVariables> + <java.io.tmpdir>${project.build.directory}/olatdata</java.io.tmpdir> + </systemPropertyVariables> <excludes> <!-- TODO:gs --> <exclude>**/TestTable.java</exclude> <exclude>**/TestUser*</exclude> <exclude>**/TestIdentity.java</exclude> <exclude>**/TestTextCase*</exclude> + <exclude>**/*PerformanceTest.java</exclude> </excludes> + <includes> + <include>**/AllTestsOlatCoreJunit4.java</include> + <include>**/AllTestsJunit4.java</include> + </includes> <!-- To run a single test add -Dtest=TestClass... test mvn -Dtest=TestSquare,TestCi*le test NOTE: Running a single test runs always twice, no idea why To run the diff --git a/src/main/java/org/olat/core/util/i18n/I18nModule.java b/src/main/java/org/olat/core/util/i18n/I18nModule.java index 615b7922a3ce2777f79a05c0fd38d3d5d9a902ff..f954ab56a51a6dbd49eb91f6b3138f04a4951d6e 100644 --- a/src/main/java/org/olat/core/util/i18n/I18nModule.java +++ b/src/main/java/org/olat/core/util/i18n/I18nModule.java @@ -129,7 +129,7 @@ public class I18nModule extends AbstractOLATModule implements Destroyable { private I18nModule(CoordinatorManager coordinatorManager) { super(); this.coordinatorManager = coordinatorManager; - if (INSTANCE != null) { throw new OLATRuntimeException("Tried to construct I18nModule, but module was already loaded!", null); } + if (INSTANCE != null && !Settings.isJUnitTest()) { throw new OLATRuntimeException("Tried to construct I18nModule, but module was already loaded!", null); } INSTANCE = this; } diff --git a/src/test/java/olat.local.properties b/src/test/java/olat.local.properties index 136c777ff02faac2e56fbe6e72c63415af7712cd..08c62816280a584d48e966da0d20d7aa64069a33 100644 --- a/src/test/java/olat.local.properties +++ b/src/test/java/olat.local.properties @@ -10,7 +10,7 @@ enabledLanguages=all localization.cache=false is.translation.server=enabled # i18n test case needs the olat3 source dir. Assumes that it's available relative to olatcore -i18n.application.src.dir=${olatcore.src}/../../../../olat3/webapp/WEB-INF/src +i18n.application.src.dir=${olatcore.src} i18n.core.src.dir=${olatcore.src} # Change this path to the i18n projects if you have them configured i18n.application.opt.src.dir=${i18n.application.src.dir} diff --git a/src/test/java/org/olat/core/test/_spring/coordinatorMock.xml b/src/test/java/org/olat/core/test/_spring/coordinatorMock.xml index 35a15e7ceb96ef51517438c34be03a8a72faa661..22cb8c1f303d8818f5fdbc6eea9ba97efe67834a 100644 --- a/src/test/java/org/olat/core/test/_spring/coordinatorMock.xml +++ b/src/test/java/org/olat/core/test/_spring/coordinatorMock.xml @@ -11,6 +11,6 @@ <context:property-placeholder location="classpath:serviceconfig/olat.properties, classpath:olat.local.properties" /> <context:annotation-config /> -<bean id="coordinatorManager" class="org.olat.core.test.CoordinatorManagerMock" /> +<bean id="coordinatorManager" class="org.olat.test.CoordinatorManagerMock" /> </beans> \ No newline at end of file diff --git a/src/test/java/org/olat/core/test/_spring/webapphelperMock.xml b/src/test/java/org/olat/core/test/_spring/webapphelperMock.xml index 8bb26223835b9cb53166370705303c568cd5f417..ea316754603a65df6127d21f143e5f4ca0b8aa8e 100644 --- a/src/test/java/org/olat/core/test/_spring/webapphelperMock.xml +++ b/src/test/java/org/olat/core/test/_spring/webapphelperMock.xml @@ -12,10 +12,7 @@ <bean id ="org.olat.core.util.WebappHelper" class="org.olat.core.util.WebappHelper" init-method="init" destroy-method="destroy"> <!-- relative path from the webapp directory to the source directory (only relavant for development/debuging mode) --> - <property name="relPathToSrc" value="" /> - <!-- set to jar when olatcore is used as jar or to absolute path pointing to olatcore - source during development. This field is modified automatically by build.xml --> - <property name="coreSourcePath" value="${olatcore.src}" /> + <property name="fullPathToSrc" value="${project.build.home.directory}/src/main/java" /> <property name="instanceId" value="myolat"/> <property name="nodeId" value="1"/> <property name="userDataRoot" value=""/> diff --git a/src/test/java/org/olat/core/util/i18n/I18nTest.java b/src/test/java/org/olat/core/util/i18n/I18nTest.java index 75b20db93925aecdfb3212ac3bbd2fd04838c4f2..a6d7a0d8a05e13beb8a1fd2d68c1f0c7c1d0fcbb 100644 --- a/src/test/java/org/olat/core/util/i18n/I18nTest.java +++ b/src/test/java/org/olat/core/util/i18n/I18nTest.java @@ -467,6 +467,7 @@ public class I18nTest extends OlatcoreTestCaseWithMocking { @Test public void testGetPropertyFile() { if (I18nModule.isTransToolEnabled()) { File baseDir = I18nModule.getPropertyFilesBaseDir(i18nMgr.getLocaleOrDefault("de"), "org.olat.core"); + assertNotNull(baseDir); File file = i18nMgr.getPropertiesFile(i18nMgr.getLocaleOrDefault("de"), "org.olat.core", baseDir); assertTrue(file.exists()); // test get metadata file diff --git a/src/test/java/org/olat/course/auditing/UserNodeAuditManagerTest.java b/src/test/java/org/olat/course/auditing/UserNodeAuditManagerTest.java index 292f542c3732acd3467e75e2d3f4e62947525324..3950985b60a009beb274b3bd940a32029a006d82 100644 --- a/src/test/java/org/olat/course/auditing/UserNodeAuditManagerTest.java +++ b/src/test/java/org/olat/course/auditing/UserNodeAuditManagerTest.java @@ -65,7 +65,7 @@ public class UserNodeAuditManagerTest extends OlatTestCase { } } - @After + //@After public void tearDown() throws Exception { //remove demo course on file system //FIXME: this does not remove all data from the database, see repositoryManger diff --git a/src/test/java/org/olat/note/NoteTest.java b/src/test/java/org/olat/note/NoteTest.java index 44fc33147eb8574789bce89dc42eaaa715d901ec..bc5fb2600287ec457382b557c474884e28acb0e4 100644 --- a/src/test/java/org/olat/note/NoteTest.java +++ b/src/test/java/org/olat/note/NoteTest.java @@ -25,6 +25,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.List; +import java.util.UUID; import org.apache.log4j.Logger; import org.junit.After; @@ -64,7 +65,8 @@ public class NoteTest extends OlatTestCase implements OLATResourceable { try { nm = NoteManager.getInstance(); // identity with null User should be ok for test case - identity = JunitTestHelper.createAndPersistIdentityAsUser("foo"); + String name = UUID.randomUUID().toString().replace("-", ""); + identity = JunitTestHelper.createAndPersistIdentityAsUser(name); res = OLATResourceManager.getInstance().createOLATResourceInstance(this); OLATResourceManager.getInstance().saveOLATResource(res); @@ -107,7 +109,7 @@ public class NoteTest extends OlatTestCase implements OLATResourceable { nm.deleteNote(note); - List notes = nm.listUserNotes(identity); + List<Note> notes = nm.listUserNotes(identity); assertTrue(notes.size()==0); } diff --git a/src/test/java/org/olat/test/OlatJerseyTestCase.java b/src/test/java/org/olat/test/OlatJerseyTestCase.java index df1736b0beec821187f6a223612acf69226ae612..0416cb8e4880b31754b0c06c3d5bf24e46d5e504 100644 --- a/src/test/java/org/olat/test/OlatJerseyTestCase.java +++ b/src/test/java/org/olat/test/OlatJerseyTestCase.java @@ -82,7 +82,8 @@ public abstract class OlatJerseyTestCase extends OlatTestCase { public final static String HOST = "localhost"; public final static String PROTOCOL = "http"; - private GrizzlyWebServer webServer; + private static boolean webServerStarted = false; + private static GrizzlyWebServer webServer; @Autowired private RestModule restModule; @@ -99,19 +100,21 @@ public abstract class OlatJerseyTestCase extends OlatTestCase { * Instantiates the Grizzly Web Server */ private void instantiateGrizzlyWebServer() { - webServer = new GrizzlyWebServer(PORT); - ServletAdapter sa = new ServletAdapter(); - Servlet servletInstance = null; - try { - servletInstance = (HttpServlet)Class.forName("com.sun.jersey.spi.container.servlet.ServletContainer").newInstance(); - } catch (Exception ex) { - log.error("Cannot instantiate the Grizzly Servlet Container", ex); + if(webServer == null) { + webServer = new GrizzlyWebServer(PORT); + ServletAdapter sa = new ServletAdapter(); + Servlet servletInstance = null; + try { + servletInstance = (HttpServlet)Class.forName("com.sun.jersey.spi.container.servlet.ServletContainer").newInstance(); + } catch (Exception ex) { + log.error("Cannot instantiate the Grizzly Servlet Container", ex); + } + sa.setServletInstance(servletInstance); + sa.addFilter(new RestApiLoginFilter(), "jerseyfilter", null); + sa.addInitParameter("javax.ws.rs.Application", OlatRestApplication.class.getName()); + sa.setContextPath("/" + CONTEXT_PATH); + webServer.addGrizzlyAdapter(sa, null); } - sa.setServletInstance(servletInstance); - sa.addFilter(new RestApiLoginFilter(), "jerseyfilter", null); - sa.addInitParameter("javax.ws.rs.Application", OlatRestApplication.class.getName()); - sa.setContextPath("/" + CONTEXT_PATH); - webServer.addGrizzlyAdapter(sa, null); } protected URI getBaseURI() { @@ -129,7 +132,9 @@ public abstract class OlatJerseyTestCase extends OlatTestCase { log.info("Starting the Grizzly Web Container..."); try { - webServer.start(); + if(!webServerStarted) { + webServer.start(); + } } catch (IOException ex) { log.error("Cannot start the Grizzly Web Container"); } @@ -144,8 +149,8 @@ public abstract class OlatJerseyTestCase extends OlatTestCase { @After public void tearDown() throws Exception { log.info("Stopping the Grizzly Web Container..."); - webServer.stop(); - webServer.getSelectorThread().stopEndpoint(); + //webServer.stop(); + //webServer.getSelectorThread().stopEndpoint(); } /** diff --git a/src/test/java/org/olat/test/_spring/coordinatorMock.xml b/src/test/java/org/olat/test/_spring/coordinatorMock.xml index 35a15e7ceb96ef51517438c34be03a8a72faa661..22cb8c1f303d8818f5fdbc6eea9ba97efe67834a 100644 --- a/src/test/java/org/olat/test/_spring/coordinatorMock.xml +++ b/src/test/java/org/olat/test/_spring/coordinatorMock.xml @@ -11,6 +11,6 @@ <context:property-placeholder location="classpath:serviceconfig/olat.properties, classpath:olat.local.properties" /> <context:annotation-config /> -<bean id="coordinatorManager" class="org.olat.core.test.CoordinatorManagerMock" /> +<bean id="coordinatorManager" class="org.olat.test.CoordinatorManagerMock" /> </beans> \ No newline at end of file diff --git a/src/test/java/org/olat/test/_spring/webapphelperMock.xml b/src/test/java/org/olat/test/_spring/webapphelperMock.xml index 04c566ca9ff3de252a08a151256fb04da7828317..15b2740285f8cd46f121bb4f9ccbadc917e761ae 100644 --- a/src/test/java/org/olat/test/_spring/webapphelperMock.xml +++ b/src/test/java/org/olat/test/_spring/webapphelperMock.xml @@ -12,10 +12,7 @@ <bean id="org.olat.core.util.WebappHelper" class="org.olat.core.util.WebappHelper" init-method="init" destroy-method="destroy"> <!-- relative path from the webapp directory to the source directory (only relavant for development/debuging mode) --> - <property name="relPathToSrc" value="" /> - <!-- set to jar when olatcore is used as jar or to absolute path pointing to olatcore - source during development. This field is modified automatically by build.xml --> - <property name="coreSourcePath" value="${olatcore.src}" /> + <property name="fullPathToSrc" value="${project.build.home.directory}/src/main/java" /> <property name="instanceId" value="myolat"/> <property name="nodeId" value="1"/> <property name="userDataRoot" value=""/> diff --git a/src/test/java/serviceconfig/olat.properties b/src/test/java/serviceconfig/olat.properties deleted file mode 100644 index 16daa71011389b14f91fed827dccfa74a9e660f2..0000000000000000000000000000000000000000 --- a/src/test/java/serviceconfig/olat.properties +++ /dev/null @@ -1 +0,0 @@ -#no default properties for test environment, see olat.local.properties \ No newline at end of file diff --git a/src/test/resources/log4j.remote.properties b/src/test/resources/log4j.remote.properties new file mode 100644 index 0000000000000000000000000000000000000000..b338a238c0a835617c2ca50c87d1697cc252320c --- /dev/null +++ b/src/test/resources/log4j.remote.properties @@ -0,0 +1,9 @@ +# Set root logger level to DEBUG and its only appender to A1. +log4j.rootLogger=INFO, A1 + +# A1 is set to be a ConsoleAppender. +log4j.appender.A1=org.apache.log4j.ConsoleAppender + +# A1 uses PatternLayout. +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x -=oOo=- %m%n