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

alfresco-tests integration #613

Open
wants to merge 9 commits into
base: sdk-4.2
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
<include>**/*-context.xml</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8" filtered="true" packaged="false">
<directory>src/test/resources</directory>
<includes>
<include>**/*-context.xml</include>
</includes>
</fileSet>
</fileSets>
</module>

Expand Down
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 @@ -17,6 +17,15 @@
</properties>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>it.vige</groupId>
<artifactId>alfresco-tests</artifactId>
<version>${alfresco.platform.version}.8</version>
</dependency>
</dependencies>

<build>
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 @@ -3,3 +3,4 @@
## System Administrators can override these values in environment specific configurations in
## alfresco/tomcat/shared/classes/alfresco-global.properties.
##
backup.extension=bak
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,12 @@
<property name="nodeLocatorService" ref="nodeLocatorService" />
</bean>

<bean id="${package}.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,99 @@
#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;

/**
* 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());
String name = (String) serviceRegistry.getNodeService().getProperty(docs.getNodeRefs().get(0),
ContentModel.PROP_NAME);
Assert.assertTrue("VALID.pdf is created", name.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());
String name = (String) serviceRegistry.getNodeService().getProperty(docs.getNodeRefs().get(0),
ContentModel.PROP_NAME);
Assert.assertTrue("VALID.pdf.bak is created", name.equals(documentName + ".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 @@ -72,6 +72,12 @@
<include>**/*-context.xml</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8" filtered="true" packaged="false">
<directory>src/test/resources</directory>
<includes>
<include>**/*-context.xml</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8" filtered="true">
<directory></directory>
<includes>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#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;

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 @@ -3,3 +3,4 @@
## System Administrators can override these values in environment specific configurations in
## alfresco/tomcat/shared/classes/alfresco-global.properties.
##
backup.extension=bak
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,12 @@
<property name="nodeLocatorService" ref="nodeLocatorService" />
</bean>

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


</beans>
Loading