View Javadoc

1   /*
2    * Copyright 2006-2013 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.junit.Before;
20  import org.junit.Test;
21  import org.kuali.rice.core.api.criteria.QueryByCriteria;
22  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
23  import org.kuali.rice.krms.api.repository.reference.ReferenceObjectBinding;
24  
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  import static org.junit.Assert.*;
29  import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
30  import static org.kuali.rice.core.api.criteria.PredicateFactory.in;
31  
32  /**
33   *   RuleManagementReferenceObjectBindingTest is to test the methods of ruleManagementServiceImpl relating to ReferenceObjectBindings
34   *
35   *   Each test focuses on one of the methods.
36   */
37  public class RuleManagementReferenceObjectBindingTest extends RuleManagementBaseTest {
38      @Override
39      @Before
40      public void setClassDiscriminator() {
41          // set a unique discriminator for test objects of this class
42          CLASS_DISCRIMINATOR = "RMROBT";
43      }
44  
45      /**
46       *  Test testCreateReferenceObjectBinding()
47       *
48       *  This test focuses specifically on the RuleManagementServiceImpl .createTestReferenceObjectBinding(ReferenceObjectBinding) method
49       */
50      @Test
51      public void testCreateReferenceObjectBinding() {
52          // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
53          RuleManagementBaseTestObjectNames t0 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t0");
54  
55          // create a ReferenceObjectBinding entry
56          ReferenceObjectBinding.Builder refObjBindingBuilder =  createTestReferenceObjectBinding(t0.object0);
57          ReferenceObjectBinding refObjBinding = ruleManagementService.getReferenceObjectBinding(
58                  refObjBindingBuilder.getId());
59          refObjBindingBuilder =  ReferenceObjectBinding.Builder.create(refObjBinding);
60  
61          // verify the Created entry
62          assertNotNull("Created ReferenceObjectBinding not found", refObjBindingBuilder);
63          assertEquals("Invalid CollectionName of refObjBindingBuilder found", "ParkingPolicies",
64                  refObjBindingBuilder.getCollectionName());
65          assertEquals("Invalid KrmsObjectId of refObjBindingBuilder found",t0.agenda_Id, refObjBindingBuilder.getKrmsObjectId());
66          assertEquals("Invalid KrmsDiscriminatorType of refObjBindingBuilder found",
67                  krmsTypeRepository.getTypeByName(t0.namespaceName, "AgendaType" + t0.object0).getId(), refObjBindingBuilder.getKrmsDiscriminatorType() );
68          assertEquals("Invalid Namespace of refObjBindingBuilder found",t0.namespaceName, refObjBindingBuilder.getNamespace());
69          assertEquals("Invalid ReferenceObjectId of refObjBindingBuilder found",t0.referenceObject_0_Id, refObjBindingBuilder.getReferenceObjectId());
70          assertEquals("Invalid ReferenceDiscriminatorType of refObjBindingBuilder found",
71                  t0.referenceObject_0_DiscriminatorType, refObjBindingBuilder.getReferenceDiscriminatorType());
72          assertEquals("Invalid Active value of refObjBindingBuilder found",true, refObjBindingBuilder.isActive());
73  
74          // try to create a ReferenceObjectBinding which already exists
75          try {
76              ruleManagementService.createReferenceObjectBinding(refObjBindingBuilder.build());
77              fail("Should have thrown IllegalStateException: the ReferenceObjectBinding to create already exists");
78          } catch (Exception e) {
79              // throws IllegalStateException: the ReferenceObjectBinding to create already exists
80          }
81  
82          // try to create a ReferenceObjectBinding entry which exists using a different Id
83          refObjBindingBuilder.setId("RefObjBindIdChanged");
84          try {
85              ruleManagementService.createReferenceObjectBinding(refObjBindingBuilder.build());
86              fail("Should have thrown DataIntegrityViolationException: OJB operation; SQL []; Duplicate entry");
87          } catch (Exception e) {
88              // throws DataIntegrityViolationException: OJB operation; SQL []; Duplicate entry
89          }
90      }
91  
92      /**
93       *  Test testGetReferenceObjectBinding()
94       *
95       *  This test focuses specifically on the RuleManagementServiceImpl .getReferenceObjectBinding("ReferenceObjectId") method
96       */
97      @Test
98      public void testGetReferenceObjectBinding() {
99          // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
100         RuleManagementBaseTestObjectNames t1 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t1");
101 
102         ReferenceObjectBinding.Builder refObjBindingBuilder =  createTestReferenceObjectBinding(t1.object0);
103 
104         ReferenceObjectBinding refObjBinding = ruleManagementService.getReferenceObjectBinding(
105                 refObjBindingBuilder.getId());
106         assertNotNull("ReferenceObjectBinding should have been returned",refObjBinding);
107         assertEquals("Incorrect value found on returned ReferenceObjectBinding",t1.referenceObject_0_Id,refObjBinding.getReferenceObjectId());
108 
109         // try to getReferenceObjectBinding using null Id
110         try {
111             refObjBinding = ruleManagementService.getReferenceObjectBinding(null);
112             fail("Should have thrown IllegalArgumentException: referenceObjectBindingId was null");
113         } catch (Exception e) {
114             // throws IllegalArgumentException: referenceObjectBindingId was null
115         }
116 
117         // try to find a ReferenceObjectBinding using a non-existent Id
118         assertNull("ReferenceObjectBinding should not have been found", ruleManagementService.getReferenceObjectBinding("junk_value"));
119     }
120 
121     /**
122      *  Test testGetReferenceObjectBindings()
123      *
124      *  This test focuses specifically on the RuleManagementServiceImpl .getReferenceObjectBindings(List<ReferenceObjectBinding>) method
125      */
126     @Test
127     public void testGetReferenceObjectBindings() {
128         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
129         RuleManagementBaseTestObjectNames t2 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t2");
130 
131         List<String> referenceObjectBindingIds = new ArrayList<String>();
132         referenceObjectBindingIds.add(createTestReferenceObjectBinding(t2.object0).getId());
133         referenceObjectBindingIds.add(createTestReferenceObjectBinding(t2.object1).getId());
134         referenceObjectBindingIds.add(createTestReferenceObjectBinding(t2.object2).getId());
135 
136         List<ReferenceObjectBinding> referenceObjectBindings = ruleManagementService.getReferenceObjectBindings(referenceObjectBindingIds);
137         int objectsFound = 0;
138         for ( ReferenceObjectBinding referenceObjectBinding : referenceObjectBindings) {
139             if ( referenceObjectBindingIds.contains( referenceObjectBinding.getId())) {
140                 objectsFound++;
141             } else {
142                 fail("Unexpected object returned");
143             }
144         }
145         assertEquals("Expected number of objects not returned",3,objectsFound);
146 
147         // try to getReferenceObjectBindings using a null Id List
148         try {
149             ruleManagementService.getReferenceObjectBindings(null);
150             fail("Should have thrown IllegalArgumentException: reference binding object ids must not be null");
151         } catch (IllegalArgumentException e) {
152             // throws IllegalArgumentException: reference binding object ids must not be null
153         }
154 
155         assertEquals("Incorrect number of objects returned", 0, ruleManagementService.getReferenceObjectBindings(new ArrayList<String>()).size());
156 
157         // try requesting a list of objects with a bad value in it
158         referenceObjectBindingIds.add("junkValue");
159         referenceObjectBindings = ruleManagementService.getReferenceObjectBindings(referenceObjectBindingIds);
160         objectsFound = 0;
161         for ( ReferenceObjectBinding referenceObjectBinding : referenceObjectBindings) {
162             if ( referenceObjectBindingIds.contains( referenceObjectBinding.getId())) {
163                 objectsFound++;
164             } else {
165                 fail("Unexpected object returned");
166             }
167         }
168         assertEquals("Expected number of objects not returned",3,objectsFound);
169     }
170 
171     /**
172      *  Test testFindReferenceObjectBindingsByReferenceObject()
173      *
174      *  This test focuses specifically on the RuleManagementServiceImpl .findReferenceObjectBindingsByReferenceObject("ReferenceObjectId") method
175      */
176     @Test
177     public void testFindReferenceObjectBindingsByReferenceObject() {
178         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
179         RuleManagementBaseTestObjectNames t3 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t3");
180         ReferenceObjectBinding.Builder refObjBindingBuilder =  createTestReferenceObjectBinding(t3.object0);
181 
182         //assertEquals("",refObjBindingBuilder.getId(),
183         List<ReferenceObjectBinding> referenceObjectBindings = ruleManagementService.findReferenceObjectBindingsByReferenceObject(
184                 refObjBindingBuilder.getReferenceDiscriminatorType(), refObjBindingBuilder.getReferenceObjectId());
185         assertEquals("Incorrect number of objects returned",1,referenceObjectBindings.size());
186 
187         // test findReferenceObjectBindingsByReferenceObject with null object discriminator
188         try {
189             ruleManagementService.findReferenceObjectBindingsByReferenceObject(null,refObjBindingBuilder.getReferenceObjectId());
190             fail("should have thrown RiceIllegalArgumentException: reference binding object discriminator type must not be null");
191         } catch (RiceIllegalArgumentException e) {
192             // throws RiceIllegalArgumentException: reference binding object discriminator type must not be null
193         }
194 
195         // test findReferenceObjectBindingsByReferenceObject with null reference object id
196         try {
197             ruleManagementService.findReferenceObjectBindingsByReferenceObject(refObjBindingBuilder.getReferenceDiscriminatorType(),null);
198             fail("should have thrown RiceIllegalArgumentException: reference object id must not be null");
199         } catch (RiceIllegalArgumentException e) {
200             // throws RiceIllegalArgumentException: reference object id must not be null
201         }
202 
203         // test with bad values for object discriminator and object id
204         referenceObjectBindings = ruleManagementService.findReferenceObjectBindingsByReferenceObject("junkvalue","junkvalue");
205         assertEquals("Incorrect number of objects returned",0,referenceObjectBindings.size());
206     }
207 
208     /**
209      *  Test testFindReferenceObjectBindingsByReferenceDiscriminatorType()
210      *
211      *  This test focuses specifically on the RuleManagementServiceImpl
212      *      .findReferenceObjectBindingsByReferenceDiscriminatorType("ReferenceDiscriminatorType") method
213      */
214     @Test
215     public void testFindReferenceObjectBindingsByReferenceDiscriminatorType() {
216         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
217         RuleManagementBaseTestObjectNames t4 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t4");
218 
219         // create two ReferenceObjectBindings with same ReferenceDiscriminatorType
220         ReferenceObjectBinding.Builder refObjBindingBuilder =  createTestReferenceObjectBinding(t4.object0);
221         refObjBindingBuilder.setReferenceDiscriminatorType("ParkingAffiliationType" + t4.discriminator);
222         ruleManagementService.updateReferenceObjectBinding(refObjBindingBuilder.build());
223 
224         refObjBindingBuilder =  createTestReferenceObjectBinding(t4.object1);
225         refObjBindingBuilder.setReferenceDiscriminatorType("ParkingAffiliationType" + t4.discriminator);
226         ruleManagementService.updateReferenceObjectBinding(refObjBindingBuilder.build());
227 
228         List<ReferenceObjectBinding> referenceObjectBindings = ruleManagementService.findReferenceObjectBindingsByReferenceDiscriminatorType(
229                 refObjBindingBuilder.getReferenceDiscriminatorType());
230         assertEquals("Incorrect number of objects returned",2,referenceObjectBindings.size());
231 
232         // check with blank ReferenceDiscriminatorType
233         try {
234             ruleManagementService.findReferenceObjectBindingsByReferenceDiscriminatorType("   ");
235             fail("Should have thrown IllegalArgumentException: referenceDiscriminatorType is null or blank");
236         } catch (IllegalArgumentException e) {
237             // throws IllegalArgumentException: referenceDiscriminatorType is null or blank
238         }
239 
240         // check with null ReferenceDiscriminatorType
241         try {
242             ruleManagementService.findReferenceObjectBindingsByReferenceDiscriminatorType(null);
243             fail("Should have thrown IllegalArgumentException: referenceDiscriminatorType is null or blank");
244         } catch (IllegalArgumentException e) {
245             // throws IllegalArgumentException: referenceDiscriminatorType is null or blank
246         }
247     }
248 
249     /**
250      *  Test testFindReferenceObjectBindingsByKrmsDiscriminatorType()
251      *
252      *  This test focuses specifically on the RuleManagementServiceImpl
253      *      .findReferenceObjectBindingsByKrmsDiscriminatorType("KrmsDiscriminatorType") method
254      */
255     @Test
256     public void testFindReferenceObjectBindingsByKrmsDiscriminatorType() {
257         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
258         RuleManagementBaseTestObjectNames t5 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t5");
259 
260         // create two ReferenceObjectBindings with same KrmsDiscriminatorType
261         ReferenceObjectBinding.Builder refObjBindingBuilder6008 =  createTestReferenceObjectBinding(t5.object0);
262 
263         ReferenceObjectBinding.Builder refObjBindingBuilder6009 =  createTestReferenceObjectBinding(t5.object1);
264         refObjBindingBuilder6009.setKrmsDiscriminatorType(refObjBindingBuilder6008.getKrmsDiscriminatorType());
265         ruleManagementService.updateReferenceObjectBinding(refObjBindingBuilder6009.build());
266 
267         List<ReferenceObjectBinding> referenceObjectBindings = ruleManagementService.findReferenceObjectBindingsByKrmsDiscriminatorType(refObjBindingBuilder6008.getKrmsDiscriminatorType());
268         assertEquals("Incorrect number of objects returned",2,referenceObjectBindings.size());
269 
270         // check with blank KrmsDiscriminatorType
271         try {
272             ruleManagementService.findReferenceObjectBindingsByKrmsDiscriminatorType("   ");
273             fail("Should have thrown IllegalArgumentException: krmsDiscriminatorType is null or blank");
274         } catch (IllegalArgumentException e) {
275             // throws IllegalArgumentException: krmsDiscriminatorType is null or blank
276         }
277 
278         // check with null KrmsDiscriminatorType
279         try {
280             ruleManagementService.findReferenceObjectBindingsByKrmsDiscriminatorType(null);
281             fail("Should have thrown IllegalArgumentException: krmsDiscriminatorType is null or blank");
282         } catch (IllegalArgumentException e) {
283             // throws IllegalArgumentException: krmsDiscriminatorType is null or blank
284         }
285     }
286 
287     /**
288      *  Test testFindReferenceObjectBindingsByKrmsObject()
289      *
290      *  This test focuses specifically on the RuleManagementServiceImpl
291      *      .findReferenceObjectBindingsByKrmsObject("KrmsObjectId") method
292      */
293     @Test
294     public void testFindReferenceObjectBindingsByKrmsObject() {
295         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
296         RuleManagementBaseTestObjectNames t6 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t6");
297 
298         // create two ReferenceObjectBindings with same KrmsObjectId
299         ReferenceObjectBinding.Builder refObjBindingBuilder0 =  createTestReferenceObjectBinding(t6.object0);
300 
301         ReferenceObjectBinding.Builder refObjBindingBuilder1 =  createTestReferenceObjectBinding(t6.object1);
302         refObjBindingBuilder1.setKrmsObjectId(refObjBindingBuilder0.getKrmsObjectId());
303         ruleManagementService.updateReferenceObjectBinding(refObjBindingBuilder1.build());
304 
305         List<ReferenceObjectBinding> referenceObjectBindings = ruleManagementService.findReferenceObjectBindingsByKrmsObject(
306                 refObjBindingBuilder0.getKrmsObjectId());
307         assertEquals("Incorrect number of objects returned",2,referenceObjectBindings.size());
308 
309         // check with blank KrmsObjectId
310         try {
311             ruleManagementService.findReferenceObjectBindingsByKrmsObject("   ");
312             fail("Should have thrown IllegalArgumentException: krmsObjectId is null or blank");
313         } catch (IllegalArgumentException e) {
314             // throws IllegalArgumentException: krmsObjectId is null or blank
315         }
316 
317         // check with null KrmsObjectId
318         try {
319             ruleManagementService.findReferenceObjectBindingsByKrmsObject(null);
320             fail("Should have thrown IllegalArgumentException: krmsObjectId is null or blank");
321         } catch (IllegalArgumentException e) {
322             // throws IllegalArgumentException: krmsObjectId is null or blank
323         }
324     }
325 
326     /**
327      *  Test testUpdateReferenceObjectBinding()
328      *
329      *  This test focuses specifically on the RuleManagementServiceImpl .updateReferenceObjectBinding(ReferenceObjectBinding) method
330      */
331     @Test
332     public void testUpdateReferenceObjectBinding() {
333         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
334         RuleManagementBaseTestObjectNames t7 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t7");
335 
336         ReferenceObjectBinding.Builder refObjBindingBuilder =  createTestReferenceObjectBinding(t7.object0);
337 
338         ReferenceObjectBinding refObjBinding = ruleManagementService.getReferenceObjectBinding(refObjBindingBuilder.getId());
339         refObjBindingBuilder =  ReferenceObjectBinding.Builder.create(refObjBinding);
340 
341         // verify all current values
342         assertNotNull("Created ReferenceObjectBinding not found", refObjBindingBuilder);
343         assertEquals("Invalid CollectionName of refObjBindingBuilder found","ParkingPolicies", refObjBindingBuilder.getCollectionName());
344         assertEquals("Invalid KrmsObjectId of refObjBindingBuilder found",t7.agenda_Id, refObjBindingBuilder.getKrmsObjectId());
345         assertEquals("Invalid KrmsDiscriminatorType of refObjBindingBuilder found",
346                 krmsTypeRepository.getTypeByName(t7.namespaceName, "AgendaType"+t7.object0).getId(),
347                 refObjBindingBuilder.getKrmsDiscriminatorType() );
348         assertEquals("Invalid Namespace of refObjBindingBuilder found",t7.namespaceName, refObjBindingBuilder.getNamespace());
349         assertEquals("Invalid ReferenceObjectId of refObjBindingBuilder found",t7.referenceObject_0_Id, refObjBindingBuilder.getReferenceObjectId());
350         assertEquals("Invalid ReferenceDiscriminatorType  of refObjBindingBuilder found","ParkingAffiliationType",
351                 refObjBindingBuilder.getReferenceDiscriminatorType());
352         assertEquals("Invalid Active value of refObjBindingBuilder found",true, refObjBindingBuilder.isActive());
353 
354         // change everything but the id and submit update
355         refObjBindingBuilder.setCollectionName("ParkingPolicies6Changed");
356         refObjBindingBuilder.setKrmsObjectId("AgendaId6Changed");
357         refObjBindingBuilder.setKrmsDiscriminatorType("KDTtype6Changed");
358         refObjBindingBuilder.setNamespace("Namespace6Changed");
359         refObjBindingBuilder.setReferenceObjectId("PA6Changed");
360         refObjBindingBuilder.setReferenceDiscriminatorType("ParkingAffiliationTypeChanged");
361         refObjBindingBuilder.setActive(false);
362         ruleManagementService.updateReferenceObjectBinding(refObjBindingBuilder.build());
363 
364         // verify updated values
365         refObjBinding = ruleManagementService.getReferenceObjectBinding(refObjBindingBuilder.getId());
366         refObjBindingBuilder =  ReferenceObjectBinding.Builder.create(refObjBinding);
367         assertNotNull("Created ReferenceObjectBinding not found", refObjBindingBuilder);
368         assertEquals("Invalid CollectionName of refObjBindingBuilder found", "ParkingPolicies6Changed",
369                 refObjBindingBuilder.getCollectionName());
370         assertEquals("Invalid KrmsObjectId of refObjBindingBuilder found","AgendaId6Changed", refObjBindingBuilder.getKrmsObjectId());
371         assertEquals("Invalid KrmsDiscriminatorType of refObjBindingBuilder found","KDTtype6Changed", refObjBindingBuilder.getKrmsDiscriminatorType() );
372         assertEquals("Invalid Namespace of refObjBindingBuilder found","Namespace6Changed", refObjBindingBuilder.getNamespace());
373         assertEquals("Invalid ReferenceObjectId of refObjBindingBuilder found","PA6Changed", refObjBindingBuilder.getReferenceObjectId());
374         assertEquals("Invalid ReferenceDiscriminatorType  of refObjBindingBuilder found","ParkingAffiliationTypeChanged", refObjBindingBuilder.getReferenceDiscriminatorType());
375         assertEquals("Invalid Active value of refObjBindingBuilder found",false, refObjBindingBuilder.isActive());
376 
377         // update a object which does not exist
378         refObjBindingBuilder.setId("junkValue");
379         try {
380             ruleManagementService.updateReferenceObjectBinding(refObjBindingBuilder.build());
381             fail("Should have thrown IllegalStateException: the ReferenceObjectBinding to update does not exists");
382         } catch (IllegalStateException e) {
383             // throws IllegalStateException: the ReferenceObjectBinding to update does not exists
384         }
385     }
386 
387     /**
388      *  Test testDeleteReferenceObjectBinding()
389      *
390      *  This test focuses specifically on the RuleManagementServiceImpl
391      *       .deleteReferenceObjectBinding("referenceObjectBinding id") method
392      */
393     @Test
394     public void testDeleteReferenceObjectBinding() {
395         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
396         RuleManagementBaseTestObjectNames t8 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t8");
397 
398         ReferenceObjectBinding.Builder refObjBindingBuilder =  createTestReferenceObjectBinding(t8.object0);
399         ReferenceObjectBinding refObjBinding = ruleManagementService.getReferenceObjectBinding(refObjBindingBuilder.getId());
400         refObjBindingBuilder =  ReferenceObjectBinding.Builder.create(refObjBinding);
401         assertNotNull("Created ReferenceObjectBinding not found", refObjBindingBuilder);
402 
403         // delete the ReferenceObjectBinding entry
404         ruleManagementService.deleteReferenceObjectBinding(refObjBinding.getId());
405         assertNull("Deleted ReferenceObjectBinding found", ruleManagementService.getReferenceObjectBinding(
406                 refObjBindingBuilder.getId()));
407 
408         // try to delete it a second time
409         try {
410             ruleManagementService.deleteReferenceObjectBinding(refObjBinding.getId());
411             fail("should have thrown IllegalStateException: the ReferenceObjectBinding to delete does not exists");
412         } catch (IllegalStateException e) {
413             // throws IllegalStateException: the ReferenceObjectBinding to delete does not exists
414         }
415 
416         // try to delete using null
417         try {
418             ruleManagementService.deleteReferenceObjectBinding(null);
419             fail("should have thrown IllegalArgumentException: referenceObjectBindingId was null");
420         } catch (IllegalArgumentException e) {
421             // throws IllegalArgumentException: referenceObjectBindingId was null
422         }
423     }
424 
425     /**
426      *  Test testFindReferenceObjectBindingIds()
427      *
428      *  This test focuses specifically on the RuleManagementServiceImpl
429      *       .findReferenceObjectBindingIds(QueryByCriteria) method
430      */
431     @Test
432     public void testFindReferenceObjectBindingIds() {
433         // get a set of unique object names for use by this test (discriminator passed can be any unique value within this class)
434         RuleManagementBaseTestObjectNames t9 =  new RuleManagementBaseTestObjectNames( CLASS_DISCRIMINATOR, "t9");
435 
436         // build three objects to search for.  Two active and one not active
437         List<String> refObjBindingBuilderIds = new ArrayList<String>();
438         ReferenceObjectBinding.Builder refObjBindingBuilder =  createTestReferenceObjectBinding(t9.object0);
439         refObjBindingBuilderIds.add(refObjBindingBuilder.getId());
440         refObjBindingBuilder =  createTestReferenceObjectBinding(t9.object1);
441         refObjBindingBuilderIds.add(refObjBindingBuilder.getId());
442         refObjBindingBuilder =  createTestReferenceObjectBinding(t9.object2);
443         refObjBindingBuilderIds.add(refObjBindingBuilder.getId());
444         refObjBindingBuilder.setActive(false);
445         ruleManagementService.updateReferenceObjectBinding(refObjBindingBuilder.build());
446 
447         // Find the three ReferenceObjectBindings by id list
448         QueryByCriteria.Builder query = QueryByCriteria.Builder.create();
449         query.setPredicates(in("id", refObjBindingBuilderIds.toArray(new String[]{})));
450 
451         List<String> referenceObjectBindingIds = ruleManagementService.findReferenceObjectBindingIds(query.build());
452         for (String referenceObjectBindingId : referenceObjectBindingIds ) {
453             assertTrue(refObjBindingBuilderIds.contains(referenceObjectBindingId));
454         }
455 
456         assertEquals("incorrect number of ReferenceObjectBindingIds found", 3, referenceObjectBindingIds.size());
457 
458         // find the two active ReferenceObjectBindings in the list
459         query = QueryByCriteria.Builder.create();
460         query.setPredicates( equal("active","Y"), in("id", refObjBindingBuilderIds.toArray(new String[]{})));
461 
462         referenceObjectBindingIds = ruleManagementService.findReferenceObjectBindingIds(query.build());
463         for (String referenceObjectBindingId : referenceObjectBindingIds ) {
464             assertTrue(refObjBindingBuilderIds.contains(referenceObjectBindingId));
465         }
466 
467         assertEquals("incorrect number of ReferenceObjectBindingIds found", 2, referenceObjectBindingIds.size());
468     }
469 }