@Test public void testCrud() throws Exception { databaseTester.onTearDown(); // crear db before tests // CREATE Assert.assertEquals(0, customerService.count()); Customer customer = new Customer(); customer.setName("Name"); customer.setEmail("*****@*****.**"); customer.setAddress("address"); customer.setPhone("111333444"); customerService.add(customer); Assert.assertEquals(1, customerService.count()); // READ Customer readcustomer = customerService.list().get(0); Assert.assertEquals(readcustomer.getName(), "Name"); Assert.assertEquals(readcustomer.getEmail(), "*****@*****.**"); Assert.assertEquals(readcustomer.getAddress(), "address"); Assert.assertEquals(readcustomer.getPhone(), "111333444"); // UPDATE readcustomer.setName("updatedName"); customerService.update(readcustomer); Customer updatedCustomer = customerService.list().get(0); Assert.assertEquals(updatedCustomer.getName(), "updatedName"); // DELETE customerService.delete(updatedCustomer.getId()); Assert.assertEquals(0, customerService.count()); }
@Before public final void startDatabase() throws Exception { if (dbConnector == null) { dbConnector = new MemoryDatabaseConnector(); dbConnector.start(); session = new JpaDatabaseSession(dbConnector); session.start(); } databaseTester = new JdbcDatabaseTester( MemoryDatabaseConnector.DRIVER, MemoryDatabaseConnector.URL, MemoryDatabaseConnector.USER, MemoryDatabaseConnector.PASSWORD); databaseTester.onTearDown(); }
@AroundInvoke public Object execute(InvocationContext invocationContext) throws Exception { // Execute following logic only if @Test method Test testAnnotation = invocationContext.getMethod().getAnnotation(Test.class); if (testAnnotation == null) { return invocationContext.proceed(); } dbUnitSetup(); DbUnitTestContext testContext = new DbUnitTestContext(); Object returnValue = null; Class<?> testClass = ProxyUtils.getUnproxiedClass(invocationContext.getTarget().getClass()); testContext.setTestClass(testClass); testContext.setTestInstance(invocationContext.getTarget()); testContext.setTestMethod(invocationContext.getMethod()); DbUnitConfiguration dbUnitConfiguration = testClass.getAnnotation(DbUnitConfiguration.class); try { dbUnitRunner.prepareTesterSetup(testContext, dbUnitConfiguration, databaseTester); // try { databaseTester.onSetup(); // } catch (Throwable e) { // do not propagate db setup exception or transaction // will not rollback // e.printStackTrace(); // } returnValue = invocationContext.proceed(); dbUnitRunner.verifyExpected(testContext); } finally { dbUnitRunner.prepareTesterTearDown(testContext, dbUnitConfiguration, databaseTester); databaseTester.onTearDown(); try { if (connection != null) { connection.close(); } } catch (Exception e) { connection = null; } } return returnValue; }
public void onTearDown() throws Exception { databaseTester.onTearDown(); goCache.clear(); }
public void afterTestMethod(TestContext arg0) throws Exception { // Clear up testing data if exists if (databaseTester != null) { databaseTester.onTearDown(); } }
@After public void tearDownAfterTest() throws Exception { databaseTester.onTearDown(); }
@After public void cleanup() throws Exception { databaseTester.onTearDown(); }