View Javadoc
1   /*
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.kuali.rice.krms.test;
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.junit.Before;
21  import org.junit.Test;
22  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
23  import org.kuali.rice.krms.api.repository.NaturalLanguageTree;
24  import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplate;
25  import org.kuali.rice.krms.api.repository.language.NaturalLanguageUsage;
26  import org.kuali.rice.krms.api.repository.proposition.PropositionDefinition;
27  
28  import java.util.Arrays;
29  import java.util.List;
30  
31  import static org.junit.Assert.*;
32  import static org.junit.Assert.assertEquals;
33  
34  /**
35   *   RuleManagementNaturalLanguageUsageTest is to test the methods of
36   *       ruleManagementServiceImpl relating toNaturalLanguageUsage
37   *
38   *   Each test focuses on one of the methods.
39   */
40  public class RuleManagementNaturalLanguageUsageTest extends RuleManagementBaseTest {
41      @Override
42      @Before
43      public void setClassDiscriminator() {
44          // set a unique discriminator for test objects of this class
45          CLASS_DISCRIMINATOR = "RMNLUT";
46      }
47  
48      /**
49       *  Test testCreateNaturalLanguageUsage()
50       *
51       *  This test focuses specifically on the RuleManagementServiceImpl
52       *      .createNaturalLanguageUsage(NaturalLanguageUsage) method
53       */
54      @Test
55      public void testCreateNaturalLanguageUsage() {
56          // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
57          RuleManagementBaseTestObjectNames t0 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t0");
58  
59          // buildTestNaturalLanguageUsage calls createNaturalLanguageUsage
60          NaturalLanguageUsage usage = buildTestNaturalLanguageUsage(t0.namespaceName, t0.object0 );
61  
62          // verify created NaturalLanguageUsage
63          usage = ruleManagementService.getNaturalLanguageUsage(t0.nlUsage0_Id);
64          assertEquals("Unexpected Name returned",t0.nlUsage0_Name,usage.getName());
65          assertEquals("Unexpected Namespace returned ", t0.namespaceName, usage.getNamespace());
66          assertEquals("Unexpected Description returned", t0.nlUsage0_Descr, usage.getDescription());
67          assertTrue("Unexpected Active value returned", usage.isActive());
68  
69          // test createNaturalLanguageUsage with null
70          try {
71              ruleManagementService.createNaturalLanguageUsage(null);
72              fail("Should have thrown IllegalArgumentException: naturalLanguageUsage was null");
73          } catch (IllegalArgumentException e) {
74              // throws IllegalArgumentException: naturalLanguageUsage was null
75          }
76      }
77  
78  
79      /**
80       *  Test testGetNaturalLanguageUsage()
81       *
82       *  This test focuses specifically on the RuleManagementServiceImpl .getNaturalLanguageUsage(String id) method
83       */
84      @Test
85      public void testGetNaturalLanguageUsage() {
86          // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
87          RuleManagementBaseTestObjectNames t1 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t1");
88  
89          // create a NaturalLanguageUsage to test with
90          NaturalLanguageUsage usage = buildTestNaturalLanguageUsage(t1.namespaceName, t1.object0 );
91  
92          // verify correct NaturalLanguageUsage returned
93          assertEquals("Unexpected Description returned",
94                  t1.nlUsage0_Descr, ruleManagementService.getNaturalLanguageUsage(t1.nlUsage0_Id).getDescription());
95  
96          // test getNaturalLanguageUsage with null
97          try {
98              ruleManagementService.getNaturalLanguageUsage(null);
99              fail("Should have thrown IllegalArgumentException: naturalLanguageUsageId was null");
100         } catch (IllegalArgumentException e) {
101             // throws IllegalArgumentException: naturalLanguageUsageId was null
102         }
103 
104         // test getNaturalLanguageUsage with blank
105         try {
106             ruleManagementService.getNaturalLanguageUsage("   ");
107             fail("Should have thrown IllegalArgumentException: naturalLanguageUsageId was blank");
108         } catch (IllegalArgumentException e) {
109             // throws IllegalArgumentException: naturalLanguageUsageId was blank
110         }
111 
112         // test getNaturalLanguageUsage wih non-existent Id
113         assertNull("Should not have return object", ruleManagementService.getNaturalLanguageUsage("badValue"));
114     }
115 
116 
117     /**
118      *  Test testUpdateNaturalLanguageUsage()
119      *
120      *  This test focuses specifically on the RuleManagementServiceImpl
121      *      .updateNaturalLanguageUsage(NaturalLanguageUsage) method
122      */
123     @Test
124     public void testUpdateNaturalLanguageUsage() {
125         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
126         RuleManagementBaseTestObjectNames t2 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t2");
127 
128         // create NaturalLanguageUsage to test with
129         NaturalLanguageUsage usage = buildTestNaturalLanguageUsage(t2.namespaceName, t2.object0 );
130 
131         // verify created NaturalLanguageUsage
132         usage = ruleManagementService.getNaturalLanguageUsage(t2.nlUsage0_Id);
133         assertEquals("Unexpected Name returned",t2.nlUsage0_Name,usage.getName());
134         assertEquals("Unexpected Namespace returned ", t2.namespaceName, usage.getNamespace());
135         assertEquals("Unexpected Description returned", t2.nlUsage0_Descr, usage.getDescription());
136         assertTrue("Unexpected Active value returned", usage.isActive());
137 
138         // Update Namespace, Name, Description and Active values
139         NaturalLanguageUsage.Builder usageBuilder =  NaturalLanguageUsage.Builder.create(usage);
140         usageBuilder.setNamespace(t2.namespaceName + "Changed");
141         usageBuilder.setName(t2.nlUsage0_Name + "Changed");
142         usageBuilder.setDescription(t2.nlUsage0_Descr + "Changed");
143         usageBuilder.setActive(false);
144         ruleManagementService.updateNaturalLanguageUsage(usageBuilder.build());
145 
146         // verify updated NaturalLanguageUsage values
147         usage = ruleManagementService.getNaturalLanguageUsage(t2.nlUsage0_Id);
148         assertEquals("Unexpected Name returned",t2.nlUsage0_Name + "Changed",usage.getName());
149         assertEquals("Unexpected Namespace returned ", t2.namespaceName + "Changed", usage.getNamespace());
150         assertEquals("Unexpected Description returned", t2.nlUsage0_Descr + "Changed", usage.getDescription());
151         assertFalse("Unexpected Active value returned", usage.isActive());
152 
153         // test updateNaturalLanguageUsage with null
154         try {
155             ruleManagementService.updateNaturalLanguageUsage(null);
156             fail("Should have thrown IllegalArgumentException: naturalLanguageUsage was null");
157         } catch (IllegalArgumentException e) {
158             // throws IllegalArgumentException: naturalLanguageUsage was null
159         }
160     }
161 
162 
163     /**
164      *  Test testDeleteNaturalLanguageUsage()
165      *
166      *  This test focuses specifically on the RuleManagementServiceImpl
167      *      .deleteNaturalLanguageUsage(String naturalLanguageUsageId) method
168      */
169     @Test
170     public void testDeleteNaturalLanguageUsage() {
171         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
172         RuleManagementBaseTestObjectNames t3 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t3");
173 
174         // create a NaturalLanguageUsage to test with
175         NaturalLanguageUsage usage = buildTestNaturalLanguageUsage(t3.namespaceName, t3.object0 );
176 
177         // verify correct NaturalLanguageUsage exists
178         assertEquals("Unexpected Description returned",
179                 t3.nlUsage0_Descr, ruleManagementService.getNaturalLanguageUsage(t3.nlUsage0_Id).getDescription());
180 
181         // test deleteNaturalLanguageUsage
182         ruleManagementService.deleteNaturalLanguageUsage(t3.nlUsage0_Id);
183 
184         // verify object deleted
185         assertNull("Should not have returned deleted entry", ruleManagementService.getNaturalLanguageUsage(t3.nlUsage0_Id));
186 
187         // test deleteNaturalLanguageUsage with null
188         try {
189             ruleManagementService.deleteNaturalLanguageUsage(null);
190             fail("Should have thrown IllegalArgumentException: naturalLanguageUsageId was null");
191         } catch (IllegalArgumentException e) {
192             // throws IllegalArgumentException: naturalLanguageUsageId was null
193         }
194 
195         // test deleteNaturalLanguageUsage with blank
196         try {
197             ruleManagementService.deleteNaturalLanguageUsage("   ");
198             fail("Should have thrown IllegalArgumentException: naturalLanguageUsageId was blank");
199         } catch (IllegalArgumentException e) {
200             // throws IllegalArgumentException: naturalLanguageUsageId was blank
201         }
202 
203         // test deleteNaturalLanguageUsage with badValue
204         try {
205             ruleManagementService.deleteNaturalLanguageUsage("badValue");
206             fail("Should have thrown IllegalStateException: the NaturalLanguageUsage to delete does not exists: badValue");
207         } catch (IllegalStateException e) {
208             // throws IllegalStateException: the NaturalLanguageUsage to delete does not exists: badValue
209         }
210     }
211 
212 
213     /**
214      *  Test testGetNaturalLanguageUsagesByNamespace()
215      *
216      *  This test focuses specifically on the RuleManagementServiceImpl
217      *      .getNaturalLanguageUsagesByNamespace(String namespace) method
218      */
219     @Test
220     public void testGetNaturalLanguageUsagesByNamespace() {
221         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
222         RuleManagementBaseTestObjectNames t4 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t4");
223 
224         // create three NaturalLanguageUsage entries with same Namespace to test with
225         buildTestNaturalLanguageUsage(t4.namespaceName, t4.object0 );
226         buildTestNaturalLanguageUsage(t4.namespaceName, t4.object1 );
227         buildTestNaturalLanguageUsage(t4.namespaceName, t4.object2 );
228         List<String> usageIds = Arrays.asList(t4.nlUsage0_Id, t4.nlUsage1_Id, t4.nlUsage2_Id);
229 
230         // test getNaturalLanguageUsagesByNamespace
231         List<NaturalLanguageUsage> usages = ruleManagementService.getNaturalLanguageUsagesByNamespace(t4.namespaceName);
232 
233         assertEquals("Should have returned 3 entries",3,usages.size());
234         for (NaturalLanguageUsage usage : usages) {
235             assertTrue("Unexpected entry id returned", usageIds.contains(usage.getId()));
236         }
237 
238         // test getNaturalLanguageUsagesByNamespace with null
239         try {
240             ruleManagementService.getNaturalLanguageUsagesByNamespace(null);
241             fail("Should have thrown IllegalArgumentException: namespace is null or blank");
242         } catch (IllegalArgumentException e) {
243             // throws IllegalArgumentException: namespace is null or blank
244         }
245 
246         // test getNaturalLanguageUsagesByNamespace with blank
247         try {
248             ruleManagementService.getNaturalLanguageUsagesByNamespace("  ");
249             fail("Should have thrown IllegalArgumentException: namespace is null or blank");
250         } catch (IllegalArgumentException e) {
251             // throws IllegalArgumentException: namespace is null or blank
252         }
253 
254         // test getNaturalLanguageUsagesByNamespace with non-existent namespace value
255         assertEquals("Should have returned 0 entries", 0, ruleManagementService.getNaturalLanguageUsagesByNamespace(
256                 "badValue").size());
257     }
258 
259 
260     /**
261      *  Test testGetNaturalLanguageUsageByNameAndNamespace()
262      *
263      *  This test focuses specifically on the RuleManagementServiceImpl
264      *      .getNaturalLanguageUsageByNameAndNamespace(String name, String namespace) method
265      */
266     @Test
267     public void testGetNaturalLanguageUsageByNameAndNamespace() {
268         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
269         RuleManagementBaseTestObjectNames t5 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t5");
270 
271         // create two NaturalLanguageUsage entries to test with
272         buildTestNaturalLanguageUsage(t5.namespaceName, t5.object0 );
273         buildTestNaturalLanguageUsage(t5.namespaceName, t5.object1 );
274 
275         assertEquals("Unexpected Description on entry returned",
276              t5.nlUsage0_Descr, ruleManagementService.getNaturalLanguageUsageByNameAndNamespace(
277                    t5.nlUsage0_Name,t5.namespaceName).getDescription());
278 
279         // test getNaturalLanguageUsageByNameAndNamespace with null name
280         try {
281             ruleManagementService.getNaturalLanguageUsageByNameAndNamespace(null, t5.namespaceName);
282             fail("Should have thrown RiceIllegalArgumentException: name was a null or blank value");
283         } catch (RiceIllegalArgumentException e) {
284             // throws RiceIllegalArgumentException: name was a null or blank value
285         }
286 
287         // test getNaturalLanguageUsageByNameAndNamespace with blank name
288         try {
289             ruleManagementService.getNaturalLanguageUsageByNameAndNamespace("  ",t5.namespaceName);
290             fail("Should have thrown RiceIllegalArgumentException: name was a null or blank value");
291         } catch (RiceIllegalArgumentException e) {
292             // throws RiceIllegalArgumentException: name was a null or blank value
293         }
294 
295         // test getNaturalLanguageUsageByNameAndNamespace with non-existent name value
296         assertNull("Should not have return object",
297                 ruleManagementService.getNaturalLanguageUsageByNameAndNamespace("badValue", t5.namespaceName));
298 
299         // test getNaturalLanguageUsageByNameAndNamespace with null namespace
300         try {
301             ruleManagementService.getNaturalLanguageUsageByNameAndNamespace(t5.nlUsage0_Name,null);
302             fail("Should have thrown RiceIllegalArgumentException: namespace was a null or blank value");
303         } catch (RiceIllegalArgumentException e) {
304             // throws RiceIllegalArgumentException: namespace was a null or blank value
305         }
306 
307         // test getNaturalLanguageUsageByNameAndNamespace with blank namespace
308         try {
309             ruleManagementService.getNaturalLanguageUsageByNameAndNamespace(t5.nlUsage0_Name,"  ");
310             fail("Should have thrown RiceIllegalArgumentException: namespace was a null or blank value");
311         } catch (RiceIllegalArgumentException e) {
312             // throws RiceIllegalArgumentException: namespace was a null or blank value
313         }
314 
315         // test getNaturalLanguageUsageByNameAndNamespace with non-existent namespace value
316         assertNull("Should not have return object",
317                 ruleManagementService.getNaturalLanguageUsageByNameAndNamespace(t5.nlUsage0_Name,"badValue"));
318     }
319 
320 
321     ////
322     //// natural language translations
323     ////
324     /**
325      *  Test testTranslateNaturalLanguageForObject()
326      *
327      *  This test focuses specifically on the RuleManagementServiceImpl
328      *      .translateNaturalLanguageForObject(String naturalLanguageUsageId,
329      *                                         String typeId,
330      *                                         String krmsObjectId,
331      *                                         String languageCode)  method
332      */
333     @Test
334     public void testTranslateNaturalLanguageForObject() {
335         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
336         RuleManagementBaseTestObjectNames t6 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t6");
337 
338         // build proposition and NaturalLanguageTemplate for testing
339         PropositionDefinition propositionDefinition = createTestPropositionForTranslation(t6.object0, t6.namespaceName,
340                 "proposition");
341         NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t6.namespaceName, "sw", "proposition",
342                 "Detta ändamål får inte vara inaktiv", true);
343 
344         // test translateNaturalLanguageForObject call
345         String translation = ruleManagementService.translateNaturalLanguageForObject(
346                 template.getNaturalLanguageUsageId(),"proposition",propositionDefinition.getId(),"sw");
347 
348         // check result of test
349         assertEquals("Unexpected translation returned","Detta ändamål får inte vara inaktiv. ",translation);
350 
351         //test with null NaturalLanguageUsageId
352         assertEquals("Should have returned '. ' String", ". ",
353                 ruleManagementService.translateNaturalLanguageForObject(null, "proposition",
354                         propositionDefinition.getId(), "sw"));
355 
356         // test with null typeId
357         try {
358             ruleManagementService.translateNaturalLanguageForObject(
359                     template.getNaturalLanguageUsageId(),null,propositionDefinition.getId(),"sw");
360             fail("Should have thrown NullPointerException");
361         } catch (NullPointerException e) {
362             // throws NullPointerException
363         }
364 
365         // test with null krmsObjectId
366         try {
367             ruleManagementService.translateNaturalLanguageForObject(
368                     template.getNaturalLanguageUsageId(),"proposition",null,"sw");
369             fail("Should have thrown RiceIllegalArgumentException: Proposition id must not be null or blank");
370         } catch (RiceIllegalArgumentException e) {
371             // throws RiceIllegalArgumentException: Proposition id must not be null or blank
372         }
373 
374         // test with null languageCode
375         try {
376             ruleManagementService.translateNaturalLanguageForObject(
377                     template.getNaturalLanguageUsageId(),"proposition",propositionDefinition.getId(),null);
378             fail("Should have thrown IllegalArgumentException: languageCode is null or blank");
379         } catch (IllegalArgumentException e) {
380             // throws IllegalArgumentException: languageCode is null or blank
381         }
382 
383         // test with blank NaturalLanguageUsageId
384         assertEquals("Should have returned '. ' String", ". ", ruleManagementService.translateNaturalLanguageForObject(
385                     "   ","proposition",propositionDefinition.getId(),"sw"));
386 
387 
388         // test with blank typeId
389         assertEquals("Should have returned empty String", StringUtils.EMPTY,
390                 ruleManagementService.translateNaturalLanguageForObject(template.getNaturalLanguageUsageId(),
391                         "    ", propositionDefinition.getId(), "sw"));
392 
393 
394         // test with blank krmsObjectId
395         try {
396             ruleManagementService.translateNaturalLanguageForObject(
397                     template.getNaturalLanguageUsageId(),"proposition","    ","sw");
398             fail("Should have thrown RiceIllegalArgumentException: Proposition id must not be null or blank");
399         } catch (RiceIllegalArgumentException e) {
400             // throws RiceIllegalArgumentException: Proposition id must not be null or blank
401         }
402 
403         // test with blank languageCode
404         try {
405             ruleManagementService.translateNaturalLanguageForObject(
406                     template.getNaturalLanguageUsageId(),"proposition",propositionDefinition.getId(),"  ");
407             fail("Should have thrown IllegalArgumentException: languageCode is null or blank");
408         } catch (IllegalArgumentException e) {
409             // throws IllegalArgumentException: languageCode is null or blank
410         }
411 
412         //test with non-existent NaturalLanguageUsageId
413         assertEquals("Should have returned '. ' String", ". ",
414                 ruleManagementService.translateNaturalLanguageForObject("badValue", "proposition",
415                         propositionDefinition.getId(), "sw"));
416 
417         // test with non-existent typeId
418         assertEquals("Should have returned empty String", StringUtils.EMPTY,
419                 ruleManagementService.translateNaturalLanguageForObject(template.getNaturalLanguageUsageId(),
420                         "badValue", propositionDefinition.getId(), "sw"));
421 
422         // test with non-existent krmsObjectId
423         try {
424             ruleManagementService.translateNaturalLanguageForObject(
425                     template.getNaturalLanguageUsageId(),"proposition","badValue","sw");
426             fail("Should have thrown RiceIllegalArgumentException: badValue is not an Id for a proposition");
427         } catch (RiceIllegalArgumentException e) {
428             // throws RiceIllegalArgumentException: badValue is not an Id for a proposition
429         }
430 
431         // test with non-existent languageCode
432         assertEquals("Should have returned '. ' String", ". ", ruleManagementService.translateNaturalLanguageForObject(
433                 template.getNaturalLanguageUsageId(),"proposition",propositionDefinition.getId(),"xx"));
434     }
435 
436 
437     /**
438      *  Test testTranslateNaturalLanguageForProposition()
439      *
440      *  This test focuses specifically on the RuleManagementServiceImpl
441      *      .translateNaturalLanguageForProposition(String naturalLanguageUsageId,
442      *                                              PropositionDefinition proposition,
443      *                                              String languageCode) method
444      */
445     @Test
446     public void testTranslateNaturalLanguageForProposition() {
447         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
448         RuleManagementBaseTestObjectNames t7 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t7");
449 
450         PropositionDefinition propositionDefinition = createTestPropositionForTranslation(t7.object0, t7.namespaceName, "proposition" );
451         NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t7.namespaceName, "tr", "proposition",
452                 "Bu nesne inaktif olmamalidir", true);
453 
454         String translation = ruleManagementService.translateNaturalLanguageForProposition(template.getNaturalLanguageUsageId(),propositionDefinition,"tr");
455 
456         assertEquals("Unexpected translation returned","Bu nesne inaktif olmamalidir. ",translation);
457 
458         // test with null naturalLanguageUsageId
459         assertEquals("Should have returned '. ' String",". ", ruleManagementService.translateNaturalLanguageForProposition(null, propositionDefinition, "tr"));
460 
461         // test with null PropositionDefinition
462         try {
463             ruleManagementService.translateNaturalLanguageForProposition(
464                     template.getNaturalLanguageUsageId(), null, "tr");
465             fail("Should have thrown NullPointerException");
466         } catch (NullPointerException e) {
467             // throws NullPointerException
468         }
469 
470             // test with null languageCode
471         try {
472             ruleManagementService.translateNaturalLanguageForProposition(template.getNaturalLanguageUsageId(),
473                     propositionDefinition, null);
474             fail("Should have thrown IllegalArgumentException: languageCode is null or blank");
475         } catch (IllegalArgumentException e) {
476             // throws IllegalArgumentException: languageCode is null or blank
477         }
478 
479         // test with blank naturalLanguageUsageId
480         assertEquals("Should have returned '. ' String", ". ",
481                 ruleManagementService.translateNaturalLanguageForProposition("    ", propositionDefinition, "tr"));
482 
483         // test with blank languageCode
484         try {
485             ruleManagementService.translateNaturalLanguageForProposition(template.getNaturalLanguageUsageId(),propositionDefinition,"    ");
486             fail("Should have thrown IllegalArgumentException: languageCode is null or blank");
487         } catch (IllegalArgumentException e) {
488             // throws IllegalArgumentException: languageCode is null or blank
489         }
490 
491         // test with non-existent naturalLanguageUsageId
492         assertEquals("Should have returned '. ' String",". ",
493                 ruleManagementService.translateNaturalLanguageForProposition("badValue",propositionDefinition,"tr"));
494 
495         // test with non-existent languageCode
496         assertEquals("Should have returned '. ' String",". ",
497                 ruleManagementService.translateNaturalLanguageForProposition(
498                 template.getNaturalLanguageUsageId(),propositionDefinition,"badValue"));
499     }
500 
501 
502     /**
503      *  Test testTranslateNaturalLanguageTreeForProposition()
504      *
505      *  This test focuses specifically on the RuleManagementServiceImpl
506      *      .translateNaturalLanguageTreeForProposition(String naturalLanguageUsageId,
507      *                                                  PropositionDefinition propositionDefinintion,
508      *                                                  String languageCode) method
509      */
510     @Test
511     public void testTranslateNaturalLanguageTreeForProposition() {
512         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
513         RuleManagementBaseTestObjectNames t8 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t8");
514 
515         // build SIMPLE proposition
516         PropositionDefinition propositionDefinition = createTestPropositionForTranslation(t8.object0, t8.namespaceName, "proposition" );
517         NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t8.namespaceName, "cy", "proposition",
518                 "Ni ddylai hyn fod yn segur, Gwrthrych", true);
519 
520         NaturalLanguageTree naturalLanguageTree = ruleManagementService.translateNaturalLanguageTreeForProposition(
521                 template.getNaturalLanguageUsageId(), propositionDefinition, "cy");
522 
523         String translation = naturalLanguageTree.getNaturalLanguage();
524         assertEquals("Unexpected translation returned","Ni ddylai hyn fod yn segur, Gwrthrych",translation);
525 
526         // SIMPLE proposition should not have children
527         assertNull("Should have returned null",naturalLanguageTree.getChildren());
528     }
529 
530     /**
531      *  Test testCompoundTranslateNaturalLanguageTreeForProposition()
532      *
533      *  This test focuses specifically on the RuleManagementServiceImpl
534      *      .translateNaturalLanguageTreeForProposition(String naturalLanguageUsageId,
535      *                                                  PropositionDefinition propositionDefinintion,
536      *                                                  String languageCode) method
537      *      where the PropositionDefinition is a Compound proposition
538      */
539     @Test
540     public void testCompoundTranslateNaturalLanguageTreeForProposition() {
541         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
542         RuleManagementBaseTestObjectNames t9 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t9");
543 
544         // Build COMPOUND proposition to test with
545         PropositionDefinition propositionDefinition = createTestCompoundProposition(t9);
546 
547         // Build the templates for the tree
548         NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t9.namespaceName, "ms",
549                 krmsTypeRepository.getTypeById(propositionDefinition.getTypeId()).getName(),
550                 "Objek ini tidak boleh aktif", true);
551         PropositionDefinition child1 = propositionDefinition.getCompoundComponents().get(0);
552         createTestNaturalLanguageTemplate(t9.namespaceName, "ms", "Account", "Objek ini tidak boleh aktif",
553                 "krms.nl.proposition", true);
554         PropositionDefinition child2 = propositionDefinition.getCompoundComponents().get(1);
555         createTestNaturalLanguageTemplate(t9.namespaceName, "ms", "Occasion", "Objek ini tidak boleh aktif",
556                 "krms.nl.proposition", true);
557 
558         // test the call to translateNaturalLanguageTreeForProposition
559         NaturalLanguageTree naturalLanguageTree = ruleManagementService.translateNaturalLanguageTreeForProposition(
560                 template.getNaturalLanguageUsageId(), propositionDefinition, "ms");
561         List<NaturalLanguageTree> naturalLanguageTrees = naturalLanguageTree.getChildren();
562         assertEquals("Should have found 2 child entries",2,naturalLanguageTrees.size());
563 
564         // test with null PropositionDefinition
565         try {
566             ruleManagementService.translateNaturalLanguageTreeForProposition(
567                     template.getNaturalLanguageUsageId(), null, "ms");
568             fail("Should have thrown NullPointerException");
569         } catch (NullPointerException e) {
570             // throws NullPointerException
571         }
572 
573         // test with a null LanguageCode;
574         try {
575             ruleManagementService.translateNaturalLanguageTreeForProposition(
576                     template.getNaturalLanguageUsageId(), propositionDefinition, null);
577             fail("Should have thrown IllegalArgumentException: languageCode is null or blank");
578         } catch (IllegalArgumentException e) {
579             // throws IllegalArgumentException: languageCode is null or blank
580         }
581     }
582 
583 
584     /**
585      *  Test testNullTranslateNaturalLanguageTreeForProposition()
586      *
587      *  This test focuses specifically on the RuleManagementServiceImpl
588      *      .translateNaturalLanguageTreeForProposition(String naturalLanguageUsageId,
589      *                                                  PropositionDefinition propositionDefinintion,
590      *                                                  String languageCode) method
591      *      where there is no NaturalLanguageTemplate
592      */
593     @Test
594     public void testNullTranslateNaturalLanguageTreeForProposition() {
595         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
596         RuleManagementBaseTestObjectNames t9 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t9");
597 
598         // build SIMPLE proposition
599         PropositionDefinition propositionDefinition = createTestPropositionForTranslation(t9.object0, t9.namespaceName, "proposition" );
600 
601         NaturalLanguageTree naturalLanguageTree = ruleManagementService.translateNaturalLanguageTreeForProposition(
602                 null, propositionDefinition, "cy2");
603 
604         String translation = naturalLanguageTree.getNaturalLanguage();
605         assertEquals("Non-empty translation returned",StringUtils.EMPTY,translation);
606 
607         // SIMPLE proposition should not have children
608         assertNull("Should have returned null",naturalLanguageTree.getChildren());
609     }
610 
611     /**
612      *  Test testEmptyTranslateNaturalLanguageTreeForProposition()
613      *
614      *  This test focuses specifically on the RuleManagementServiceImpl
615      *      .translateNaturalLanguageTreeForProposition(String naturalLanguageUsageId,
616      *                                                  PropositionDefinition propositionDefinintion,
617      *                                                  String languageCode) method
618      *      where there is no NaturalLanguageTemplate associated with the PropositionDefinition and languageCode
619      */
620     @Test
621     public void testEmptyTranslateNaturalLanguageTreeForProposition() {
622         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
623         RuleManagementBaseTestObjectNames t10 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t10");
624 
625         // build SIMPLE proposition
626         PropositionDefinition propositionDefinition = createTestPropositionForTranslation(t10.object0, t10.namespaceName, "proposition2" );
627         NaturalLanguageTemplate template = createTestNaturalLanguageTemplate(t10.namespaceName, "cy", "proposition2",
628                 "Ddylai hyn fod yn segur, Gwrthrych", true);
629 
630         NaturalLanguageTree naturalLanguageTree = ruleManagementService.translateNaturalLanguageTreeForProposition(
631                 template.getNaturalLanguageUsageId(), propositionDefinition, "en");
632 
633         String translation = naturalLanguageTree.getNaturalLanguage();
634         assertEquals("Non-empty translation returned",StringUtils.EMPTY,translation);
635 
636         // SIMPLE proposition should not have children
637         assertNull("Should have returned null",naturalLanguageTree.getChildren());
638     }
639 }