@PropertySource

@PropertySource("tempest-${spring.profiles.active}.properties")
@PropertySource(factory = YamlPropertySourceFactory.class, value = "classpath:SlaTimeMap.yml")
import com.citi.tm.api.report.portfolio.tradePortfolio.TradePortfolioReportServiceTest.TestContextConfiguration;
import com.citi.tm.model.g10.trade.TradeSchema;
import com.citi.tm.model.report.portfolio.PortfolioReport;
import com.citi.tm.model.report.portfolio.TradePortfolioDto;
import java.time.Instant;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.stubbing.OngoingStubbing;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.server.ResponseStatusException;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

/*@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
    classes = {TestContextConfiguration.class, TradePortfolioReportService.class},
    initializers = {ConfigFileApplicationContextInitializer.class})
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestContextConfiguration.class)
@ActiveProfiles("test")
public class TradePortfolioReportServiceTest {

  @Configuration
  @Import(TradePortfolioReportService.class)
  @EnableConfigurationProperties(TradePortfolioSlaTime.class)
  static class TestContextConfiguration {
    @Bean
    public List<ReactiveMongoTemplate> templates() {
      ReactiveMongoTemplate template = mock(ReactiveMongoTemplate.class);
      return asList(template);
    }
  }
原文地址:https://www.cnblogs.com/tonggc1668/p/11971567.html