@Test public void testCreate() { dao.create(e1); assertNotNull(e1.getId()); Product retrieved = dao.find(e1.getId()); assertEquals("Car", retrieved.getName()); assertEquals(BigDecimal.valueOf(123.456), retrieved.getPrice()); assertEquals("brief description", retrieved.getDescription()); assertEquals(Integer.valueOf(5), retrieved.getAmount()); assertEquals(new Date(1333449110), retrieved.getCreated()); assertEquals(e1, retrieved); }
@Override @Transactional(readOnly = true) public List<Product> findByVat(Vat vat) { if (vat == null) { throw new IllegalArgumentException("Vat is null"); } return productDAO.findByVat(vat); }
@Override @Transactional(readOnly = true) public List<Product> findByCategory(Category category) { if (category == null) { throw new IllegalArgumentException("Category is null"); } return productDAO.findByCategory(category); }
@Test public void testEdit() { dao.create(e2); e2.setName("Car"); e2.setPrice(BigDecimal.valueOf(123.456)); e2.setDescription("brief description"); e2.setAmount(5); e2.setCreated(new Date(1333449110)); dao.edit(e2); Product retrieved = dao.find(e2.getId()); assertEquals("Car", retrieved.getName()); assertEquals(BigDecimal.valueOf(123.456), retrieved.getPrice()); assertEquals("brief description", retrieved.getDescription()); assertEquals(Integer.valueOf(5), retrieved.getAmount()); assertEquals(new Date(1333449110), retrieved.getCreated()); assertEquals(e2, retrieved); }
@Override public void remove(Product entity) { if (entity == null) { throw new IllegalArgumentException("Product is null"); } if (!orderProductDAO.findByProduct(entity).isEmpty()) { throw new IllegalArgumentException("Cannot remove product, because is ordered by customer"); } productDAO.remove(entity); }