1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.lookup;
17
18 import org.junit.Ignore;
19 import org.junit.Test;
20 import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
21 import org.kuali.rice.kim.api.identity.Person;
22 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
23 import org.kuali.rice.kim.impl.identity.PersonImpl;
24 import org.kuali.rice.kns.lookup.LookupResultsService;
25 import org.kuali.rice.kns.service.KNSServiceLocator;
26 import org.kuali.rice.krad.service.KRADServiceLocator;
27 import org.kuali.test.KRADTestCase;
28
29 import java.util.Collection;
30 import java.util.HashMap;
31 import java.util.HashSet;
32 import java.util.Iterator;
33 import java.util.Map;
34 import java.util.Set;
35
36
37
38
39
40
41
42 public class LookupResultsServiceTest extends KRADTestCase {
43 public final static String MOCK_PARAMETER_NMSPC = "KR-NS";
44 public final static String MOCK_PARAMETER_DETAIL_TYPE_CODE = "All";
45 public final static String MOCK_PARAMETER_NAME = "DATE_TO_STRING_FORMAT_FOR_FILE_NAME";
46 public final static String MOCK_PERSON = "quickstart";
47
48
49
50
51
52 @Ignore
53 @Test public void testLookupIds() {
54 Map<String, String> parameterPK = new HashMap<String, String>();
55 parameterPK.put("namespaceCode", MOCK_PARAMETER_NMSPC);
56 parameterPK.put("componentCode", MOCK_PARAMETER_DETAIL_TYPE_CODE);
57 parameterPK.put("name", MOCK_PARAMETER_NAME);
58 final ParameterBo parameter = (ParameterBo) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(ParameterBo.class, parameterPK);
59 final Person person = KimApiServiceLocator.getPersonService().getPerson(LookupResultsServiceTest.MOCK_PERSON);
60 final LookupResultsDDBo ddBo = new LookupResultsDDBo("horse");
61 final LookupResultsService lookupResultsService = KNSServiceLocator.getLookupResultsService();
62
63 org.junit.Assert.assertEquals("Parameter's lookup id should be its object id", parameter.getObjectId(), lookupResultsService.getLookupId(parameter));
64 org.junit.Assert.assertNull("Person's lookup id should be null", lookupResultsService.getLookupId(person));
65 org.junit.Assert.assertEquals("LookupResultsDDBo's lookup id should be a squashed PK String", "someValue-horse", lookupResultsService.getLookupId(ddBo));
66 }
67
68
69
70
71
72 @Ignore
73 @Test public void testPersistableBusinessObjectSearch() throws Exception {
74 Map<String, String> parameterPK = new HashMap<String, String>();
75 parameterPK.put("namespaceCode", MOCK_PARAMETER_NMSPC);
76 parameterPK.put("componentCode", MOCK_PARAMETER_DETAIL_TYPE_CODE);
77 parameterPK.put("name", MOCK_PARAMETER_NAME);
78 final ParameterBo parameter = (ParameterBo) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(ParameterBo.class, parameterPK);
79 final LookupResultsService lookupResultsService = KNSServiceLocator.getLookupResultsService();
80
81 Set<String> parameterIds = new HashSet<String>();
82 parameterIds.add(lookupResultsService.getLookupId(parameter));
83 lookupResultsService.persistSelectedObjectIds("testPBOSearch", parameterIds, LookupResultsServiceTest.MOCK_PERSON);
84
85
86 Collection<ParameterBo> retrievedParameters = lookupResultsService.retrieveSelectedResultBOs("testPBOSearch", ParameterBo.class, LookupResultsServiceTest.MOCK_PERSON);
87 org.junit.Assert.assertNotNull("We have a collection of retrieved Parameters", retrievedParameters);
88 org.junit.Assert.assertEquals("Retrieved parameters collection size is 1", new Integer(1), new Integer(retrievedParameters.size()));
89 final Iterator<ParameterBo> parameterIterator = retrievedParameters.iterator();
90 final ParameterBo retrievedParameter = parameterIterator.next();
91 while (parameterIterator.hasNext()) {
92 parameterIterator.next();
93 }
94 org.junit.Assert.assertTrue("Parameter was one which was saved", retrievedParameter.getNamespaceCode().equals(MOCK_PARAMETER_NMSPC) && retrievedParameter.getComponentCode().equals(MOCK_PARAMETER_DETAIL_TYPE_CODE) && retrievedParameter.getName().equals(MOCK_PARAMETER_NAME));
95 }
96
97
98
99
100
101 @Test public void testDataDictionaryBusinessObjectSearch() throws Exception {
102 final LookupResultsDDBo ddBo = new LookupResultsDDBo("gorilla");
103 final LookupResultsService lookupResultsService = KNSServiceLocator.getLookupResultsService();
104
105 Set<String> ddBoIds = new HashSet<String>();
106 ddBoIds.add(lookupResultsService.getLookupId(ddBo));
107 lookupResultsService.persistSelectedObjectIds("testDDBOSearch", ddBoIds, LookupResultsServiceTest.MOCK_PERSON);
108
109 Collection<LookupResultsDDBo> retrievedDDBos = lookupResultsService.retrieveSelectedResultBOs("testDDBOSearch", LookupResultsDDBo.class, LookupResultsServiceTest.MOCK_PERSON);
110 org.junit.Assert.assertNotNull("We have a collection of retrieved Parameters", retrievedDDBos);
111 org.junit.Assert.assertEquals("Retrieved parameters collection size is 1", new Integer(1), new Integer(retrievedDDBos.size()));
112 final Iterator<LookupResultsDDBo> ddBosIterator = retrievedDDBos.iterator();
113 final LookupResultsDDBo retrievedDDBo = ddBosIterator.next();
114 while (ddBosIterator.hasNext()) {
115 ddBosIterator.next();
116 }
117 org.junit.Assert.assertEquals("LookupResultsDDBo lookup worked as expected", "gorilla", retrievedDDBo.getSomeValue());
118 }
119
120
121
122
123
124 @Test public void testBadSearch() {
125 boolean threwException = false;
126 final LookupResultsService lookupResultsService = KNSServiceLocator.getLookupResultsService();
127 try {
128 lookupResultsService.retrieveSelectedResultBOs("test data2", PersonImpl.class, LookupResultsServiceTest.MOCK_PERSON);
129 } catch (RuntimeException re) {
130 threwException = true;
131 } catch (Exception e) {
132 e.printStackTrace();
133 }
134 org.junit.Assert.assertTrue("Exception should have been thrown", threwException);
135 }
136 }