Merge pull request #215 from michaelsuzukisagi/master

Adding integration test profile
This commit is contained in:
Michael
2014-09-11 09:47:03 +01:00
15 changed files with 524 additions and 136 deletions

1
.gitignore vendored
View File

@@ -12,3 +12,4 @@ pom.xml.next
release.properties
**.settings
**bin
**.DS_Store

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>alfresco-amp-archetype</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>

View File

@@ -53,6 +53,24 @@
<include>**/*.xml</include>
</includes>
</fileSet>
<fileSet filtered="false" packaged="false" encoding="UTF-8">
<directory>src/integration/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="false" encoding="UTF-8">
<directory>src/integration/resources</directory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
<fileSet filtered="false" encoding="UTF-8">
<directory>src/integration/properties</directory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8">
<directory></directory>
<includes>

View File

@@ -73,6 +73,16 @@
<groupId>${alfresco.groupId}</groupId>
<artifactId>alfresco-repository</artifactId>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.39.0</version>
<exclusions>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api-2.5</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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());
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<By> fluentWait = new FluentWait<By>(by);
fluentWait.pollingEvery(interval, TimeUnit.MILLISECONDS);
fluentWait.withTimeout(limit, TimeUnit.MILLISECONDS);
fluentWait.until(new Predicate<By>()
{
public boolean apply(By by)
{
try
{
return driver.findElement(by).isDisplayed();
}
catch (NoSuchElementException ex)
{
return false;
}
}
});
return driver.findElement(by);
}
}

View File

@@ -1 +1,6 @@
Message: ${message}
<html>
<body>
<h1 id="demo-title">Welcome to Demoamp</h1>
<p id="demo-message">${demoMessage}</p>
</body>
</html>

View File

@@ -22,13 +22,8 @@
<bean id="changeme.exampleBean" class="org.alfresco.demoamp.Demo" init-method="init" />
<!-- A simple module component that will be executed once -->
<bean id="changeme.exampleComponent" class="org.alfresco.demoamp.DemoComponent" parent="module.baseComponent" >
<property name="moduleId" value="${project.artifactId}" /> <!-- See module.properties -->
<property name="name" value="exampleComponent" />
<property name="description" value="A demonstration component" />
<property name="sinceVersion" value="2.0" />
<property name="appliesFromVersion" value="2.0" />
<property name="nodeService" ref="NodeService" />
<bean id="webscript.webscript.get" class="org.alfresco.demoamp.DemoComponent" parent="webscript">
<property name="nodeService" ref="NodeService"/>
<property name="nodeLocatorService" ref="nodeLocatorService" />
</bean>

View File

@@ -25,14 +25,30 @@
package org.alfresco.demoamp;
/**
* This class does nothing except dump some output to <i>system.out</i>.
* This is a simple class that generates a message for demo hello world,
* and also outputs to <i>system.out</i> 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);
}
}

View File

@@ -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<String, Object> 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<String, Object> model = new HashMap<String, Object>();
model.put("demoMessage", msg);
return model;
}
}

View File

@@ -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);

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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());
}
}

View File

@@ -126,6 +126,7 @@
<h2.version>1.3.174</h2.version>
<h2-support.version>1.5</h2-support.version>
<junit.version>4.11</junit.version>
<skip.unit.test>false</skip.unit.test>
</properties>
<!-- This repository is only needed to retrieve Alfresco parent POM.
@@ -335,11 +336,11 @@
<directory>src/main/resources</directory>
<filtering>${app.filtering.enabled}</filtering>
</resource>
<resource>
<directory>${app.amp.folder}</directory>
<targetPath>${app.amp.output.folder}</targetPath>
<filtering>${app.filtering.enabled}</filtering>
</resource>
<resource>
<directory>${app.amp.folder}</directory>
<targetPath>${app.amp.output.folder}</targetPath>
<filtering>${app.filtering.enabled}</filtering>
</resource>
</resources>
<testResources>
<testResource>
@@ -487,7 +488,6 @@
</plugin>
</plugins>
</build>
</profile>
<!-- Enables alfresco testing dependencies if a src/test/java folder is found, by adding appropriate dependencies -->
@@ -516,40 +516,40 @@
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- Add RAD capabilities for remote JUnit test running. Scope=test so the custom JUnit remote runner is found in the Maven test classpath -->
<dependency>
<groupId>org.alfresco.maven</groupId>
<artifactId>alfresco-rad</artifactId>
<version>${maven.alfresco.version}</version>
<scope>test</scope>
</dependency>
<!--
| Requires this explicit test dependency, for a Spring 3.0.5 bug
| See https://jira.springsource.org/browse/SPR-8527
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.6.RELEASE</version>
<scope>provided</scope>
</dependency>
<!-- SDK AMP Testing Dependencies -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>tk.skuro.alfresco</groupId>
<artifactId>h2-support</artifactId>
<version>${h2-support.version}</version>
<scope>test</scope>
</dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- Add RAD capabilities for remote JUnit test running. Scope=test so the custom JUnit remote runner is found in the Maven test classpath -->
<dependency>
<groupId>org.alfresco.maven</groupId>
<artifactId>alfresco-rad</artifactId>
<version>${maven.alfresco.version}</version>
<scope>test</scope>
</dependency>
<!--
| Requires this explicit test dependency, for a Spring 3.0.5 bug
| See https://jira.springsource.org/browse/SPR-8527
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.6.RELEASE</version>
<scope>provided</scope>
</dependency>
<!-- SDK AMP Testing Dependencies -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>tk.skuro.alfresco</groupId>
<artifactId>h2-support</artifactId>
<version>${h2-support.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
@@ -694,11 +694,11 @@
<artifactId>slf4j-log4j12</artifactId>
<version>${app.slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.alfresco.maven</groupId>
<artifactId>alfresco-rad</artifactId>
<version>${maven.alfresco.version}</version>
</dependency>
<dependency>
<groupId>org.alfresco.maven</groupId>
<artifactId>alfresco-rad</artifactId>
<version>${maven.alfresco.version}</version>
</dependency>
</dependencies>
</profile>
@@ -771,6 +771,127 @@
</plugins>
</build>
</profile>
<profile>
<id>integration</id>
<activation>
<file>
<exists>src/integration/java</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-integration-resource</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integration/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>add-integration-resources</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/integration-classes</outputDirectory>
<resources>
<resource>
<directory>src/integration/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>ui-test</id>
<properties>
<maven.tomcat.fork>true</maven.tomcat.fork>
<skipTests>false</skipTests>
</properties>
<build>
<plugins>
<!-- compile integration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>compile-integration-test</id>
<!--
Do not change the phase as it wont compile unless in the right phase so
mvn install -Pui-test wont work.
-->
<phase>compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<compilerArguments>
<d>${project.build.directory}/integration-classes</d>
</compilerArguments>
</configuration>
</execution>
</executions>
</plugin>
<!-- Force to skip unit test -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<skipTests>${skip.unit.test}</skipTests>
</configuration>
</plugin>
<!-- Run integration test with failsafe, with config to fail build if test failure -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<configuration>
<testSourceDirectory>src/integration/java</testSourceDirectory>
<testClassesDirectory>${project.build.directory}/integration-classes</testClassesDirectory>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- Does any SDK dev environment preparation (e.g. spring-loaded download) -->
<profile>
<id>setup</id>