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