I'm using Spring 4.3.3.RELEASE
, Hibernate 5.0.11.Final
, JUnit 4.1.2
, SDN4.1.3-RELEASE
and neo4j-ogm-2.0.5
. I read and try to implement @DirtyContext
that can reset my Database after each test method finish running. But When I look at my Database, All nodes that i created in Test method still there.
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = MockApplication.class)
@ContextConfiguration(classes = TestConfig.class)
@DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)
public class OrderServiceTest {
@Autowired
private OrderService orderService;
@Autowired
private CustomerService customerService;
@Autowired
private TableService tableService;
@Test
public void orderMenuFoodAndDrink() throws Exception {
Customer customer = new Customer();
customer.setName("Customer 1");
customerService.save(customer);
Table table = new Table ();
table.setCustomer(customer);
tableService.save(table);
ObjectResult result = orderService.orderTable(customer.getId());
assertThat(result.getTables().get(0), is(table`enter code here`));
}
}
And this is How I set my Configuration Context with Java Annotation
@Configuration
public class TestConfig {
@Primary
@Bean
public OrderService OrderService() {
OrderService OrderService = new OrderServiceImpl();
return OrderService;
}
}
OrderService
is my Interface Class, and OrderServiceImpl
is my Service Implementation. I have two references, but all of those is not working, because when I look at my database, all nodes still there, not deleted