Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

junit tests through mock #596

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion archetypes/alfresco-allinone-archetype/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.alfresco.maven</groupId>
<artifactId>alfresco-sdk-aggregator</artifactId>
<version>4.1.0-SNAPSHOT</version>
<version>4.2.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
<include>**/*-context.xml</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="false" encoding="UTF-8">
<directory>src/test/resources</directory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
</fileSets>
</module>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
backup.extension=bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
<import resource="classpath:test-context.xml" />
<import
resource="classpath:alfresco/module/${artifactId}/context/service-context.xml" />
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ db.driver=org.postgresql.Driver
# alfresco/tomcat/shared/classes/alfresco-global.properties.
#
index.subsystem.name=solr6
solr.host=${rootArtifactId}-ass
solr.host=${rootArtifactId}-search
solr.port=8983
solr.secureComms=none

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/**
* Copyright (C) 2017 Alfresco Software Limited.
* <p/>
* This file is part of the Alfresco SDK project.
* <p/>
* Licensed 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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 ${package}.platformsample;

import java.util.List;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.beans.factory.annotation.Autowired;

/**
* A basic component that will create a backup of a content.
* Only choose the extension for the backup in your
* alfresco-global.properties
*
* @author Luca Stancapiano
*/
public class BackupAction extends ActionExecuterAbstractBase {

public static String DOCUMENT_NAME = "documentName";

@Autowired
private FileFolderService fileFolderService;

private String extension;

@Override
public void executeImpl(Action action, NodeRef actionedUponNodeRef) {
String documentName = (String) action.getParameterValue(DOCUMENT_NAME);
fileFolderService.create(actionedUponNodeRef, documentName + "." + extension, ContentModel.TYPE_CONTENT);

}

@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
// TODO Auto-generated method stub

}

public void setExtension(String extension) {
this.extension = extension;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
<property name="nodeService" ref="NodeService" />
<property name="nodeLocatorService" ref="nodeLocatorService" />
</bean>

<bean id="backupAction" class="${package}.platformsample.BackupAction"
parent="action-executer">
<property name="extension">
<value>${backup.extension}</value>
</property>
</bean>


</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#set($symbol_pound='#')
#set($symbol_dollar='$')
#set($symbol_escape='\' )
/**
* Copyright (C) 2017 Alfresco Software Limited.
* <p/>
* This file is part of the Alfresco SDK project.
* <p/>
* Licensed 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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 ${package}.platformsample;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import org.alfresco.mock.test.AbstractForm;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.QName;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
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;

import ${package}.platformsample.BackupAction;

/**
* Unit testing the mock system
* through the backup action
*
* @author Luca Stancapiano
*/
@RunWith(RemoteTestRunner.class)
@Remote(runnerClass = SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:test-module-context.xml")
public class SimpleMockTest extends AbstractForm {

@Autowired
private BackupAction myAction;

private String documentName = "VALID.pdf";

@Before
public void init() {
super.init();

// insert a document
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
properties.put(ContentModel.PROP_NAME, documentName);
properties.put(ContentModel.PROP_DESCRIPTION, documentName);
String content = new String(com.adobe.xmp.impl.Base64.encode(documentName));
insertDocument(workspace, documentName, content, properties);

// verify the document is created
ResultSet docs = serviceRegistry.getSearchService().query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
SearchService.LANGUAGE_FTS_ALFRESCO, "PATH:\"/" + documentName + "\"");
Assert.assertEquals("A document is created", 1, docs.length());
Assert.assertTrue("VALID.pdf is created", docs.getNodeRefs().get(0).getId().equals(documentName));
}

@Test
public void execute() {

// execute the injected action
Map<String, Serializable> parameterValues = new HashMap<String, Serializable>();
parameterValues.put(BackupAction.DOCUMENT_NAME, documentName);
Action action = new ActionImpl(null, null, null, parameterValues);
myAction.executeImpl(action, workspace);

// verify the document is created
ResultSet docs = serviceRegistry.getSearchService().query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
SearchService.LANGUAGE_FTS_ALFRESCO, "PATH:\"/" + documentName + ".bak\"");
Assert.assertEquals("A backup document is created", 1, docs.length());
Assert.assertTrue("VALID.pdf.bak is created", docs.getNodeRefs().get(0).getId().equals(documentName + ".bak"));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
backup.extension=bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
<import resource="classpath:test-context.xml" />
<import
resource="classpath:alfresco/module/${artifactId}/context/service-context.xml" />
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ services:
- "${symbol_dollar}{postgres.port}:5432"
volumes:
- ${rootArtifactId}-db-volume:/var/lib/postgresql/data
${rootArtifactId}-ass:
${rootArtifactId}-search:
image: alfresco/alfresco-search-services:1.2.0
environment:
SOLR_ALFRESCO_HOST: ${rootArtifactId}-acs
SOLR_ALFRESCO_PORT: 8080
SOLR_SOLR_HOST: ${rootArtifactId}-ass
SOLR_SOLR_HOST: ${rootArtifactId}-search
SOLR_SOLR_PORT: 8983
SOLR_CREATE_ALFRESCO_DEFAULTS: alfresco,archive
ports:
- "8983:8983"
volumes:
- ${rootArtifactId}-ass-volume:/opt/alfresco-search-services/contentstore
- ${rootArtifactId}-ass-volume:/opt/alfresco-search-services/data
- ${rootArtifactId}-search-volume:/opt/alfresco-search-services/contentstore
- ${rootArtifactId}-search-volume:/opt/alfresco-search-services/data
volumes:
${rootArtifactId}-acs-volume:
external: true
${rootArtifactId}-db-volume:
external: true
${rootArtifactId}-ass-volume:
${rootArtifactId}-search-volume:
external: true
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ EXIT /B %ERRORLEVEL%
:start
docker volume create ${rootArtifactId}-acs-volume
docker volume create ${rootArtifactId}-db-volume
docker volume create ${rootArtifactId}-ass-volume
docker volume create ${rootArtifactId}-search-volume
docker-compose -f "%COMPOSE_FILE_PATH%" up --build -d
EXIT /B 0
:start_share
Expand Down Expand Up @@ -124,5 +124,5 @@ EXIT /B 0
:purge
docker volume rm -f ${rootArtifactId}-acs-volume
docker volume rm -f ${rootArtifactId}-db-volume
docker volume rm -f ${rootArtifactId}-ass-volume
docker volume rm -f ${rootArtifactId}-search-volume
EXIT /B 0
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fi
start() {
docker volume create ${rootArtifactId}-acs-volume
docker volume create ${rootArtifactId}-db-volume
docker volume create ${rootArtifactId}-ass-volume
docker volume create ${rootArtifactId}-search-volume
docker-compose -f "${symbol_dollar}COMPOSE_FILE_PATH" up --build -d
}

Expand All @@ -33,7 +33,7 @@ down() {
purge() {
docker volume rm -f ${rootArtifactId}-acs-volume
docker volume rm -f ${rootArtifactId}-db-volume
docker volume rm -f ${rootArtifactId}-ass-volume
docker volume rm -f ${rootArtifactId}-search-volume
}

build() {
Expand Down
2 changes: 1 addition & 1 deletion archetypes/alfresco-platform-jar-archetype/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>org.alfresco.maven</groupId>
<artifactId>alfresco-sdk-aggregator</artifactId>
<version>4.1.0-SNAPSHOT</version>
<version>4.2.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
<include>**/*-context.xml</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="false" encoding="UTF-8">
<directory>src/test/resources</directory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8" filtered="true">
<directory></directory>
<includes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ services:
- "${symbol_dollar}{postgres.port}:5432"
volumes:
- ${rootArtifactId}-db-volume:/var/lib/postgresql/data
${rootArtifactId}-ass:
${rootArtifactId}-search:
image: alfresco/alfresco-search-services:1.2.0
environment:
SOLR_ALFRESCO_HOST: ${rootArtifactId}-acs
SOLR_ALFRESCO_PORT: 8080
SOLR_SOLR_HOST: ${rootArtifactId}-ass
SOLR_SOLR_HOST: ${rootArtifactId}-search
SOLR_SOLR_PORT: 8983
SOLR_CREATE_ALFRESCO_DEFAULTS: alfresco,archive
ports:
- "8983:8983"
volumes:
- ${rootArtifactId}-ass-volume:/opt/alfresco-search-services/contentstore
- ${rootArtifactId}-ass-volume:/opt/alfresco-search-services/data
- ${rootArtifactId}-search-volume:/opt/alfresco-search-services/contentstore
- ${rootArtifactId}-search-volume:/opt/alfresco-search-services/data
volumes:
${rootArtifactId}-acs-volume:
external: true
${rootArtifactId}-db-volume:
external: true
${rootArtifactId}-ass-volume:
${rootArtifactId}-search-volume:
external: true
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ EXIT /B %ERRORLEVEL%
:start
docker volume create ${rootArtifactId}-acs-volume
docker volume create ${rootArtifactId}-db-volume
docker volume create ${rootArtifactId}-ass-volume
docker volume create ${rootArtifactId}-search-volume
docker-compose -f "%COMPOSE_FILE_PATH%" up --build -d
EXIT /B 0
:down
Expand All @@ -96,5 +96,5 @@ EXIT /B 0
:purge
docker volume rm -f ${rootArtifactId}-acs-volume
docker volume rm -f ${rootArtifactId}-db-volume
docker volume rm -f ${rootArtifactId}-ass-volume
docker volume rm -f ${rootArtifactId}-search-volume
EXIT /B 0
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fi
start() {
docker volume create ${rootArtifactId}-acs-volume
docker volume create ${rootArtifactId}-db-volume
docker volume create ${rootArtifactId}-ass-volume
docker volume create ${rootArtifactId}-search-volume
docker-compose -f "${symbol_dollar}COMPOSE_FILE_PATH" up --build -d
}

Expand All @@ -25,7 +25,7 @@ down() {
purge() {
docker volume rm -f ${rootArtifactId}-acs-volume
docker volume rm -f ${rootArtifactId}-db-volume
docker volume rm -f ${rootArtifactId}-ass-volume
docker volume rm -f ${rootArtifactId}-search-volume
}

build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ db.driver=org.postgresql.Driver
# alfresco/tomcat/shared/classes/alfresco-global.properties.
#
index.subsystem.name=solr6
solr.host=${rootArtifactId}-ass
solr.host=${rootArtifactId}-search
solr.port=8983
solr.secureComms=none

Expand Down