001    /**
002     * Copyright 2005-2011 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     */
016    package org.kuali.rice.kew.quicklinks;
017    
018    import org.junit.Test;
019    import org.kuali.rice.core.api.util.KeyValue;
020    import org.kuali.rice.kew.quicklinks.service.QuickLinksService;
021    import org.kuali.rice.kew.service.KEWServiceLocator;
022    import org.kuali.rice.kew.test.KEWTestCase;
023    import org.kuali.rice.test.BaselineTestCase;
024    import org.kuali.rice.test.SQLDataLoader;
025    
026    import java.util.List;
027    
028    import static org.junit.Assert.*;
029    
030    /**
031     * Test the QuickLinks Service
032     *
033     * @author Kuali Rice Team (rice.collab@kuali.org)
034     */
035    @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
036    public class QuickLinksServiceTest extends KEWTestCase {
037        private static String principalId = "admin";
038        private static String badPrincipalId = "joeshmoe";
039    
040        private QuickLinksService service;
041    
042        @Override
043        protected void loadTestData() throws Exception {
044            new SQLDataLoader("classpath:org/kuali/rice/kew/quicklinks/actionItem.sql", ";").runSql();
045            new SQLDataLoader("classpath:org/kuali/rice/kew/quicklinks/documentRoute.sql", ";").runSql();
046            new SQLDataLoader("classpath:org/kuali/rice/kew/quicklinks/documentType.sql", ";").runSql();
047            new SQLDataLoader("classpath:org/kuali/rice/kew/quicklinks/userOption.sql", ";").runSql();
048        }
049    
050        @Override
051        protected void setUpAfterDataLoad() throws Exception {
052            service = (QuickLinksService) KEWServiceLocator.getService(KEWServiceLocator.QUICK_LINKS_SERVICE);
053        }
054    
055        @Test
056        public void testGetActionListStats() {
057            List<ActionListStats> actionListStats = service.getActionListStats(principalId);
058            assertNotNull("No collection returned", actionListStats);
059            assertTrue("No test data", actionListStats.size() > 0);
060            assertEquals("Wrong number of Action List Stats", 3, actionListStats.size());
061            ActionListStats als = actionListStats.get(0);
062            assertEquals("Wrong count", 1, als.getCount());
063            assertEquals("Wrong Type Label", "Add/modify EDEN workgroup", als.getDocumentTypeLabelText());
064            assertEquals("Wrong Type name", "EDENSERVICE-DOCS.WKGRPREQ", als.getDocumentTypeName());
065            als = actionListStats.get(2);
066            assertEquals("Wrong count", 4, als.getCount());
067            assertEquals("Wrong Type Label", "Travel Request", als.getDocumentTypeLabelText());
068            assertEquals("Wrong Type name", "TravelRequest", als.getDocumentTypeName());
069    
070            actionListStats = service.getActionListStats(badPrincipalId);
071            assertNotNull("No collection returned", actionListStats);
072            assertFalse("Found test data", actionListStats.size() > 0);
073        }
074    
075        @Test
076        public void testGetWatchedDocuments() {
077            List<WatchedDocument> watchedDocuments = service.getWatchedDocuments(principalId);
078            assertNotNull("No collection returned", watchedDocuments);
079            assertTrue("No test data", watchedDocuments.size() > 0);
080            assertEquals("Wrong number of Watched Documents", 28, watchedDocuments.size());
081    
082            WatchedDocument wd = watchedDocuments.get(0);
083            assertEquals("Wrong header id", "2694", wd.getDocumentHeaderId());
084            assertEquals("Wrong status code", "ENROUTE", wd.getDocumentStatusCode());
085            assertEquals("Wrong document title", "Travel Doc 2 - esdf", wd.getDocumentTitle());
086    
087            wd = watchedDocuments.get(27);
088            assertEquals("Wrong header id", "2120", wd.getDocumentHeaderId());
089            assertEquals("Wrong status code", "ENROUTE", wd.getDocumentStatusCode());
090            assertEquals("Wrong document title", "Routing workgroup CreatinAGroup123", wd.getDocumentTitle());
091    
092            watchedDocuments = service.getWatchedDocuments(badPrincipalId);
093            assertNotNull("No collection returned", watchedDocuments);
094            assertFalse("Found test data", watchedDocuments.size() > 0);
095        }
096    
097        @Test
098        public void testGetRecentSearches() {
099            List<KeyValue> recentSearches = service.getRecentSearches(principalId);
100            assertNotNull("No collection returned", recentSearches);
101            assertTrue("No test data", recentSearches.size() > 0);
102            assertEquals("Wrong number of Recent Searches", 5, recentSearches.size());
103    
104            KeyValue kv = recentSearches.get(0);
105            assertEquals("Wrong key", "DocSearch.LastSearch.Holding4", kv.getKey());
106            assertEquals("Wrong value", "Created=12/22/2008..;", kv.getValue().trim());
107    
108            kv = recentSearches.get(4);
109            assertEquals("Wrong key", "DocSearch.LastSearch.Holding0", kv.getKey());
110            assertEquals("Wrong value", "Created=11/04/2008..;", kv.getValue().trim());
111    
112            recentSearches = service.getRecentSearches(badPrincipalId);
113            assertNotNull("No collection returned", recentSearches);
114            assertFalse("Found test data", recentSearches.size() > 0);
115        }
116    
117        @Test
118        public void testGetNamedSearches() {
119            List<KeyValue> namedSearches = service.getNamedSearches(principalId);
120            assertNotNull("No collection returned", namedSearches);
121            assertTrue("No test data", namedSearches.size() > 0);
122            assertEquals("Wrong number of Named Searches", 3, namedSearches.size());
123    
124            KeyValue kv = namedSearches.get(0);
125            assertEquals("Wrong key", "DocSearch.NamedSearch.FindAlumni", kv.getKey());
126            assertEquals("Wrong value", "FindAlumni", kv.getValue());
127    
128            kv = namedSearches.get(2);
129            assertEquals("Wrong key", "DocSearch.NamedSearch.FindStudent", kv.getKey());
130            assertEquals("Wrong value", "FindStudent", kv.getValue());
131    
132            namedSearches = service.getRecentSearches(badPrincipalId);
133            assertNotNull("No collection returned", namedSearches);
134            assertFalse("Found test data", namedSearches.size() > 0);
135        }
136    
137        @Test
138        public void testGetInitiatedDocumentTypesList() {
139            List<InitiatedDocumentType> initiatedDocumentTypesList = service.getInitiatedDocumentTypesList(principalId);
140            assertNotNull("No collection returned", initiatedDocumentTypesList);
141            assertTrue("No test data", initiatedDocumentTypesList.size() > 0);
142            assertEquals("Wrong number of Document Types List", 8, initiatedDocumentTypesList.size());
143    
144            InitiatedDocumentType idt = initiatedDocumentTypesList.get(0);
145            assertEquals("Wrong Type Label Text", "Add/modify EDEN workgroup", idt.getDocumentTypeLabelText());
146            assertEquals("Wrong Type Name", "EDENSERVICE-DOCS.WKGRPREQ", idt.getDocumentTypeName());
147    
148            idt = initiatedDocumentTypesList.get(7);
149            assertEquals("Wrong Type Label Text", "Travel Request", idt.getDocumentTypeLabelText());
150            assertEquals("Wrong Type Name", "TravelRequest", idt.getDocumentTypeName());
151    
152    
153            initiatedDocumentTypesList = service.getInitiatedDocumentTypesList(badPrincipalId);
154            assertNotNull("No collection returned", initiatedDocumentTypesList);
155            assertFalse("Found test data", initiatedDocumentTypesList.size() > 0);
156        }
157    }