mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
ALF-4135 - Webscript support for deleting replication definitions
Includes webscript unit tests, and expands the service unit tests git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21641 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Deletes a persisted Replication Definition</shortname>
|
||||||
|
<description>Deletes a previously persisted replication defintion with the supplied name</description>
|
||||||
|
<url>/api/replication-definition/{replication_definition_name}</url>
|
||||||
|
<format default="json"/>
|
||||||
|
<authentication>admin</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
</webscript>
|
@@ -876,4 +876,10 @@
|
|||||||
parent="abstractReplicationWebScript">
|
parent="abstractReplicationWebScript">
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<!-- Deletes a replication definition -->
|
||||||
|
<bean id="webscript.org.alfresco.repository.replication.replication-definition.delete"
|
||||||
|
class="org.alfresco.repo.web.scripts.replication.ReplicationDefinitionDelete"
|
||||||
|
parent="abstractReplicationWebScript">
|
||||||
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* 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.web.scripts.replication;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.replication.ReplicationDefinition;
|
||||||
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
|
import org.springframework.extensions.webscripts.Status;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptException;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nick Burch
|
||||||
|
* @since 3.4
|
||||||
|
*/
|
||||||
|
public class ReplicationDefinitionDelete extends AbstractReplicationWebscript
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected Map<String, Object> buildModel(ReplicationModelBuilder modelBuilder,
|
||||||
|
WebScriptRequest req, Status status, Cache cache)
|
||||||
|
{
|
||||||
|
// Which definition did they ask for?
|
||||||
|
String replicationDefinitionName =
|
||||||
|
req.getServiceMatch().getTemplateVars().get("replication_definition_name");
|
||||||
|
ReplicationDefinition replicationDefinition =
|
||||||
|
replicationService.loadReplicationDefinition(replicationDefinitionName);
|
||||||
|
|
||||||
|
// Does it exist?
|
||||||
|
if(replicationDefinition == null) {
|
||||||
|
throw new WebScriptException(
|
||||||
|
Status.STATUS_NOT_FOUND,
|
||||||
|
"No Replication Definition found with that name"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete it
|
||||||
|
replicationService.deleteReplicationDefinition(replicationDefinition);
|
||||||
|
|
||||||
|
// Report it as gone
|
||||||
|
throw new WebScriptException(
|
||||||
|
Status.STATUS_GONE,
|
||||||
|
"Replication Definition deleted"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@@ -44,6 +44,7 @@ import org.springframework.extensions.webscripts.Status;
|
|||||||
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
||||||
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
|
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
|
||||||
import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest;
|
import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest;
|
||||||
|
import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
|
||||||
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1113,6 +1114,117 @@ public class ReplicationRestApiTest extends BaseWebScriptTest
|
|||||||
assertEquals(0, json.getJSONArray("payload").length());
|
assertEquals(0, json.getJSONArray("payload").length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testReplicationDefinitionDelete() throws Exception
|
||||||
|
{
|
||||||
|
Response response;
|
||||||
|
|
||||||
|
|
||||||
|
// Not allowed if you're not an admin
|
||||||
|
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
|
||||||
|
response = sendRequest(new DeleteRequest(URL_DEFINITION + "MadeUp"), Status.STATUS_UNAUTHORIZED);
|
||||||
|
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
|
||||||
|
|
||||||
|
AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
|
||||||
|
response = sendRequest(new DeleteRequest(URL_DEFINITION + "MadeUp"), Status.STATUS_UNAUTHORIZED);
|
||||||
|
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
|
||||||
|
|
||||||
|
|
||||||
|
// Ensure there aren't any to start with
|
||||||
|
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||||
|
assertEquals(0, replicationService.loadReplicationDefinitions().size());
|
||||||
|
|
||||||
|
|
||||||
|
// You need to specify a real definition
|
||||||
|
response = sendRequest(new DeleteRequest(URL_DEFINITION + "MadeUp"), Status.STATUS_NOT_FOUND);
|
||||||
|
assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
|
||||||
|
|
||||||
|
|
||||||
|
// Create one, and then delete it
|
||||||
|
ReplicationDefinition rd = replicationService.createReplicationDefinition("Test", "Testing");
|
||||||
|
replicationService.saveReplicationDefinition(rd);
|
||||||
|
assertEquals(1, replicationService.loadReplicationDefinitions().size());
|
||||||
|
|
||||||
|
// Because some of the delete operations happen post-commit, and
|
||||||
|
// because we don't have real transactions, fake it
|
||||||
|
UserTransaction txn = transactionService.getUserTransaction();
|
||||||
|
txn.begin();
|
||||||
|
|
||||||
|
// Call the delete webscript
|
||||||
|
response = sendRequest(new DeleteRequest(URL_DEFINITION + "Test"), Status.STATUS_GONE);
|
||||||
|
assertEquals(Status.STATUS_GONE, response.getStatus());
|
||||||
|
|
||||||
|
// Let the node service do its work
|
||||||
|
txn.commit();
|
||||||
|
Thread.sleep(50);
|
||||||
|
|
||||||
|
|
||||||
|
// Check the details webscript to ensure it went
|
||||||
|
response = sendRequest(new GetRequest(URL_DEFINITION + "Test"), Status.STATUS_NOT_FOUND);
|
||||||
|
assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
|
||||||
|
|
||||||
|
|
||||||
|
// Check the replication service to ensure it went
|
||||||
|
assertNull(replicationService.loadReplicationDefinition("Test"));
|
||||||
|
assertEquals(0, replicationService.loadReplicationDefinitions().size());
|
||||||
|
|
||||||
|
|
||||||
|
// If there are several, make sure the right one goes
|
||||||
|
rd = replicationService.createReplicationDefinition("Test", "Testing");
|
||||||
|
replicationService.saveReplicationDefinition(rd);
|
||||||
|
rd = replicationService.createReplicationDefinition("Test 2", "Testing");
|
||||||
|
replicationService.saveReplicationDefinition(rd);
|
||||||
|
rd = replicationService.createReplicationDefinition("Test 3", "Testing");
|
||||||
|
replicationService.saveReplicationDefinition(rd);
|
||||||
|
|
||||||
|
// Delete one of three, correct one goes
|
||||||
|
assertEquals(3, replicationService.loadReplicationDefinitions().size());
|
||||||
|
|
||||||
|
txn = transactionService.getUserTransaction();
|
||||||
|
txn.begin();
|
||||||
|
|
||||||
|
response = sendRequest(new DeleteRequest(URL_DEFINITION + "Test"), Status.STATUS_GONE);
|
||||||
|
assertEquals(Status.STATUS_GONE, response.getStatus());
|
||||||
|
|
||||||
|
txn.commit();
|
||||||
|
Thread.sleep(50);
|
||||||
|
|
||||||
|
assertEquals(2, replicationService.loadReplicationDefinitions().size());
|
||||||
|
assertNull(replicationService.loadReplicationDefinition("Test"));
|
||||||
|
assertNotNull(replicationService.loadReplicationDefinition("Test 2"));
|
||||||
|
assertNotNull(replicationService.loadReplicationDefinition("Test 3"));
|
||||||
|
|
||||||
|
// Delete the next one, correct one goes
|
||||||
|
txn = transactionService.getUserTransaction();
|
||||||
|
txn.begin();
|
||||||
|
|
||||||
|
response = sendRequest(new DeleteRequest(URL_DEFINITION + "Test 3"), Status.STATUS_GONE);
|
||||||
|
assertEquals(Status.STATUS_GONE, response.getStatus());
|
||||||
|
|
||||||
|
txn.commit();
|
||||||
|
Thread.sleep(50);
|
||||||
|
|
||||||
|
assertEquals(1, replicationService.loadReplicationDefinitions().size());
|
||||||
|
assertNull(replicationService.loadReplicationDefinition("Test"));
|
||||||
|
assertNotNull(replicationService.loadReplicationDefinition("Test 2"));
|
||||||
|
assertNull(replicationService.loadReplicationDefinition("Test 3"));
|
||||||
|
|
||||||
|
|
||||||
|
// Ensure you can't delete for a 2nd time
|
||||||
|
txn = transactionService.getUserTransaction();
|
||||||
|
txn.begin();
|
||||||
|
|
||||||
|
response = sendRequest(new DeleteRequest(URL_DEFINITION + "Test 3"), Status.STATUS_NOT_FOUND);
|
||||||
|
assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
|
||||||
|
|
||||||
|
txn.commit();
|
||||||
|
Thread.sleep(50);
|
||||||
|
|
||||||
|
assertEquals(1, replicationService.loadReplicationDefinitions().size());
|
||||||
|
assertNull(replicationService.loadReplicationDefinition("Test"));
|
||||||
|
assertNotNull(replicationService.loadReplicationDefinition("Test 2"));
|
||||||
|
assertNull(replicationService.loadReplicationDefinition("Test 3"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception
|
protected void setUp() throws Exception
|
||||||
@@ -1121,7 +1233,7 @@ public class ReplicationRestApiTest extends BaseWebScriptTest
|
|||||||
ApplicationContext appContext = getServer().getApplicationContext();
|
ApplicationContext appContext = getServer().getApplicationContext();
|
||||||
|
|
||||||
nodeService = (NodeService)appContext.getBean("nodeService");
|
nodeService = (NodeService)appContext.getBean("nodeService");
|
||||||
replicationService = (ReplicationService)appContext.getBean("replicationService");
|
replicationService = (ReplicationService)appContext.getBean("ReplicationService");
|
||||||
actionTrackingService = (ActionTrackingService)appContext.getBean("actionTrackingService");
|
actionTrackingService = (ActionTrackingService)appContext.getBean("actionTrackingService");
|
||||||
repositoryHelper = (Repository)appContext.getBean("repositoryHelper");
|
repositoryHelper = (Repository)appContext.getBean("repositoryHelper");
|
||||||
transactionService = (TransactionService)appContext.getBean("transactionService");
|
transactionService = (TransactionService)appContext.getBean("transactionService");
|
||||||
|
Reference in New Issue
Block a user