/** Tests the basic insert step. */ @Test public void testHandle() { display.setProjectId(ID2); final BaseResult result = mock(BaseResult.class); when(result.getSourceName()).thenReturn(TEST_SOURCE_NAME); when(calcDao.findCalculationId(ID2, TEST_SOURCE_NAME)).thenReturn(null); when(calcDao.insertCalculation(eq(ID2), eq(TEST_SOURCE_NAME), anyListOf(Long.class))) .thenReturn(ID); display.write(null, result); verify(calcDao).insertSummary(ID, result); }
/** Tests init plus insert. */ @SuppressWarnings({"unchecked", "rawtypes"}) @Test public void testSetupHandle() { final List<String> catNames = Arrays.asList(CAT1, CAT2); when(calcDao.findCategories(catNames)) .thenReturn( (List) Arrays.asList( new DefaultCalculationCategory(CAT1, CAT_ID1), new DefaultCalculationCategory(CAT2, CAT_ID2))); when(calcDao.findProjectId(TEST_PROJ_NAME)).thenReturn(ID2); display.setProjectConfig(TEST_PROJ_NAME, catNames); final BaseResult result = mock(BaseResult.class); when(result.getSourceName()).thenReturn(TEST_SOURCE_NAME); when(calcDao.findCalculationId(ID2, TEST_SOURCE_NAME)).thenReturn(null); when(calcDao.insertCalculation( eq(ID2), eq(TEST_SOURCE_NAME), (Collection<Long>) argThat(hasItems(CAT_ID1, CAT_ID2)))) .thenReturn(ID); display.write(null, result); display.finish(null); verify(calcDao).insertSummary(ID, result); }
/** * Fills a {@link BaseResult} instance with data from the AST. * * @param srcName The identifier for the source of the data. * @param ast The AST to traverse. * @return The filled result instance. */ private BaseResult extractSnapshotData(final String srcName, final CommonTree ast) { final BaseResult result = new DefaultBaseResult(srcName); int atomColCount = 0; Atom curAtom = new DefaultAtom(); @SuppressWarnings("unchecked") final List<CommonTree> eventList = ast.getChildren(); if (eventList == null) { logger.error("Parse failed: no AST children found for source " + srcName); return result; } for (CommonTree curNode : eventList) { switch (curNode.getType()) { case SnapshotLexer.EOF: break; case SnapshotLexer.CPUTIME: result.getCpuTimes().add(processCpuTime(curNode)); break; case SnapshotLexer.TERM: result.getTerminationDates().add(processTermDate(curNode)); break; case SnapshotLexer.MULT: result.setMult(toInt(curNode.getText())); break; case SnapshotLexer.FREQVAL: final Double freqVal = toDouble(curNode.getText()); if (freqVal != null) { result.getFrequencyValues().add(freqVal); } break; case SnapshotLexer.XYZINT: case SnapshotLexer.XYZFLOAT: handleAtom(curNode.getText(), curAtom, atomColCount); atomColCount++; if (atomColCount % ATOM_COL_COUNT == 0) { result.addAtom(curAtom); curAtom = new DefaultAtom(); } break; case SnapshotLexer.ELECENG: result.setElecEn(toDouble(curNode.getText())); break; case SnapshotLexer.FUNCSET: final String[] funcSetSplit = curNode.getText().split("/"); result.setFunctional(funcSetSplit[0]); result.setBasisSet(funcSetSplit[1]); break; case SnapshotLexer.SOLVENT: final String[] solvSplit = curNode.getText().split("="); result.setSolvent(solvSplit[1]); break; case SnapshotLexer.ZPECORR: result.setZpeCorrection(toDouble(curNode.getText())); break; case SnapshotLexer.G298: result.setGibbs298(toDouble(curNode.getText())); break; case SnapshotLexer.H298: result.setEnthalpy298(toDouble(curNode.getText())); break; case SnapshotLexer.CHARGE: result.setCharge(toInt(curNode.getText())); break; case SnapshotLexer.STOI: result.setStoichiometry(curNode.getText()); break; case SnapshotLexer.DIPTOT: result.setDipoleMomentTotal(toDouble(curNode.getText())); break; case SnapshotLexer.NATOMS: result.setAtomCount(toInt(curNode.getText())); break; default: logger.warn(String.format("Unhandled data %s %s", curNode.getType(), curNode.getText())); break; } } return result; }