2003 characters | 50 lines | 1.96 KB
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration(locations = {"classpath:net/adaptiveservices/aims/rc/dao/applicationContext-dao.xml"})
- @TransactionConfiguration(transactionManager = "transactionManager")
- @Transactional
- public class ItemDaoIT {
- @Autowired
- private ItemDao itemDao;
- @Autowired
- private StockDao stockDao;
- @Test
- // @Rollback
- Stock newStock = new Stock();
- newStock.setTitle("Experiment");
- assertThat(newStock.getId(), allOf(notNullValue(), greaterThan(0L)));
- Stock stock = stockDao.findById(stockId);
- assertNotNull(stock);
- Item item = new Item();
- item.setName("Item name");
- item.setDataType(createDataType("Text"));
- item.setStock(stock);
- //TODO It's a workaround. For some cases cascade operation is not working.
- //itemDao.saveOrUpdate( item );
- stock.getItems().add(item);
- Stock savedStock = stockDao.saveOrUpdate(stock);
- assertThat(savedStock.getId(), allOf(notNullValue(), greaterThan(0L)));
- Stock foundStock = stockDao.findById(savedStock.getId());
- assertNotNull(foundStock);
- Set<Item> items = foundStock.getItems();
- assertFalse(items.isEmpty());
- Item foundItem = items.iterator().next();
- assertThat(foundItem.getId(), allOf(notNullValue(), greaterThan(0L))); // ×ôõÑÂÑŒ þшøñúð, чтþ id null
- assertTrue(items.contains(item));
- assertNotNull(foundItem.getStock());
- assertEquals(foundItem.getStock(), foundStock);
- assertThat(foundItem.getDataType(), notNullValue());
- assertThat(foundItem.getDataType().getId(), allOf(notNullValue(), greaterThan(0L)));
- }
