コード例 #1
0
  @Test
  public void deleteStudy_shouldDeleteGivenStudy() throws Exception {

    final String studyName = "Study Name";

    List<StudyDef> studies = studyManagerService.getStudies();
    Assert.assertEquals("There are 4 studies", 4, studies.size());
    Assert.assertNull(getStudy(studyName, studies));

    StudyDef study = new StudyDef();
    study.setName(studyName);
    study.setCreator(userService.getUsers().get(0));
    study.setDateCreated(new Date());

    studyManagerService.saveStudy(study);
    studies = studyManagerService.getStudies();
    Assert.assertEquals("Added 1 study, now there are 5", 5, studies.size());

    study = getStudy(studyName, studies);
    Assert.assertNotNull(study);

    studyManagerService.deleteStudy(study);

    studies = studyManagerService.getStudies();
    Assert.assertEquals("Deleted the study so there are 4 studies again", 4, studies.size());
    Assert.assertNull(getStudy(studyName, studies));
  }
コード例 #2
0
  @Test
  public void getStudies_shouldReturnAllStudies() throws Exception {
    List<StudyDef> studies = studyManagerService.getStudies();

    Assert.assertNotNull(studies);
    Assert.assertEquals("There are 4 studies", 4, studies.size());
    Assert.assertNotNull(getStudy("Sample Study", studies));
  }
コード例 #3
0
  @Test
  public void saveFormData_editExistingData() throws Exception {
    int formDefVersionId = formService.getForms().get(0).getVersions().get(0).getFormDefVersionId();
    List<FormDataHeader> data = studyManagerService.getFormData(formDefVersionId, null, null, null);
    int dataCount = data.size();

    // create some form data
    FormData formData = new FormData();
    formData.setData("testing");
    formData.setFormDefVersionId(formDefVersionId);
    formData.setCreator(userService.getUsers().get(0));
    formData.setDateCreated(new Date());
    formService.saveFormData(formData);

    // check if the form data was created
    Assert.assertNotNull("FormData Id is set", formData.getId());
    data = studyManagerService.getFormData(formDefVersionId, null, null, null);
    Assert.assertEquals("One extra FormData", dataCount + 1, data.size());
    dataCount = data.size();

    // try edit the form data and save
    formData.setData("testing updated");
    formData.setChangedBy(formData.getCreator());
    formData.setDateChanged(new Date());
    formService.saveFormData(formData);

    // check if the form data was updated
    data = studyManagerService.getFormData(formDefVersionId, null, null, null);
    Assert.assertEquals("No extra FormData", dataCount, data.size());
    FormData savedFormData = studyManagerService.getFormData(formData.getId());
    Assert.assertEquals("Data text is updated", "testing updated", savedFormData.getData());

    // check if the version was correctly saved
    List<FormDataVersion> versions = studyManagerService.getFormDataVersion(formData.getId());
    Assert.assertEquals("Only 1 previous version", 1, versions.size());
    Assert.assertEquals(
        "Previous version data text is correct", "testing", versions.get(0).getData());
  }