Loading archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/test/java/org/alfresco/demoamp/test/DemoComponentTest.java +35 −25 Original line number Diff line number Diff line package org.alfresco.demoamp.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import org.alfresco.demoamp.DemoComponent; Loading @@ -9,47 +9,55 @@ import org.alfresco.model.ContentModel; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.util.ApplicationContextHelper; import org.apache.log4j.Logger; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.tradeshift.test.remote.Remote; import com.tradeshift.test.remote.RemoteTestRunner; /** * A simple class demonstrating how to run out-of-container tests * loading Alfresco application context. * * @author columbro * This class uses the RemoteTestRunner to try and connect to * localhost:4578 and send the test name and method to be executed on * a running Alfresco. One or more hostnames can be configured in the @Remote * annotation. * * If there is no available remote server to run the test, it falls * back on local running of JUnits. * * For proper functioning the test class file must match exactly * the one deployed in the webapp (either via JRebel or static deployment) * otherwise "incompatible magic value XXXXX" class error loading issues will arise. * * @author Gabriele Columbro * @author Maurizio Pillitu * */ @RunWith(RemoteTestRunner.class) @Remote(runnerClass=SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:alfresco/application-context.xml") public class DemoComponentTest { private static final String ADMIN_USER_NAME = "admin"; static Logger log = Logger.getLogger(DemoComponentTest.class); protected static ApplicationContext applicationContext; protected static DemoComponent demoComponent; protected static NodeService nodeService; @BeforeClass public static void initAppContext() { // TODO: Make testing properly working without need for helpers // TODO: Provide this in an SDK base class ApplicationContextHelper.setUseLazyLoading(false); ApplicationContextHelper.setNoAutoStart(true); applicationContext = ApplicationContextHelper.getApplicationContext(new String[] { "classpath:alfresco/application-context.xml" }); demoComponent = (DemoComponent) applicationContext.getBean("changeme.exampleComponent"); nodeService = (NodeService) applicationContext.getBean("NodeService"); AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER_NAME); log.debug("Sample test logging: If you see this message, means your unit test logging is properly configured. Change it in test-log4j.properties"); log.debug("Sample test logging: Application Context properly loaded"); } @Autowired protected DemoComponent demoComponent; @Autowired @Qualifier("NodeService") protected NodeService nodeService; @Test public void testWiring() { Loading @@ -58,6 +66,7 @@ public class DemoComponentTest { @Test public void testGetCompanyHome() { AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER_NAME); NodeRef companyHome = demoComponent.getCompanyHome(); assertNotNull(companyHome); String companyHomeName = (String) nodeService.getProperty(companyHome, ContentModel.PROP_NAME); Loading @@ -67,6 +76,7 @@ public class DemoComponentTest { @Test public void testChildNodesCount() { AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER_NAME); NodeRef companyHome = demoComponent.getCompanyHome(); int childNodeCount = demoComponent.childNodesCount(companyHome); assertNotNull(childNodeCount); Loading archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/test/resources/rebel.xml 0 → 100644 +22 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="UTF-8"?> <!-- This is a JRebel configuration file, allows hot re-deploying. If you have JRebel you can enable it by setting the following variables: MAVEN_OPTS=-Xms256m -Xmx2G -XX:PermSize=300m -javaagent:${jrebel.dir}/jrebel.jar --> <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd"> <classpath> <dir name="${project.build.outputDirectory}"/> <dir name="${project.build.testOutputDirectory}"/> </classpath> <!-- <web> <link target="/"> <dir name="${project.build.directory}/${project.build.artifactId}/web"/> </link> </web> --> </application> No newline at end of file Loading
archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/test/java/org/alfresco/demoamp/test/DemoComponentTest.java +35 −25 Original line number Diff line number Diff line package org.alfresco.demoamp.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import org.alfresco.demoamp.DemoComponent; Loading @@ -9,47 +9,55 @@ import org.alfresco.model.ContentModel; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.util.ApplicationContextHelper; import org.apache.log4j.Logger; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.tradeshift.test.remote.Remote; import com.tradeshift.test.remote.RemoteTestRunner; /** * A simple class demonstrating how to run out-of-container tests * loading Alfresco application context. * * @author columbro * This class uses the RemoteTestRunner to try and connect to * localhost:4578 and send the test name and method to be executed on * a running Alfresco. One or more hostnames can be configured in the @Remote * annotation. * * If there is no available remote server to run the test, it falls * back on local running of JUnits. * * For proper functioning the test class file must match exactly * the one deployed in the webapp (either via JRebel or static deployment) * otherwise "incompatible magic value XXXXX" class error loading issues will arise. * * @author Gabriele Columbro * @author Maurizio Pillitu * */ @RunWith(RemoteTestRunner.class) @Remote(runnerClass=SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:alfresco/application-context.xml") public class DemoComponentTest { private static final String ADMIN_USER_NAME = "admin"; static Logger log = Logger.getLogger(DemoComponentTest.class); protected static ApplicationContext applicationContext; protected static DemoComponent demoComponent; protected static NodeService nodeService; @BeforeClass public static void initAppContext() { // TODO: Make testing properly working without need for helpers // TODO: Provide this in an SDK base class ApplicationContextHelper.setUseLazyLoading(false); ApplicationContextHelper.setNoAutoStart(true); applicationContext = ApplicationContextHelper.getApplicationContext(new String[] { "classpath:alfresco/application-context.xml" }); demoComponent = (DemoComponent) applicationContext.getBean("changeme.exampleComponent"); nodeService = (NodeService) applicationContext.getBean("NodeService"); AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER_NAME); log.debug("Sample test logging: If you see this message, means your unit test logging is properly configured. Change it in test-log4j.properties"); log.debug("Sample test logging: Application Context properly loaded"); } @Autowired protected DemoComponent demoComponent; @Autowired @Qualifier("NodeService") protected NodeService nodeService; @Test public void testWiring() { Loading @@ -58,6 +66,7 @@ public class DemoComponentTest { @Test public void testGetCompanyHome() { AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER_NAME); NodeRef companyHome = demoComponent.getCompanyHome(); assertNotNull(companyHome); String companyHomeName = (String) nodeService.getProperty(companyHome, ContentModel.PROP_NAME); Loading @@ -67,6 +76,7 @@ public class DemoComponentTest { @Test public void testChildNodesCount() { AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER_NAME); NodeRef companyHome = demoComponent.getCompanyHome(); int childNodeCount = demoComponent.childNodesCount(companyHome); assertNotNull(childNodeCount); Loading
archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/test/resources/rebel.xml 0 → 100644 +22 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="UTF-8"?> <!-- This is a JRebel configuration file, allows hot re-deploying. If you have JRebel you can enable it by setting the following variables: MAVEN_OPTS=-Xms256m -Xmx2G -XX:PermSize=300m -javaagent:${jrebel.dir}/jrebel.jar --> <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd"> <classpath> <dir name="${project.build.outputDirectory}"/> <dir name="${project.build.testOutputDirectory}"/> </classpath> <!-- <web> <link target="/"> <dir name="${project.build.directory}/${project.build.artifactId}/web"/> </link> </web> --> </application> No newline at end of file