From 1448f64560e7b235fc611c29dcb89cf54efd3d51 Mon Sep 17 00:00:00 2001 From: mindthegab Date: Tue, 23 Dec 2014 12:35:05 -0500 Subject: [PATCH] added unit test to repo-amp for consistency --- .../demoamp/test/DemoComponentTest.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/repo-amp/src/test/java/org/alfresco/demoamp/test/DemoComponentTest.java diff --git a/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/repo-amp/src/test/java/org/alfresco/demoamp/test/DemoComponentTest.java b/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/repo-amp/src/test/java/org/alfresco/demoamp/test/DemoComponentTest.java new file mode 100644 index 00000000..cbbfae4c --- /dev/null +++ b/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/repo-amp/src/test/java/org/alfresco/demoamp/test/DemoComponentTest.java @@ -0,0 +1,86 @@ +package org.alfresco.demoamp.test; + + +import static org.junit.Assert.assertEquals; + +import static org.junit.Assert.assertNotNull; + +import org.alfresco.demoamp.DemoComponent; +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.apache.log4j.Logger; +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.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. + * + * 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); + + @Autowired + protected DemoComponent demoComponent; + + @Autowired + @Qualifier("NodeService") + protected NodeService nodeService; + + @Test + public void testWiring() { + assertNotNull(demoComponent); + } + + @Test + public void testGetCompanyHome() { + AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER_NAME); + NodeRef companyHome = demoComponent.getCompanyHome(); + assertNotNull(companyHome); + String companyHomeName = (String) nodeService.getProperty(companyHome, ContentModel.PROP_NAME); + assertNotNull(companyHomeName); + assertEquals("Company Home", companyHomeName); + } + + @Test + public void testChildNodesCount() { + AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER_NAME); + NodeRef companyHome = demoComponent.getCompanyHome(); + int childNodeCount = demoComponent.childNodesCount(companyHome); + assertNotNull(childNodeCount); + // There are 7 folders by default under Company Home + assertEquals(7, childNodeCount); + } + +}