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