@ContextConfiguration(locations={"../config/applicationContext-dao.xml",
"../config/applicationContext-service.xml"})
public class CustomerServiceTest extends AbstractTransactionalJUnit4SpringContextTests{
@Autowired
private CustomerService service;
@Before
public void before(){
}
@Test
public void testCanRemoveCustomer(){
String sql = "insert into sys_user(user_name, customer_id) values('rgm', 99)";
this.simpleJdbcTemplate.getJdbcOperations().update(sql);
List<CustomerBean> customers = new ArrayList<CustomerBean>();
CustomerBean customer = new CustomerBean();
customer.setId(99);
customers.add(customer);
boolean result = service.canRemoveCustomer(customers);
Assert.assertEquals(false, result);
}
@Test
public void testCreateCustomer(){
CustomerBean customer = new CustomerBean();
customer.setCustomerName("aaaaaaaaaaa");
try{
service.createCustomer(customer);
}catch(Exception e){
Assert.fail(e.getMessage());
}
String sql = "select count(*) from sys_customer where customer_name = 'aaaaaaaaaaa'";
long c = this.simpleJdbcTemplate.getJdbcOperations().queryForLong(sql);
Assert.assertEquals(1, c);
}
}
"../config/applicationContext-service.xml"})
public class CustomerServiceTest extends AbstractTransactionalJUnit4SpringContextTests{
@Autowired
private CustomerService service;
@Before
public void before(){
}
@Test
public void testCanRemoveCustomer(){
String sql = "insert into sys_user(user_name, customer_id) values('rgm', 99)";
this.simpleJdbcTemplate.getJdbcOperations().update(sql);
List<CustomerBean> customers = new ArrayList<CustomerBean>();
CustomerBean customer = new CustomerBean();
customer.setId(99);
customers.add(customer);
boolean result = service.canRemoveCustomer(customers);
Assert.assertEquals(false, result);
}
@Test
public void testCreateCustomer(){
CustomerBean customer = new CustomerBean();
customer.setCustomerName("aaaaaaaaaaa");
try{
service.createCustomer(customer);
}catch(Exception e){
Assert.fail(e.getMessage());
}
String sql = "select count(*) from sys_customer where customer_name = 'aaaaaaaaaaa'";
long c = this.simpleJdbcTemplate.getJdbcOperations().queryForLong(sql);
Assert.assertEquals(1, c);
}
}