View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.quicklinks;
17  
18  import org.junit.Test;
19  import org.kuali.rice.core.api.util.KeyValue;
20  import org.kuali.rice.kew.quicklinks.service.QuickLinksService;
21  import org.kuali.rice.kew.service.KEWServiceLocator;
22  import org.kuali.rice.kew.test.KEWTestCase;
23  import org.kuali.rice.test.BaselineTestCase;
24  import org.kuali.rice.test.SQLDataLoader;
25  
26  import java.sql.Date;
27  import java.text.DateFormat;
28  import java.text.SimpleDateFormat;
29  import java.util.List;
30  
31  import static org.junit.Assert.*;
32  
33  /**
34   * Test the QuickLinks Service
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
39  public class QuickLinksServiceTest extends KEWTestCase {
40      private static String principalId = "admin";
41      private static String badPrincipalId = "joeshmoe";
42  
43      private QuickLinksService service;
44  
45      @Override
46      protected void loadTestData() throws Exception {
47          new SQLDataLoader("classpath:org/kuali/rice/kew/quicklinks/actionItem.sql", ";").runSql();
48          new SQLDataLoader("classpath:org/kuali/rice/kew/quicklinks/documentRoute.sql", ";").runSql();
49          new SQLDataLoader("classpath:org/kuali/rice/kew/quicklinks/documentType.sql", ";").runSql();
50          new SQLDataLoader("classpath:org/kuali/rice/kew/quicklinks/userOption.sql", ";").runSql();
51      }
52  
53      @Override
54      protected void setUpAfterDataLoad() throws Exception {
55          service = (QuickLinksService) KEWServiceLocator.getService(KEWServiceLocator.QUICK_LINKS_SERVICE);
56      }
57  
58      @Test
59      public void testGetActionListStats() {
60          List<ActionListStats> actionListStats = service.getActionListStats(principalId);
61          assertNotNull("No collection returned", actionListStats);
62          assertTrue("No test data", actionListStats.size() > 0);
63          assertEquals("Wrong number of Action List Stats", 3, actionListStats.size());
64          ActionListStats als = actionListStats.get(0);
65          assertEquals("Wrong count", 1, als.getCount());
66          assertEquals("Wrong Type Label", "Add/modify EDEN workgroup", als.getDocumentTypeLabelText());
67          assertEquals("Wrong Type name", "EDENSERVICE-DOCS.WKGRPREQ", als.getDocumentTypeName());
68          als = actionListStats.get(2);
69          assertEquals("Wrong count", 4, als.getCount());
70          assertEquals("Wrong Type Label", "Travel Request", als.getDocumentTypeLabelText());
71          assertEquals("Wrong Type name", "TravelRequest", als.getDocumentTypeName());
72  
73          actionListStats = service.getActionListStats(badPrincipalId);
74          assertNotNull("No collection returned", actionListStats);
75          assertFalse("Found test data", actionListStats.size() > 0);
76      }
77  
78      @Test
79      public void testGetWatchedDocuments() {
80          List<WatchedDocument> watchedDocuments = service.getWatchedDocuments(principalId);
81          assertNotNull("No collection returned", watchedDocuments);
82          assertTrue("No test data", watchedDocuments.size() > 0);
83          assertEquals("Wrong number of Watched Documents", 28, watchedDocuments.size());
84  
85          WatchedDocument wd = watchedDocuments.get(0);
86          assertEquals("Wrong header id", "2694", wd.getDocumentHeaderId());
87          assertEquals("Wrong status code", "ENROUTE", wd.getDocumentStatusCode());
88          assertEquals("Wrong document title", "Travel Doc 2 - esdf", wd.getDocumentTitle());
89  
90          wd = watchedDocuments.get(27);
91          assertEquals("Wrong header id", "2120", wd.getDocumentHeaderId());
92          assertEquals("Wrong status code", "ENROUTE", wd.getDocumentStatusCode());
93          assertEquals("Wrong document title", "Routing workgroup CreatinAGroup123", wd.getDocumentTitle());
94  
95          watchedDocuments = service.getWatchedDocuments(badPrincipalId);
96          assertNotNull("No collection returned", watchedDocuments);
97          assertFalse("Found test data", watchedDocuments.size() > 0);
98      }
99  
100     @Test
101     public void testGetRecentSearches() {
102 		DateFormat df = new SimpleDateFormat("'Created='MM/dd/yyyy'..;'");
103         List<KeyValue> recentSearches = service.getRecentSearches(principalId);
104 
105         assertNotNull("No collection returned", recentSearches);
106         assertTrue("No test data", recentSearches.size() > 0);
107         assertEquals("Wrong number of Recent Searches", 5, recentSearches.size());
108 
109         KeyValue kv = recentSearches.get(0);
110         assertEquals("Wrong key", "DocSearch.LastSearch.Holding4", kv.getKey());
111         assertEquals("Wrong value", df.format(new Date( 1229925600000L)), kv.getValue().trim());
112 
113         kv = recentSearches.get(4);
114         assertEquals("Wrong key", "DocSearch.LastSearch.Holding0", kv.getKey());
115         assertEquals("Wrong value", df.format(new Date( 1225778400000L)), kv.getValue().trim());
116 
117         recentSearches = service.getRecentSearches(badPrincipalId);
118         assertNotNull("No collection returned", recentSearches);
119         assertFalse("Found test data", recentSearches.size() > 0);
120     }
121 
122     @Test
123     public void testGetNamedSearches() {
124         List<KeyValue> namedSearches = service.getNamedSearches(principalId);
125         assertNotNull("No collection returned", namedSearches);
126         assertTrue("No test data", namedSearches.size() > 0);
127         assertEquals("Wrong number of Named Searches", 3, namedSearches.size());
128 
129         KeyValue kv = namedSearches.get(0);
130         assertEquals("Wrong key", "DocSearch.NamedSearch.FindAlumni", kv.getKey());
131         assertEquals("Wrong value", "FindAlumni", kv.getValue());
132 
133         kv = namedSearches.get(2);
134         assertEquals("Wrong key", "DocSearch.NamedSearch.FindStudent", kv.getKey());
135         assertEquals("Wrong value", "FindStudent", kv.getValue());
136 
137         namedSearches = service.getRecentSearches(badPrincipalId);
138         assertNotNull("No collection returned", namedSearches);
139         assertFalse("Found test data", namedSearches.size() > 0);
140     }
141 
142     @Test
143     public void testGetInitiatedDocumentTypesList() {
144         List<InitiatedDocumentType> initiatedDocumentTypesList = service.getInitiatedDocumentTypesList(principalId);
145         assertNotNull("No collection returned", initiatedDocumentTypesList);
146         assertTrue("No test data", initiatedDocumentTypesList.size() > 0);
147         assertEquals("Wrong number of Document Types List", 8, initiatedDocumentTypesList.size());
148 
149         InitiatedDocumentType idt = initiatedDocumentTypesList.get(0);
150         assertEquals("Wrong Type Label Text", "Add/modify EDEN workgroup", idt.getDocumentTypeLabelText());
151         assertEquals("Wrong Type Name", "EDENSERVICE-DOCS.WKGRPREQ", idt.getDocumentTypeName());
152 
153         idt = initiatedDocumentTypesList.get(7);
154         assertEquals("Wrong Type Label Text", "Travel Request", idt.getDocumentTypeLabelText());
155         assertEquals("Wrong Type Name", "TravelRequest", idt.getDocumentTypeName());
156 
157 
158         initiatedDocumentTypesList = service.getInitiatedDocumentTypesList(badPrincipalId);
159         assertNotNull("No collection returned", initiatedDocumentTypesList);
160         assertFalse("Found test data", initiatedDocumentTypesList.size() > 0);
161     }
162 }