org.springframework.boot.test.util.TestPropertyValues#applyTo ( )源码实例Demo

下面列出了org.springframework.boot.test.util.TestPropertyValues#applyTo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void initialize(@NotNull ConfigurableApplicationContext configurableApplicationContext) {
	String jdbcUrl = String.format("jdbc:postgresql://%s:%d/%s", postgres.getContainerIpAddress(),
			postgres.getMappedPort(5432), "postgres");

	TestPropertyValues values = TestPropertyValues.of(
			"postgres.host=" + postgres.getContainerIpAddress(),
			"postgres.port=" + postgres.getMappedPort(5432),
			"postgres.url=" + jdbcUrl,
			"postgres.database-name=postgres",
			"spring.application.name=friend-service",
			"spring.datasource.data-username=postgres",
			"spring.datasource.data-password=password",
			"spring.datasource.url=" + jdbcUrl,
			"eureka.client.enabled=false");

	values.applyTo(configurableApplicationContext);
}
 
@Override
public void initialize(@NotNull ConfigurableApplicationContext configurableApplicationContext) {
	String jdbcUrl = String.format("jdbc:postgresql://%s:%d/%s", postgres.getContainerIpAddress(),
			postgres.getMappedPort(5432), "postgres");

	TestPropertyValues values = TestPropertyValues.of(
			"postgres.host=" + postgres.getContainerIpAddress(),
			"postgres.port=" + postgres.getMappedPort(5432),
			"postgres.url=" + jdbcUrl,
			"postgres.database-name=postgres",
			"spring.application.name=user-service",
			"spring.datasource.data-username=postgres",
			"spring.datasource.data-password=password",
			"spring.datasource.url=" + jdbcUrl,
			"eureka.client.enabled=false");

	values.applyTo(configurableApplicationContext);
}
 
源代码3 项目: blog-tutorials   文件: GetPersonByIdIT.java
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
  TestPropertyValues values = TestPropertyValues.of(
    "spring.datasource.url=" + postgreSQLContainer.getJdbcUrl(),
    "spring.datasource.password=" + postgreSQLContainer.getPassword(),
    "spring.datasource.username=" + postgreSQLContainer.getUsername()
  );
  values.applyTo(configurableApplicationContext);
}
 
源代码4 项目: blog-tutorials   文件: GetAllPersonsIT.java
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
  TestPropertyValues values = TestPropertyValues.of(
    "spring.datasource.url=" + postgreSQLContainer.getJdbcUrl(),
    "spring.datasource.password=" + postgreSQLContainer.getPassword(),
    "spring.datasource.username=" + postgreSQLContainer.getUsername()
  );
  values.applyTo(configurableApplicationContext);
}
 
源代码5 项目: blog-tutorials   文件: DeletePersonIT.java
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
  TestPropertyValues values = TestPropertyValues.of(
    "spring.datasource.url=" + postgreSQLContainer.getJdbcUrl(),
    "spring.datasource.password=" + postgreSQLContainer.getPassword(),
    "spring.datasource.username=" + postgreSQLContainer.getUsername()
  );
  values.applyTo(configurableApplicationContext);
}
 
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    INSTANCE.start();
    String url = applicationContext.getEnvironment()
                                   .getProperty("spring.datasource.url")
                                   .replace("<port>", INSTANCE.getMappedPort(MS_SQL_SERVER_PORT).toString());
    TestPropertyValues values = TestPropertyValues.of(
            "spring.datasource.url=" + url);
    values.applyTo(applicationContext);
    DatabaseCreator creator = new DatabaseCreator(url, INSTANCE.getUsername(), INSTANCE.getPassword());
    creator.createDatabaseIfItDoesntExist();
}
 
@Override
public void initialize(@NotNull ConfigurableApplicationContext configurableApplicationContext) {
    String jdbcUrl = String.format("jdbc:postgresql://%s:%d/%s", postgres.getContainerIpAddress(),
            postgres.getMappedPort(5432), "postgres");
    TestPropertyValues values = TestPropertyValues.of(
            "postgres.host=" + postgres.getContainerIpAddress(),
            "postgres.port=" + postgres.getMappedPort(5432),
            "postgres.url=" + jdbcUrl,
            "spring.datasource.url=" + jdbcUrl,
            "spring.cloud.stream.kafka.binder.brokers=" + kafka.getBootstrapServers(),
            "eureka.client.enabled=false");
    values.applyTo(configurableApplicationContext);
}
 
@Override
public void initialize(@NotNull ConfigurableApplicationContext configurableApplicationContext) {
    String jdbcUrl = String.format("jdbc:postgresql://%s:%d/%s", postgres.getContainerIpAddress(),
            postgres.getMappedPort(5432), "postgres");
    TestPropertyValues values = TestPropertyValues.of(
            "postgres.host=" + postgres.getContainerIpAddress(),
            "postgres.port=" + postgres.getMappedPort(5432),
            "postgres.url=" + jdbcUrl,
            "spring.datasource.url=" + jdbcUrl,
            "spring.cloud.stream.kafka.binder.brokers=" + kafka.getBootstrapServers(),
            "eureka.client.enabled=false");
    values.applyTo(configurableApplicationContext);
}
 
@Test(expected = IllegalArgumentException.class)
public void testEmptyFormat() {
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
	TestPropertyValues testPropertyValues = TestPropertyValues.of("format:");
	testPropertyValues.applyTo(context);
	context.register(Conf.class);
	context.refresh();
	TimestampTaskProperties properties = context
		.getBean(TimestampTaskProperties.class);
	properties.getFormat();
}