2003 characters | 50 lines | 1.96 KB
DOWNLOAD | RAW | EMBED | CREATE NEW VERSION OF THIS PASTE | REPORT ABUSE | x
  1. @RunWith(SpringJUnit4ClassRunner.class)
  2. @ContextConfiguration(locations = {"classpath:net/adaptiveservices/aims/rc/dao/applicationContext-dao.xml"})
  3. @TransactionConfiguration(transactionManager = "transactionManager")
  4. @Transactional
  5. public class ItemDaoIT {
  6.  
  7.     @Autowired
  8.     private ItemDao itemDao;
  9.  
  10.     @Autowired
  11.     private StockDao stockDao;
  12.  
  13.  @Test
  14. //    @Rollback
  15.     public void testManyToOneStockFindFirst() throws Exception {
  16.         Stock newStock = new Stock();
  17.         newStock.setTitle("Experiment");
  18.         Long stockId = stockDao.saveOrUpdate(newStock).getId();
  19.         assertThat(newStock.getId(), allOf(notNullValue(), greaterThan(0L)));
  20.  
  21.         Stock stock = stockDao.findById(stockId);
  22.         assertNotNull(stock);
  23.  
  24.         Item item = new Item();
  25.         item.setName("Item name");
  26.         item.setDataType(createDataType("Text"));
  27.         item.setStock(stock);
  28.  
  29.         //TODO It's a workaround. For some cases cascade operation is not working.
  30.         //itemDao.saveOrUpdate( item );
  31.  
  32.         stock.getItems().add(item);
  33.  
  34.         Stock savedStock = stockDao.saveOrUpdate(stock);
  35.         assertThat(savedStock.getId(), allOf(notNullValue(), greaterThan(0L)));
  36.  
  37.         Stock foundStock = stockDao.findById(savedStock.getId());
  38.         assertNotNull(foundStock);
  39.  
  40.         Set<Item> items = foundStock.getItems();
  41.         assertFalse(items.isEmpty());
  42.  
  43.         Item foundItem = items.iterator().next();
  44.         assertThat(foundItem.getId(), allOf(notNullValue(), greaterThan(0L))); // Здесь ошибка, что id null
  45.         assertTrue(items.contains(item));
  46.         assertNotNull(foundItem.getStock());
  47.         assertEquals(foundItem.getStock(), foundStock);
  48.         assertThat(foundItem.getDataType(), notNullValue());
  49.         assertThat(foundItem.getDataType().getId(), allOf(notNullValue(), greaterThan(0L)));
  50.     }