001/**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kew.actions;
017
018import org.junit.Test;
019import org.kuali.rice.kew.actions.BlanketApproveTest.NotifySetup;
020import org.kuali.rice.kew.api.WorkflowDocument;
021import org.kuali.rice.kew.api.WorkflowDocumentFactory;
022import org.kuali.rice.kew.api.action.ActionType;
023import org.kuali.rice.kew.test.KEWTestCase;
024
025import static org.junit.Assert.*;
026
027/**
028 * Test SuperUserDissaprove actions from WorkflowDocument
029 *
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 */
032public class SuperUserDisapproveTest extends KEWTestCase {
033    private static final String DOC_TYPE = NotifySetup.DOCUMENT_TYPE_NAME;
034    private static final String DOC_TYPE_WITH_NOTIFY = "SUDisapproveWithNotificationTest";
035
036    protected void loadTestData() throws Exception {
037        loadXmlFile("ActionsConfig.xml");
038    }
039        
040    @Test public void testSuperUserDisapprove() throws Exception {
041        superUserDisapprove(false);
042    }
043
044    @Test public void testSuperUserDisapproveWithNotification() throws Exception {
045        superUserDisapprove(true);
046    }
047
048    protected void superUserDisapprove(boolean notify) throws Exception {
049        WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), notify ? DOC_TYPE_WITH_NOTIFY: DOC_TYPE);
050        document.route("");
051
052        WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()).approve("");
053        WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).approve("");
054        WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()).approve("");
055
056        document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId());
057        assertTrue("WorkflowDocument should indicate jhopf as SuperUser", document.isValidAction(ActionType.SU_DISAPPROVE));
058        document.superUserDisapprove("");
059        assertTrue("Document should be final after Super User Disapprove", document.isDisapproved());
060        if (notify) {
061            assertTrue(WorkflowDocumentFactory.loadDocument(document.getInitiatorPrincipalId(), document.getDocumentId()).isAcknowledgeRequested());
062            assertTrue(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).isAcknowledgeRequested());
063            assertTrue(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()).isAcknowledgeRequested());
064            // jhopf took the super user action so should not be notified of disapproval (see KULRICE-752)
065            assertFalse(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()).isAcknowledgeRequested());
066        }
067        }
068        
069    @Test public void testSuperUserInitiatorDisapprove() throws Exception {
070        superUserInitiatorDisapprove(false);
071    }
072
073    @Test public void testSuperUserInitiatorDisapproveWithNotification() throws Exception {
074        superUserInitiatorDisapprove(true);
075    }
076    
077    protected void superUserInitiatorDisapprove(boolean notify) throws Exception {
078                WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), notify ? DOC_TYPE_WITH_NOTIFY: DOC_TYPE);
079        document.route("");
080        
081        WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()).approve("");
082        WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).approve("");
083        WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()).approve("");
084
085        document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
086        assertTrue("WorkflowDocument should indicate ewestfal as SuperUser", document.isValidAction(ActionType.SU_DISAPPROVE));
087        document.superUserDisapprove("");
088        assertTrue("Document should be final after Super User Disapprove", document.isDisapproved());
089        if (notify) {
090            assertTrue(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()).isAcknowledgeRequested());
091            assertTrue(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()).isAcknowledgeRequested());
092            // initiator doesn't get Ack for their own action
093            assertFalse(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).isAcknowledgeRequested());
094        }
095        }
096
097    @Test public void testSuperUserInitiatorImmediateDisapprove() throws Exception {
098        superUserInitiatorImmediateDisapprove(false);
099    }
100
101    @Test public void testSuperUserInitiatorImmediateDisapproveWithNotification() throws Exception {
102        superUserInitiatorImmediateDisapprove(true);
103    }
104
105    protected void superUserInitiatorImmediateDisapprove(boolean notify) throws Exception {
106        WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), notify ? DOC_TYPE_WITH_NOTIFY: DOC_TYPE);
107        assertTrue("WorkflowDocument should indicate ewestfal as SuperUser", document.isValidAction(ActionType.SU_DISAPPROVE));
108        document.superUserDisapprove("");
109        assertTrue("Document should be final after Super User Disapprove", document.isDisapproved());
110        // initiator doesn't get Ack for their own action
111        assertFalse(WorkflowDocumentFactory.loadDocument(document.getInitiatorPrincipalId(), document.getDocumentId()).isAcknowledgeRequested());
112        assertFalse(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).isAcknowledgeRequested());
113    }
114        
115    @Test public void testSuperUserDisapproveInvalidUser() throws Exception {
116                WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
117        document.route("");
118        
119        document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("quickstart"), document.getDocumentId());
120        try {
121                assertFalse("WorkflowDocument should not indicate quickstart as SuperUser", document.isValidAction(ActionType.SU_DISAPPROVE));
122                document.superUserDisapprove("");
123                fail("invalid user attempted to SuperUserApprove");
124        } catch (Exception e) {
125        }
126        
127        }
128        
129}