Last active
September 16, 2019 13:33
Spring Boot Test Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@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 { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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