diff --git a/archetypes/alfresco-allinone-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/archetypes/alfresco-allinone-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml index d76717bd..528e3aed 100644 --- a/archetypes/alfresco-allinone-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/archetypes/alfresco-allinone-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -47,6 +47,12 @@ **/*-context.xml + + src/test/resources + + **/*-context.xml + + diff --git a/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-integration-tests/src/test/resources/test-module-context.xml b/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-integration-tests/src/test/resources/test-module-context.xml new file mode 100644 index 00000000..f91da734 --- /dev/null +++ b/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-integration-tests/src/test/resources/test-module-context.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/pom.xml b/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/pom.xml index ae7b530e..d4085a26 100644 --- a/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/pom.xml +++ b/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/pom.xml @@ -17,6 +17,15 @@ + + org.springframework + spring-test + + + it.vige + alfresco-tests + ${alfresco.platform.version}.8 + diff --git a/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/main/java/platformsample/BackupAction.java b/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/main/java/platformsample/BackupAction.java new file mode 100644 index 00000000..8c2c305f --- /dev/null +++ b/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/main/java/platformsample/BackupAction.java @@ -0,0 +1,66 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/** + * Copyright (C) 2017 Alfresco Software Limited. + *

+ * This file is part of the Alfresco SDK project. + *

+ * 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 + *

+ * 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 ${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 paramList) { + // TODO Auto-generated method stub + + } + + public void setExtension(String extension) { + this.extension = extension; + } + +} diff --git a/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/main/resources/alfresco/module/__artifactId__/alfresco-global.properties b/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/main/resources/alfresco/module/__artifactId__/alfresco-global.properties index f566f222..04f01486 100644 --- a/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/main/resources/alfresco/module/__artifactId__/alfresco-global.properties +++ b/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/main/resources/alfresco/module/__artifactId__/alfresco-global.properties @@ -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 diff --git a/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/main/resources/alfresco/module/__artifactId__/context/service-context.xml b/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/main/resources/alfresco/module/__artifactId__/context/service-context.xml index a3c12c4d..5e72b5d8 100644 --- a/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/main/resources/alfresco/module/__artifactId__/context/service-context.xml +++ b/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/main/resources/alfresco/module/__artifactId__/context/service-context.xml @@ -40,5 +40,12 @@ + + + ${backup.extension} + + + diff --git a/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/test/java/platformsample/SimpleMockTest.java b/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/test/java/platformsample/SimpleMockTest.java new file mode 100644 index 00000000..da91f5ca --- /dev/null +++ b/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/test/java/platformsample/SimpleMockTest.java @@ -0,0 +1,99 @@ +#set($symbol_pound='#') +#set($symbol_dollar='$') +#set($symbol_escape='\' ) +/** + * Copyright (C) 2017 Alfresco Software Limited. + *

+ * This file is part of the Alfresco SDK project. + *

+ * 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 + *

+ * 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 ${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 properties = new HashMap(); + 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 parameterValues = new HashMap(); + 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")); + + } +} diff --git a/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/test/resources/test-module-context.xml b/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/test/resources/test-module-context.xml new file mode 100644 index 00000000..f91da734 --- /dev/null +++ b/archetypes/alfresco-allinone-archetype/src/main/resources/archetype-resources/__rootArtifactId__-platform/src/test/resources/test-module-context.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/archetypes/alfresco-platform-jar-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/archetypes/alfresco-platform-jar-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml index e4f4ad8b..d7184695 100644 --- a/archetypes/alfresco-platform-jar-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/archetypes/alfresco-platform-jar-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -72,6 +72,12 @@ **/*-context.xml + + src/test/resources + + **/*-context.xml + + diff --git a/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/main/java/platformsample/BackupAction.java b/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/main/java/platformsample/BackupAction.java new file mode 100644 index 00000000..c29cab4c --- /dev/null +++ b/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/main/java/platformsample/BackupAction.java @@ -0,0 +1,59 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/** + * Copyright (C) 2017 Alfresco Software Limited. + *

+ * This file is part of the Alfresco SDK project. + *

+ * 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 + *

+ * 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 ${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 paramList) { + // TODO Auto-generated method stub + + } + + public void setExtension(String extension) { + this.extension = extension; + } + +} diff --git a/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/main/resources/alfresco/module/__artifactId__/alfresco-global.properties b/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/main/resources/alfresco/module/__artifactId__/alfresco-global.properties index f566f222..04f01486 100644 --- a/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/main/resources/alfresco/module/__artifactId__/alfresco-global.properties +++ b/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/main/resources/alfresco/module/__artifactId__/alfresco-global.properties @@ -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 diff --git a/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/main/resources/alfresco/module/__artifactId__/context/service-context.xml b/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/main/resources/alfresco/module/__artifactId__/context/service-context.xml index a3c12c4d..5e72b5d8 100644 --- a/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/main/resources/alfresco/module/__artifactId__/context/service-context.xml +++ b/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/main/resources/alfresco/module/__artifactId__/context/service-context.xml @@ -40,5 +40,12 @@ + + + ${backup.extension} + + + diff --git a/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/test/java/platformsample/SimpleMockTest.java b/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/test/java/platformsample/SimpleMockTest.java new file mode 100644 index 00000000..2f9db42d --- /dev/null +++ b/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/test/java/platformsample/SimpleMockTest.java @@ -0,0 +1,96 @@ +#set($symbol_pound='#') +#set($symbol_dollar='$') +#set($symbol_escape='\' ) +/** + * Copyright (C) 2017 Alfresco Software Limited. + *

+ * This file is part of the Alfresco SDK project. + *

+ * 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 + *

+ * 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 ${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; + +@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 properties = new HashMap(); + 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().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 parameterValues = new HashMap(); + 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().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")); + + } +} diff --git a/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/test/resources/test-module-context.xml b/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/test/resources/test-module-context.xml new file mode 100644 index 00000000..f91da734 --- /dev/null +++ b/archetypes/alfresco-platform-jar-archetype/src/main/resources/archetype-resources/src/test/resources/test-module-context.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/docs/working-with-generated-projects/structure-aio.md b/docs/working-with-generated-projects/structure-aio.md index 724f661a..333e9967 100644 --- a/docs/working-with-generated-projects/structure-aio.md +++ b/docs/working-with-generated-projects/structure-aio.md @@ -60,6 +60,7 @@ my-all-in-one-project │ │ │ └── com │ │ │ └── example │ │ │ └── platformsample +│ │ │ ├── BackupAction.java │ │ │ ├── DemoComponent.java │ │ │ ├── Demo.java │ │ │ └── HelloWorldWebScript.java @@ -94,11 +95,14 @@ my-all-in-one-project │ │ └── resources │ │ └── test.html │ └── test -│ └── java -│ └── com -│ └── example -│ └── platformsample -│ └── HelloWorldWebScriptControllerTest.java +│ ├── java +│ │ └── com +│ │ └── example +│ │ └── platformsample +│ │ ├── SimpleMockTest.java +│ │ └── HelloWorldWebScriptControllerTest.java +│ └── resources +│ └── test-module-context.xml ├── my-all-in-one-project-share-docker | ├── pom.xml │ └── src diff --git a/docs/working-with-generated-projects/structure-platform.md b/docs/working-with-generated-projects/structure-platform.md index 1c404b2d..12366bfc 100644 --- a/docs/working-with-generated-projects/structure-platform.md +++ b/docs/working-with-generated-projects/structure-platform.md @@ -39,6 +39,7 @@ my-platform-jar-project │   │   └── com │   │   └── example │   │   └── platformsample + │   │   ├── BackupAction.java │   │   ├── Demo.java │   │   ├── DemoComponent.java │   │   └── HelloWorldWebScript.java @@ -75,13 +76,16 @@ my-platform-jar-project │   └── sample-process.bpmn20.xml └── test └── java - └── com - └── example - └── platformsample - ├── CustomContentModelIT.java - ├── DemoComponentIT.java - ├── HelloWorldWebScriptControllerTest.java - └── HelloWorldWebScriptIT.java + ├── com + │ └── example + │ └── platformsample + │ ├── SimpleMockTest.java + │ ├── CustomContentModelIT.java + │ ├── DemoComponentIT.java + │ ├── HelloWorldWebScriptControllerTest.java + │ └── HelloWorldWebScriptIT.java + └── resources + └── test-module-context.xml ``` From a high level standpoint, we can describe the content of the project as follows: