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.DataIntegrityViolationException;
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 DataIntegrityViolationException: OJB operation; SQL []; Cannot add or update a child row: a foreign key constraint fails");
141 } catch (DataIntegrityViolationException e) {
142
143 }
144 }
145
146
147
148
149
150
151 @Test
152 public void testGetNaturalLanguageTemplate() {
153
154 RuleManagementBaseTestObjectNames t1 = new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t1");
155
156 NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t1.namespaceName, "sw", "reqActive",
157 "Detta ändamål får inte vara inaktiv");
158 assertNotNull(ruleManagementService.getNaturalLanguageTemplate("sw-reqActive"));
159 assertEquals("Unexpected language code found", "sw", template.getLanguageCode());
160
161 try {
162 ruleManagementService.getNaturalLanguageTemplate(null);
163 fail("Should have thrown IllegalArgumentException: naturalLanguageTemplateId was null");
164 } catch (IllegalArgumentException e) {
165
166 }
167
168
169 try {
170 ruleManagementService.getNaturalLanguageTemplate(" ");
171 fail("Should have thrown IllegalArgumentException: naturalLanguageTemplateId was blank");
172 } catch (IllegalArgumentException e) {
173
174 }
175
176 assertNull(ruleManagementService.getNaturalLanguageTemplate("badId"));
177 }
178
179
180
181
182
183
184 @Test
185 public void testUpdateNaturalLanguageTemplate() {
186
187 RuleManagementBaseTestObjectNames t2 = new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t2");
188
189 NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t2.namespaceName, "pl", "reqActive",
190 "Isthay Objectway ustmay otnay ebay inActiveway");
191 NaturalLanguageTemplate.Builder naturalLanguageTemplateBuilder = NaturalLanguageTemplate.Builder.create(
192 ruleManagementService.getNaturalLanguageTemplate("pl-reqActive"));
193
194 naturalLanguageTemplateBuilder.setTemplate("Ten obiekt nie moze byc nieaktywne");
195 naturalLanguageTemplateBuilder.setActive(true);
196 ruleManagementService.updateNaturalLanguageTemplate(naturalLanguageTemplateBuilder.build());
197
198 assertEquals("Unexpected template value found", "Ten obiekt nie moze byc nieaktywne", ruleManagementService.getNaturalLanguageTemplate("pl-reqActive").getTemplate());
199
200 assertEquals("Unexpected isActive value found", false, 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");
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");
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");
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
313 assertEquals("Unexpected Active value", false, template.isActive());
314
315
316 try {
317 ruleManagementService.findNaturalLanguageTemplateByLanguageCodeTypeIdAndNluId(
318 null,template.getTypeId(),template.getNaturalLanguageUsageId());
319 fail("Should have thrown IllegalArgumentException: languageCode is null or blank");
320 } catch (IllegalArgumentException e) {
321
322 }
323
324
325 ruleManagementService.findNaturalLanguageTemplateByLanguageCodeTypeIdAndNluId(
326 template.getLanguageCode(),null,template.getNaturalLanguageUsageId());
327
328
329 ruleManagementService.findNaturalLanguageTemplateByLanguageCodeTypeIdAndNluId(
330 template.getLanguageCode(),template.getTypeId(),null);
331
332
333 try {
334 ruleManagementService.findNaturalLanguageTemplateByLanguageCodeTypeIdAndNluId(
335 " ",template.getTypeId(),template.getNaturalLanguageUsageId());
336 fail("Should have thrown IllegalArgumentException: languageCode is null or blank");
337 } catch (IllegalArgumentException e) {
338
339 }
340 }
341
342
343
344
345
346
347
348
349 @Test
350 public void testFindNaturalLanguageTemplatesByNaturalLanguageUsage() {
351
352 RuleManagementBaseTestObjectNames t6 = new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t6");
353
354
355 NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t6.namespaceName, "sl", "reqActive-SL",
356 "Ta predmet ne sme biti neaktiven");
357 assertNotNull("Should have found NaturalLanguageTemplate", ruleManagementService.getNaturalLanguageTemplate("sl-reqActive-SL"));
358
359
360 List<NaturalLanguageTemplate> templates = ruleManagementService.findNaturalLanguageTemplatesByNaturalLanguageUsage(template.getNaturalLanguageUsageId());
361 assertEquals("Unexpected number of templates returned ",1,templates.size());
362 template = templates.get(0);
363
364
365 assertEquals("Unexpected template id returned","sl-reqActive-SL",template.getId());
366 assertEquals("Unexpected language code found", "sl", template.getLanguageCode());
367 assertEquals("Unexpected template found", "Ta predmet ne sme biti neaktiven", template.getTemplate());
368 assertEquals("Unexpected TypeId value", krmsTypeRepository.getTypeByName(t6.namespaceName, "reqActive-SL").getId(), template.getTypeId());
369
370 assertEquals("Unexpected Active value", false, template.isActive());
371
372
373 try {
374 ruleManagementService.findNaturalLanguageTemplatesByNaturalLanguageUsage(null);
375 fail("Should have thrown IllegalArgumentException: naturalLanguageUsageId is null or blank");
376 } catch (IllegalArgumentException e) {
377
378 }
379
380
381 try {
382 ruleManagementService.findNaturalLanguageTemplatesByNaturalLanguageUsage(" ");
383 fail("Should have thrown IllegalArgumentException: naturalLanguageUsageId is null or blank");
384 } catch (IllegalArgumentException e) {
385
386 }
387
388
389 assertEquals("Unexpected number of templates returned ",0,
390 ruleManagementService.findNaturalLanguageTemplatesByNaturalLanguageUsage("badValue").size());
391 }
392
393
394
395
396
397
398
399
400 @Test
401 public void testFindNaturalLanguageTemplatesByType() {
402
403 RuleManagementBaseTestObjectNames t7 = new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t7");
404
405
406 NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t7.namespaceName, "es", "reqActive-ES",
407 "Este objeto no debe estar inactivo");
408 assertNotNull("Should have found NaturalLanguageTemplate", ruleManagementService.getNaturalLanguageTemplate("es-reqActive-ES"));
409
410
411 List<NaturalLanguageTemplate> templates = ruleManagementService.findNaturalLanguageTemplatesByType(template.getTypeId());
412 assertEquals("Unexpected number of templates returned ",1,templates.size());
413
414
415 try {
416 ruleManagementService.findNaturalLanguageTemplatesByType(null);
417 fail("Should have thrown IllegalArgumentException: typeId is null or blank");
418 } catch (IllegalArgumentException e) {
419
420 }
421
422
423 try {
424 ruleManagementService.findNaturalLanguageTemplatesByType(" ");
425 fail("Should have thrown IllegalArgumentException: typeId is null or blank");
426 } catch (IllegalArgumentException e) {
427
428 }
429
430
431 assertEquals("Unexpected number of templates returned ",0,
432 ruleManagementService.findNaturalLanguageTemplatesByType("badValue").size());
433 }
434
435
436
437
438
439
440
441
442 @Test
443 public void testFindNaturalLanguageTemplatesByTemplate() {
444
445 RuleManagementBaseTestObjectNames t8 = new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t8");
446
447 NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t8.namespaceName, "sv", "reqActive",
448 "Detta ändamal far inte vara inaktiv");
449 assertNotNull("Should have found NaturalLanguageTemplate", ruleManagementService.getNaturalLanguageTemplate("sv-reqActive"));
450
451
452 List<NaturalLanguageTemplate> templates =
453 ruleManagementService.findNaturalLanguageTemplatesByTemplate("Detta ändamal far inte vara inaktiv");
454 assertEquals("Unexpected number of templates returned ",1,templates.size());
455
456
457 try {
458 ruleManagementService.findNaturalLanguageTemplatesByTemplate(null);
459 fail("Should have thrown IllegalArgumentException: template is null or blank");
460 } catch (IllegalArgumentException e) {
461
462 }
463
464
465 try {
466 ruleManagementService.findNaturalLanguageTemplatesByTemplate(" ");
467 fail("Should have thrown IllegalArgumentException: template is null or blank");
468 } catch (IllegalArgumentException e) {
469
470 }
471
472
473 assertEquals("Unexpected number of templates returned ",0,
474 ruleManagementService.findNaturalLanguageTemplatesByTemplate("badValue").size());
475 }
476 }