String newName = testName + " test " + Math.random();
User submitter = (User) loadObject(User.class);
assertTrue("Empty user table.", submitter != null);
Study s = new Study();
s.setName(newName);
Submission sub = getFixture().createSubmission(submitter, s);
getSubmissionHome().store(sub);
// force commit immediately, important:
setComplete();
endTransaction();
logger.info("study created: " + s.getName() + "id = " + s.getId());
logger.info("submission created: " + "id = " + sub.getId());
onSetUp();
// 2. add a nexus file:
// String path = "/12Tx432C.nex"; Failure
// String path = "/TestNexusFile.nex";
// String path = "/M12c11.nex";
String path = "/M1389.nex"; // 17k
// String path = "/M1001"; //489k
// String path = "/M999.nx";
// String path = "/EF1 Spiders.nex";
// String path = "/wtset.nex";
// String path = "/multiTrees-label.nex";
// String path = "/charset-taxset-partition.nex";
// String path = "/49LBR.PDI-branch-length-continue.nex"; // continuous matrix, provided by
// Peter M.
File nexusFile = new File(getClass().getResource(path).toURI());
Collection<File> files = new ArrayList<File>();
files.add(nexusFile);
long t1 = System.currentTimeMillis();
getSubmissionHome().refresh(sub);
// sub = (Submission) loadObject(Submission.class, sub.getId());
s = sub.getStudy();
assertTrue("Failed to refresh submission.", sub != null);
getFixture().addNexusFiles(sub, files, null);
getStudyService().addNexusFiles(s, files);
// force commit immediately, important:
setComplete();
endTransaction();
long t2 = System.currentTimeMillis();
logger.info("files added: " + s.getName() + "id = " + s.getId() + " Time =" + (t2 - t1));
// 3. verify
String studySQL = "select count(*) from Study where study_id=" + s.getId();
String subSQL = "select count(*) from Submission where submission_id=" + sub.getId();
int count = jdbcTemplate.queryForInt(studySQL);
assertTrue(count == 1);
count = jdbcTemplate.queryForInt(subSQL);
assertTrue(count == 1);
onSetUp();
// verify clob:
// Notes: this is important: why?? there are two copies of s in the same session.
// how???
Study study2 = (Study) hibernateTemplate.load(Study.class, sub.getStudy().getId());
// hibernateTemplate.refresh(sub);
String nexusString = study2.getNexusFiles().values().iterator().next();
int nexusStringLength = (int) nexusString.length();
logger.info("test clob: length=" + nexusStringLength + "content = " + nexusString);
assertTrue(nexusStringLength > 0);
// 4. delete: delete submission: