diff --git a/.gitignore b/.gitignore index cf317585..3c5c31a2 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ pom.xml.next release.properties **.settings **bin +**.DS_Store diff --git a/archetypes/alfresco-amp-archetype/.classpath b/archetypes/alfresco-amp-archetype/.classpath deleted file mode 100644 index b4ac4c6f..00000000 --- a/archetypes/alfresco-amp-archetype/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/archetypes/alfresco-amp-archetype/.project b/archetypes/alfresco-amp-archetype/.project deleted file mode 100644 index 365fc830..00000000 --- a/archetypes/alfresco-amp-archetype/.project +++ /dev/null @@ -1,29 +0,0 @@ - - - alfresco-amp-archetype - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.maven.ide.eclipse.maven2Builder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.m2e.core.maven2Nature - org.eclipse.jdt.core.javanature - org.maven.ide.eclipse.maven2Nature - - diff --git a/archetypes/alfresco-amp-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/archetypes/alfresco-amp-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml index 4cd86986..a0437878 100644 --- a/archetypes/alfresco-amp-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/archetypes/alfresco-amp-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -53,6 +53,24 @@ **/*.xml + + src/integration/java + + **/*.java + + + + src/integration/resources + + **/* + + + + src/integration/properties + + **/* + + diff --git a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/pom.xml b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/pom.xml index 02997a85..d478e2b0 100644 --- a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/pom.xml +++ b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/pom.xml @@ -73,6 +73,16 @@ ${alfresco.groupId} alfresco-repository + + org.seleniumhq.selenium + selenium-java + 2.39.0 + + + org.mortbay.jetty + servlet-api-2.5 + + + - diff --git a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/integration/java/org/alfresco/demoamp/DemoTestIT.java b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/integration/java/org/alfresco/demoamp/DemoTestIT.java new file mode 100644 index 00000000..72925b20 --- /dev/null +++ b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/integration/java/org/alfresco/demoamp/DemoTestIT.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2005-2012 Alfresco Software Limited. + * This file is part of Alfresco + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.demoamp; + +import org.alfresco.demoamp.po.DemoPage; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; + +public class DemoTestIT +{ + private static WebDriver driver; + + @BeforeClass + public static void setup() + { + //Create WebDriver + driver = new FirefoxDriver(); + //Login and obtain ticket + driver.get("http://localhost:8080/alfresco/service/api/login?u=admin&pw=admin"); + WebElement ticket = driver.findElement(By.tagName("ticket")); + String token =String.format("?alf_ticket=%s",ticket.getText()); + //Navigate to sample page with token + driver.get("http://localhost:8080/alfresco/service/sample/helloworld" + token); + } + + @AfterClass + public static void teardown() + { + if(driver != null) + { + driver.quit(); + } + } + + @Test + public void titleDisplayed() + { + DemoPage page = new DemoPage(driver); + Assert.assertNotNull(page); + Assert.assertTrue(page.isTitleVisible()); + Assert.assertEquals("Welcome to Demoamp", page.getTitle()); + } + + /** + * Message should include the directory name + * and number of folders currently in that directory. + */ + @Test + public void messageIsDisplayed() + { + DemoPage page = new DemoPage(driver); + Assert.assertNotNull(page); + Assert.assertTrue(page.isMessageVisible()); + Assert.assertEquals("Company Home has 7 folders", page.getMessage()); + } + + @Test + public void findLogo() + { + DemoPage page = new DemoPage(driver); + Assert.assertFalse(page.hasLogo()); + } +} diff --git a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/integration/java/org/alfresco/demoamp/po/DemoPage.java b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/integration/java/org/alfresco/demoamp/po/DemoPage.java new file mode 100644 index 00000000..fcf59a91 --- /dev/null +++ b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/integration/java/org/alfresco/demoamp/po/DemoPage.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2005-2012 Alfresco Software Limited. + * This file is part of Alfresco + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.demoamp.po; + +import java.util.concurrent.TimeUnit; + +import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.TimeoutException; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.FluentWait; + +import com.google.common.base.Predicate; +/** + * Demo page object that encapsulates the demo webscript hello world page. + * @author Michael Suzuki + * + */ +public class DemoPage +{ + private static final By TITLE_LOCATOR = By.id("demo-title"); + private static final By MESSAGE_LOCATOR = By.id("demo-message"); + + private WebDriver driver; + /** + * Constructor + * @param driver + */ + public DemoPage(WebDriver driver) + { + this.driver = driver; + } + + public boolean isTitleVisible() + { + return driver.findElement(TITLE_LOCATOR).isDisplayed(); + } + + public String getTitle() + { + return driver.findElement(TITLE_LOCATOR).getText(); + } + public boolean isMessageVisible() + { + return driver.findElement(MESSAGE_LOCATOR).isDisplayed(); + } + public String getMessage() + { + return driver.findElement(MESSAGE_LOCATOR).getText(); + } + /** + * Sample find with wait element to keep searching for a set time. + * @return true if the logo is exists + */ + public boolean hasLogo() + { + try + { + return findAndWait(By.id("logo"), 6000, 1000).isDisplayed(); + + } + catch(TimeoutException te){ } + return false; + } + /** + * Mechanism to keep looking for an element on the page. + * @param by selector + * @param limit max time to wait in ms + * @param interval time to wait between calls in ms + * @return + */ + public WebElement findAndWait(final By by, final long limit, final long interval) + { + FluentWait fluentWait = new FluentWait(by); + fluentWait.pollingEvery(interval, TimeUnit.MILLISECONDS); + fluentWait.withTimeout(limit, TimeUnit.MILLISECONDS); + fluentWait.until(new Predicate() + { + public boolean apply(By by) + { + try + { + return driver.findElement(by).isDisplayed(); + } + catch (NoSuchElementException ex) + { + return false; + } + } + }); + return driver.findElement(by); + } +} diff --git a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/amp/config/alfresco/extension/templates/webscripts/webscript.get.html.ftl b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/amp/config/alfresco/extension/templates/webscripts/webscript.get.html.ftl index f4672ea6..ca0cf4e9 100644 --- a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/amp/config/alfresco/extension/templates/webscripts/webscript.get.html.ftl +++ b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/amp/config/alfresco/extension/templates/webscripts/webscript.get.html.ftl @@ -1 +1,6 @@ -Message: ${message} \ No newline at end of file + + +

Welcome to Demoamp

+

${demoMessage}

+ + \ No newline at end of file diff --git a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/amp/config/alfresco/extension/templates/webscripts/webscript.get.js b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/amp/config/alfresco/extension/templates/webscripts/webscript.get.js deleted file mode 100644 index 1c5dc480..00000000 --- a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/amp/config/alfresco/extension/templates/webscripts/webscript.get.js +++ /dev/null @@ -1 +0,0 @@ -model["message"] = "Hello World!"; \ No newline at end of file diff --git a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/amp/config/alfresco/module/__artifactId__/context/service-context.xml b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/amp/config/alfresco/module/__artifactId__/context/service-context.xml index 10441e94..a51a1014 100644 --- a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/amp/config/alfresco/module/__artifactId__/context/service-context.xml +++ b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/amp/config/alfresco/module/__artifactId__/context/service-context.xml @@ -22,13 +22,8 @@ - - - - - - - + + diff --git a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/java/org/alfresco/demoamp/Demo.java b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/java/org/alfresco/demoamp/Demo.java index 402f7195..765e07f4 100644 --- a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/java/org/alfresco/demoamp/Demo.java +++ b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/java/org/alfresco/demoamp/Demo.java @@ -25,14 +25,30 @@ package org.alfresco.demoamp; /** - * This class does nothing except dump some output to system.out. + * This is a simple class that generates a message for demo hello world, + * and also outputs to system.out a message. * NB: This code is taken from Alfresco Eclipse SDK Samples * @author Derek Hulley + * @author Michael Suzuki */ public class Demo { - public void init() - { - System.out.println("SDK Demo AMP class has been loaded"); - } + public void init() + { + System.out.println("SDK Demo AMP class has been loaded"); + } + /** + * Generates a message. + * @param directoryName String directory identifier + * @param folders int count of folders for that directory + * @return String message + */ + public static String generateMessage(final String directoryName, final int folders) + { + if(directoryName == null || directoryName.isEmpty()) + { + throw new RuntimeException("Directory name is required"); + } + return String.format("%s has %d folders", directoryName, folders); + } } diff --git a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/java/org/alfresco/demoamp/DemoComponent.java b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/java/org/alfresco/demoamp/DemoComponent.java index 45896271..06be0cf1 100644 --- a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/java/org/alfresco/demoamp/DemoComponent.java +++ b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/main/java/org/alfresco/demoamp/DemoComponent.java @@ -1,27 +1,33 @@ /* - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.alfresco.demoamp; +import java.util.HashMap; +import java.util.Map; -import org.alfresco.repo.module.AbstractModuleComponent; +import org.alfresco.model.ContentModel; import org.alfresco.repo.nodelocator.NodeLocatorService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.extensions.webscripts.DeclarativeWebScript; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptRequest; + /** * A basic component that will be started for this module. @@ -30,32 +36,22 @@ import org.apache.commons.logging.LogFactory; * * @author Gabriele Columbro * @author Maurizio Pillitu + * @author Michael Suzuki */ -public class DemoComponent extends AbstractModuleComponent +public class DemoComponent extends DeclarativeWebScript { Log log = LogFactory.getLog(DemoComponent.class); - private NodeService nodeService; - private NodeLocatorService nodeLocatorService; - public void setNodeService(NodeService nodeService) { + public void setNodeService(NodeService nodeService) + { this.nodeService = nodeService; } - public void setNodeLocatorService(NodeLocatorService nodeLocatorService) { - this.nodeLocatorService = nodeLocatorService; - } - - /** - * Bogus component execution - */ - @Override - protected void executeInternal() throws Throwable + public void setNodeLocatorService(NodeLocatorService nodeLocatorService) { - System.out.println("DemoComponent has been executed"); - log.debug("Test debug logging. Congratulation your AMP is working"); - log.info("This is only for information purposed. Better remove me from the log in Production"); + this.nodeLocatorService = nodeLocatorService; } /** @@ -76,8 +72,23 @@ public class DemoComponent extends AbstractModuleComponent * @return */ public NodeRef getCompanyHome() - { return nodeLocatorService.getNode("companyhome", null, null); } + /** + * Binding data to webscript demoamp. + * @param req webscript request + * @param status + * @return {@link java.util.Map} data binding + */ + protected Map executeImpl(WebScriptRequest req, Status status ) + { + NodeRef companyHome = getCompanyHome(); + String companyHomeName = (String) nodeService.getProperty(companyHome, ContentModel.PROP_NAME); + int directoryCount = childNodesCount(companyHome); + String msg = Demo.generateMessage(companyHomeName, directoryCount); + Map model = new HashMap(); + model.put("demoMessage", msg); + return model; + } } diff --git a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/test/java/org/alfresco/demoamp/test/DemoComponentTest.java b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/test/java/org/alfresco/demoamp/DemoComponentTest.java similarity index 88% rename from archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/test/java/org/alfresco/demoamp/test/DemoComponentTest.java rename to archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/test/java/org/alfresco/demoamp/DemoComponentTest.java index cbbfae4c..4f512105 100644 --- a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/test/java/org/alfresco/demoamp/test/DemoComponentTest.java +++ b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/test/java/org/alfresco/demoamp/DemoComponentTest.java @@ -1,4 +1,4 @@ -package org.alfresco.demoamp.test; +package org.alfresco.demoamp; import static org.junit.Assert.assertEquals; @@ -45,7 +45,8 @@ import com.tradeshift.test.remote.RemoteTestRunner; @RunWith(RemoteTestRunner.class) @Remote(runnerClass=SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:alfresco/application-context.xml") -public class DemoComponentTest { +public class DemoComponentTest +{ private static final String ADMIN_USER_NAME = "admin"; @@ -59,13 +60,15 @@ public class DemoComponentTest { protected NodeService nodeService; @Test - public void testWiring() { + public void testWiring() + { assertNotNull(demoComponent); } @Test - public void testGetCompanyHome() { - AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER_NAME); + public void testGetCompanyHome() + { + AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER_NAME); NodeRef companyHome = demoComponent.getCompanyHome(); assertNotNull(companyHome); String companyHomeName = (String) nodeService.getProperty(companyHome, ContentModel.PROP_NAME); @@ -74,8 +77,9 @@ public class DemoComponentTest { } @Test - public void testChildNodesCount() { - AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER_NAME); + public void testChildNodesCount() + { + AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER_NAME); NodeRef companyHome = demoComponent.getCompanyHome(); int childNodeCount = demoComponent.childNodesCount(companyHome); assertNotNull(childNodeCount); diff --git a/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/test/java/org/alfresco/demoamp/DemoTest.java b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/test/java/org/alfresco/demoamp/DemoTest.java new file mode 100644 index 00000000..5e2b1c3a --- /dev/null +++ b/archetypes/alfresco-amp-archetype/src/main/resources/archetype-resources/src/test/java/org/alfresco/demoamp/DemoTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2005-2012 Alfresco Software Limited. + * This file is part of Alfresco + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.demoamp; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + + +/**s + * Hello world demo unit test, show the basics of junit and unit testing. + * Create the message to display on hello world webscript. + * @author Michael Suzuki + * + */ +@RunWith(JUnit4.class) +public class DemoTest +{ + @Test + public void init() + { + Demo demo = new Demo(); + Assert.assertNotNull(demo); + } + + @Test(expected = RuntimeException.class) + public void initWithNull() + { + Demo.generateMessage(null, 10); + } + @Test + public void toStringTest() + { + String msg = Demo.generateMessage("Home", 10); + Assert.assertNotNull(msg); + Assert.assertEquals("Home has 10 folders",msg.toString()); + } + @Test + public void negativeValue() + { + String msg = Demo.generateMessage("Home", -10); + Assert.assertNotNull(msg); + Assert.assertEquals("Home has -10 folders",msg.toString()); + } +} diff --git a/poms/alfresco-sdk-parent/pom.xml b/poms/alfresco-sdk-parent/pom.xml index 715e097a..8820c333 100644 --- a/poms/alfresco-sdk-parent/pom.xml +++ b/poms/alfresco-sdk-parent/pom.xml @@ -126,6 +126,7 @@ 1.3.174 1.5 4.11 + false @@ -516,40 +516,40 @@ - junit - junit - test - - - - org.alfresco.maven - alfresco-rad - ${maven.alfresco.version} - test - - - - org.springframework - spring-context - 3.0.6.RELEASE - provided - - - - com.h2database - h2 - ${h2.version} - test - - - tk.skuro.alfresco - h2-support - ${h2-support.version} - test - + junit + junit + test + + + + org.alfresco.maven + alfresco-rad + ${maven.alfresco.version} + test + + + + org.springframework + spring-context + 3.0.6.RELEASE + provided + + + + com.h2database + h2 + ${h2.version} + test + + + tk.skuro.alfresco + h2-support + ${h2-support.version} + test + @@ -694,11 +694,11 @@ slf4j-log4j12 ${app.slf4j.version} - - org.alfresco.maven - alfresco-rad - ${maven.alfresco.version} - + + org.alfresco.maven + alfresco-rad + ${maven.alfresco.version} + @@ -771,6 +771,127 @@ + + integration + + + src/integration/java + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.9.1 + + + add-integration-resource + generate-sources + + add-test-source + + + + src/integration/java + + + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + add-integration-resources + generate-resources + + copy-resources + + + ${project.build.directory}/integration-classes + + + src/integration/resources + + + + + + + + + + + ui-test + + true + false + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + + compile-integration-test + + compile + + testCompile + + + + ${project.build.directory}/integration-classes + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.17 + + ${skip.unit.test} + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.17 + + src/integration/java + ${project.build.directory}/integration-classes + + + + integration-test + + integration-test + + + + verify + + verify + + + + + + + setup