Skip to content

Instantly share code, notes, and snippets.

@ThangLeQuoc
Last active September 16, 2019 13:33
Show Gist options
  • Save ThangLeQuoc/04a89c6ee41d7dbe9c063daaf98c9821 to your computer and use it in GitHub Desktop.
Save ThangLeQuoc/04a89c6ee41d7dbe9c063daaf98c9821 to your computer and use it in GitHub Desktop.
Spring Boot Test Configuration
//@ContextConfiguration(classes = { H2ContextConfiguration.class })
//@EnableAutoConfiguration
//@TestPropertySource(locations = "classpath:/application-test.properties")
//@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
//@EnableAutoConfiguration
//@SpringBootTest(classes = OrderServiceIntegrationTestContext.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
//@RunWith(SpringRunner.class)
//@ContextConfiguration(classes = { H2ContextConfiguration.class })
//@EnableAutoConfiguration
//@TestPropertySource(locations = "classpath:/application-test.properties")
//@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@RunWith(SpringRunner.class)
@ComponentScan(
includeFilters = {
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,
value = { OrderService.class, OrderServiceImpl.class})
},
excludeFilters = {
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,
value = { DatabaseConfiguration.class, ActivitiBPMConfiguration.class, ElasticsearchConfiguration.class,
ElasticSearchUpdater.class, CacheConfiguration.class, MetricsConfiguration.class}),
@ComponentScan.Filter(type = FilterType.REGEX,
pattern = {"vn.nextlogix.repository.search.*"})})
public class OrderServiceIntegrationTestContext {
}
package vn.nextlogix.service.util;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import vn.nextlogix.base.H2DatabaseContextConfiguration;
import vn.nextlogix.config.OrderStateMachineConfiguration;
import vn.nextlogix.repository.search.OrderMainSearchRepository;
import vn.nextlogix.service.CompanyProfileService;
import vn.nextlogix.service.OrderService;
import vn.nextlogix.service.SequenceService;
import vn.nextlogix.service.impl.OrderServiceImpl;
import vn.nextlogix.service.mapper.*;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import static org.junit.Assert.assertTrue;
@SpringBootTest(classes = {OrderService.class, OrderServiceImpl.class}, webEnvironment = SpringBootTest.WebEnvironment.NONE)
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = { H2DatabaseContextConfiguration.class,
OrderStateMachineConfiguration.class})
//@EnableAutoConfiguration
@TestPropertySource(locations = "classpath:/application-test.properties")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) //
public class OrderServiceIntegrationTestV2 {
@PersistenceContext
EntityManager entityManager;
/* Mock Beans */
@MockBean OrderMainSearchRepository orderMainSearchRepository;
@MockBean CompanyProfileService companyProfileService;
@MockBean SequenceService sequenceService;
/* Mock Mapper Class */
@MockBean OrderMapper orderMapper;
@MockBean OrderJourneyMapper orderJourneyMapper;
@MockBean OrderMainMapper orderMainMapper;
@MockBean PostOfficeMapper postOfficeMapper;
@MockBean CompanyMapper companyMapper;
@MockBean OrderStatusGroupMapper orderStatusGroupMapper;
@MockBean CustomerMapper customerMapper;
@MockBean QuotationMapper quotationMapper;
@MockBean OrderMediaMapper orderMediaMapper;
@MockBean CallHistoryMapper callHistoryMapper;
@MockBean OrderProductMapper orderProductMapper;
@MockBean ProductMapper productMapper;
@MockBean DistrictMapper districtMapper;
@Autowired
OrderService orderService;
@Test
@Ignore
// @Sql("classpath:/testScript/baseScript/baseDistrict.sql")
public void testSaveNewDistrict() {
// District district = new District();
assertTrue(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment