001package edu.samplu.admin.config.namespace.pending;
002
003import edu.samplu.admin.test.AdminTmplMthdSTNavBase;
004import edu.samplu.common.ITUtil;
005import org.apache.commons.lang.RandomStringUtils;
006
007/**
008 * @author Kuali Rice Team (rice.collab@kuali.org)
009 */
010
011public abstract class PendingBase extends AdminTmplMthdSTNavBase {
012    /**
013     * methodToCall.insertAdHocRoutePerson
014     */
015    protected static final String ADD_PERSON_ELEMENT_NAME = "methodToCall.insertAdHocRoutePerson";
016
017    /**
018     * newAdHocRoutePerson.id
019     */
020    protected static final String ADD_PERSON_TEXT_ELEMENT_NAME = "newAdHocRoutePerson.id";
021
022    /**
023     * methodToCall.toggleTab.tabAdHocRecipients
024     */
025    protected static final String DOCUMENT_AD_HOC_RECIPIENTS_TOGGLE = "methodToCall.toggleTab.tabAdHocRecipients";
026    /**
027     * document.documentHeader.documentDescription
028     */
029    protected static final String DOCUMENT_DESCRIPTION_NAME = "document.documentHeader.documentDescription";
030
031    /**
032     * document.newMaintainableObject.code
033     */
034    protected static final String DOCUMENT_CODE_NAME = "document.newMaintainableObject.code";
035
036    /**
037     * document.newMaintainableObject.name
038     */
039    protected static final String DOCUMENT_NAME = "document.newMaintainableObject.name";
040
041    /**
042     * document.newMaintainableObject.applicationId
043     */
044    protected static final String DOCUMENT_APPLICATIONID_NAME = "document.newMaintainableObject.applicationId";
045
046    /**
047     * methodToCall.performLookup.(!!org.kuali.rice.kim.impl.group.GroupBo!!).(((namespaceCode:newAdHocRouteWorkgroup.recipientNamespaceCode,name:newAdHocRouteWorkgroup.recipientName))).((`newAdHocRouteWorkgroup.recipientNamespaceCode:namespaceCode,newAdHocRouteWorkgroup.recipientName:name`)).((<>)).(([])).((**)).((^^)).((&&)).((//)).((~~)).(::::;;::::).anchor
048     */
049    protected static final String NAME_LOOKUP_COMPONENT_NAME ="methodToCall.performLookup.(!!org.kuali.rice.kim.impl.group.GroupBo!!).(((namespaceCode:newAdHocRouteWorkgroup.recipientNamespaceCode,name:newAdHocRouteWorkgroup.recipientName))).((`newAdHocRouteWorkgroup.recipientNamespaceCode:namespaceCode,newAdHocRouteWorkgroup.recipientName:name`)).((<>)).(([])).((**)).((^^)).((&&)).((//)).((~~)).(::::;;::::).anchor";
050
051    /**
052     * newAdHocRoutePerson.actionRequested
053     */
054    protected static final String NEW_AD_HOC_ROUTE_PERSON_ACTION_REQUESTED = "newAdHocRoutePerson.actionRequested";
055
056    /**
057     * methodToCall.route
058     */
059    protected static final String SUBMIT_NAME = "methodToCall.route";
060
061    protected void assertSuperGroup(String docId) throws InterruptedException {
062        // second checkbox (APPROVED)
063        waitAndClick("#tab-SuperUserAction-div > div:nth-child(2) > table:nth-child(2) > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(1) > input:nth-child(1)");
064        waitAndTypeByName("superUserAnnotation","test suaction");
065        waitAndClickByName("methodToCall.takeSuperUserActions");
066        if(!isTextPresent("Group1")) {
067            assertTextPresent("superuser approved in Document " + docId);
068        } else {
069            fail("Super User Approve functionality may not be working.");
070        }
071    }
072        /**
073        * {@inheritDoc}
074        * Namespace
075        * @return
076        */
077    @Override
078    protected String getLinkLocator() {
079        return "Namespace";
080    }
081
082    protected void fillInAddAdHocPersons(String[][] personsActions) throws Exception {
083        waitAndClickByName(DOCUMENT_AD_HOC_RECIPIENTS_TOGGLE);
084
085        for (String[] personAction: personsActions) {
086            waitAndTypeByName(ADD_PERSON_TEXT_ELEMENT_NAME, personAction[0]);
087            if (personAction.length > 1) {
088                selectByName(NEW_AD_HOC_ROUTE_PERSON_ACTION_REQUESTED, personAction[1]);
089            }
090            waitAndClickByName(ADD_PERSON_ELEMENT_NAME);
091            Thread.sleep(1000);
092        }
093    }
094
095    protected void fillInAdHocGroups(String[][] groupsActions) throws Exception {
096        waitAndClickByName(DOCUMENT_AD_HOC_RECIPIENTS_TOGGLE);
097        for (String[] groupAction: groupsActions) {
098            waitAndClickByName(NAME_LOOKUP_COMPONENT_NAME);
099            waitAndTypeByName("name", groupAction[0]);
100            waitAndClickByXpath(SEARCH_XPATH);
101            waitAndClickByLinkText("return value");
102            if (groupAction.length > 1) {
103                selectByName("newAdHocRouteWorkgroup.actionRequested", groupAction[1]);
104            }
105            waitAndClickByName("methodToCall.insertAdHocRouteWorkgroup");
106            Thread.sleep(1000);
107        }
108    }
109
110    protected void fillInNamespaceOverview(String descBase, String codeNameBase, String nameBase, String appId) throws Exception {
111        selectFrameIframePortlet();
112        waitAndCreateNew();
113        waitAndTypeByName(DOCUMENT_DESCRIPTION_NAME, descBase + " " + ITUtil.createUniqueDtsPlusTwoRandomCharsNot9Digits());
114        String randomFour = RandomStringUtils.randomAlphabetic(4).toLowerCase();
115        waitAndTypeByName(DOCUMENT_CODE_NAME, codeNameBase + randomFour);
116        waitAndTypeByName(DOCUMENT_NAME, nameBase + randomFour);
117        waitAndTypeByName(DOCUMENT_APPLICATIONID_NAME, appId);
118    }
119
120    protected String submitAndLookupDoc() throws InterruptedException {
121        waitAndClickByName(SUBMIT_NAME);
122        String docId= waitForDocId();
123        switchToWindow("Kuali Portal Index");
124        waitAndClickDocSearch();
125        selectFrameIframePortlet();
126        waitAndTypeByName("documentId",docId);
127        waitAndClickByXpath(SEARCH_XPATH);
128        if(!isTextPresent("No values match this search.")) {
129            waitAndClickByLinkText(docId);
130            switchToWindow("Kuali :: Namespace");
131        } else {
132            fail("Previous Document may have routing problem so the latest Document is not able to submit correctly.");
133        }
134        return docId;
135    }
136
137    protected void assertSuperPerson(String user, String action, String docId) throws InterruptedException {
138        waitAndClickByName("selectedActionRequests");
139        waitAndTypeByName("superUserAnnotation","test suaction");
140        waitAndClickByName("methodToCall.takeSuperUserActions");
141
142        Thread.sleep(1000);
143        if(!isTextPresent(user)) {
144            assertTextPresent("superuser " + action + " in Document " + docId);
145        } else {
146            fail("Super User Approve functionality may not be working.");
147        }
148    }
149}