1 /*****************************************************************************
5 * Creation date 12 Oct 2012
8 *****************************************************************************/
9 package test.splat.dao;
11 import java.io.FileNotFoundException;
12 import java.io.IOException;
13 import java.sql.SQLException;
14 import java.util.Date;
15 import java.util.HashMap;
16 import java.util.List;
19 import org.hibernate.criterion.Order;
20 import org.hibernate.criterion.Restrictions;
21 import org.splat.dal.bo.kernel.User;
22 import org.splat.dal.bo.som.Document;
23 import org.splat.dal.bo.som.DocumentType;
24 import org.splat.dal.bo.som.ProgressState;
25 import org.splat.dal.bo.som.ProjectElement;
26 import org.splat.dal.bo.som.Publication;
27 import org.splat.dal.bo.som.Scenario;
28 import org.splat.dal.bo.som.Study;
29 import org.splat.dal.bo.som.Document.Properties;
30 import org.splat.dal.dao.som.Database;
31 import org.splat.dal.dao.som.DocumentDAO;
32 import org.splat.dal.dao.som.StudyDAO;
33 import org.splat.kernel.InvalidPropertyException;
34 import org.splat.kernel.MissedPropertyException;
35 import org.splat.kernel.MultiplyDefinedException;
36 import org.splat.log.AppLogger;
37 import org.splat.service.DocumentTypeService;
38 import org.splat.service.PublicationService;
39 import org.splat.service.StepService;
40 import org.splat.service.StudyService;
41 import org.splat.service.technical.ProjectSettingsService;
42 import org.splat.service.technical.ProjectSettingsService.Step;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.beans.factory.annotation.Qualifier;
45 import org.springframework.orm.hibernate3.HibernateTemplate;
46 import org.testng.Assert;
47 import org.testng.annotations.Test;
49 import test.splat.common.BaseTest;
52 * Test class for StudyDAO.
54 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
57 public class TestStudyDAO extends BaseTest {
60 * Logger for the class.
62 private static final AppLogger LOG = AppLogger
63 .getLogger(TestStudyDAO.class);
66 * The tested StudyDAO. Later injected by Spring.
69 @Qualifier("studyDAO")
70 private transient StudyDAO _studyDAO;
73 * The PublicationService. Later injected by Spring.
76 @Qualifier("publicationService")
77 private transient PublicationService _publicationService;
80 * The StepService. Later injected by Spring.
83 @Qualifier("stepService")
84 private transient StepService _stepService;
87 * The ProjectSettingsService. Later injected by Spring.
90 @Qualifier("projectSettings")
91 private transient ProjectSettingsService _projectSettings;
94 * The DocumentTypeService. Later injected by Spring.
97 @Qualifier("documentTypeService")
98 private transient DocumentTypeService _documentTypeService;
101 * The DocumentDAO. Later injected by Spring.
104 @Qualifier("documentDAO")
105 private transient DocumentDAO _documentDAO;
108 * The StudyService. Later injected by Spring.
111 @Qualifier("studyService")
112 private transient StudyService _studyService;
115 * Test creation of a study.<BR>
116 * <B>Description :</B> <BR>
117 * <i>Create a study.</i><BR>
118 * <B>Action : </B><BR>
119 * <i>1. call DAO's create method for a good transient study.</i><BR>
120 * <i>2. call DAO's create method for a study with non-zero id.</i><BR>
121 * <B>Test data : </B><BR>
122 * <i>no input parameters</i><BR>
123 * <i>no input parameters</i><BR>
125 * <B>Outcome results:</B><BR>
128 * <li>Object is created in the database successfully<BR>
130 * <li>Another new object is created with new generated id<BR>
135 * @throws InvalidPropertyException
136 * if an invalid property is used when creating objects
137 * @throws MultiplyDefinedException
138 * when trying to create an object with already existing id
139 * @throws MissedPropertyException
140 * if a mandatory property is not defined for an object to be created
141 * @throws SQLException
142 * @throws IOException
146 public void testCreate() throws InvalidPropertyException,
147 MissedPropertyException, MultiplyDefinedException, IOException,
149 LOG.debug(">>>>> BEGIN testCreate()");
150 startNestedTransaction();
152 Study aStudy = createStudy();
153 // Call DAO's create method for a good transient study.
154 long id = _studyDAO.create(aStudy);
155 Assert.assertNotNull(id,
156 "Create method returns null instead of a new id.");
157 Assert.assertTrue(id > 0, "The new id is not a positive number.");
159 LOG.debug("Created id: " + id);
161 Study aStudyFound = getHibernateTemplate().get(Study.class, id);
164 // Call DAO's create method for a study with non-zero id.
165 Study aBadStudy = new Study((new Study.Properties()).setTitle(
166 "2.Bad test study").setManager(aStudy.getAuthor()).setDate(
167 aStudy.getDate()).setReference("sid"));
168 aBadStudy.setIndex(aStudyFound.getIndex());
171 List<Study> res = _studyDAO.getAll(Order.asc("rid"));
173 Assert.assertNotNull(res,
174 "Method getFilteredList must not return null.");
175 Assert.assertEquals(res.size(), 1, "Number of found objects is wrong.");
176 Assert.assertEquals(aBadStudy.getIndex(), id, "Id must be equal.");
178 Assert.assertNotNull(aBadStudy.getIndex(),
179 "Create method returns null instead of a new id.");
180 Assert.assertTrue(aBadStudy.getIndex() > 0,
181 "The new id is not a positive number.");
183 long id2 = _studyDAO.create(aBadStudy);
187 LOG.debug("Created second id: " + id2);
189 res = _studyDAO.getAll();
192 Assert.assertNotNull(res,
193 "Method getFilteredList must not return null.");
194 Assert.assertNotNull(res.get(0),
195 "Method getFilteredList must not return null.");
196 Assert.assertNotNull(res.get(1),
197 "Method getFilteredList must not return null.");
198 Assert.assertEquals(res.size(), 2, "Number of found objects is wrong.");
199 Assert.assertEquals(res.get(0).getIndex(), id,
200 "Sorting is incorrect or id of the first element is wrong.");
201 Assert.assertEquals(res.get(1).getIndex(), id2,
202 "Sorting is incorrect or id of the second element is wrong.");
203 id = res.get(0).getIndex();
204 id2 = res.get(1).getIndex();
205 Assert.assertFalse(id == id2, "Ids of objects must not be duplicated.");
207 rollbackNestedTransaction();
208 LOG.debug(">>>>> END testCreate()");
212 * Test of getting a study.<BR>
213 * <B>Description :</B> <BR>
214 * <i>Create a study and try to get it from the database.</i><BR>
215 * <B>Action : </B><BR>
216 * <i>1. call DAO's read method for an existing id.</i><BR>
217 * <i>2. call DAO's read method for a not existing id.</i><BR>
218 * <B>Test data : </B><BR>
219 * <i>no input parameters</i><BR>
220 * <i>no input parameters</i><BR>
222 * <B>Outcome results:</B><BR>
225 * <li>Object is found in the database successfully<BR>
227 * <li>Result of search is null<BR>
232 * @throws InvalidPropertyException
233 * if an invalid property is used when creating objects
234 * @throws MultiplyDefinedException
235 * when trying to create an object with already existing id
236 * @throws MissedPropertyException
237 * if a mandatory property is not defined for an object to be created
238 * @throws SQLException
239 * @throws IOException
243 public void testGet() throws InvalidPropertyException,
244 MissedPropertyException, MultiplyDefinedException, IOException,
246 LOG.debug(">>>>> BEGIN testGet()");
247 startNestedTransaction();
249 Study aStudy = createStudy();
250 // Call DAO's create method for a good transient study.
251 Long id = aStudy.getIndex();
252 Assert.assertNotNull(id,
253 "Create method returns null instead of a new id.");
254 Assert.assertTrue(id > 0, "The new id is not a positive number.");
256 // Call DAO's get method for an existing id.
258 getHibernateTemplate().evict(aStudy);
259 getHibernateTemplate().clear();
260 Study aStudyFound = _studyDAO.get(id);
262 Assert.assertNotNull(aStudyFound);
264 // Call DAO's get method for a not existing id.
265 aStudyFound = _studyDAO.get(-1L);
266 getHibernateTemplate().flush();
267 Assert.assertNull(aStudyFound,
268 "A found object with not existing id must be null.");
270 aStudyFound = _studyDAO.get(0L);
271 getHibernateTemplate().flush();
272 Assert.assertNull(aStudyFound,
273 "A found object with not existing id must be null.");
275 aStudyFound = _studyDAO.get(id + 1);
276 getHibernateTemplate().flush();
277 Assert.assertNull(aStudyFound,
278 "A found object with not existing id must be null.");
280 rollbackNestedTransaction();
281 LOG.debug(">>>>> END testGet()");
285 * Test of updating a study.<BR>
286 * <B>Description :</B> <BR>
287 * <i>Create a study and try to update it with another data.</i><BR>
288 * <B>Action : </B><BR>
289 * <i>1. call DAO's update method for an existing id.</i><BR>
290 * <i>2. call DAO's update method for a not existing id.</i><BR>
291 * <i>3. call DAO's update method for wrong data.</i><BR>
292 * <B>Test data : </B><BR>
293 * <i>no input parameters</i><BR>
294 * <i>no input parameters</i><BR>
295 * <i>no input parameters</i><BR>
297 * <B>Outcome results:</B><BR>
300 * <li>Object is update in the database successfully<BR>
302 * <li>Exception is thrown<BR>
304 * <li>Exception is thrown<BR>
309 * @throws InvalidPropertyException
310 * if an invalid property is used when creating objects
311 * @throws MultiplyDefinedException
312 * when trying to create an object with already existing id
313 * @throws MissedPropertyException
314 * if a mandatory property is not defined for an object to be created
315 * @throws SQLException
316 * @throws IOException
320 public void testUpdate() throws InvalidPropertyException,
321 MissedPropertyException, MultiplyDefinedException, IOException,
323 LOG.debug(">>>>> BEGIN testUpdate()");
324 startNestedTransaction();
326 Study aStudy = createStudy();
327 // Call DAO's create method for a good transient study.
328 Long id = _studyDAO.create(aStudy);
329 Assert.assertNotNull(id,
330 "Create method returns null instead of a new id.");
331 Assert.assertTrue(id > 0, "The new id is not a positive number.");
333 // Call DAO's update method for an existing id.
334 Assert.assertTrue(aStudy.getProgressState() != ProgressState.APPROVED,
335 "The initial state of the study should not be APPROVED.");
336 aStudy.setProgressState(ProgressState.APPROVED);
337 aStudy.setTitle(aStudy.getTitle() + " updated");
338 _studyDAO.update(aStudy);
340 // Check that the object has been updated.
341 Study aStudyFound = _studyDAO.get(id);
343 // Call DAO's create method for a study with non-zero id.
344 Study aBadStudy = new Study((new Study.Properties()).setTitle(
345 "Test study").setManager(aStudy.getAuthor()).setDate(
347 // aBadKelm.setIndex(aKelmFound.getIndex());
349 _studyDAO.update(aBadStudy);
350 getHibernateTemplate().flush();
351 Assert.fail("Update with not existing id must be failed.");
352 } catch (Exception e) {
353 LOG.debug("Expected exception is thrown: "
354 + e.getClass().getSimpleName() + ": " + e.getMessage());
356 // Call update with bad data (null title).
357 aBadStudy.setIndex(aStudyFound.getIndex());
358 aBadStudy.setTitle(null);
360 _studyDAO.update(aBadStudy);
361 getHibernateTemplate().flush();
362 Assert.fail("Update with null title must be failed.");
363 } catch (Exception e) {
364 LOG.debug("Expected exception is thrown: "
365 + e.getClass().getSimpleName() + ": " + e.getMessage());
367 // Call update with bad data (null state).
368 aBadStudy.setTitle(aStudyFound.getTitle());
369 aBadStudy.setProgressState(null);
371 _studyDAO.update(aBadStudy);
372 getHibernateTemplate().flush();
373 Assert.fail("Update with null state must be failed.");
374 } catch (Exception e) {
375 LOG.debug("Expected exception is thrown: "
376 + e.getClass().getSimpleName() + ": " + e.getMessage());
379 rollbackNestedTransaction();
380 LOG.debug(">>>>> END testUpdate()");
384 * Test of deleting a study.<BR>
385 * <B>Description :</B> <BR>
386 * <i>Create a study and try to delete it.</i><BR>
387 * <B>Action : </B><BR>
388 * <i>1. call DAO's delete method for an existing id.</i><BR>
389 * <i>2. call DAO's delete method for a not existing id.</i><BR>
390 * <B>Test data : </B><BR>
391 * <i>no input parameters</i><BR>
392 * <i>no input parameters</i><BR>
394 * <B>Outcome results:</B><BR>
397 * <li>Object is found in the database successfully<BR>
399 * <li>Exception is thrown<BR>
404 * @throws InvalidPropertyException
405 * if an invalid property is used when creating objects
406 * @throws MultiplyDefinedException
407 * when trying to create an object with already existing id
408 * @throws MissedPropertyException
409 * if a mandatory property is not defined for an object to be created
410 * @throws SQLException
411 * @throws IOException
415 public void testDelete() throws InvalidPropertyException,
416 MissedPropertyException, MultiplyDefinedException, IOException,
418 LOG.debug(">>>>> BEGIN testDelete()");
419 startNestedTransaction();
421 Study aStudy = createStudy();
422 // Call DAO's create method for a good transient study.
423 Long id = aStudy.getIndex();// _studyDAO.create(aStudy);
424 Assert.assertNotNull(id,
425 "Create method returns null instead of a new id.");
426 Assert.assertTrue(id > 0, "The new id is not a positive number.");
429 // Call DAO's delete method for an existing id.
430 _studyDAO.merge(aStudy);
431 _studyDAO.delete(aStudy);
433 // Check that the object has been deleted.
434 Study aStudyFound = _studyDAO.get(id);
436 Assert.assertNull(aStudyFound, "Deleted object must not be found.");
437 // Call DAO's delete method for a not existing id.
438 getHibernateTemplate().flush();
440 rollbackNestedTransaction();
441 LOG.debug(">>>>> END testDelete()");
445 * Test of getting a filtered list of studys.<BR>
446 * <B>Description :</B> <BR>
447 * <i>Create two studys and try to get them from the database.</i><BR>
448 * <B>Action : </B><BR>
449 * <i>1. Find objects with the given value of the property of a child object.</i><BR>
450 * <i>2. Get ordered list of objects with the given value of the property of a child object.</i><BR>
451 * <B>Test data : </B><BR>
452 * <i>no input parameters</i><BR>
453 * <i>no input parameters</i><BR>
455 * <B>Outcome results:</B><BR>
458 * <li>Objects are found in the database successfully<BR>
460 * <li>Objects are found in the database and sorted in the right order<BR>
465 * @throws InvalidPropertyException
466 * if an invalid property is used when creating objects
467 * @throws MultiplyDefinedException
468 * when trying to create an object with already existing id
469 * @throws MissedPropertyException
470 * if a mandatory property is not defined for an object to be created
471 * @throws SQLException
472 * @throws IOException
476 public void testGetFilteredList() throws InvalidPropertyException,
477 MissedPropertyException, MultiplyDefinedException, IOException,
479 LOG.debug(">>>>> BEGIN testGetFilteredList()");
480 startNestedTransaction();
482 // Create several objects in the database
483 Study aStudy = createStudy();
484 long id = _studyDAO.create(aStudy);
485 Study aNewStudy = new Study((new Study.Properties()).setTitle(
486 "TST_Study N2").setManager(aStudy.getAuthor()).setReference(
487 "sid").setDate(aStudy.getDate()));
488 long id2 = _studyDAO.create(aNewStudy);
492 // ////////////////////////////////////////////////////
493 // Call DAO's getFilteredList method without order parameter.
494 List<Study> res = _studyDAO.getFilteredList("manager", Restrictions.eq(
495 "username", aStudy.getAuthor().getUsername()));
497 Assert.assertNotNull(res,
498 "Method getFilteredList must not return null.");
499 Assert.assertEquals(res.size(), 2, "Number of found objects is wrong.");
501 // ////////////////////////////////////////////////////
502 // Call DAO's getFilteredList method with defined order parameter.
503 res = _studyDAO.getFilteredList("manager", Restrictions.eq("username",
504 aStudy.getAuthor().getUsername()), Order.asc("title"));
506 Assert.assertNotNull(res,
507 "Method getFilteredList must not return null.");
508 Assert.assertEquals(res.size(), 2, "Number of found objects is wrong.");
509 Assert.assertEquals(res.get(0).getIndex(), id,
510 "Sorting of results is not correct.");
511 Assert.assertEquals(res.get(1).getIndex(), id2,
512 "Sorting of results is not correct.");
514 rollbackNestedTransaction();
515 LOG.debug(">>>>> END testGetFilteredList()");
519 * Create a persistent scenario for tests.
521 * @return a persistent scenario
522 * @throws InvalidPropertyException
523 * if an invalid property is used when creating objects
524 * @throws MultiplyDefinedException
525 * when trying to create an object with already existing id
526 * @throws MissedPropertyException
527 * if a mandatory property is not defined for an object to be created
528 * @throws IOException
529 * if document creation is failed
530 * @throws SQLException
531 * if project settings loading is failed
533 private Study createStudy() throws InvalidPropertyException,
534 MissedPropertyException, MultiplyDefinedException, IOException,
536 // Create a scenario for tests
537 HibernateTemplate ht = getHibernateTemplate();
539 Database.getInstance().reset();
540 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
541 // Load workflow customization
543 _projectSettings.configure("classpath:test/som.xml");
544 } catch (FileNotFoundException e) {
545 Assert.fail("Can't find som.xml: ", e);
547 List<Step> steps = _projectSettings.getAllSteps();
548 Assert.assertTrue(steps.size() > 0, "No steps are created.");
550 // Create a test user
551 User.Properties uprop = new User.Properties();
552 uprop.setUsername("TST_Username").setName("TST_SimanUnitTestsUser")
553 .setFirstName("TST_FirstName").setDisplayName("TST_test.user")
554 .addRole("TST_user").setMailAddress(
555 "noreply@salome-platform.org");
556 uprop.disableCheck();
557 User anAuthor = new User(uprop);
558 ht.saveOrUpdate(anAuthor);
560 // Create a test study
561 Study.Properties stprops = new Study.Properties().setReference(
562 "TST_SID_01").setTitle("TST_Study").setManager(anAuthor);
563 Study aStudy = new Study(stprops);
564 ht.saveOrUpdate(aStudy);
566 // Create a test scenario
567 Scenario.Properties sprops = new Scenario.Properties().setTitle(
568 "TST_Scenario").setManager(anAuthor).setOwnerStudy(aStudy);
569 Scenario aScenario = new Scenario(sprops);
570 aStudy.getScenariiList().add(aScenario);
571 ht.saveOrUpdate(anAuthor);
572 ht.saveOrUpdate(aStudy);
573 ht.saveOrUpdate(aScenario);
575 // Create documents for each scenario step
576 Document.Properties dprop = new Document.Properties().setAuthor(
577 anAuthor).setDate(new Date());
579 Publication usedPub = null;
580 Map<Long, Long> usedMap = new HashMap<Long, Long>();
581 for (int stepNum = 1; stepNum <= steps.size(); stepNum++) {
582 Step step = _projectSettings.getStep(stepNum);
583 LOG.debug("Create scenario step: " + stepNum);
584 ProjectElement projElem;
586 if (step.appliesTo(Study.class)) {
589 projElem = aScenario;
591 org.splat.som.Step aScStep = new org.splat.som.Step(step, projElem);
592 List<DocumentType> dtypes = _documentTypeService
593 .selectTypesOf(step);
594 if (dtypes.size() > 0) {
595 DocumentType dtype = dtypes.get(0);
596 // Create a document published in the scenario
597 // document<i>: document type[0] - first type used on the step
598 // <source-file>.brep
599 // <attached-file>.med
601 dprop.setName("document" + stepNum).setType(dtype);
602 if (step.getNumber() > 3) {
603 dprop.setFormat("med");
605 dprop.setFormat("py");
607 Publication pub = createDoc(projElem, aScStep, dprop, "med",
609 if (usedPub != null) {
610 pub.addDependency(usedPub);
611 LOG.debug("Add dependency: " + pub.value().getTitle()
612 + " from " + usedPub.value().getTitle());
613 ht.saveOrUpdate(pub.value());
616 usedMap.put(pub.getIndex(), usedPub.getIndex());
620 if (dtypes.size() <= 0) {
621 LOG.debug("No document types are found for scenario step " + i);
625 // Check that the scenario and its documents have been created correctly.
627 Assert.assertNotNull(ht.find("from Document"),
628 "No documents in the database.");
629 Assert.assertTrue(ht.find("from Document").size() > 0,
630 "No documents in the database.");
632 Assert.assertNotNull(ht.find("from Publication where owner="
633 + aScenario.getIndex()), "No publications in the database.");
635 ht.find("from Publication where owner=" + aScenario.getIndex())
636 .size() > 0, "No publications in the database.");
638 for (Publication p : (List<Publication>) ht
639 .find("from Publication where owner=" + aScenario.getIndex())) {
640 LOG.debug("Publication found: [id=" + p.getIndex() + ", owner="
641 + p.getOwner().getIndex() + ", doc=" + p.value().getIndex()
643 Assert.assertEquals(p.getOwner().getIndex(), aScenario.getIndex(),
644 "The publication was not attached to the scenario.");
647 // Remove the scenario from the current hibernate session.
649 // Check that the scenario is created in the database.
650 Scenario aScen = ht.load(Scenario.class, aScenario.getIndex());
651 Assert.assertNotNull(aScen, "Scenario was not saved in the database.");
652 Assert.assertTrue(aScen.getDocums().size() > 0,
653 "No publications in the scenario.");
655 Assert.assertTrue(i > 0,
656 "More then one document must be in the database");
658 // Check created uses relations
660 .assertTrue(usedMap.size() > 0,
661 "Uses relations must be created.");
662 boolean foundAny = false;
663 for (Long usingId : usedMap.keySet()) {
664 for (Publication pub : aScen.getDocums()) {
665 if (pub.getIndex() == usingId) {
666 boolean found = false;
667 for (Publication used : aScen.getDocums()) {
668 found = (used.getIndex() == usedMap.get(usingId));
674 for (Publication used : aStudy.getDocums()) {
675 found = (used.getIndex() == usedMap.get(usingId));
681 Assert.assertTrue(found,
682 "Uses relation was not created in the database.");
683 foundAny = foundAny || found;
687 Assert.assertTrue(foundAny,
688 "No Uses relation was created in the database.");
690 return aScenario.getOwnerStudy();
694 * Create a document published in the scenario. <BR>
696 * document type - type used on the step <BR>
697 * <source-file>.brep <BR>
698 * <attached-file>.med
701 * the scenario to add the document to
703 * scenario step where the document to be published
705 * document properties
706 * @param attachedFileExt
707 * extension of the secon attached (exported) file
709 * outdated document flag
710 * @return the publication of the created document
711 * @throws IOException
712 * @throws MultiplyDefinedException
713 * @throws InvalidPropertyException
714 * @throws MissedPropertyException
716 private Publication createDoc(final ProjectElement aScenario,
717 final org.splat.som.Step aScStep, final Properties dprop,
718 final String attachedFileExt, final boolean isOutdated)
719 throws MissedPropertyException, InvalidPropertyException,
720 MultiplyDefinedException, IOException {
721 // Create a document published in the scenario
722 // document<i>: document type - type used on the step
723 // <source-file>.brep
724 // <attached-file>.med
725 Publication pub = _stepService.createDocument(aScStep, dprop);
726 Assert.assertNotNull(pub.getOwner(),
727 "The publication must be attached to the scenario.");
728 Assert.assertEquals(pub.getOwner().getIndex(), aScenario.getIndex(),
729 "The publication was not attached to the scenario.");
735 HibernateTemplate ht = getHibernateTemplate();
736 ht.saveOrUpdate(pub);
739 ht.save(pub.value());
741 ht.saveOrUpdate(_publicationService.attach(pub, attachedFileExt));
747 * Test of getting a study.<BR>
748 * <B>Description :</B> <BR>
749 * <i>Create a study and try to get it from the database.</i><BR>
750 * <B>Action : </B><BR>
751 * <i>1. call DAO's read method for an existing id.</i><BR>
752 * <i>2. call DAO's read method for a not existing id.</i><BR>
753 * <B>Test data : </B><BR>
754 * <i>no input parameters</i><BR>
755 * <i>no input parameters</i><BR>
757 * <B>Outcome results:</B><BR>
760 * <li>Object is found in the database successfully<BR>
762 * <li>Result of search is null<BR>
767 * @throws InvalidPropertyException
768 * if an invalid property is used when creating objects
769 * @throws MultiplyDefinedException
770 * when trying to create an object with already existing id
771 * @throws MissedPropertyException
772 * if a mandatory property is not defined for an object to be created
773 * @throws SQLException
774 * @throws IOException
778 public void testIsReferenced() throws InvalidPropertyException,
779 MissedPropertyException, MultiplyDefinedException, IOException,
781 LOG.debug(">>>>> BEGIN testIsReferenced()");
782 startNestedTransaction();
784 HibernateTemplate ht = getHibernateTemplate();
785 Study aStudy = createStudy();
786 // Call DAO's create method for a good transient study.
787 Long id = aStudy.getIndex();
788 Assert.assertNotNull(id,
789 "Create method returns null instead of a new id.");
790 Assert.assertTrue(id > 0, "The new id is not a positive number.");
792 // Call DAO's get method for an existing id.
794 getHibernateTemplate().evict(aStudy);
795 getHibernateTemplate().clear();
796 Study aStudyFound = _studyDAO.get(id);
798 ProjectElement projElem;
802 for (int i = _projectSettings.getAllSteps().size(); i > 0; i--) {
803 LOG.debug("Remove documents from the step " + i);
804 step = _projectSettings.getStep(i);
805 if (step.appliesTo(Study.class)) {
806 projElem = aStudyFound;
808 projElem = aStudyFound.getScenarii()[0];
811 org.splat.som.Step aScStep = new org.splat.som.Step(step, projElem);
813 if (aScStep.getDocuments().size() > 0) {
814 doc = aScStep.getDocuments().get(0).value();
815 docId = doc.getIndex();
816 /* Assert.assertEquals(_documentDAO.isReferenced(doc), (ht.find(
817 "from UsesRelation where refer=" + docId).size() + ht
818 .find("from UsedByRelation where refer=" + docId)
823 rollbackNestedTransaction();
824 LOG.debug(">>>>> END testIsReferenced()");