ALF-4408 - prevent creation of duplicate named replication definitions, and update the unit tests to properly test this, not just almost test it...

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21986 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2010-08-25 12:02:42 +00:00
parent 8f0876a332
commit 926effbcae
2 changed files with 25 additions and 2 deletions

View File

@@ -55,9 +55,16 @@ public class ReplicationDefinitionsPost extends AbstractReplicationWebscript
if(! json.has("description"))
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "description is required but wasn't supplied");
// Create
// Ensure one doesn't already exist with that name
String name = json.getString("name");
if(replicationService.loadReplicationDefinition(name) != null)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "A replication definition already exists with that name");
}
// Create the definition
replicationDefinition = replicationService.createReplicationDefinition(
json.getString("name"), json.getString("description")
name, json.getString("description")
);
// Set the extra parts

View File

@@ -818,9 +818,25 @@ public class ReplicationRestApiTest extends BaseWebScriptTest
// Ensure we can't create with a duplicate name
json = new JSONObject();
json.put("name", "Test");
json.put("description", "New Duplicate");
json.put("targetName", "New Duplicate Target");
response = sendRequest(new PostRequest(URL_DEFINITIONS, json.toString(), JSON), Status.STATUS_BAD_REQUEST);
assertEquals(Status.STATUS_BAD_REQUEST, response.getStatus());
// Ensure that even though we got BAD REQUEST back, nothing changed
rd = replicationService.loadReplicationDefinition("New Definition");
assertEquals("New Definition", rd.getReplicationName());
assertEquals("Testing", rd.getDescription());
assertEquals(ActionStatus.New, rd.getExecutionStatus());
assertEquals(null, rd.getExecutionStartDate());
assertEquals(null, rd.getExecutionEndDate());
assertEquals(null, rd.getExecutionFailureMessage());
assertEquals(null, rd.getLocalTransferReport());
assertEquals(null, rd.getRemoteTransferReport());
assertEquals(null, rd.getTargetName());
assertEquals(0, rd.getPayload().size());
assertEquals(true, rd.isEnabled());
}
public void testReplicationDefinitionPut() throws Exception