From cbb5adc8c8fa692e4bc4bf4266784db48bf63fe1 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Fri, 14 Oct 2011 09:48:55 +0200 Subject: [PATCH] FXOLAT-207: fix some erros in Spring configuration specific to tests, make the Grizzly start only once to prevent memory leaks, update pom to use the resources in src/test/java..., fix some path in olat.local.properties (test specific) --- pom.xml | 24 ++++++++++++ .../org/olat/core/util/i18n/I18nModule.java | 2 +- src/test/java/olat.local.properties | 2 +- .../core/test/_spring/coordinatorMock.xml | 2 +- .../core/test/_spring/webapphelperMock.xml | 5 +-- .../org/olat/core/util/i18n/I18nTest.java | 1 + .../auditing/UserNodeAuditManagerTest.java | 2 +- src/test/java/org/olat/note/NoteTest.java | 6 ++- .../org/olat/test/OlatJerseyTestCase.java | 37 +++++++++++-------- .../org/olat/test/_spring/coordinatorMock.xml | 2 +- .../olat/test/_spring/webapphelperMock.xml | 5 +-- src/test/java/serviceconfig/olat.properties | 1 - src/test/resources/log4j.remote.properties | 9 +++++ 13 files changed, 66 insertions(+), 32 deletions(-) delete mode 100644 src/test/java/serviceconfig/olat.properties create mode 100644 src/test/resources/log4j.remote.properties diff --git a/pom.xml b/pom.xml index 566f14d1287..b31e76866af 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 615b7922a3c..f954ab56a51 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 136c777ff02..08c62816280 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 35a15e7ceb9..22cb8c1f303 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 8bb26223835..ea316754603 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 75b20db9392..a6d7a0d8a05 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 292f542c373..3950985b60a 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 44fc33147eb..bc5fb260028 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 df1736b0bee..0416cb8e488 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 35a15e7ceb9..22cb8c1f303 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 04c566ca9ff..15b2740285f 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 16daa710113..00000000000 --- 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 00000000000..b338a238c0a --- /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 -- GitLab