DefaultTransferService extends AbstractSaveService<Transfer> implements TransferService { @Override public void addTransferSample(TransferSample transferSample) throws IOException { Transfer managedTransfer = get(transferSample.getTransfer().getId()); Sample managedSample = sampleService.get(transferSample.getItem().getId()); transferSample.setTransfer(managedTransfer); transferSample.setItem(managedSample); validateAddition(managedTransfer, transferSample); transferStore.update(managedTransfer); sampleService.update(managedSample); }  @Override List<Transfer> list(); @Override SaveDao<Transfer> getDao(); @Override long countPendingForUser(User user); @Override List<Transfer> listByProperties(Lab sender, Group recipient, Project project, Date transferTime); @Override void addTransferSample(TransferSample transferSample); @Override DeletionStore getDeletionStore(); @Override AuthorizationManager getAuthorizationManager(); @Override void authorizeDeletion(Transfer object);  }
@Test public void testValidateFirstReceipt() throws Exception { Transfer transfer = makeTransfer(makeLab(1L), makeGroup(1L)); addTransferSample(transfer, makeSample(1L)); List<ValidationError> errors = validate(transfer, null); assertTrue(errors.isEmpty()); }
@Test public void testValidateSingleReceipt() throws Exception { Sample sample = makeSample(1L); Transfer previousReceipt = makeTransfer(makeLab(1L), makeGroup(1L)); previousReceipt.setId(1L); addTransferSample(previousReceipt, sample); Transfer transfer = makeTransfer(makeLab(1L), makeGroup(1L)); addTransferSample(transfer, sample); List<ValidationError> errors = validate(transfer, null); assertError(errors, "Items can only have one receipt (external lab to internal group) transfer"); }
@Test public void testValidateFirstDistribution() throws Exception { Transfer transfer = makeTransfer(makeGroup(1L), "Recipient"); addTransferSample(transfer, makeSample(1L), true); List<ValidationError> errors = validate(transfer, null); assertTrue(errors.isEmpty()); }
@Test public void testValidateSingleDistribution() throws Exception { Sample sample = makeSample(1L); Transfer previousDistribution = makeTransfer(makeGroup(1L), "Recipient 1"); previousDistribution.setId(1L); addTransferSample(previousDistribution, sample, true); Transfer transfer = makeTransfer(makeGroup(1L), "Recipient 2"); addTransferSample(transfer, sample, true); List<ValidationError> errors = validate(transfer, null); assertError(errors, "Items can only have one distribution (internal group to external named recipient) transfer"); }
@Test public void testValidateItemChangeAllowed() throws Exception { Group group1 = makeGroup(1L); setUser(false, group1); Transfer before = makeTransfer(group1, "Recipient"); addTransferSample(before, makeSample(1L), true); addTransferSample(before, makeSample(2L), true); Transfer updated = copyTransfer(before); updated.getSampleTransfers().removeIf(item -> item.getItem().getId() == 2L); List<ValidationError> errors = validate(updated, before); assertNoError(errors, "Only administrators and members of the sender group can modify items"); }
@Test public void testValidateItemChangeNotAllowed() throws Exception { setUser(false); Transfer before = makeTransfer(makeGroup(1L), "Recipient"); addTransferSample(before, makeSample(1L), true); addTransferSample(before, makeSample(2L), true); Transfer updated = copyTransfer(before); updated.getSampleTransfers().removeIf(item -> item.getItem().getId() == 2L); List<ValidationError> errors = validate(updated, before); assertError(errors, "Only administrators and members of the sender group can modify items"); }