]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman-Common/src/test/splat/service/TestSearchService.java
Salome HOME
Search knowledge is implemented. Unit tests are improved. Lucene index is not used...
[tools/siman.git] / Workspace / Siman-Common / src / test / splat / service / TestSearchService.java
1 /*****************************************************************************
2  * Company         OPEN CASCADE
3  * Application     SIMAN
4  * File            $Id$ 
5  * Creation date   12 Oct 2012
6  * @author         $Author$
7  * @version        $Revision$
8  *****************************************************************************/
9 package test.splat.service;
10
11 import java.util.ArrayList;
12 import java.util.Calendar;
13 import java.util.Date;
14 import java.util.Iterator;
15 import java.util.List;
16
17 import org.splat.dal.bo.kernel.User;
18 import org.splat.dal.bo.som.ContributorRelation;
19 import org.splat.dal.bo.som.DocumentType;
20 import org.splat.dal.bo.som.KnowledgeElement;
21 import org.splat.dal.bo.som.KnowledgeElementType;
22 import org.splat.dal.bo.som.Scenario;
23 import org.splat.dal.bo.som.SimulationContext;
24 import org.splat.dal.bo.som.Study;
25 import org.splat.dal.bo.som.ValidationCycle;
26 import org.splat.dal.bo.som.ValidationCycleRelation;
27 import org.splat.dal.bo.som.ValidationStep;
28 import org.splat.dal.bo.som.Visibility;
29 import org.splat.dal.dao.kernel.UserDAO;
30 import org.splat.dal.dao.som.Database;
31 import org.splat.dal.dao.som.KnowledgeElementDAO;
32 import org.splat.dal.dao.som.KnowledgeElementTypeDAO;
33 import org.splat.dal.dao.som.ScenarioDAO;
34 import org.splat.dal.dao.som.StudyDAO;
35 import org.splat.dal.dao.som.ValidationCycleDAO;
36 import org.splat.exception.BusinessException;
37 import org.splat.log.AppLogger;
38 import org.splat.service.DocumentTypeService;
39 import org.splat.service.PublicationService;
40 import org.splat.service.SearchService;
41 import org.splat.service.SimulationContextService;
42 import org.splat.service.StepService;
43 import org.splat.service.StudyService;
44 import org.splat.service.dto.KnowledgeSearchFilterDTO;
45 import org.splat.service.dto.Proxy;
46 import org.splat.service.dto.StudySearchFilterDTO;
47 import org.splat.service.technical.ProjectSettingsService;
48 import org.springframework.beans.factory.annotation.Autowired;
49 import org.springframework.beans.factory.annotation.Qualifier;
50 import org.springframework.orm.hibernate3.HibernateTemplate;
51 import org.testng.Assert;
52 import org.testng.annotations.Test;
53
54 import test.splat.common.BaseTest;
55 import test.splat.util.TestEntitiesGenerator;
56
57 /**
58  * Test class for StudyService.
59  * 
60  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
61  * 
62  */
63 public class TestSearchService extends BaseTest {
64
65         /**
66          * Logger for the class.
67          */
68         private static final AppLogger LOG = AppLogger
69                         .getLogger(TestSearchService.class);
70
71         /**
72          * The StudyDAO. Later injected by Spring.
73          */
74         @Autowired
75         @Qualifier("studyDAO")
76         private transient StudyDAO _studyDAO;
77
78         /**
79          * The ScenarioDAO. Later injected by Spring.
80          */
81         @Autowired
82         @Qualifier("scenarioDAO")
83         private transient ScenarioDAO _scenarioDAO;
84
85         /**
86          * The KnowledgeElementDAO. Later injected by Spring.
87          */
88         @Autowired
89         @Qualifier("knowledgeElementDAO")
90         private transient KnowledgeElementDAO _knowledgeElementDAO;
91
92         /**
93          * The KnowledgeElementTypeDAO. Later injected by Spring.
94          */
95         @Autowired
96         @Qualifier("knowledgeElementTypeDAO")
97         private transient KnowledgeElementTypeDAO _knowledgeElementTypeDAO;
98
99         /**
100          * The PublicationService. Later injected by Spring.
101          */
102         @Autowired
103         @Qualifier("publicationService")
104         private transient PublicationService _publicationService;
105
106         /**
107          * The StepService. Later injected by Spring.
108          */
109         @Autowired
110         @Qualifier("stepService")
111         private transient StepService _stepService;
112
113         /**
114          * The ProjectSettingsService. Later injected by Spring.
115          */
116         @Autowired
117         @Qualifier("projectSettings")
118         private transient ProjectSettingsService _projectSettings;
119
120         /**
121          * The DocumentTypeService. Later injected by Spring.
122          */
123         @Autowired
124         @Qualifier("documentTypeService")
125         private transient DocumentTypeService _documentTypeService;
126
127         /**
128          * The StudyService. Later injected by Spring.
129          */
130         @Autowired
131         @Qualifier("studyService")
132         private transient StudyService _studyService;
133
134         /**
135          * The SearchService. Later injected by Spring.
136          */
137         @Autowired
138         @Qualifier("searchService")
139         private transient SearchService _searchService;
140
141         /**
142          * The UserDAO. Later injected by Spring.
143          */
144         @Autowired
145         @Qualifier("userDAO")
146         private transient UserDAO _userDAO;
147
148         /**
149          * The ValidationCycleDAO. Later injected by Spring.
150          */
151         @Autowired
152         @Qualifier("validationCycleDAO")
153         private transient ValidationCycleDAO _validationCycleDAO;
154
155         /**
156          * The SimulationContextService. Later injected by Spring.
157          */
158         @Autowired
159         @Qualifier("simulationContextService")
160         private transient SimulationContextService _simulationContextService;
161
162         /**
163          * Test of searching a study.<BR>
164          * <B>Description :</B> <BR>
165          * <i>Create studies and try to find them according next document index.</i><BR>
166          * <B>Action : </B><BR>
167          * <i>
168          * <ol>
169          * <li>Search study by state</li>
170          * <li>Search study by reference</li>
171          * <li>Search study by author</li>
172          * <li>Search study by actor</li>
173          * <li>Search study by title</li>
174          * <li>Search study by simulation contexts</li>
175          * <li>Search study by all criteria</li>
176          * <li>Search study by any criteria</li>
177          * </ol>
178          * </i> <B>Test data : </B><BR>
179          * <i>no input parameters</i><BR>
180          * 
181          * <B>Outcome results:</B><BR>
182          * <i>
183          * <ul>
184          * <li>A study must be found according to the given criteria<BR>
185          * </li>
186          * </ul>
187          * </i>
188          * 
189          * @throws BusinessException
190          *             if can't create test user or study
191          */
192         @Test
193         public void testSelectStudiesWhere() throws BusinessException {
194                 LOG.debug(">>>>> BEGIN testSelectStudiesWhere()");
195                 startNestedTransaction();
196
197                 HibernateTemplate ht = getHibernateTemplate();
198                 Calendar calend = java.util.Calendar.getInstance();
199                 calend.roll(Calendar.DATE, false);
200                 Date beforeCreation = calend.getTime();
201
202                 Database.getInstance().reset();
203                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
204                 // Load workflow customization
205                 try {
206                         _projectSettings.configure(ClassLoader.getSystemResource(
207                                         "test/som.xml").getPath());
208                 } catch (Exception e) {
209                         Assert.fail("Can't load som.xml: ", e);
210                 }
211
212                 User goodUser = TestEntitiesGenerator.getTestUser("goodUser");
213                 _userDAO.create(goodUser);
214                 User otherUser = TestEntitiesGenerator.getTestUser("otherUser");
215                 _userDAO.create(otherUser);
216                 User thirdUser = TestEntitiesGenerator.getTestUser("thirdUser");
217                 _userDAO.create(thirdUser);
218
219                 // ============== STUDY 0: Private : goodUser
220                 // Create private study
221                 Study aStudy = TestEntitiesGenerator.getTestStudy(goodUser);
222                 aStudy.setTitle("0.This is private study");
223                 Long privateStudyId = _studyDAO.create(aStudy);
224
225                 // Add simulation context to the study 0
226                 SimulationContext.Properties cprop = new SimulationContext.Properties();
227                 cprop.setType(_simulationContextService.selectType("product"))
228                                 .setValue("Test Simulation Context: Product");
229                 SimulationContext ctx = _studyService.addProjectContext(aStudy, cprop);
230                 ht.flush();
231
232                 // ============== STUDY 1: Public : goodUser : otherUser is contributor
233                 // Create public study with predefined title
234                 aStudy = TestEntitiesGenerator.getTestStudy(goodUser);
235                 aStudy.setVisibility(Visibility.PUBLIC);
236                 aStudy.setTitle("2.This is a public study");
237                 aStudy.addRelation(new ContributorRelation(aStudy, otherUser));
238                 Long titleStudyId = _studyDAO.create(aStudy);
239
240                 // Add simulation context to the study 1
241                 cprop.setType(_simulationContextService.selectType("product"))
242                                 .setValue("Test Simulation Context: Product1");
243                 _studyService.addProjectContext(aStudy, cprop);
244                 ht.flush();
245
246                 // ============== STUDY 2: Public : otherUser
247                 // Create public study with predefined reference
248                 aStudy = TestEntitiesGenerator.getTestStudy(otherUser);
249                 aStudy.setVisibility(Visibility.PUBLIC);
250                 aStudy.setTitle("1.This is another public study");
251                 aStudy.setReference("TEST_REF");
252                 Long refStudyId = _studyDAO.create(aStudy);
253
254                 // ============== STUDY 3: Private : thirdUser : otherUser is contributor
255                 // Create private study of third user with otherUser as a reviewer
256                 aStudy = TestEntitiesGenerator.getTestStudy(thirdUser);
257                 aStudy.setTitle("3.This is a private study of third user");
258                 Long reviewStudyId = _studyDAO.create(aStudy);
259
260                 // Create validation cycle for the last study
261                 ValidationCycle.Properties vprop = new ValidationCycle.Properties();
262                 DocumentType type = _documentTypeService.selectType("specification");
263                 vprop.setDocumentType(type);
264                 vprop.setActor(ValidationStep.REVIEW, otherUser);
265                 ValidationCycle cycle = new ValidationCycle(aStudy, vprop);
266                 _validationCycleDAO.create(cycle);
267                 ValidationCycleRelation link = cycle.getContext();
268                 aStudy.addRelation(link);
269                 ht.flush();
270                 calend = java.util.Calendar.getInstance();
271                 calend.roll(Calendar.DATE, true);
272                 Date afterCreation = calend.getTime();
273
274                 // ============== START OF TEST CALLS
275                 // Search by study author
276                 StudySearchFilterDTO filter = new StudySearchFilterDTO();
277                 filter.setAuthor(String.valueOf(goodUser.getIndex()));
278                 List<Proxy> res = _searchService.selectStudiesWhere(filter);
279                 Assert.assertNotNull(res);
280                 Assert.assertEquals(res.size(), 1);
281                 Assert.assertEquals(res.get(0).getIndex(), titleStudyId);
282
283                 // Search for other logged in study contributor
284                 filter = new StudySearchFilterDTO();
285                 filter.setConnectedUserId(otherUser.getIndex());
286                 res = _searchService.selectStudiesWhere(filter);
287                 Assert.assertNotNull(res);
288                 Assert.assertEquals(res.size(), 3);
289                 Assert.assertEquals(res.get(0).getIndex(), refStudyId); // Public study
290                 Assert.assertEquals(res.get(1).getIndex(), titleStudyId); // Public study
291                 Assert.assertEquals(res.get(2).getIndex(), reviewStudyId); // OtherUser is reviewer in this study
292
293                 // Search for logged in study contributor
294                 filter = new StudySearchFilterDTO();
295                 filter.setConnectedUserId(goodUser.getIndex());
296                 res = _searchService.selectStudiesWhere(filter);
297                 Assert.assertNotNull(res);
298                 Assert.assertEquals(res.size(), 3);
299                 Assert.assertEquals(res.get(0).getIndex(), privateStudyId); // goodUser is author
300                 Assert.assertEquals(res.get(1).getIndex(), refStudyId); // Public study
301                 Assert.assertEquals(res.get(2).getIndex(), titleStudyId); // Public study
302
303                 // Search by study title contents
304                 filter = new StudySearchFilterDTO();
305                 filter.setWords("study public");
306                 res = _searchService.selectStudiesWhere(filter);
307                 Assert.assertNotNull(res);
308                 Assert.assertEquals(res.size(), 2);
309                 Assert.assertEquals(res.get(0).getIndex(), refStudyId);
310                 Assert.assertEquals(res.get(1).getIndex(), titleStudyId);
311
312                 // Search by study reference
313                 filter = new StudySearchFilterDTO();
314                 filter.setReference("TEST_REF");
315                 res = _searchService.selectStudiesWhere(filter);
316                 Assert.assertNotNull(res);
317                 Assert.assertEquals(res.size(), 1);
318                 Assert.assertEquals(res.get(0).getIndex(), refStudyId);
319
320                 // Search a study by simulation context
321                 filter = new StudySearchFilterDTO();
322                 filter.setConnectedUserId(goodUser.getIndex());
323                 List<SimulationContext> contexts = new ArrayList<SimulationContext>();
324                 contexts.add(ctx);
325                 filter.setSimContexts(contexts);
326                 res = _searchService.selectStudiesWhere(filter);
327                 Assert.assertNotNull(res);
328                 Assert.assertEquals(res.size(), 1);
329                 Assert.assertEquals(res.get(0).getIndex(), privateStudyId);
330                 // Check simualtion contexts of the found study
331                 for (Proxy proxy: res) {
332                 aStudy = _studyService.selectStudy(proxy.getIndex());
333                 Iterator<SimulationContext> ctxIter = aStudy
334                                 .SimulationContextIterator();
335                 contexts.clear();
336                 while (ctxIter.hasNext()) {
337                         contexts.add(ctxIter.next());
338                 }
339                 Assert.assertEquals(contexts.size(), 1);
340                 Assert.assertEquals(contexts.get(0), ctx);
341                 }
342
343                 // Search for dates
344                 filter = new StudySearchFilterDTO();
345                 filter.setCreatedAfter(beforeCreation);
346                 filter.setCreatedBefore(afterCreation);
347                 res = _searchService.selectStudiesWhere(filter);
348                 Assert.assertNotNull(res);
349                 Assert.assertEquals(res.size(), 2);
350                 Assert.assertEquals(res.get(0).getIndex(), refStudyId);
351                 Assert.assertEquals(res.get(1).getIndex(), titleStudyId);
352                 
353                 // Search for dates with no result
354                 filter = new StudySearchFilterDTO();
355                 filter.setCreatedAfter(afterCreation);
356                 res = _searchService.selectStudiesWhere(filter);
357                 Assert.assertNotNull(res);
358                 Assert.assertEquals(res.size(), 0);
359                 
360                 rollbackNestedTransaction();
361                 LOG.debug(">>>>> END testSelectStudiesWhere()");
362         }
363
364         /**
365          * Test of searching a study.<BR>
366          * <B>Description :</B> <BR>
367          * <i>Create studies and try to find them according next document index.</i><BR>
368          * <B>Action : </B><BR>
369          * <i>
370          * <ol>
371          * <li>Search study by state</li>
372          * <li>Search study by reference</li>
373          * <li>Search study by author</li>
374          * <li>Search study by actor</li>
375          * <li>Search study by title</li>
376          * <li>Search study by simulation contexts</li>
377          * <li>Search study by all criteria</li>
378          * <li>Search study by any criteria</li>
379          * </ol>
380          * </i> <B>Test data : </B><BR>
381          * <i>no input parameters</i><BR>
382          * 
383          * <B>Outcome results:</B><BR>
384          * <i>
385          * <ul>
386          * <li>A study must be found according to the given criteria<BR>
387          * </li>
388          * </ul>
389          * </i>
390          * 
391          * @throws BusinessException
392          *             if can't create test user or study
393          */
394         @Test
395         public void testSelectKnowledgeElementsWhere() throws BusinessException {
396                 LOG.debug(">>>>> BEGIN testSelectKnowledgeElementsWhere()");
397                 startNestedTransaction();
398
399                 HibernateTemplate ht = getHibernateTemplate();
400                 
401                 Calendar calend = java.util.Calendar.getInstance();
402                 calend.roll(Calendar.DATE, false);
403                 Date beforeCreation = calend.getTime();
404
405                 Database.getInstance().reset();
406                 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
407                 // Load workflow customization
408                 try {
409                         _projectSettings.configure(ClassLoader.getSystemResource(
410                                         "test/som.xml").getPath());
411                 } catch (Exception e) {
412                         Assert.fail("Can't load som.xml: ", e);
413                 }
414
415                 User goodUser = TestEntitiesGenerator.getTestUser("goodUser");
416                 _userDAO.create(goodUser);
417                 User otherUser = TestEntitiesGenerator.getTestUser("otherUser");
418                 _userDAO.create(otherUser);
419                 User thirdUser = TestEntitiesGenerator.getTestUser("thirdUser");
420                 _userDAO.create(thirdUser);
421                 KnowledgeElementType ktype1 = new KnowledgeElementType("testKType1");
422                 KnowledgeElementType ktype2 = new KnowledgeElementType("testKType2");
423                 _knowledgeElementTypeDAO.create(ktype1);
424                 _knowledgeElementTypeDAO.create(ktype2);
425
426                 // ============== STUDY 0: Private : goodUser
427                 // Create private study
428                 Study aStudy = TestEntitiesGenerator.getTestStudy(goodUser);
429                 aStudy.setTitle("0.This is private study");
430                 Long privateStudyId = _studyDAO.create(aStudy);
431
432                 // Add simulation context to the study 0
433                 SimulationContext.Properties cprop = new SimulationContext.Properties();
434                 cprop.setType(_simulationContextService.selectType("product"))
435                                 .setValue("Test Simulation Context: Product");
436                 SimulationContext ctx = _studyService.addProjectContext(aStudy, cprop);
437                 ht.flush();
438
439                 // Add a scenario to the study 0
440                 Scenario scen = TestEntitiesGenerator.getTestScenario(aStudy);
441                 _scenarioDAO.create(scen);
442                 ht.flush();
443
444                 // Add knowledge elements to the scenario
445                 KnowledgeElement kelm01 = TestEntitiesGenerator
446                                 .getTestKnowledgeElement(scen, ktype1, "TestKelm01 title");
447                 KnowledgeElement kelm02 = TestEntitiesGenerator
448                                 .getTestKnowledgeElement(scen, ktype2, "TestKelm02 title");
449                 _knowledgeElementDAO.create(kelm01);
450                 _knowledgeElementDAO.create(kelm02);
451                 ht.flush();
452
453                 // ============== STUDY 1: Public : goodUser : otherUser is contributor
454                 // Create public study with predefined title
455                 aStudy = TestEntitiesGenerator.getTestStudy(goodUser);
456                 aStudy.setVisibility(Visibility.PUBLIC);
457                 aStudy.setTitle("2.This is a public study");
458                 aStudy.addRelation(new ContributorRelation(aStudy, otherUser));
459                 Long titleStudyId = _studyDAO.create(aStudy);
460
461                 // Add a scenario to the study 1
462                 scen = TestEntitiesGenerator.getTestScenario(aStudy);
463                 _scenarioDAO.create(scen);
464                 ht.flush();
465
466                 // Add knowledge elements to the scenario
467                 KnowledgeElement kelm11 = TestEntitiesGenerator
468                                 .getTestKnowledgeElement(scen, ktype1, "TestKelm11 title");
469                 KnowledgeElement kelm12 = TestEntitiesGenerator
470                                 .getTestKnowledgeElement(scen, ktype2, "TestKelm12 title");
471                 _knowledgeElementDAO.create(kelm11);
472                 _knowledgeElementDAO.create(kelm12);
473
474                 // Add simulation context to the study 1
475                 cprop.setType(_simulationContextService.selectType("product"))
476                                 .setValue("Test Simulation Context: Product1");
477                 _studyService.addProjectContext(aStudy, cprop);
478                 ht.flush();
479
480                 // ============== STUDY 2: Public : otherUser
481                 // Create public study with predefined reference
482                 aStudy = TestEntitiesGenerator.getTestStudy(otherUser);
483                 aStudy.setVisibility(Visibility.PUBLIC);
484                 aStudy.setTitle("1.This is another public study");
485                 aStudy.setReference("TEST_REF");
486                 Long refStudyId = _studyDAO.create(aStudy);
487                 // Add a scenario to the study 2
488                 scen = TestEntitiesGenerator.getTestScenario(aStudy);
489                 _scenarioDAO.create(scen);
490                 ht.flush();
491
492                 // Add knowledge elements to the scenario
493                 KnowledgeElement kelm21 = TestEntitiesGenerator
494                                 .getTestKnowledgeElement(scen, ktype1, "TestKelm21 title");
495                 KnowledgeElement kelm22 = TestEntitiesGenerator
496                                 .getTestKnowledgeElement(scen, ktype2, "TestKelm22 title");
497                 _knowledgeElementDAO.create(kelm21);
498                 _knowledgeElementDAO.create(kelm22);
499                 ht.flush();
500
501                 // ============== STUDY 3: Private : thirdUser : otherUser is contributor
502                 // Create private study of third user with otherUser as a reviewer
503                 aStudy = TestEntitiesGenerator.getTestStudy(thirdUser);
504                 aStudy.setTitle("3.This is a private study of third user");
505                 Long reviewStudyId = _studyDAO.create(aStudy);
506
507                 // Create validation cycle for the last study
508                 ValidationCycle.Properties vprop = new ValidationCycle.Properties();
509                 DocumentType type = _documentTypeService.selectType("specification");
510                 vprop.setDocumentType(type);
511                 vprop.setActor(ValidationStep.REVIEW, otherUser);
512                 ValidationCycle cycle = new ValidationCycle(aStudy, vprop);
513                 _validationCycleDAO.create(cycle);
514                 ValidationCycleRelation link = cycle.getContext();
515                 aStudy.addRelation(link);
516                 ht.flush();
517                 // Add a scenario to the study 3
518                 scen = TestEntitiesGenerator.getTestScenario(aStudy);
519                 _scenarioDAO.create(scen);
520                 ht.flush();
521
522                 // Add knowledge elements to the scenario
523                 KnowledgeElement kelm31 = TestEntitiesGenerator
524                                 .getTestKnowledgeElement(scen, ktype1, "TestKelm31 title");
525                 KnowledgeElement kelm32 = TestEntitiesGenerator
526                                 .getTestKnowledgeElement(scen, ktype2, "TestKelm32 title");
527                 _knowledgeElementDAO.create(kelm31);
528                 _knowledgeElementDAO.create(kelm32);
529                 ht.flush();
530                 calend = java.util.Calendar.getInstance();
531                 calend.roll(Calendar.DATE, true);
532                 Date afterCreation = calend.getTime();
533
534                 // ============== START OF TEST CALLS
535                 // Search by author goodUser as not logged in user
536                 KnowledgeSearchFilterDTO filter = new KnowledgeSearchFilterDTO();
537                 filter.setAuthor(String.valueOf(goodUser.getIndex()));
538                 List<Proxy> res = _searchService.selectKnowledgeElementsWhere(filter);
539                 Assert.assertNotNull(res);
540                 Assert.assertEquals(res.size(), 2);
541                 Assert.assertEquals(res.get(0).getTitle(), kelm11.getTitle());
542                 Assert.assertEquals(res.get(1).getTitle(), kelm12.getTitle());
543
544                 // Search for other logged in study contributor (what is visible for otherUser by default)
545                 filter = new KnowledgeSearchFilterDTO();
546                 filter.setConnectedUserId(otherUser.getIndex());
547                 res = _searchService.selectKnowledgeElementsWhere(filter);
548                 Assert.assertNotNull(res);
549                 Assert.assertEquals(res.size(), 6);
550                 Assert.assertEquals(res.get(0).getTitle(), kelm11.getTitle());
551                 Assert.assertEquals(res.get(1).getTitle(), kelm12.getTitle());
552                 Assert.assertEquals(res.get(2).getTitle(), kelm21.getTitle());
553                 Assert.assertEquals(res.get(3).getTitle(), kelm22.getTitle());
554                 Assert.assertEquals(res.get(4).getTitle(), kelm31.getTitle());
555                 Assert.assertEquals(res.get(5).getTitle(), kelm32.getTitle());
556
557                 // Search for logged in study contributor
558                 filter = new KnowledgeSearchFilterDTO();
559                 filter.setConnectedUserId(goodUser.getIndex());
560                 res = _searchService.selectKnowledgeElementsWhere(filter);
561                 Assert.assertNotNull(res);
562                 Assert.assertEquals(res.size(), 6);
563                 Assert.assertEquals(res.get(0).getTitle(), kelm01.getTitle());
564                 Assert.assertEquals(res.get(1).getTitle(), kelm02.getTitle());
565                 Assert.assertEquals(res.get(2).getTitle(), kelm11.getTitle());
566                 Assert.assertEquals(res.get(3).getTitle(), kelm12.getTitle());
567                 Assert.assertEquals(res.get(4).getTitle(), kelm21.getTitle());
568                 Assert.assertEquals(res.get(5).getTitle(), kelm22.getTitle());
569
570                 // Search by title contents
571                 filter = new KnowledgeSearchFilterDTO();
572                 filter.setWords("TestKelm22");
573                 res = _searchService.selectKnowledgeElementsWhere(filter);
574                 Assert.assertNotNull(res);
575                 Assert.assertEquals(res.size(), 1);
576                 Assert.assertEquals(res.get(0).getTitle(), kelm22.getTitle());
577
578                 // Search by reference
579                  filter = new KnowledgeSearchFilterDTO();
580                  filter.setReference(kelm22.getReference());
581                  res = _searchService.selectKnowledgeElementsWhere(filter);
582                  Assert.assertNotNull(res);
583                  Assert.assertEquals(res.size(), 1);
584                  Assert.assertEquals(res.get(0).getTitle(), kelm22.getTitle());
585
586                 // Search by simulation context
587                 filter = new KnowledgeSearchFilterDTO();
588                 filter.setConnectedUserId(goodUser.getIndex());
589                 List<SimulationContext> contexts = new ArrayList<SimulationContext>();
590                 contexts.add(ctx);
591                 filter.setSimContexts(contexts);
592                 res = _searchService.selectKnowledgeElementsWhere(filter);
593                 Assert.assertNotNull(res);
594                 Assert.assertEquals(res.size(), 2);
595                 Assert.assertEquals(res.get(0).getTitle(), kelm01.getTitle());
596                 Assert.assertEquals(res.get(1).getTitle(), kelm02.getTitle());
597                 // Check simualtion contexts of the found study
598                 for (Proxy proxy : res) {
599                         KnowledgeElement kelm = _knowledgeElementDAO.get(proxy.getIndex());
600                         aStudy = _studyService.selectStudy(kelm.getOwnerScenario()
601                                         .getOwnerStudy().getIndex());
602                         Iterator<SimulationContext> ctxIter = aStudy
603                                         .SimulationContextIterator();
604                         contexts.clear();
605                         while (ctxIter.hasNext()) {
606                                 contexts.add(ctxIter.next());
607                         }
608                         Assert.assertEquals(contexts.size(), 1);
609                         Assert.assertEquals(contexts.get(0), ctx);
610                 }
611
612                 // Search for dates
613                 filter = new KnowledgeSearchFilterDTO();
614                 filter.setCreatedAfter(beforeCreation);
615                 filter.setCreatedBefore(afterCreation);
616                 res = _searchService.selectKnowledgeElementsWhere(filter);
617                 Assert.assertNotNull(res);
618                 Assert.assertEquals(res.size(), 4);
619                 Assert.assertEquals(res.get(0).getTitle(), kelm11.getTitle());
620                 Assert.assertEquals(res.get(1).getTitle(), kelm12.getTitle());
621                 Assert.assertEquals(res.get(2).getTitle(), kelm21.getTitle());
622                 Assert.assertEquals(res.get(3).getTitle(), kelm22.getTitle());
623                 
624                 // Search for dates with no result
625                 filter = new KnowledgeSearchFilterDTO();
626                 filter.setCreatedAfter(afterCreation);
627                 res = _searchService.selectKnowledgeElementsWhere(filter);
628                 Assert.assertNotNull(res);
629                 Assert.assertEquals(res.size(), 0);
630                 
631                 rollbackNestedTransaction();
632                 LOG.debug(">>>>> END testSelectKnowledgeElementsWhere()");
633         }
634 }