/**
* test CRUD for {@link Contract}
*/
public void testContractCRUD() {
// C
Contract contract = getTestUtils().getTestContract();
try {
/*List<Consideration> considerations = new ArrayList<Consideration>();
considerations.add((Consideration) getTestUtils().getTestConsideration(Consideration.class));
contract.setConsiderations(considerations);*/
} catch (Exception e) {
fail("could not add consideration");
log.error(e);
}
getBoSvc().save(contract);
// R
contract.refresh();
getTestUtils().testContractFields(contract);
assertNotNull("considerations should not be null", contract.getConsiderations());
assertEquals("default number of considerations differs", 2, contract.getConsiderations().size());
assertNotNull("client object should not be null", contract.getClient());
assertNotNull("client principal name should not be null", contract.getClientPrincipalName());
// U
String serviceOffered = "flat 3f2";
contract.setServiceOffered(serviceOffered);
contract.refresh();
assertEquals("contract svc offered does not match after update", serviceOffered, contract.getServiceOffered());
// D
getBoSvc().delete(contract);
assertNull("contract should not exist", getBoSvc().findBySinglePrimaryKey(Contract.class, contract.getId()));
// the two default considerations should have been deleted
assertNull("consideration should not exist", getBoSvc().findBySinglePrimaryKey(
MatterConsideration.class, contract.getConsiderations().get(0).getId()));
assertNull("consideration should not exist", getBoSvc().findBySinglePrimaryKey(
MatterConsideration.class, contract.getConsiderations().get(1).getId()));
assertNull("duration should not exist", getBoSvc().findBySinglePrimaryKey(ContractDuration.class, contract.getId()));
Map<String, Object> criteria = new HashMap<String, Object>();
criteria.put("contractId", contract.getId());
assertEquals("contract signatories should have been deleted", 0, getBoSvc().findMatching(ContractSignatory.class, criteria).size());
assertEquals("contract parties should have been deleted", 0, getBoSvc().findMatching(ContractParty.class, criteria).size());
}