1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.test.service;
17
18 import org.junit.Test;
19 import org.kuali.rice.core.api.config.property.ConfigContext;
20 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
21 import org.kuali.rice.kim.api.identity.IdentityService;
22 import org.kuali.rice.kim.api.identity.entity.Entity;
23 import org.kuali.rice.kim.api.identity.entity.EntityDefault;
24 import org.kuali.rice.kim.api.identity.principal.Principal;
25 import org.kuali.rice.kim.impl.identity.EntityDefaultInfoCacheBo;
26 import org.kuali.rice.kim.impl.identity.IdentityArchiveService;
27 import org.kuali.rice.kim.test.KIMTestCase;
28 import org.kuali.rice.krad.data.KradDataServiceLocator;
29 import org.kuali.rice.test.BaselineTestCase;
30
31 import java.util.ArrayList;
32 import java.util.Collections;
33 import java.util.List;
34 import java.util.UUID;
35
36 import static org.junit.Assert.*;
37
38
39
40
41
42
43 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
44 public class IdentityCurrentAndArchivedServiceTest extends KIMTestCase {
45
46 public static final String KIM_IDENTITY_SERVICE = "kimIdentityService";
47 public static final String KIM_IDENTITY_ARCHIVE_SERVICE = "kimIdentityArchiveService";
48
49
50 private IdentityService identityService;
51 private IdentityArchiveService identityArchiveService;
52
53 public static IdentityArchiveService getIdentityArchiveService() {
54 return GlobalResourceLoader.getService(KIM_IDENTITY_ARCHIVE_SERVICE);
55 }
56 public static IdentityService getIdentityService() {
57 return GlobalResourceLoader.getService(KIM_IDENTITY_SERVICE);
58 }
59
60 public void setUp() throws Exception {
61 super.setUp();
62 if (null == identityService) {
63 identityService = getIdentityService();
64 }
65
66 if (null == identityArchiveService) {
67 identityArchiveService = getIdentityArchiveService();
68 }
69 }
70
71 @Test
72 public void testGetEntityDefault() throws Exception {
73
74 MinimalKEDIBuilder builder = new MinimalKEDIBuilder("bogususer");
75 builder.setEntityId("bogususer");
76 EntityDefault bogusUserInfo = builder.build();
77
78
79 identityArchiveService.saveEntityDefaultToArchive(bogusUserInfo);
80 identityArchiveService.flushToArchive();
81
82
83 EntityDefault retrieved = identityArchiveService.getEntityDefaultFromArchiveByPrincipalId(
84 builder.getPrincipalId());
85 assertNotNull("no value retrieved for principalId: " + retrieved.getPrincipals().get(0).getPrincipalId(), retrieved);
86
87
88 retrieved = identityService.getEntityDefaultByPrincipalId("bogususer");
89 assertNotNull("no value retrieved for principalId: " + retrieved.getPrincipals().get(0).getPrincipalId(), retrieved);
90
91
92 EntityDefault retrieveAgain = identityService.getEntityDefaultByPrincipalId("bogususer");
93 assertNotNull("no value retrieved for principalId: " + retrieveAgain.getPrincipals().get(0).getPrincipalId(), retrieveAgain);
94
95
96 }
97
98
99 @SuppressWarnings("unused")
100 private static class MinimalKEDIBuilder {
101 private String entityId;
102 private String principalId;
103 private String principalName;
104 private Boolean active;
105
106 public MinimalKEDIBuilder(String name) {
107 entityId = UUID.randomUUID().toString();
108 principalId = principalName = name;
109 }
110
111 public EntityDefault build() {
112 if (entityId == null) entityId = UUID.randomUUID().toString();
113 if (principalId == null) principalId = UUID.randomUUID().toString();
114 if (principalName == null) principalName = principalId;
115 if (active == null) active = true;
116
117 Principal.Builder principal = Principal.Builder.create(principalName);
118 principal.setActive(active);
119 principal.setEntityId(entityId);
120 principal.setPrincipalId(principalId);
121
122 EntityDefault.Builder kedi = EntityDefault.Builder.create();
123 kedi.setPrincipals(Collections.singletonList(principal));
124 kedi.setEntityId(entityId);
125
126 return kedi.build();
127 }
128
129
130
131
132 public String getEntityId() {
133 return this.entityId;
134 }
135
136
137
138
139 public void setEntityId(String entityId) {
140 this.entityId = entityId;
141 }
142
143
144
145
146 public String getPrincipalId() {
147 return this.principalId;
148 }
149
150
151
152
153 public void setPrincipalId(String principalId) {
154 this.principalId = principalId;
155 }
156
157
158
159
160 public String getPrincipalName() {
161 return this.principalName;
162 }
163
164
165
166
167 public void setPrincipalName(String principalName) {
168 this.principalName = principalName;
169 }
170
171
172
173
174 public Boolean getActive() {
175 return this.active;
176 }
177
178
179
180
181 public void setActive(Boolean active) {
182 this.active = active;
183 }
184
185
186 }
187
188 }