1 /*****************************************************************************
5 * Creation date 12 Oct 2012
8 *****************************************************************************/
9 package test.splat.service;
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;
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.ProgressState;
23 import org.splat.dal.bo.som.ReaderRelation;
24 import org.splat.dal.bo.som.Scenario;
25 import org.splat.dal.bo.som.SimulationContext;
26 import org.splat.dal.bo.som.Study;
27 import org.splat.dal.bo.som.ValidationCycle;
28 import org.splat.dal.bo.som.ValidationCycleRelation;
29 import org.splat.dal.bo.som.ValidationStep;
30 import org.splat.dal.bo.som.Visibility;
31 import org.splat.dal.dao.kernel.UserDAO;
32 import org.splat.dal.dao.som.Database;
33 import org.splat.dal.dao.som.KnowledgeElementDAO;
34 import org.splat.dal.dao.som.KnowledgeElementTypeDAO;
35 import org.splat.dal.dao.som.ScenarioDAO;
36 import org.splat.dal.dao.som.StudyDAO;
37 import org.splat.dal.dao.som.ValidationCycleDAO;
38 import org.splat.exception.BusinessException;
39 import org.splat.log.AppLogger;
40 import org.splat.service.DocumentTypeService;
41 import org.splat.service.PublicationService;
42 import org.splat.service.SearchService;
43 import org.splat.service.SimulationContextService;
44 import org.splat.service.StepService;
45 import org.splat.service.StudyService;
46 import org.splat.service.dto.KnowledgeSearchFilterDTO;
47 import org.splat.service.dto.Proxy;
48 import org.splat.service.dto.StudySearchFilterDTO;
49 import org.splat.service.technical.ProjectSettingsService;
50 import org.springframework.beans.factory.annotation.Autowired;
51 import org.springframework.beans.factory.annotation.Qualifier;
52 import org.springframework.orm.hibernate3.HibernateTemplate;
53 import org.testng.Assert;
54 import org.testng.annotations.Test;
56 import test.splat.common.BaseTest;
57 import test.splat.util.TestEntitiesGenerator;
60 * Test class for StudyService.
62 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
65 public class TestSearchService extends BaseTest {
68 * Logger for the class.
70 private static final AppLogger LOG = AppLogger
71 .getLogger(TestSearchService.class);
74 * The StudyDAO. Later injected by Spring.
77 @Qualifier("studyDAO")
78 private transient StudyDAO _studyDAO;
81 * The ScenarioDAO. Later injected by Spring.
84 @Qualifier("scenarioDAO")
85 private transient ScenarioDAO _scenarioDAO;
88 * The KnowledgeElementDAO. Later injected by Spring.
91 @Qualifier("knowledgeElementDAO")
92 private transient KnowledgeElementDAO _knowledgeElementDAO;
95 * The KnowledgeElementTypeDAO. Later injected by Spring.
98 @Qualifier("knowledgeElementTypeDAO")
99 private transient KnowledgeElementTypeDAO _knowledgeElementTypeDAO;
102 * The PublicationService. Later injected by Spring.
105 @Qualifier("publicationService")
106 private transient PublicationService _publicationService;
109 * The StepService. Later injected by Spring.
112 @Qualifier("stepService")
113 private transient StepService _stepService;
116 * The ProjectSettingsService. Later injected by Spring.
119 @Qualifier("projectSettings")
120 private transient ProjectSettingsService _projectSettings;
123 * The DocumentTypeService. Later injected by Spring.
126 @Qualifier("documentTypeService")
127 private transient DocumentTypeService _documentTypeService;
130 * The StudyService. Later injected by Spring.
133 @Qualifier("studyService")
134 private transient StudyService _studyService;
137 * The SearchService. Later injected by Spring.
140 @Qualifier("searchService")
141 private transient SearchService _searchService;
144 * The UserDAO. Later injected by Spring.
147 @Qualifier("userDAO")
148 private transient UserDAO _userDAO;
151 * The ValidationCycleDAO. Later injected by Spring.
154 @Qualifier("validationCycleDAO")
155 private transient ValidationCycleDAO _validationCycleDAO;
158 * The SimulationContextService. Later injected by Spring.
161 @Qualifier("simulationContextService")
162 private transient SimulationContextService _simulationContextService;
165 * Test of searching a study.<BR>
166 * <B>Description :</B> <BR>
167 * <i>Create studies and try to find them according next document index.</i><BR>
168 * <B>Action : </B><BR>
171 * <li>Search study by state</li>
172 * <li>Search study by reference</li>
173 * <li>Search study by author</li>
174 * <li>Search study by actor</li>
175 * <li>Search study by title</li>
176 * <li>Search study by simulation contexts</li>
177 * <li>Search study by all criteria</li>
178 * <li>Search study by any criteria</li>
180 * </i> <B>Test data : </B><BR>
181 * <i>no input parameters</i><BR>
183 * <B>Outcome results:</B><BR>
186 * <li>A study must be found according to the given criteria<BR>
191 * @throws BusinessException
192 * if can't create test user or study
195 public void testSelectStudiesWhere() throws BusinessException {
196 LOG.debug(">>>>> BEGIN testSelectStudiesWhere()");
197 startNestedTransaction();
199 HibernateTemplate ht = getHibernateTemplate();
200 Calendar calend = java.util.Calendar.getInstance();
201 calend.roll(Calendar.DATE, false);
202 Date beforeCreation = calend.getTime();
204 Database.getInstance().reset();
205 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
206 // Load workflow customization
208 _projectSettings.configure("classpath:test/som.xml");
209 } catch (Exception e) {
210 Assert.fail("Can't load som.xml: ", e);
213 User goodUser = TestEntitiesGenerator.getTestUser("goodUser");
214 _userDAO.create(goodUser);
215 User otherUser = TestEntitiesGenerator.getTestUser("otherUser");
216 _userDAO.create(otherUser);
217 User thirdUser = TestEntitiesGenerator.getTestUser("thirdUser");
218 _userDAO.create(thirdUser);
219 User reader = TestEntitiesGenerator.getTestUser("readerUser");
220 _userDAO.create(reader);
222 // ============== STUDY 0: Private : goodUser : readerUser is reader : otherUser is contributor
223 // Create private study
224 Study aStudy = TestEntitiesGenerator.getTestStudy(goodUser);
225 aStudy.setTitle("0.This is private study");
226 aStudy.addRelation(new ReaderRelation(aStudy, reader));
227 aStudy.addRelation(new ContributorRelation(aStudy, otherUser));
228 Long privateStudyId = _studyDAO.create(aStudy);
230 // Add simulation context to the study 0
231 SimulationContext.Properties cprop = new SimulationContext.Properties();
232 cprop.setType(_simulationContextService.selectType("product"))
233 .setValue("Test Simulation Context: Product");
234 SimulationContext ctx = _studyService.addProjectContext(aStudy, cprop);
237 // ============== STUDY 1: Public : goodUser : otherUser is contributor
238 // Create public study with predefined title
239 aStudy = TestEntitiesGenerator.getTestStudy(goodUser);
240 aStudy.setVisibility(Visibility.PUBLIC);
241 aStudy.setTitle("2.This is a public study");
242 aStudy.addRelation(new ContributorRelation(aStudy, otherUser));
243 Long titleStudyId = _studyDAO.create(aStudy);
245 // Add simulation context to the study 1
246 cprop.setType(_simulationContextService.selectType("product"))
247 .setValue("Test Simulation Context: Product1");
248 _studyService.addProjectContext(aStudy, cprop);
251 // ============== STUDY 2: Public : otherUser
252 // Create public study with predefined reference
253 aStudy = TestEntitiesGenerator.getTestStudy(otherUser);
254 aStudy.setVisibility(Visibility.PUBLIC);
255 aStudy.setTitle("1.This is another public study");
256 aStudy.setReference("TEST_REF");
257 Long refStudyId = _studyDAO.create(aStudy);
259 // ============== STUDY 3: Private : inDraft : thirdUser : otherUser is reviewer
260 // Create private study of third user with otherUser as a reviewer
261 aStudy = TestEntitiesGenerator.getTestStudy(thirdUser);
262 aStudy.setTitle("3.This is a private study of third user");
263 aStudy.setProgressState(ProgressState.inDRAFT);
264 Long reviewStudyId = _studyDAO.create(aStudy);
266 // Create validation cycle for the last study
267 ValidationCycle.Properties vprop = new ValidationCycle.Properties();
268 DocumentType type = _documentTypeService.selectType("specification");
269 vprop.setDocumentType(type);
270 vprop.setActor(ValidationStep.REVIEW, otherUser);
271 ValidationCycle cycle = new ValidationCycle(aStudy, vprop);
272 _validationCycleDAO.create(cycle);
273 ValidationCycleRelation link = cycle.getContext();
274 aStudy.addRelation(link);
276 calend = java.util.Calendar.getInstance();
277 calend.roll(Calendar.DATE, true);
278 Date afterCreation = calend.getTime();
280 // ============== START OF TEST CALLS
281 // Search by study author
282 StudySearchFilterDTO filter = new StudySearchFilterDTO();
283 filter.setAuthor(String.valueOf(goodUser.getIndex()));
284 List<Proxy> res = _searchService.selectStudiesWhere(filter);
285 Assert.assertNotNull(res);
286 Assert.assertEquals(res.size(), 1);
287 Assert.assertEquals(res.get(0).getIndex(), titleStudyId);
289 // Search for logged in study contributor otherUser
290 filter = new StudySearchFilterDTO();
291 filter.setConnectedUserId(otherUser.getIndex());
292 res = _searchService.selectStudiesWhere(filter);
293 Assert.assertNotNull(res);
294 Assert.assertEquals(res.size(), 4);
295 Assert.assertEquals(res.get(0).getIndex(), privateStudyId); // OtherUser is contributor in this study
296 Assert.assertEquals(res.get(1).getIndex(), refStudyId); // Public study
297 Assert.assertEquals(res.get(2).getIndex(), titleStudyId); // Public study
298 Assert.assertEquals(res.get(3).getIndex(), reviewStudyId); // OtherUser is reviewer in this study
300 // Search for logged in study reader readerUser
301 filter = new StudySearchFilterDTO();
302 filter.setConnectedUserId(reader.getIndex());
303 res = _searchService.selectStudiesWhere(filter);
304 Assert.assertNotNull(res);
305 Assert.assertEquals(res.size(), 3);
306 Assert.assertEquals(res.get(0).getIndex(), privateStudyId); // readerUser is reader in this study
307 Assert.assertEquals(res.get(1).getIndex(), refStudyId); // Public study
308 Assert.assertEquals(res.get(2).getIndex(), titleStudyId); // Public study
310 // Search for logged in study contributor goodUser
311 filter = new StudySearchFilterDTO();
312 filter.setConnectedUserId(goodUser.getIndex());
313 res = _searchService.selectStudiesWhere(filter);
314 Assert.assertNotNull(res);
315 Assert.assertEquals(res.size(), 3);
316 Assert.assertEquals(res.get(0).getIndex(), privateStudyId); // goodUser is author
317 Assert.assertEquals(res.get(1).getIndex(), refStudyId); // Public study
318 Assert.assertEquals(res.get(2).getIndex(), titleStudyId); // Public study
320 // Search for logged in study contributor otherUser filtered by Draft state
321 filter = new StudySearchFilterDTO();
322 filter.setConnectedUserId(otherUser.getIndex());
323 filter.setState(ProgressState.inDRAFT);
324 res = _searchService.selectStudiesWhere(filter);
325 Assert.assertNotNull(res);
326 Assert.assertEquals(res.size(), 1);
327 Assert.assertEquals(res.get(0).getIndex(), reviewStudyId); // OtherUser is reviewer in this study
329 // Search by study title contents
330 filter = new StudySearchFilterDTO();
331 filter.setWords("study public");
332 res = _searchService.selectStudiesWhere(filter);
333 Assert.assertNotNull(res);
334 Assert.assertEquals(res.size(), 2);
335 Assert.assertEquals(res.get(0).getIndex(), refStudyId);
336 Assert.assertEquals(res.get(1).getIndex(), titleStudyId);
338 // Search by study reference
339 filter = new StudySearchFilterDTO();
340 filter.setReference("TEST_REF");
341 res = _searchService.selectStudiesWhere(filter);
342 Assert.assertNotNull(res);
343 Assert.assertEquals(res.size(), 1);
344 Assert.assertEquals(res.get(0).getIndex(), refStudyId);
346 // Search a study by simulation context
347 filter = new StudySearchFilterDTO();
348 filter.setConnectedUserId(goodUser.getIndex());
349 List<SimulationContext> contexts = new ArrayList<SimulationContext>();
351 filter.setSimContexts(contexts);
352 res = _searchService.selectStudiesWhere(filter);
353 Assert.assertNotNull(res);
354 Assert.assertEquals(res.size(), 1);
355 Assert.assertEquals(res.get(0).getIndex(), privateStudyId);
356 // Check simualtion contexts of the found study
357 for (Proxy proxy: res) {
358 aStudy = _studyService.selectStudy(proxy.getIndex());
359 Iterator<SimulationContext> ctxIter = aStudy
360 .SimulationContextIterator();
362 while (ctxIter.hasNext()) {
363 contexts.add(ctxIter.next());
365 Assert.assertEquals(contexts.size(), 1);
366 Assert.assertEquals(contexts.get(0), ctx);
370 filter = new StudySearchFilterDTO();
371 filter.setCreatedAfter(beforeCreation);
372 filter.setCreatedBefore(afterCreation);
373 res = _searchService.selectStudiesWhere(filter);
374 Assert.assertNotNull(res);
375 Assert.assertEquals(res.size(), 2);
376 Assert.assertEquals(res.get(0).getIndex(), refStudyId);
377 Assert.assertEquals(res.get(1).getIndex(), titleStudyId);
379 // Search for dates with no result
380 filter = new StudySearchFilterDTO();
381 filter.setCreatedAfter(afterCreation);
382 res = _searchService.selectStudiesWhere(filter);
383 Assert.assertNotNull(res);
384 Assert.assertEquals(res.size(), 0);
386 rollbackNestedTransaction();
387 LOG.debug(">>>>> END testSelectStudiesWhere()");
391 * Test of searching a study.<BR>
392 * <B>Description :</B> <BR>
393 * <i>Create studies and try to find them according next document index.</i><BR>
394 * <B>Action : </B><BR>
397 * <li>Search study by state</li>
398 * <li>Search study by reference</li>
399 * <li>Search study by author</li>
400 * <li>Search study by actor</li>
401 * <li>Search study by title</li>
402 * <li>Search study by simulation contexts</li>
403 * <li>Search study by all criteria</li>
404 * <li>Search study by any criteria</li>
406 * </i> <B>Test data : </B><BR>
407 * <i>no input parameters</i><BR>
409 * <B>Outcome results:</B><BR>
412 * <li>A study must be found according to the given criteria<BR>
417 * @throws BusinessException
418 * if can't create test user or study
421 public void testSelectKnowledgeElementsWhere() throws BusinessException {
422 LOG.debug(">>>>> BEGIN testSelectKnowledgeElementsWhere()");
423 startNestedTransaction();
425 HibernateTemplate ht = getHibernateTemplate();
427 Calendar calend = java.util.Calendar.getInstance();
428 calend.roll(Calendar.DATE, false);
429 Date beforeCreation = calend.getTime();
431 Database.getInstance().reset();
432 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
433 // Load workflow customization
435 _projectSettings.configure("classpath:test/som.xml");
436 } catch (Exception e) {
437 Assert.fail("Can't load som.xml: ", e);
440 User goodUser = TestEntitiesGenerator.getTestUser("goodUser");
441 _userDAO.create(goodUser);
442 User otherUser = TestEntitiesGenerator.getTestUser("otherUser");
443 _userDAO.create(otherUser);
444 User thirdUser = TestEntitiesGenerator.getTestUser("thirdUser");
445 _userDAO.create(thirdUser);
446 User reader = TestEntitiesGenerator.getTestUser("readerUser");
447 _userDAO.create(reader);
448 KnowledgeElementType ktype1 = new KnowledgeElementType("testKType1");
449 KnowledgeElementType ktype2 = new KnowledgeElementType("testKType2");
450 ktype2.setState(ProgressState.inWORK);
451 _knowledgeElementTypeDAO.create(ktype1);
452 _knowledgeElementTypeDAO.create(ktype2);
454 // ============== STUDY 0: Private : goodUser
455 // Create private study
456 Study aStudy = TestEntitiesGenerator.getTestStudy(goodUser);
457 aStudy.setTitle("0.This is private study");
458 Long privateStudyId = _studyDAO.create(aStudy);
460 // Add simulation context to the study 0
461 SimulationContext.Properties cprop = new SimulationContext.Properties();
462 cprop.setType(_simulationContextService.selectType("product"))
463 .setValue("Test Simulation Context: Product");
464 SimulationContext ctx = _studyService.addProjectContext(aStudy, cprop);
467 // Add a scenario to the study 0
468 Scenario scen = TestEntitiesGenerator.getTestScenario(aStudy);
469 _scenarioDAO.create(scen);
472 // Add knowledge elements to the scenario
473 KnowledgeElement kelm01 = TestEntitiesGenerator
474 .getTestKnowledgeElement(scen, ktype1, "TestKelm01 title");
475 KnowledgeElement kelm02 = TestEntitiesGenerator
476 .getTestKnowledgeElement(scen, ktype2, "TestKelm02 title");
477 _knowledgeElementDAO.create(kelm01);
478 _knowledgeElementDAO.create(kelm02);
481 // ============== STUDY 1: Public : goodUser : otherUser is contributor
482 // Create public study with predefined title
483 aStudy = TestEntitiesGenerator.getTestStudy(goodUser);
484 aStudy.setVisibility(Visibility.PUBLIC);
485 aStudy.setTitle("2.This is a public study");
486 aStudy.addRelation(new ContributorRelation(aStudy, otherUser));
487 Long titleStudyId = _studyDAO.create(aStudy);
489 // Add a scenario to the study 1
490 scen = TestEntitiesGenerator.getTestScenario(aStudy);
491 _scenarioDAO.create(scen);
494 // Add knowledge elements to the scenario
495 KnowledgeElement kelm11 = TestEntitiesGenerator
496 .getTestKnowledgeElement(scen, ktype1, "TestKelm11 title");
497 KnowledgeElement kelm12 = TestEntitiesGenerator
498 .getTestKnowledgeElement(scen, ktype2, "TestKelm12 title");
499 _knowledgeElementDAO.create(kelm11);
500 _knowledgeElementDAO.create(kelm12);
502 // Add simulation context to the study 1
503 cprop.setType(_simulationContextService.selectType("product"))
504 .setValue("Test Simulation Context: Product1");
505 _studyService.addProjectContext(aStudy, cprop);
508 // ============== STUDY 2: Public : otherUser
509 // Create public study with predefined reference
510 aStudy = TestEntitiesGenerator.getTestStudy(otherUser);
511 aStudy.setVisibility(Visibility.PUBLIC);
512 aStudy.setTitle("1.This is another public study");
513 aStudy.setReference("TEST_REF");
514 Long refStudyId = _studyDAO.create(aStudy);
515 // Add a scenario to the study 2
516 scen = TestEntitiesGenerator.getTestScenario(aStudy);
517 _scenarioDAO.create(scen);
520 // Add knowledge elements to the scenario
521 KnowledgeElement kelm21 = TestEntitiesGenerator
522 .getTestKnowledgeElement(scen, ktype1, "TestKelm21 title");
523 KnowledgeElement kelm22 = TestEntitiesGenerator
524 .getTestKnowledgeElement(scen, ktype2, "TestKelm22 title");
525 _knowledgeElementDAO.create(kelm21);
526 _knowledgeElementDAO.create(kelm22);
529 // ============== STUDY 3: Private : thirdUser : otherUser is reviewer
530 // Create private study of third user with otherUser as a reviewer
531 aStudy = TestEntitiesGenerator.getTestStudy(thirdUser);
532 aStudy.setTitle("3.This is a private study of third user");
533 Long reviewStudyId = _studyDAO.create(aStudy);
535 // Create validation cycle for the last study
536 ValidationCycle.Properties vprop = new ValidationCycle.Properties();
537 DocumentType type = _documentTypeService.selectType("specification");
538 vprop.setDocumentType(type);
539 vprop.setActor(ValidationStep.REVIEW, otherUser);
540 ValidationCycle cycle = new ValidationCycle(aStudy, vprop);
541 _validationCycleDAO.create(cycle);
542 ValidationCycleRelation link = cycle.getContext();
543 aStudy.addRelation(link);
545 // Add a scenario to the study 3
546 scen = TestEntitiesGenerator.getTestScenario(aStudy);
547 _scenarioDAO.create(scen);
550 // Add knowledge elements to the scenario
551 KnowledgeElement kelm31 = TestEntitiesGenerator
552 .getTestKnowledgeElement(scen, ktype1, "TestKelm31 title");
553 KnowledgeElement kelm32 = TestEntitiesGenerator
554 .getTestKnowledgeElement(scen, ktype2, "TestKelm32 title");
555 _knowledgeElementDAO.create(kelm31);
556 _knowledgeElementDAO.create(kelm32);
559 // ============== STUDY 4: Private : thirdUser : otherUser is contributor : readerUser is reader
560 // Create private study of third user with otherUser as a reviewer
561 aStudy = TestEntitiesGenerator.getTestStudy(thirdUser);
562 aStudy.setTitle("4.This is a private study of third user");
563 aStudy.addRelation(new ContributorRelation(aStudy, otherUser));
564 aStudy.addRelation(new ReaderRelation(aStudy, reader));
565 _studyDAO.create(aStudy);
568 // Add a scenario to the study 4
569 scen = TestEntitiesGenerator.getTestScenario(aStudy);
570 _scenarioDAO.create(scen);
573 // Add knowledge elements to the scenario
574 KnowledgeElement kelm41 = TestEntitiesGenerator
575 .getTestKnowledgeElement(scen, ktype1, "TestKelm41 title");
576 KnowledgeElement kelm42 = TestEntitiesGenerator
577 .getTestKnowledgeElement(scen, ktype2, "TestKelm42 title");
578 _knowledgeElementDAO.create(kelm41);
579 _knowledgeElementDAO.create(kelm42);
582 calend = java.util.Calendar.getInstance();
583 calend.roll(Calendar.DATE, true);
584 Date afterCreation = calend.getTime();
586 // ============== START OF TEST CALLS
587 // Search by author goodUser as not logged in user
588 KnowledgeSearchFilterDTO filter = new KnowledgeSearchFilterDTO();
589 filter.setAuthor(String.valueOf(goodUser.getIndex()));
590 List<Proxy> res = _searchService.selectKnowledgeElementsWhere(filter);
591 Assert.assertNotNull(res);
592 Assert.assertEquals(res.size(), 2);
593 Assert.assertEquals(res.get(0).getTitle(), kelm11.getTitle());
594 Assert.assertEquals(res.get(1).getTitle(), kelm12.getTitle());
596 // Search by author goodUser as not logged in user and filter by state
597 filter = new KnowledgeSearchFilterDTO();
598 filter.setAuthor(String.valueOf(goodUser.getIndex()));
599 filter.setState(ProgressState.inWORK);
600 res = _searchService.selectKnowledgeElementsWhere(filter);
601 Assert.assertNotNull(res);
602 Assert.assertEquals(res.size(), 1);
603 Assert.assertEquals(res.get(0).getTitle(), kelm12.getTitle());
605 // Search for other logged in study contributor (what is visible for otherUser by default)
606 filter = new KnowledgeSearchFilterDTO();
607 filter.setConnectedUserId(otherUser.getIndex());
608 res = _searchService.selectKnowledgeElementsWhere(filter);
609 Assert.assertNotNull(res);
610 Assert.assertEquals(res.size(), 8);
611 Assert.assertEquals(res.get(0).getTitle(), kelm11.getTitle());
612 Assert.assertEquals(res.get(1).getTitle(), kelm12.getTitle());
613 Assert.assertEquals(res.get(2).getTitle(), kelm21.getTitle());
614 Assert.assertEquals(res.get(3).getTitle(), kelm22.getTitle());
615 Assert.assertEquals(res.get(4).getTitle(), kelm31.getTitle());
616 Assert.assertEquals(res.get(5).getTitle(), kelm32.getTitle());
617 Assert.assertEquals(res.get(6).getTitle(), kelm41.getTitle());
618 Assert.assertEquals(res.get(7).getTitle(), kelm42.getTitle());
620 // Search for logged in goodUser
621 filter = new KnowledgeSearchFilterDTO();
622 filter.setConnectedUserId(goodUser.getIndex());
623 res = _searchService.selectKnowledgeElementsWhere(filter);
624 Assert.assertNotNull(res);
625 Assert.assertEquals(res.size(), 6);
626 Assert.assertEquals(res.get(0).getTitle(), kelm01.getTitle());
627 Assert.assertEquals(res.get(1).getTitle(), kelm02.getTitle());
628 Assert.assertEquals(res.get(2).getTitle(), kelm11.getTitle());
629 Assert.assertEquals(res.get(3).getTitle(), kelm12.getTitle());
630 Assert.assertEquals(res.get(4).getTitle(), kelm21.getTitle());
631 Assert.assertEquals(res.get(5).getTitle(), kelm22.getTitle());
633 // Search for logged in study contributor otherUser
634 filter = new KnowledgeSearchFilterDTO();
635 filter.setConnectedUserId(otherUser.getIndex());
636 res = _searchService.selectKnowledgeElementsWhere(filter);
637 Assert.assertNotNull(res);
638 Assert.assertEquals(res.size(), 8);
639 Assert.assertEquals(res.get(0).getTitle(), kelm11.getTitle());
640 Assert.assertEquals(res.get(1).getTitle(), kelm12.getTitle());
641 Assert.assertEquals(res.get(2).getTitle(), kelm21.getTitle());
642 Assert.assertEquals(res.get(3).getTitle(), kelm22.getTitle());
643 Assert.assertEquals(res.get(4).getTitle(), kelm31.getTitle());
644 Assert.assertEquals(res.get(5).getTitle(), kelm32.getTitle());
645 Assert.assertEquals(res.get(6).getTitle(), kelm41.getTitle());
646 Assert.assertEquals(res.get(7).getTitle(), kelm42.getTitle());
648 // Search for logged in study reader readerUser
649 filter = new KnowledgeSearchFilterDTO();
650 filter.setConnectedUserId(reader.getIndex());
651 res = _searchService.selectKnowledgeElementsWhere(filter);
652 Assert.assertNotNull(res);
653 Assert.assertEquals(res.size(), 6);
654 Assert.assertEquals(res.get(0).getTitle(), kelm11.getTitle());
655 Assert.assertEquals(res.get(1).getTitle(), kelm12.getTitle());
656 Assert.assertEquals(res.get(2).getTitle(), kelm21.getTitle());
657 Assert.assertEquals(res.get(3).getTitle(), kelm22.getTitle());
658 Assert.assertEquals(res.get(4).getTitle(), kelm41.getTitle());
659 Assert.assertEquals(res.get(5).getTitle(), kelm42.getTitle());
661 // Search by title contents
662 filter = new KnowledgeSearchFilterDTO();
663 filter.setWords("TestKelm22");
664 res = _searchService.selectKnowledgeElementsWhere(filter);
665 Assert.assertNotNull(res);
666 Assert.assertEquals(res.size(), 1);
667 Assert.assertEquals(res.get(0).getTitle(), kelm22.getTitle());
669 // Search by reference
670 filter = new KnowledgeSearchFilterDTO();
671 filter.setReference(kelm22.getReference());
672 res = _searchService.selectKnowledgeElementsWhere(filter);
673 Assert.assertNotNull(res);
674 Assert.assertEquals(res.size(), 1);
675 Assert.assertEquals(res.get(0).getTitle(), kelm22.getTitle());
677 // Search by simulation context
678 filter = new KnowledgeSearchFilterDTO();
679 filter.setConnectedUserId(goodUser.getIndex());
680 List<SimulationContext> contexts = new ArrayList<SimulationContext>();
682 filter.setSimContexts(contexts);
683 res = _searchService.selectKnowledgeElementsWhere(filter);
684 Assert.assertNotNull(res);
685 Assert.assertEquals(res.size(), 2);
686 Assert.assertEquals(res.get(0).getTitle(), kelm01.getTitle());
687 Assert.assertEquals(res.get(1).getTitle(), kelm02.getTitle());
688 // Check simualtion contexts of the found study
689 for (Proxy proxy : res) {
690 KnowledgeElement kelm = _knowledgeElementDAO.get(proxy.getIndex());
691 aStudy = _studyService.selectStudy(kelm.getOwnerScenario()
692 .getOwnerStudy().getIndex());
693 Iterator<SimulationContext> ctxIter = aStudy
694 .SimulationContextIterator();
696 while (ctxIter.hasNext()) {
697 contexts.add(ctxIter.next());
699 Assert.assertEquals(contexts.size(), 1);
700 Assert.assertEquals(contexts.get(0), ctx);
704 filter = new KnowledgeSearchFilterDTO();
705 filter.setCreatedAfter(beforeCreation);
706 filter.setCreatedBefore(afterCreation);
707 res = _searchService.selectKnowledgeElementsWhere(filter);
708 Assert.assertNotNull(res);
709 Assert.assertEquals(res.size(), 4);
710 Assert.assertEquals(res.get(0).getTitle(), kelm11.getTitle());
711 Assert.assertEquals(res.get(1).getTitle(), kelm12.getTitle());
712 Assert.assertEquals(res.get(2).getTitle(), kelm21.getTitle());
713 Assert.assertEquals(res.get(3).getTitle(), kelm22.getTitle());
715 // Search for dates with no result
716 filter = new KnowledgeSearchFilterDTO();
717 filter.setCreatedAfter(afterCreation);
718 res = _searchService.selectKnowledgeElementsWhere(filter);
719 Assert.assertNotNull(res);
720 Assert.assertEquals(res.size(), 0);
722 rollbackNestedTransaction();
723 LOG.debug(">>>>> END testSelectKnowledgeElementsWhere()");