baseURL = "http://"+req.getServerName()+":"+req.getServerPort()+"/DotAjaxDirector/com.dotmarketing.portlets.workflows.business.TestableWfStepAjax?cmd=add&stepName=Edit&schemeId=" + ws.getId();
testUrl = new URL(baseURL);
IOUtils.toString(testUrl.openStream(),"UTF-8");
List<WorkflowStep> steps = wapi.findSteps(ws);
Assert.assertTrue(steps.size()==1);
WorkflowStep step1 = steps.get(0);
/*
* Create scheme step2
*/
baseURL = "http://"+req.getServerName()+":"+req.getServerPort()+"/DotAjaxDirector/com.dotmarketing.portlets.workflows.business.TestableWfStepAjax?cmd=add&stepName=Publish&schemeId=" + ws.getId();
testUrl = new URL(baseURL);
IOUtils.toString(testUrl.openStream(),"UTF-8");
steps = wapi.findSteps(ws);
Assert.assertTrue(steps.size()==2);
WorkflowStep step2 = steps.get(1);
/*
* Add action to scheme step1
*/
baseURL = "http://"+req.getServerName()+":"+req.getServerPort()+"/DotAjaxDirector/com.dotmarketing.portlets.workflows.business.TestableWfActionAjax?cmd=save&stepId="+step1.getId()+"&schemeId="+UtilMethods.webifyString(ws.getId())+"&actionName=Edit&whoCanUse=";
baseURL+=role.getId()+",&actionIconSelect=workflowIcon&actionAssignable=true&actionCommentable=true&actionRequiresCheckout=false&actionRoleHierarchyForAssign=false";
baseURL+="&actionAssignToSelect="+role.getId()+"&actionNextStep="+step2.getId()+"&actionCondition=";
testUrl = new URL(baseURL);
IOUtils.toString(testUrl.openStream(),"UTF-8");
List<WorkflowAction> actions1= wapi.findActions(step1, systemUser);
Assert.assertTrue(actions1.size()==1);
WorkflowAction action1 = actions1.get(0);
/*
* Add action to scheme step2
*/
baseURL = "http://"+req.getServerName()+":"+req.getServerPort()+"/DotAjaxDirector/com.dotmarketing.portlets.workflows.business.TestableWfActionAjax?cmd=save&stepId="+step2.getId()+"&schemeId="+UtilMethods.webifyString(ws.getId())+"&actionName=Publish&whoCanUse=";
baseURL+=role.getId()+",&actionIconSelect=workflowIcon&actionAssignable=true&actionCommentable=true&actionRequiresCheckout=false&actionRoleHierarchyForAssign=false";
baseURL+="&actionAssignToSelect="+role.getId()+"&actionNextStep="+step2.getId()+"&actionCondition=";
testUrl = new URL(baseURL);
IOUtils.toString(testUrl.openStream(),"UTF-8");
List<WorkflowAction> actions2= wapi.findActions(step2, systemUser);
Assert.assertTrue(actions2.size()==1);
WorkflowAction action2 = actions2.get(0);
/*
* Create structure and add workflow scheme
*/
Structure st = StructureCache.getStructureByVelocityVarName("Issue5197Structure");
if(!UtilMethods.isSet(st) || !UtilMethods.isSet(st.getInode())){
st = new Structure();
st.setHost(host.getIdentifier());
st.setDescription("Testing issue 5197");
st.setName("Issue5197Structure");
st.setVelocityVarName("Issue5197Structure");
st.setStructureType(Structure.STRUCTURE_TYPE_CONTENT);
st.setFixed(false);
st.setOwner(systemUser.getUserId());
st.setExpireDateVar("");
st.setPublishDateVar("");
StructureFactory.saveStructure(st);
Permission p = new Permission();
p.setInode(st.getPermissionId());
p.setRoleId(roleAPI.loadCMSAnonymousRole().getId());
p.setPermission(PermissionAPI.PERMISSION_READ);
perAPI.save(p, st, systemUser, true);
p = new Permission();
p.setInode(st.getPermissionId());
p.setRoleId(roleAPI.loadCMSAnonymousRole().getId());
p.setPermission(PermissionAPI.PERMISSION_EDIT);
perAPI.save(p, st, systemUser, true);
p = new Permission();
p.setInode(st.getPermissionId());
p.setRoleId(roleAPI.loadCMSAnonymousRole().getId());
p.setPermission(PermissionAPI.PERMISSION_PUBLISH);
perAPI.save(p, st, systemUser, true);
Field title = new Field("Title",Field.FieldType.TEXT,Field.DataType.TEXT,st,true,true,true,1,"", "", "", false, false, true);
title.setVelocityVarName("title");
FieldFactory.saveField(title);
FieldsCache.addField(title);
}
APILocator.getWorkflowAPI().saveSchemeForStruct(st, ws);
/*
* Create test content and set it up in scheme step
*/
Contentlet contentlet1 = new Contentlet();
contentlet1.setStructureInode(st.getInode());
contentlet1.setHost(host.getIdentifier());
contentlet1.setLanguageId(APILocator.getLanguageAPI().getDefaultLanguage().getId());
contentlet1.setStringProperty("title", "test5197-1"+UtilMethods.dateToHTMLDate(new Date(), "MM-dd-yyyy-HHmmss"));
contentlet1.setHost(host.getIdentifier());
contentlet1 = APILocator.getContentletAPI().checkin(contentlet1, systemUser,false);
if(perAPI.doesUserHavePermission(contentlet1, PermissionAPI.PERMISSION_PUBLISH, systemUser))
APILocator.getVersionableAPI().setLive(contentlet1);
/*
* Test that delete is not possible for step2
* while has associated step or content
*/
contentlet1.setStringProperty("wfActionId", action1.getId());
contentlet1.setStringProperty("wfActionComments", "step1");
contentlet1.setStringProperty("wfActionAssign", role.getId());
wapi.fireWorkflowNoCheckin(contentlet1, systemUser);
contentlet1.setStringProperty("wfActionId", action2.getId());
contentlet1.setStringProperty("wfActionComments", "step2");
contentlet1.setStringProperty("wfActionAssign", role.getId());
wapi.fireWorkflowNoCheckin(contentlet1, systemUser);
WorkflowStep currentStep = wapi.findStepByContentlet(contentlet1);
Assert.assertTrue(currentStep.getId().equals(step2.getId()));
/*
* Validate that step2 could not be deleted
*/
try{
wapi.deleteStep(step2);
}catch(Exception e){
/*
* Should enter here with this exception
* </br> <b> Step : 'Publish' is being referenced by </b> </br></br> Step : 'Edit' -> Action : 'Edit' </br></br>
*/
}
Assert.assertTrue(UtilMethods.isSet(wapi.findStep(step2.getId())));
/*
* Validate correct deletion of step1
*/
wapi.deleteStep(step1);
/*
* Validate that the step 1 was deleted from the scheme
*/
steps = wapi.findSteps(ws);
Assert.assertTrue(steps.size()==1);
Assert.assertTrue(steps.get(0).getId().equals(step2.getId()));
/*
* Validate that step2 could not be deleted
*/
try{
wapi.deleteStep(step2);
}catch(Exception e){
/*
* Should enter here with this exception
* </br> <b> Step : 'Publish' is being referenced by: X Contentlet(s) </br></br>
*/
}
currentStep = wapi.findStepByContentlet(contentlet1);
Assert.assertTrue(currentStep.getId().equals(step2.getId()));
/*
* Validate that step2 is not deleted
*/
steps = wapi.findSteps(ws);