From 245a05fd246a6f0b591ae2ffe9b15f340546ca49 Mon Sep 17 00:00:00 2001 From: rkv Date: Fri, 19 Apr 2013 15:34:57 +0000 Subject: [PATCH] Unit test for getStudyResultType is added. --- .../test/splat/service/TestStudyService.java | 174 +++++++++++------- 1 file changed, 108 insertions(+), 66 deletions(-) diff --git a/Workspace/Siman-Common/src/test/splat/service/TestStudyService.java b/Workspace/Siman-Common/src/test/splat/service/TestStudyService.java index 5b68c34..4e23d39 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestStudyService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestStudyService.java @@ -534,6 +534,33 @@ public class TestStudyService extends BaseTest { LOG.debug(">>>>> END testGetDescription()"); } + /** + * Test of retrieval of a study description. + * + * @throws BusinessException + * if there is something wrong likely unrelated to the tested method + */ + @Test + public void testGetStudyResultType() throws BusinessException { + LOG.debug(">>>>> BEGIN testGetStudyResultType()"); + startNestedTransaction(); + + User user = TestEntitiesGenerator.getTestUser("GoodUser"); + _userDAO.create(user); + Study study = TestEntitiesGenerator.getTestStudy(user); + _studyDAO.create(study); + _studyDAO.flush(); + + // Empty description: + DocumentType dtype = _studyService.getStudyResultType(study); + Assert.assertNotNull(dtype, + "returned study result type must not be null"); + Assert.assertEquals(dtype.getName(), "report"); + + rollbackNestedTransaction(); + LOG.debug(">>>>> END testGetStudyResultType()"); + } + /** * Test of setting of a study description. * @@ -831,11 +858,12 @@ public class TestStudyService extends BaseTest { // ///////////////////////////////////////////////////////// ht.clear(); // Check removal of contributors relation - List found1 = ht.find("from ContributorRelation where owner=" + studyId); + List found1 = ht + .find("from ContributorRelation where owner=" + studyId); Assert.assertEquals(found1.size(), 1, "ContributorRelation is not created"); ht.clear(); - + _studyService.removeStudy(studyId); ht.flush(); @@ -911,7 +939,8 @@ public class TestStudyService extends BaseTest { throws BusinessException, IOException { HibernateTemplate ht = getHibernateTemplate(); // Add documents to the first study activity - org.splat.som.Step aStep = _projectElementService.getFirstStep(aProjElem); + org.splat.som.Step aStep = _projectElementService + .getFirstStep(aProjElem); Document.Properties dprop = new Document.Properties().setAuthor( aProjElem.getAuthor()).setDate(new Date()).setName(docname) .setType(dtype).setFormat("py"); @@ -976,7 +1005,8 @@ public class TestStudyService extends BaseTest { } @Test - public void testReaders() throws InvalidPropertyException, BusinessException { + public void testReaders() throws InvalidPropertyException, + BusinessException { LOG.debug(">>>>> BEGIN testReaders()"); startNestedTransaction(); @@ -990,16 +1020,17 @@ public class TestStudyService extends BaseTest { ht.clear(); long studyId = study.getIndex(); long userId = user.getIndex(); - - //get a non-existing user id - User nonExistingUser = TestEntitiesGenerator.getTestUser("nonExistingUser"); + + // get a non-existing user id + User nonExistingUser = TestEntitiesGenerator + .getTestUser("nonExistingUser"); _userDAO.create(nonExistingUser); long nonExistingUserId = nonExistingUser.getIndex(); _userDAO.delete(nonExistingUser); _userDAO.flush(); ht.clear(); - //get a non-existing study id + // get a non-existing study id Study nonExistingStudy = TestEntitiesGenerator.getTestStudy(user); _studyDAO.create(nonExistingStudy); long nonExistingStudyId = nonExistingStudy.getIndex(); @@ -1007,107 +1038,118 @@ public class TestStudyService extends BaseTest { _userDAO.flush(); ht.clear(); + // ============================================================================================================================== + // 1.Non-existing user and study ids + // ============================================================================================================================== - // ============================================================================================================================== - // 1.Non-existing user and study ids - // ============================================================================================================================== - - //Test getReaders method with a non-existing study id + // Test getReaders method with a non-existing study id try { _studyService.getReaders(nonExistingStudyId); - Assert.fail("retrieval of readers with non-existing study id " + - "must throw InvalidParameterException"); - } catch(InvalidParameterException e) { + Assert.fail("retrieval of readers with non-existing study id " + + "must throw InvalidParameterException"); + } catch (InvalidParameterException e) { LOG.debug("Expected exception is thrown: " + e.getClass().getSimpleName() + ": " + e.getMessage()); } - - //Test removeReader method with a non-existing study id + + // Test removeReader method with a non-existing study id try { _studyService.removeReader(nonExistingStudyId, userId); - Assert.fail("attempt to remove from readers with non-existing study id " + - "must throw InvalidParameterException"); - } catch(InvalidParameterException e) { + Assert + .fail("attempt to remove from readers with non-existing study id " + + "must throw InvalidParameterException"); + } catch (InvalidParameterException e) { LOG.debug("Expected exception is thrown: " + e.getClass().getSimpleName() + ": " + e.getMessage()); } - - //Test removeReader method with an non-existing user id + + // Test removeReader method with an non-existing user id try { _studyService.removeReader(studyId, nonExistingUserId); - Assert.fail("attempt to remove from readers with non-existing user id " + - "must throw InvalidParameterException"); - } catch(InvalidParameterException e) { + Assert + .fail("attempt to remove from readers with non-existing user id " + + "must throw InvalidParameterException"); + } catch (InvalidParameterException e) { LOG.debug("Expected exception is thrown: " + e.getClass().getSimpleName() + ": " + e.getMessage()); } - //Test addReader method with a non-existing study id + // Test addReader method with a non-existing study id try { _studyService.addReader(nonExistingStudyId, userId); - Assert.fail("attempt to add a user to readers of a study with non-existing study id " + - "must throw InvalidParameterException"); - } catch(InvalidParameterException e) { + Assert + .fail("attempt to add a user to readers of a study with non-existing study id " + + "must throw InvalidParameterException"); + } catch (InvalidParameterException e) { LOG.debug("Expected exception is thrown: " + e.getClass().getSimpleName() + ": " + e.getMessage()); } - - //Test addReader method with a non-existing user id + + // Test addReader method with a non-existing user id try { _studyService.addReader(studyId, nonExistingUserId); - Assert.fail("attempt to add to readers a user with non-existing id " + - "must throw InvalidParameterException"); - } catch(InvalidParameterException e) { + Assert + .fail("attempt to add to readers a user with non-existing id " + + "must throw InvalidParameterException"); + } catch (InvalidParameterException e) { LOG.debug("Expected exception is thrown: " + e.getClass().getSimpleName() + ": " + e.getMessage()); } - // ============================================================================================================================== - // 2.Existing user who is not yet reader - // ============================================================================================================================== + // ============================================================================================================================== + // 2.Existing user who is not yet reader + // ============================================================================================================================== - //Test getReaders method with no readers + // Test getReaders method with no readers Assert.assertTrue(_studyService.getReaders(studyId).isEmpty(), "returned list for a study without readers must be empty"); - - //Test removeReader method with an existing user who is not reader - Assert.assertFalse(_studyService.removeReader(studyId, userId), - "attempt to remove from readers of a non-reader user must return false"); - - //ADD A READER: - //Test addReader method with an existing user who is not yet reader + + // Test removeReader method with an existing user who is not reader + Assert + .assertFalse(_studyService.removeReader(studyId, userId), + "attempt to remove from readers of a non-reader user must return false"); + + // ADD A READER: + // Test addReader method with an existing user who is not yet reader Assert.assertTrue(_studyService.addReader(studyId, userId), "addition of a user who is not yet reader must return true"); - + _studyDAO.flush(); ht.clear(); study = _studyDAO.get(studyId); - - List readerRelations = study.getRelations(ReaderRelation.class); - Assert.assertTrue(readerRelations.size() == 1, "The retrieved relations list has wrong size"); - Assert.assertEquals(readerRelations.get(0).getFrom(), study, - "the retrieved relation does not equal the one that has been added."); - Assert.assertEquals(readerRelations.get(0).getTo(), user, - "the retrieved relation does not equal the one that has been added."); + List readerRelations = study + .getRelations(ReaderRelation.class); + Assert.assertTrue(readerRelations.size() == 1, + "The retrieved relations list has wrong size"); + Assert + .assertEquals(readerRelations.get(0).getFrom(), study, + "the retrieved relation does not equal the one that has been added."); + Assert + .assertEquals(readerRelations.get(0).getTo(), user, + "the retrieved relation does not equal the one that has been added."); - // ============================================================================================================================== - // 3.Existing reader - // ============================================================================================================================== + // ============================================================================================================================== + // 3.Existing reader + // ============================================================================================================================== - //Test getReaders method with an existing reader + // Test getReaders method with an existing reader List readers = _studyService.getReaders(studyId); - Assert.assertTrue(readers.size() == 1, "The retrieved reader list has wrong size"); - Assert.assertEquals(readers.get(0), BeanHelper.copyBean(user, UserDTO.class), - "the retrieved user does not equal the one that has been added."); + Assert.assertTrue(readers.size() == 1, + "The retrieved reader list has wrong size"); + Assert + .assertEquals(readers.get(0), BeanHelper.copyBean(user, + UserDTO.class), + "the retrieved user does not equal the one that has been added."); - //Test addReader method with a user who is already reader + // Test addReader method with a user who is already reader Assert.assertFalse(_studyService.addReader(studyId, userId), "addition of a user who is already reader must return false"); - - //Test removeReader method with a user user who is already reader - Assert.assertTrue(_studyService.removeReader(studyId, userId), - "removal from readers of a user who is study reader must return true"); + + // Test removeReader method with a user user who is already reader + Assert + .assertTrue(_studyService.removeReader(studyId, userId), + "removal from readers of a user who is study reader must return true"); Assert.assertTrue(study.getRelations(ReaderRelation.class).isEmpty(), "a relation has not been properly removed"); -- 2.39.2