From 0326fa47b794ea5fb6ec683016bc47817cfa4e6c Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 26 Jul 2021 13:51:23 +0100 Subject: [PATCH] Make DataJpaTestSchemaCredentialsIntegrationTests create the schema Closes gh-26106 --- .../DataJpaTestSchemaCredentialsIntegrationTests.java | 11 ++++++----- .../boot/test/autoconfigure/orm/jpa/schema.sql | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/test/resources/org/springframework/boot/test/autoconfigure/orm/jpa/schema.sql diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestSchemaCredentialsIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestSchemaCredentialsIntegrationTests.java index 8753dbcf07..1d5a1c1200 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestSchemaCredentialsIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestSchemaCredentialsIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import javax.sql.DataSource; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.TestPropertySource; +import org.springframework.jdbc.core.JdbcTemplate; import static org.assertj.core.api.Assertions.assertThat; @@ -31,9 +31,8 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Andy Wilkinson */ -@DataJpaTest -@TestPropertySource( - properties = { "spring.datasource.schema-username=alice", "spring.datasource.schema-password=secret" }) +@DataJpaTest(properties = { "spring.datasource.schema-username=alice", "spring.datasource.schema-password=secret", + "spring.datasource.schema=classpath:org/springframework/boot/test/autoconfigure/orm/jpa/schema.sql" }) class DataJpaTestSchemaCredentialsIntegrationTests { @Autowired @@ -43,6 +42,8 @@ class DataJpaTestSchemaCredentialsIntegrationTests { void replacesDefinedDataSourceWithEmbeddedDefault() throws Exception { String product = this.dataSource.getConnection().getMetaData().getDatabaseProductName(); assertThat(product).isEqualTo("H2"); + assertThat(new JdbcTemplate(this.dataSource).queryForList("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES", + String.class)).contains("EXAMPLE"); } } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/resources/org/springframework/boot/test/autoconfigure/orm/jpa/schema.sql b/spring-boot-project/spring-boot-test-autoconfigure/src/test/resources/org/springframework/boot/test/autoconfigure/orm/jpa/schema.sql new file mode 100644 index 0000000000..e22c8c94cc --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/resources/org/springframework/boot/test/autoconfigure/orm/jpa/schema.sql @@ -0,0 +1 @@ +CREATE TABLE example(identifier INT, name varchar(64));