Search in sources :

Example 21 with ReplicationDefinition

use of org.alfresco.service.cmr.replication.ReplicationDefinition in project alfresco-remote-api by Alfresco.

the class ReplicationRestApiTest method tearDown.

/* (non-Javadoc)
     * @see junit.framework.TestCase#tearDown()
     */
@Override
protected void tearDown() throws Exception {
    super.tearDown();
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    personManager.clearPeople();
    // Zap any replication definitions we created
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    for (ReplicationDefinition rd : replicationService.loadReplicationDefinitions()) {
        replicationService.deleteReplicationDefinition(rd);
    }
    AuthenticationUtil.clearCurrentSecurityContext();
    txn.commit();
}
Also used : UserTransaction(javax.transaction.UserTransaction) ReplicationDefinition(org.alfresco.service.cmr.replication.ReplicationDefinition)

Example 22 with ReplicationDefinition

use of org.alfresco.service.cmr.replication.ReplicationDefinition in project alfresco-remote-api by Alfresco.

the class ReplicationRestApiTest method testReplicationDefinitionDelete.

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_NO_CONTENT);
    assertEquals(Status.STATUS_NO_CONTENT, 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_NO_CONTENT);
    assertEquals(Status.STATUS_NO_CONTENT, 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_NO_CONTENT);
    assertEquals(Status.STATUS_NO_CONTENT, 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"));
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) UserTransaction(javax.transaction.UserTransaction) ReplicationDefinition(org.alfresco.service.cmr.replication.ReplicationDefinition) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Aggregations

ReplicationDefinition (org.alfresco.service.cmr.replication.ReplicationDefinition)22 JSONObject (org.json.JSONObject)12 UserTransaction (javax.transaction.UserTransaction)11 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)11 JSONArray (org.json.JSONArray)7 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)6 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)5 ActionImpl (org.alfresco.repo.action.ActionImpl)4 IOException (java.io.IOException)3 ExecutionSummary (org.alfresco.service.cmr.action.ExecutionSummary)3 JSONException (org.json.JSONException)3 JSONTokener (org.json.JSONTokener)3 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)3 TestPersonManager (org.alfresco.repo.security.person.TestPersonManager)2 ExecutionDetails (org.alfresco.service.cmr.action.ExecutionDetails)2 MutableAuthenticationService (org.alfresco.service.cmr.security.MutableAuthenticationService)2 PersonService (org.alfresco.service.cmr.security.PersonService)2 ApplicationContext (org.springframework.context.ApplicationContext)2 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)2 ArrayList (java.util.ArrayList)1