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.
*
// /////////////////////////////////////////////////////////
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();
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");
}
@Test
- public void testReaders() throws InvalidPropertyException, BusinessException {
+ public void testReaders() throws InvalidPropertyException,
+ BusinessException {
LOG.debug(">>>>> BEGIN testReaders()");
startNestedTransaction();
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();
_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<Relation> 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<Relation> 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<UserDTO> 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");