@Test public void okCouponCrud() throws Exception { try { Coupon coup = new Coupon(sec, new BigDecimal(1), sec.getCloseDate(), null, null); sec.addCoupon(coup); txTemplate.execute( new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { secRepo.saveNew(sec); } }); sec = secRepo.getById(sec.getId()); sec.changeCoupon(coup.getId(), new BigDecimal("11.1"), coup.getCoupDate(), null, null); txTemplate.execute( new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { secRepo.save(sec); } }); sec = secRepo.getById(sec.getId()); assertEquals(sec.getCoupons().get(coup.getId()).getAmount(), new BigDecimal("11.1")); boolean removed = false; sec = secRepo.getById(sec.getId()); sec.removeCoupon(coup.getId()); txTemplate.execute( new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { secRepo.save(sec); } }); sec = secRepo.getById(sec.getId()); try { sec.getCoupons().get(coup.getId()); } catch (IllegalArgumentException e) { removed = true; } assertEquals(removed, true); } finally { txTemplate.execute( new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { secRepo.remove(sec.getId()); } }); } }
@Test public void okSecurityCrud() throws Exception { txTemplate.execute( new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { secRepo.saveNew(sec); } }); assertEquals(secRepo.getById(sec.getId()), sec); sec = secRepo.getById(sec.getId()); sec.setName("new name"); txTemplate.execute( new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { secRepo.save(sec); } }); assertEquals(secRepo.getById(sec.getId()).getName(), sec.getName()); boolean removed = false; txTemplate.execute( new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { secRepo.remove(sec.getId()); } }); try { secRepo.getById(sec.getId()); } catch (IllegalArgumentException e) { removed = true; } assertEquals(removed, true); }