mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Initial replication service tests
Fix up the definition parameter persisting, and test that we can create/save/load/list the definitions propertly git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@20965 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -41,11 +41,9 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication
|
|||||||
private static final long serialVersionUID = 3183721054220388564L;
|
private static final long serialVersionUID = 3183721054220388564L;
|
||||||
|
|
||||||
public static final String REPLICATION_DEFINITION_NAME = "replicationActionName";
|
public static final String REPLICATION_DEFINITION_NAME = "replicationActionName";
|
||||||
|
public static final String REPLICATION_DEFINITION_TARGET = "replicationTarget";
|
||||||
public String description;
|
public static final String REPLICATION_DEFINITION_PAYLOAD = "replicationPayload";
|
||||||
public String targetName;
|
public static final String REPLICATION_DEFINITION_TRANSFER_REPORT = "replicationTransferReport";
|
||||||
public List<NodeRef> payload;
|
|
||||||
public NodeRef localTransferReport;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id
|
* @param id
|
||||||
@@ -68,7 +66,7 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication
|
|||||||
*/
|
*/
|
||||||
public ReplicationDefinitionImpl(String id, QName replicationName, String description)
|
public ReplicationDefinitionImpl(String id, QName replicationName, String description)
|
||||||
{
|
{
|
||||||
super(null, id);
|
super(null, id, description);
|
||||||
setParameterValue(REPLICATION_DEFINITION_NAME, replicationName);
|
setParameterValue(REPLICATION_DEFINITION_NAME, replicationName);
|
||||||
setDescription(description);
|
setDescription(description);
|
||||||
}
|
}
|
||||||
@@ -91,11 +89,15 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication
|
|||||||
* @see
|
* @see
|
||||||
* org.alfresco.service.cmr.replication.ReplicationDefinition#getPayload()
|
* org.alfresco.service.cmr.replication.ReplicationDefinition#getPayload()
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public List<NodeRef> getPayload() {
|
public List<NodeRef> getPayload() {
|
||||||
if(this.payload == null) {
|
List<NodeRef> payload = (List<NodeRef>)
|
||||||
this.payload = new ArrayList<NodeRef>();
|
getParameterValue(REPLICATION_DEFINITION_PAYLOAD);
|
||||||
|
if(payload == null) {
|
||||||
|
payload = new ArrayList<NodeRef>();
|
||||||
|
setParameterValue(REPLICATION_DEFINITION_PAYLOAD, (Serializable)payload);
|
||||||
}
|
}
|
||||||
return this.payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -103,7 +105,7 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication
|
|||||||
* org.alfresco.service.cmr.replication.ReplicationDefinition#getTargetName()
|
* org.alfresco.service.cmr.replication.ReplicationDefinition#getTargetName()
|
||||||
*/
|
*/
|
||||||
public String getTargetName() {
|
public String getTargetName() {
|
||||||
return this.targetName;
|
return (String)getParameterValue(REPLICATION_DEFINITION_TARGET);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -111,7 +113,7 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication
|
|||||||
* org.alfresco.service.cmr.replication.ReplicationDefinition#setTargetName(String)
|
* org.alfresco.service.cmr.replication.ReplicationDefinition#setTargetName(String)
|
||||||
*/
|
*/
|
||||||
public void setTargetName(String targetName) {
|
public void setTargetName(String targetName) {
|
||||||
this.targetName = targetName;
|
setParameterValue(REPLICATION_DEFINITION_TARGET, targetName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -119,7 +121,7 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication
|
|||||||
* org.alfresco.service.cmr.replication.ReplicationDefinition#getLocalTransferReport()
|
* org.alfresco.service.cmr.replication.ReplicationDefinition#getLocalTransferReport()
|
||||||
*/
|
*/
|
||||||
public NodeRef getLocalTransferReport() {
|
public NodeRef getLocalTransferReport() {
|
||||||
return localTransferReport;
|
return (NodeRef)getParameterValue(REPLICATION_DEFINITION_TRANSFER_REPORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -127,6 +129,6 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication
|
|||||||
* org.alfresco.service.cmr.replication.ReplicationDefinition#setLocalTransferReport(NodeRef)
|
* org.alfresco.service.cmr.replication.ReplicationDefinition#setLocalTransferReport(NodeRef)
|
||||||
*/
|
*/
|
||||||
public void setLocalTransferReport(NodeRef report) {
|
public void setLocalTransferReport(NodeRef report) {
|
||||||
this.localTransferReport = report;
|
setParameterValue(REPLICATION_DEFINITION_TRANSFER_REPORT, report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
package org.alfresco.repo.replication;
|
package org.alfresco.repo.replication;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -47,6 +48,9 @@ public class ReplicationDefinitionPersisterImpl implements ReplicationDefinition
|
|||||||
/** Reference to the replication action space node */
|
/** Reference to the replication action space node */
|
||||||
private static final StoreRef SPACES_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
|
private static final StoreRef SPACES_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
|
||||||
protected static final NodeRef REPLICATION_ACTION_ROOT_NODE_REF = new NodeRef(SPACES_STORE, "replication_actions_space");
|
protected static final NodeRef REPLICATION_ACTION_ROOT_NODE_REF = new NodeRef(SPACES_STORE, "replication_actions_space");
|
||||||
|
protected static final Set<QName> ACTION_TYPES = new HashSet<QName>(
|
||||||
|
Arrays.asList(new QName[] { ActionModel.TYPE_ACTION }));
|
||||||
|
|
||||||
|
|
||||||
/* Injected services */
|
/* Injected services */
|
||||||
private NodeService nodeService;
|
private NodeService nodeService;
|
||||||
@@ -79,10 +83,8 @@ public class ReplicationDefinitionPersisterImpl implements ReplicationDefinition
|
|||||||
// Note that in the call to getChildAssocs below, only the specified
|
// Note that in the call to getChildAssocs below, only the specified
|
||||||
// types are included.
|
// types are included.
|
||||||
// Subtypes of the type action:action will not be returned.
|
// Subtypes of the type action:action will not be returned.
|
||||||
Set<QName> actionTypes = new HashSet<QName>();
|
|
||||||
actionTypes.add(ActionModel.TYPE_ACTION);
|
|
||||||
|
|
||||||
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(REPLICATION_ACTION_ROOT_NODE_REF, actionTypes);
|
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(REPLICATION_ACTION_ROOT_NODE_REF, ACTION_TYPES);
|
||||||
|
|
||||||
List<ReplicationDefinition> renderingActions = new ArrayList<ReplicationDefinition>(childAssocs.size());
|
List<ReplicationDefinition> renderingActions = new ArrayList<ReplicationDefinition>(childAssocs.size());
|
||||||
for (ChildAssociationRef actionAssoc : childAssocs)
|
for (ChildAssociationRef actionAssoc : childAssocs)
|
||||||
|
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2010 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.repo.replication;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.action.ActionService;
|
||||||
|
import org.alfresco.service.cmr.replication.ReplicationDefinition;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nick Burch
|
||||||
|
*/
|
||||||
|
public class ReplicationServiceImplTest extends TestCase
|
||||||
|
{
|
||||||
|
private ActionService actionService = mock(ActionService.class);
|
||||||
|
private NodeService nodeService = mock(NodeService.class);
|
||||||
|
|
||||||
|
private final ReplicationDefinitionPersisterImpl replicationDefinitionPersister = mock(ReplicationDefinitionPersisterImpl.class);
|
||||||
|
private ReplicationServiceImpl replicationService;
|
||||||
|
|
||||||
|
private final QName ACTION_NAME = QName.createQName(NamespaceService.ALFRESCO_URI, "testName");
|
||||||
|
private final QName ACTION_NAME2 = QName.createQName(NamespaceService.ALFRESCO_URI, "testName2");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception
|
||||||
|
{
|
||||||
|
replicationService = new ReplicationServiceImpl();
|
||||||
|
replicationService.setActionService(actionService);
|
||||||
|
replicationService.setNodeService(nodeService);
|
||||||
|
replicationService.setReplicationDefinitionPersister(replicationDefinitionPersister);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCreation() throws Exception
|
||||||
|
{
|
||||||
|
ReplicationDefinition replicationAction =
|
||||||
|
replicationService.createReplicationDefinition(ACTION_NAME, "Test Definition");
|
||||||
|
assertNotNull(replicationAction);
|
||||||
|
assertEquals("Test Definition", replicationAction.getDescription());
|
||||||
|
assertEquals(ACTION_NAME, replicationAction.getReplicationName());
|
||||||
|
|
||||||
|
String id = replicationAction.getId();
|
||||||
|
assertNotNull(id);
|
||||||
|
assertTrue(id.length() > 0);
|
||||||
|
|
||||||
|
assertNotNull(replicationAction.getPayload());
|
||||||
|
assertEquals(0, replicationAction.getPayload().size());
|
||||||
|
|
||||||
|
assertNull(replicationAction.getLocalTransferReport());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,140 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2010 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.repo.replication;
|
||||||
|
|
||||||
|
import org.alfresco.repo.model.Repository;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
|
import org.alfresco.service.cmr.replication.ReplicationDefinition;
|
||||||
|
import org.alfresco.service.cmr.replication.ReplicationService;
|
||||||
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.alfresco.util.BaseAlfrescoSpringTest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nick Burch
|
||||||
|
*/
|
||||||
|
public class ReplicationServiceIntegrationTest extends BaseAlfrescoSpringTest
|
||||||
|
{
|
||||||
|
private ReplicationService replicationService;
|
||||||
|
private NodeService nodeService;
|
||||||
|
|
||||||
|
private final QName ACTION_NAME = QName.createQName(NamespaceService.ALFRESCO_URI, "testName");
|
||||||
|
private final QName ACTION_NAME2 = QName.createQName(NamespaceService.ALFRESCO_URI, "testName2");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSetUpInTransaction() throws Exception
|
||||||
|
{
|
||||||
|
super.onSetUpInTransaction();
|
||||||
|
replicationService = (ReplicationService) this.applicationContext.getBean("replicationService");
|
||||||
|
nodeService = (NodeService) this.applicationContext.getBean("nodeService");
|
||||||
|
|
||||||
|
// Set the current security context as admin
|
||||||
|
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||||
|
|
||||||
|
// Zap any existing entries
|
||||||
|
NodeRef replicationRoot = ReplicationDefinitionPersisterImpl.REPLICATION_ACTION_ROOT_NODE_REF;
|
||||||
|
for(ChildAssociationRef child : nodeService.getChildAssocs(replicationRoot)) {
|
||||||
|
QName type = nodeService.getType( child.getChildRef() );
|
||||||
|
if(ReplicationDefinitionPersisterImpl.ACTION_TYPES.contains(type)) {
|
||||||
|
nodeService.deleteNode(child.getChildRef());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCreation() throws Exception
|
||||||
|
{
|
||||||
|
ReplicationDefinition replicationAction =
|
||||||
|
replicationService.createReplicationDefinition(ACTION_NAME, "Test Definition");
|
||||||
|
assertNotNull(replicationAction);
|
||||||
|
assertEquals("Test Definition", replicationAction.getDescription());
|
||||||
|
assertEquals(ACTION_NAME, replicationAction.getReplicationName());
|
||||||
|
|
||||||
|
String id = replicationAction.getId();
|
||||||
|
assertNotNull(id);
|
||||||
|
assertTrue(id.length() > 0);
|
||||||
|
|
||||||
|
assertNotNull(replicationAction.getPayload());
|
||||||
|
assertEquals(0, replicationAction.getPayload().size());
|
||||||
|
|
||||||
|
assertNull(replicationAction.getLocalTransferReport());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCreateSaveLoad() throws Exception
|
||||||
|
{
|
||||||
|
ReplicationDefinition replicationAction =
|
||||||
|
replicationService.createReplicationDefinition(ACTION_NAME, "Test Definition");
|
||||||
|
replicationAction.getPayload().add(
|
||||||
|
new NodeRef("workspace://SpacesStore/Testing")
|
||||||
|
);
|
||||||
|
replicationAction.getPayload().add(
|
||||||
|
new NodeRef("workspace://SpacesStore/Testing2")
|
||||||
|
);
|
||||||
|
assertEquals(2, replicationAction.getPayload().size());
|
||||||
|
|
||||||
|
replicationService.saveReplicationDefinition(replicationAction);
|
||||||
|
|
||||||
|
ReplicationDefinition retrieved =
|
||||||
|
replicationService.loadReplicationDefinition(ACTION_NAME);
|
||||||
|
assertNotNull(retrieved);
|
||||||
|
assertEquals(ACTION_NAME, retrieved.getReplicationName());
|
||||||
|
assertEquals("Test Definition", retrieved.getDescription());
|
||||||
|
assertEquals(2, retrieved.getPayload().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testLoadList() throws Exception
|
||||||
|
{
|
||||||
|
assertEquals(0, replicationService.loadReplicationDefinitions().size());
|
||||||
|
|
||||||
|
// Create and store
|
||||||
|
ReplicationDefinition rd1 = replicationService.createReplicationDefinition(ACTION_NAME, "Test 1");
|
||||||
|
ReplicationDefinition rd2 = replicationService.createReplicationDefinition(ACTION_NAME2, "Test 2");
|
||||||
|
|
||||||
|
assertEquals(0, replicationService.loadReplicationDefinitions().size());
|
||||||
|
|
||||||
|
replicationService.saveReplicationDefinition(rd1);
|
||||||
|
|
||||||
|
assertEquals(1, replicationService.loadReplicationDefinitions().size());
|
||||||
|
assertEquals(ACTION_NAME, replicationService.loadReplicationDefinitions().get(0).getReplicationName());
|
||||||
|
|
||||||
|
replicationService.saveReplicationDefinition(rd2);
|
||||||
|
assertEquals(2, replicationService.loadReplicationDefinitions().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testLoadByTarget() throws Exception
|
||||||
|
{
|
||||||
|
assertEquals(0, replicationService.loadReplicationDefinitions().size());
|
||||||
|
assertEquals(0, replicationService.loadReplicationDefinitions("TestTarget").size());
|
||||||
|
assertEquals(0, replicationService.loadReplicationDefinitions("TestTarget2").size());
|
||||||
|
|
||||||
|
// Store some
|
||||||
|
ReplicationDefinition rdTT = replicationService.createReplicationDefinition(ACTION_NAME, "Test");
|
||||||
|
rdTT.setTargetName("TestTarget");
|
||||||
|
replicationService.saveReplicationDefinition(rdTT);
|
||||||
|
|
||||||
|
// Check it shows up correctly
|
||||||
|
assertEquals(1, replicationService.loadReplicationDefinitions().size());
|
||||||
|
assertEquals(1, replicationService.loadReplicationDefinitions("TestTarget").size());
|
||||||
|
assertEquals(0, replicationService.loadReplicationDefinitions("TestTarget2").size());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user