1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.krms.test;
18
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplate;
22 import org.springframework.dao.DataAccessException;
23
24 import java.util.List;
25
26 import static junit.framework.Assert.assertNotNull;
27 import static junit.framework.Assert.assertNull;
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.fail;
30
31
32
33
34
35
36
37 public class RuleManagementNaturalLanguageTemplateTest extends RuleManagementBaseTest {
38 @Override
39 @Before
40 public void setClassDiscriminator() {
41
42 CLASS_DISCRIMINATOR = "RMLTT";
43 }
44
45
46
47
48
49
50 @Test
51 public void testCreateNaturalLanguageTemplate() {
52
53 RuleManagementBaseTestObjectNames t0 = new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t0");
54
55
56 assertNull(ruleManagementService.getNaturalLanguageTemplate("en-reqActive"));
57
58
59 NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t0.namespaceName, "en", "reqActive",
60 "Must not be inActive");
61
62
63 template = ruleManagementService.getNaturalLanguageTemplate("en-reqActive");
64 assertNotNull(ruleManagementService.getNaturalLanguageTemplate("en-reqActive"));
65 assertEquals("Unexpected language code found", "en", template.getLanguageCode());
66 assertEquals("Unexpected template found", "Must not be inActive", template.getTemplate());
67 assertEquals("Unexpected TypeId value", krmsTypeRepository.getTypeByName(t0.namespaceName, "reqActive").getId(), template.getTypeId());
68
69 assertEquals("Unexpected Active value", false, template.isActive());
70
71
72 try {
73 NaturalLanguageTemplate.Builder.create(null,template.getNaturalLanguageUsageId(),"Ky objekt nuk duhet të jetë joaktive",template.getTypeId());
74 fail("Should have thrown IllegalArgumentException: languageCode is null or blank");
75 } catch (IllegalArgumentException e ) {
76
77 }
78
79
80 try {
81 NaturalLanguageTemplate.Builder.create(" ",template.getNaturalLanguageUsageId(),"Objektu hau ezin da ez-aktiboak",template.getTypeId());
82 fail("Should have thrown IllegalArgumentException: languageCode is null or blank");
83 } catch (IllegalArgumentException e ) {
84
85 }
86
87
88 try {
89 NaturalLanguageTemplate.Builder.create("it",null,"Questo oggetto non deve essere inattivo",template.getTypeId());
90 fail("Should have thrown IllegalArgumentException: naturalLanguageUsageId is null or blank");
91 } catch (IllegalArgumentException e ) {
92
93 }
94
95
96 try {
97 NaturalLanguageTemplate.Builder.create("ja"," ","このオブジェクトは、非アクティブにすることはできません",template.getTypeId());
98 fail("Should have thrown IllegalArgumentException: naturalLanguageUsageId is null or blank");
99 } catch (IllegalArgumentException e ) {
100
101 }
102
103
104 try {
105 NaturalLanguageTemplate.Builder.create("az",template.getNaturalLanguageUsageId(),null,template.getTypeId());
106 fail("Should have thrown IllegalArgumentException: template is null or blank");
107 } catch (IllegalArgumentException e ) {
108
109 }
110
111
112 try {
113 NaturalLanguageTemplate.Builder.create("bg",template.getNaturalLanguageUsageId()," ",template.getTypeId());
114 fail("Should have thrown IllegalArgumentException: template is null or blank");
115 } catch (IllegalArgumentException e ) {
116
117 }
118
119
120 try {
121 NaturalLanguageTemplate.Builder.create("hr",template.getNaturalLanguageUsageId(),"Ovaj objekt ne smije biti neaktivna",null);
122 fail("Should have thrown IllegalArgumentException: typeId is null or blank");
123 } catch (IllegalArgumentException e ) {
124
125 }
126
127
128 try {
129 NaturalLanguageTemplate.Builder.create("cs",template.getNaturalLanguageUsageId(),"Tento objekt nesmí být neaktivní"," ");
130 fail("Should have thrown IllegalArgumentException: typeId is null or blank");
131 } catch (IllegalArgumentException e ) {
132
133 }
134
135
136 NaturalLanguageTemplate.Builder naturalLanguageTemplateBuilder = NaturalLanguageTemplate.Builder.create("da",template.getNaturalLanguageUsageId(),"Dette formål må ikke være inaktiv","badId");
137 naturalLanguageTemplateBuilder.setId("da" + "-" + "reqActive");
138 try {
139 ruleManagementService.createNaturalLanguageTemplate(naturalLanguageTemplateBuilder.build());
140 fail("Should have thrown PersistenceException");
141 } catch (DataAccessException e) {
142
143
144
145 }
146 }
147
148
149
150
151
152
153 @Test
154 public void testGetNaturalLanguageTemplate() {
155
156 RuleManagementBaseTestObjectNames t1 = new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t1");
157
158 NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t1.namespaceName, "sw", "reqActive",
159 "Detta ändamål får inte vara inaktiv");
160 assertNotNull(ruleManagementService.getNaturalLanguageTemplate("sw-reqActive"));
161 assertEquals("Unexpected language code found", "sw", template.getLanguageCode());
162
163 try {
164 ruleManagementService.getNaturalLanguageTemplate(null);
165 fail("Should have thrown IllegalArgumentException: naturalLanguageTemplateId was null");
166 } catch (IllegalArgumentException e) {
167
168 }
169
170
171 try {
172 ruleManagementService.getNaturalLanguageTemplate(" ");
173 fail("Should have thrown IllegalArgumentException: naturalLanguageTemplateId was blank");
174 } catch (IllegalArgumentException e) {
175
176 }
177
178 assertNull(ruleManagementService.getNaturalLanguageTemplate("badId"));
179 }
180
181
182
183
184
185
186 @Test
187 public void testUpdateNaturalLanguageTemplate() {
188
189 RuleManagementBaseTestObjectNames t2 = new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t2");
190
191 NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t2.namespaceName, "pl", "reqActive",
192 "Isthay Objectway ustmay otnay ebay inActiveway");
193 NaturalLanguageTemplate.Builder naturalLanguageTemplateBuilder = NaturalLanguageTemplate.Builder.create(
194 ruleManagementService.getNaturalLanguageTemplate("pl-reqActive"));
195
196 naturalLanguageTemplateBuilder.setTemplate("Ten obiekt nie moze byc nieaktywne");
197 naturalLanguageTemplateBuilder.setActive(true);
198 ruleManagementService.updateNaturalLanguageTemplate(naturalLanguageTemplateBuilder.build());
199
200 assertEquals("Unexpected template value found", "Ten obiekt nie moze byc nieaktywne", ruleManagementService.getNaturalLanguageTemplate("pl-reqActive").getTemplate());
201
202 assertEquals("Unexpected isActive value found", false, ruleManagementService.getNaturalLanguageTemplate("pl-reqActive").isActive());
203 }
204
205
206
207
208
209
210 @Test
211 public void testDeleteNaturalLanguageTemplate() {
212
213 RuleManagementBaseTestObjectNames t3 = new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t3");
214
215 NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t3.namespaceName, "pt", "reqActive",
216 "Este objeto nao deve ser inativo");
217 assertNotNull("Should have found NaturalLanguageTemplate", ruleManagementService.getNaturalLanguageTemplate("pt-reqActive"));
218
219 ruleManagementService.deleteNaturalLanguageTemplate("pt-reqActive");
220
221
222 assertNull("Should not have found NaturalLanguageTemplate", ruleManagementService.getNaturalLanguageTemplate("pt-reqActive"));
223
224
225 try {
226 ruleManagementService.deleteNaturalLanguageTemplate(null);
227 fail("Should have thrown IllegalArgumentException: naturalLanguageTemplateId was null");
228 } catch (IllegalArgumentException e) {
229
230 }
231
232
233 try {
234 ruleManagementService.deleteNaturalLanguageTemplate(" ");
235 fail("Should have thrown IllegalArgumentException: naturalLanguageTemplateId was blank");
236 } catch (IllegalArgumentException e) {
237
238 }
239
240
241 try {
242 ruleManagementService.deleteNaturalLanguageTemplate("badValue");
243 fail("Should have thrown IllegalStateException: the NaturalLanguageTemplate to delete does not exists: badValue");
244 } catch (IllegalStateException e) {
245
246 }
247 }
248
249
250
251
252
253
254
255 @Test
256 public void testFindNaturalLanguageTemplatesByLanguageCode() {
257
258 RuleManagementBaseTestObjectNames t4 = new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t4");
259
260 NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t4.namespaceName, "ro", "reqActive",
261 "Acest obiect nu trebuie sa fie inactiv");
262 assertNotNull("Should have found NaturalLanguageTemplate", ruleManagementService.getNaturalLanguageTemplate("ro-reqActive"));
263
264 List<NaturalLanguageTemplate> nlTemplates = ruleManagementService.findNaturalLanguageTemplatesByLanguageCode("ro");
265 assertEquals("Unexpected number of templates returned ",1,nlTemplates.size());
266 assertEquals("Unexpected template id returned","ro-reqActive",nlTemplates.get(0).getId());
267
268
269 try {
270 ruleManagementService.findNaturalLanguageTemplatesByLanguageCode(null);
271 fail("Should have thrown IllegalArgumentException: languageCode is null or blank");
272 } catch (IllegalArgumentException e) {
273
274 }
275
276
277 try {
278 ruleManagementService.findNaturalLanguageTemplatesByLanguageCode(" ");
279 fail("Should have thrown IllegalArgumentException: languageCode is null or blank");
280 } catch (IllegalArgumentException e) {
281
282 }
283
284
285 assertEquals("Unexpected number of templates returned ",0,
286 ruleManagementService.findNaturalLanguageTemplatesByLanguageCode("badValue").size());
287 }
288
289
290
291
292
293
294
295
296 @Test
297 public void testFindNaturalLanguageTemplateByLanguageCodeTypeIdAndNluId() {
298
299 RuleManagementBaseTestObjectNames t5 = new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t5");
300
301 NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t5.namespaceName, "sk", "reqActive",
302 "Tento objekt nesmie byt neaktívne");
303 assertNotNull("Should have found NaturalLanguageTemplate", ruleManagementService.getNaturalLanguageTemplate("sk-reqActive"));
304
305
306 template = ruleManagementService.findNaturalLanguageTemplateByLanguageCodeTypeIdAndNluId(
307 template.getLanguageCode(),template.getTypeId(),template.getNaturalLanguageUsageId());
308
309
310 assertEquals("Unexpected template id returned","sk-reqActive",template.getId());
311 assertEquals("Unexpected language code found", "sk", template.getLanguageCode());
312 assertEquals("Unexpected template found", "Tento objekt nesmie byt neaktívne", template.getTemplate());
313 assertEquals("Unexpected TypeId value", krmsTypeRepository.getTypeByName(t5.namespaceName, "reqActive").getId(), template.getTypeId());
314
315 assertEquals("Unexpected Active value", false, template.isActive());
316
317
318 try {
319 ruleManagementService.findNaturalLanguageTemplateByLanguageCodeTypeIdAndNluId(
320 null,template.getTypeId(),template.getNaturalLanguageUsageId());
321 fail("Should have thrown IllegalArgumentException: languageCode is null or blank");
322 } catch (IllegalArgumentException e) {
323
324 }
325
326
327 ruleManagementService.findNaturalLanguageTemplateByLanguageCodeTypeIdAndNluId(
328 template.getLanguageCode(),null,template.getNaturalLanguageUsageId());
329
330
331 ruleManagementService.findNaturalLanguageTemplateByLanguageCodeTypeIdAndNluId(
332 template.getLanguageCode(),template.getTypeId(),null);
333
334
335 try {
336 ruleManagementService.findNaturalLanguageTemplateByLanguageCodeTypeIdAndNluId(
337 " ",template.getTypeId(),template.getNaturalLanguageUsageId());
338 fail("Should have thrown IllegalArgumentException: languageCode is null or blank");
339 } catch (IllegalArgumentException e) {
340
341 }
342 }
343
344
345
346
347
348
349
350
351 @Test
352 public void testFindNaturalLanguageTemplatesByNaturalLanguageUsage() {
353
354 RuleManagementBaseTestObjectNames t6 = new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t6");
355
356
357 NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t6.namespaceName, "sl", "reqActive-SL",
358 "Ta predmet ne sme biti neaktiven");
359 assertNotNull("Should have found NaturalLanguageTemplate", ruleManagementService.getNaturalLanguageTemplate("sl-reqActive-SL"));
360
361
362 List<NaturalLanguageTemplate> templates = ruleManagementService.findNaturalLanguageTemplatesByNaturalLanguageUsage(template.getNaturalLanguageUsageId());
363 assertEquals("Unexpected number of templates returned ",1,templates.size());
364 template = templates.get(0);
365
366
367 assertEquals("Unexpected template id returned","sl-reqActive-SL",template.getId());
368 assertEquals("Unexpected language code found", "sl", template.getLanguageCode());
369 assertEquals("Unexpected template found", "Ta predmet ne sme biti neaktiven", template.getTemplate());
370 assertEquals("Unexpected TypeId value", krmsTypeRepository.getTypeByName(t6.namespaceName, "reqActive-SL").getId(), template.getTypeId());
371
372 assertEquals("Unexpected Active value", false, template.isActive());
373
374
375 try {
376 ruleManagementService.findNaturalLanguageTemplatesByNaturalLanguageUsage(null);
377 fail("Should have thrown IllegalArgumentException: naturalLanguageUsageId is null or blank");
378 } catch (IllegalArgumentException e) {
379
380 }
381
382
383 try {
384 ruleManagementService.findNaturalLanguageTemplatesByNaturalLanguageUsage(" ");
385 fail("Should have thrown IllegalArgumentException: naturalLanguageUsageId is null or blank");
386 } catch (IllegalArgumentException e) {
387
388 }
389
390
391 assertEquals("Unexpected number of templates returned ",0,
392 ruleManagementService.findNaturalLanguageTemplatesByNaturalLanguageUsage("badValue").size());
393 }
394
395
396
397
398
399
400
401
402 @Test
403 public void testFindNaturalLanguageTemplatesByType() {
404
405 RuleManagementBaseTestObjectNames t7 = new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t7");
406
407
408 NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t7.namespaceName, "es", "reqActive-ES",
409 "Este objeto no debe estar inactivo");
410 assertNotNull("Should have found NaturalLanguageTemplate", ruleManagementService.getNaturalLanguageTemplate("es-reqActive-ES"));
411
412
413 List<NaturalLanguageTemplate> templates = ruleManagementService.findNaturalLanguageTemplatesByType(template.getTypeId());
414 assertEquals("Unexpected number of templates returned ",1,templates.size());
415
416
417 try {
418 ruleManagementService.findNaturalLanguageTemplatesByType(null);
419 fail("Should have thrown IllegalArgumentException: typeId is null or blank");
420 } catch (IllegalArgumentException e) {
421
422 }
423
424
425 try {
426 ruleManagementService.findNaturalLanguageTemplatesByType(" ");
427 fail("Should have thrown IllegalArgumentException: typeId is null or blank");
428 } catch (IllegalArgumentException e) {
429
430 }
431
432
433 assertEquals("Unexpected number of templates returned ",0,
434 ruleManagementService.findNaturalLanguageTemplatesByType("badValue").size());
435 }
436
437
438
439
440
441
442
443
444 @Test
445 public void testFindNaturalLanguageTemplatesByTemplate() {
446
447 RuleManagementBaseTestObjectNames t8 = new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t8");
448
449 NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t8.namespaceName, "sv", "reqActive",
450 "Detta ändamal far inte vara inaktiv");
451 assertNotNull("Should have found NaturalLanguageTemplate", ruleManagementService.getNaturalLanguageTemplate("sv-reqActive"));
452
453
454 List<NaturalLanguageTemplate> templates =
455 ruleManagementService.findNaturalLanguageTemplatesByTemplate("Detta ändamal far inte vara inaktiv");
456 assertEquals("Unexpected number of templates returned ",1,templates.size());
457
458
459 try {
460 ruleManagementService.findNaturalLanguageTemplatesByTemplate(null);
461 fail("Should have thrown IllegalArgumentException: template is null or blank");
462 } catch (IllegalArgumentException e) {
463
464 }
465
466
467 try {
468 ruleManagementService.findNaturalLanguageTemplatesByTemplate(" ");
469 fail("Should have thrown IllegalArgumentException: template is null or blank");
470 } catch (IllegalArgumentException e) {
471
472 }
473
474
475 assertEquals("Unexpected number of templates returned ",0,
476 ruleManagementService.findNaturalLanguageTemplatesByTemplate("badValue").size());
477 }
478 }