package org.xmx0632.deliciousfruit.repository;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springside.modules.test.spring.SpringTransactionalTestCase;
import org.xmx0632.deliciousfruit.entity.FruitProduct;
import org.xmx0632.deliciousfruit.entity.FruitSubPromotion;
@ContextConfiguration(locations = { "/applicationContext.xml" })
public class FruitSubPromotionDaoTest extends SpringTransactionalTestCase {
@Autowired
private FruitSubPromotionDao fruitSubPromotionDao;
@Autowired
private FruitProductDao fruitProductDao;
private FruitSubPromotion fruitSubPromotion;
@After
public void teardown() {
if (fruitSubPromotion != null) {
System.out.println("delete " + fruitSubPromotion);
jdbcTemplate
.execute("delete from tbl_fruit_sub_promotion where id = "
+ fruitSubPromotion.getId());
}
}
@Test
public void testFindOne() {
FruitSubPromotion list = fruitSubPromotionDao.findOne(Long.valueOf(-1));
assertNull(list);
}
@Test
public void shouldNotThrowExceptionWhenAssociateProductDeleted() {
fruitSubPromotion = new FruitSubPromotion();
fruitSubPromotion.setProductName("productName");
FruitProduct product = new FruitProduct();
product.setId(Long.valueOf(-1));
fruitSubPromotion.setProduct(product);
FruitProduct promotionProduct = new FruitProduct();
promotionProduct.setId(Long.valueOf(-2));
fruitSubPromotion.setPromotionProduct(promotionProduct);
fruitSubPromotionDao.save(fruitSubPromotion);
System.out.println(fruitSubPromotion.getId());
FruitSubPromotion fsp = fruitSubPromotionDao.findOne(fruitSubPromotion
.getId());
assertNotNull(fsp);
}
}