Merge branch 'TAS-2071' into 'master'

Tas 2071

See merge request !309
This commit is contained in:
Claudia Agache
2016-12-09 14:18:32 +00:00
2 changed files with 164 additions and 14 deletions
@@ -0,0 +1,155 @@
package org.alfresco.rest.workflow.processes;
import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.dataprep.CMISUtil.Priority;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.core.RestRequest;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestItemModel;
import org.alfresco.rest.model.RestProcessModel;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.TestGroup;
import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.report.Bug;
import org.alfresco.utility.testrail.ExecutionType;
import org.alfresco.utility.testrail.annotation.TestRail;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class AddProcessItemCoreTests extends RestTest
{
private FileModel document, document2;
private SiteModel siteModel;
private UserModel userWhoStartsProcess, assignee, adminUser, anotherUser, adminTenantUser, tenantUserAssignee, adminTenantUser2, tenantUser;
private RestProcessModel processModel;
private RestItemModel processItem;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws Exception
{
adminUser = dataUser.getAdminUser();
userWhoStartsProcess = dataUser.createRandomTestUser();
assignee = dataUser.createRandomTestUser();
siteModel = dataSite.usingUser(adminUser).createPublicRandomSite();
document = dataContent.usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN);
dataWorkflow.usingUser(userWhoStartsProcess).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee);
}
@Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE })
@TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, description = "Add process item using by the user who started the process.")
public void addProcessItemByUserThatStartedTheProcess() throws Exception
{
processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel();
processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
processItem.assertThat().field("createdAt").isNotEmpty().and().field("size").is("19").and().field("createdBy").is(adminUser.getUsername()).and()
.field("modifiedAt").isNotEmpty().and().field("name").is(document.getName()).and().field("modifiedBy").is(userWhoStartsProcess.getUsername())
.and().field("id").isNotEmpty().and().field("mimeType").is(document.getFileType().mimeType);
}
@Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE })
@TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, description = "Add process item by a random user.")
public void addProcessItemByAnyUser() throws Exception
{
anotherUser = dataUser.createRandomTestUser();
document2 = dataContent.usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN);
processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel();
processItem = restClient.authenticateUser(anotherUser).withWorkflowAPI().usingProcess(processModel).addProcessItem(document2);
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError()
.containsSummary(String.format(RestErrorModel.ACCESS_INFORMATION_NOT_ALLOWED, processModel.getId()));
}
@Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE, TestGroup.NETWORKS })
@TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, description = "Add process item using by the admin in same network.")
public void addProcessItemByAdminSameNetwork() throws Exception
{
restClient.authenticateUser(adminUser);
adminTenantUser = UserModel.getAdminTenantUser();
restClient.usingTenant().createTenant(adminTenantUser);
tenantUser = dataUser.usingUser(adminTenantUser).createUserWithTenant("uTenant");
tenantUserAssignee = dataUser.usingUser(adminTenantUser).createUserWithTenant("uTenantAssignee");
siteModel = dataSite.usingUser(adminTenantUser).createPublicRandomSite();
dataWorkflow.usingUser(tenantUser).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(tenantUserAssignee);
processModel = restClient.withWorkflowAPI().getProcesses().getOneRandomEntry().onModel();
processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
processItem.assertThat().field("createdAt").isNotEmpty().and().field("size").is("19").and().field("createdBy").is(adminUser.getUsername()).and()
.field("modifiedAt").isNotEmpty().and().field("name").is(document.getName()).and().field("modifiedBy").is(adminUser.getUsername()).and()
.field("id").isNotEmpty().and().field("mimeType").is(document.getFileType().mimeType);
}
@Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE, TestGroup.NETWORKS })
@TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.SANITY, description = "Add process item using by admin in other network.")
public void addProcessItemByAdminInOtherNetwork() throws Exception
{
adminTenantUser = UserModel.getAdminTenantUser();
restClient.authenticateUser(adminUser).usingTenant().createTenant(adminTenantUser);
tenantUserAssignee = dataUser.usingUser(adminTenantUser).createUserWithTenant("uTenantAssignee");
adminTenantUser2 = UserModel.getAdminTenantUser();
restClient.usingTenant().createTenant(adminTenantUser2);
processModel = restClient.authenticateUser(adminTenantUser).withWorkflowAPI().addProcess("activitiAdhoc", tenantUserAssignee, false, Priority.Normal);
restClient.authenticateUser(adminTenantUser2);
processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document);
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PROCESS_RUNNING_IN_ANOTHER_TENANT);
}
@Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE })
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, description = "Adding process item is falling in case of invalid process id is provided")
public void failedAddingProcessItemIfInvalidProcessIdIsProvided() throws Exception
{
processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel();
processModel.setId("invalidProcessId");
processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError()
.containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidProcessId"));
}
@Bug(id = "ACE-5683")
@Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE })
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, description = "Adding process item is falling in case of invalid body item is provided")
public void failedAddingProcessItemIfInvalidItemBodyIsProvided() throws Exception
{
document.setNodeRef("invalidNodeRef");
processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidId"));
}
@Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE })
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, description = "Adding process item is falling in case of empty body item value is provided")
public void failedAddingProcessItemIfEmptyItemBodyIsProvided() throws Exception
{
document.setNodeRef("");
processItem = restClient.withWorkflowAPI().usingProcess(processModel).addProcessItem(document);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.REQUIRED_TO_ADD, "itemId"));
}
@Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE })
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, description = "Adding process item is falling in case of incomplete body (empty) is provided")
public void failedAddingProcessItemIfIncompleteBodyIsProvided() throws Exception
{
processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel();
RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, "{}", "processes/{processId}/items", processModel.getId());
restClient.processModel(RestItemModel.class, request);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.REQUIRED_TO_ADD, "itemId"));
}
}
@@ -22,7 +22,7 @@ import org.testng.annotations.Test;
public class AddTaskItemCoreTests extends RestTest
{
private UserModel userModel, assigneeUser, adminUser;
private UserModel userModel, assigneeUser, adminUser, anotherUser;
private SiteModel siteModel;
private FileModel fileModel, document;
private TaskModel taskModel;
@@ -41,21 +41,16 @@ public class AddTaskItemCoreTests extends RestTest
taskModel = dataWorkflow.usingUser(userModel).usingSite(siteModel).usingResource(fileModel).createNewTaskAndAssignTo(assigneeUser);
taskId = taskModel.getId();
restClient.authenticateUser(userModel);
}
@Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS, TestGroup.CORE })
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Add task item using random user.")
public void addTaskItemByRandomUser() throws JsonToModelConversionException, Exception
{
document = dataContent.usingSite(siteModel).createContent(DocumentType.XML);
anotherUser = dataUser.createRandomTestUser();
taskItem = restClient.authenticateUser(anotherUser).withWorkflowAPI().usingTask(taskModel).addTaskItem(fileModel);
taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
taskItem.assertThat().field("createdAt").isNotEmpty().and().field("size").isNotEmpty().and().field("createdBy").is(adminUser.getUsername()).and()
.field("modifiedAt").isNotEmpty().and().field("name").is(document.getName()).and().field("modifiedBy").is(userModel.getUsername()).and()
.field("id").is(document.getNodeRefWithoutVersion()).and().field("mimeType").is(document.getFileType().mimeType);
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
}
@Bug(id = "ACE-5683")
@@ -63,8 +58,8 @@ public class AddTaskItemCoreTests extends RestTest
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Adding task item, is falling in case invalid itemBody is provided")
public void failedAddingTaskItemIfInvalidItemBodyIsProvided() throws Exception
{
document.setNodeRef("invalidNodeRef");
taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document);
fileModel.setNodeRef("invalidNodeRef");
taskItem = restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).addTaskItem(fileModel);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidNodeRef"));
}
@@ -74,8 +69,8 @@ public class AddTaskItemCoreTests extends RestTest
@TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.TASKS }, executionType = ExecutionType.REGRESSION, description = "Adding task item is falling in case empty item body is provided")
public void failedAddingTaskItemIfEmptyItemBodyIsProvided() throws Exception
{
document.setNodeRef("");
taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document);
fileModel.setNodeRef("");
taskItem = restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).addTaskItem(fileModel);
// TODO - expected error message to be added
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("");
@@ -86,7 +81,7 @@ public class AddTaskItemCoreTests extends RestTest
public void failedAddingTaskItemIfInvalidTaskIdIsProvided() throws Exception
{
taskModel.setId("invalidTaskId");
taskItem = restClient.withWorkflowAPI().usingTask(taskModel).addTaskItem(document);
taskItem = restClient.authenticateUser(userModel).withWorkflowAPI().usingTask(taskModel).addTaskItem(fileModel);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidTaskId"));
}