diff --git a/core/build.gradle b/core/build.gradle index 3358eb32c..9e1f6338c 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -716,8 +716,6 @@ task registryToolIntegrationTest { // Dedicated test suite for schema-dependent tests. task sqlIntegrationTest(type: FilteringTest) { - systemProperties project.getProperties().subMap('sql_schema_resource_root') - excludeTestCases = false tests = ['google/registry/schema/integration/SqlIntegrationTestSuite.*'] } diff --git a/core/src/test/java/google/registry/model/transaction/JpaTransactionManagerRule.java b/core/src/test/java/google/registry/model/transaction/JpaTransactionManagerRule.java index cb98977ff..7fa1ffe41 100644 --- a/core/src/test/java/google/registry/model/transaction/JpaTransactionManagerRule.java +++ b/core/src/test/java/google/registry/model/transaction/JpaTransactionManagerRule.java @@ -18,7 +18,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.joda.time.DateTimeZone.UTC; import static org.testcontainers.containers.PostgreSQLContainer.POSTGRESQL_PORT; -import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Charsets; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -33,7 +32,6 @@ import google.registry.testing.FakeClock; import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; -import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.sql.Connection; @@ -45,7 +43,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Properties; import javax.persistence.EntityManagerFactory; import org.hibernate.cfg.Environment; @@ -63,19 +60,6 @@ import org.testcontainers.containers.PostgreSQLContainer; * TransactionManagerFactory} with the {@link JpaTransactionManagerImpl} generated by the rule * itself, so that all SQL queries will be sent to the database instance created by {@link * PostgreSQLContainer} to achieve test purpose. - * - *

The location of the Nomulus golden schema may be overridden with the {@code - * "sql_schema_resource_root} system property. This feature is needed by the server/schema - * compatibility tests, which need to use different versions of the schema off the classpath. - * - *

If defined, the value of the {@code "sql_schema_resource_root} should be an URL string that - * points to the jar or resource root directory. Here are some examples: - * - *

*/ public class JpaTransactionManagerRule extends ExternalResource { private static final String GOLDEN_SCHEMA_SQL_PATH = "sql/schema/nomulus.golden.sql"; @@ -84,11 +68,6 @@ public class JpaTransactionManagerRule extends ExternalResource { private static final String MANAGEMENT_DB_NAME = "management"; private static final String POSTGRES_DB_NAME = "postgres"; - // Name of the optional property that specifies the root path of the golden schema. - // TODO(weiminyu): revert this. The :integration project offers a better solution. - @VisibleForTesting - static final String GOLDEN_SCHEMA_RESOURCE_ROOT_PROP = "sql_schema_resource_root"; - private final DateTime now = DateTime.now(UTC); private final FakeClock clock = new FakeClock(now); private final String initScriptPath; @@ -126,7 +105,7 @@ public class JpaTransactionManagerRule extends ExternalResource { @Override public void before() throws Exception { executeSql(MANAGEMENT_DB_NAME, readSqlInClassPath(DB_CLEANUP_SQL_PATH)); - executeSql(POSTGRES_DB_NAME, readInitialScript()); + executeSql(POSTGRES_DB_NAME, readSqlInClassPath(initScriptPath)); if (!extraEntityClasses.isEmpty()) { File tempSqlFile = File.createTempFile("tempSqlFile", ".sql"); tempSqlFile.deleteOnExit(); @@ -197,38 +176,6 @@ public class JpaTransactionManagerRule extends ExternalResource { } } - @VisibleForTesting - Optional getInitScriptUrlOverride() { - String schemaRootPath = System.getProperty(GOLDEN_SCHEMA_RESOURCE_ROOT_PROP, "").trim(); - if (schemaRootPath.isEmpty() || !initScriptPath.equals(GOLDEN_SCHEMA_SQL_PATH)) { - return Optional.empty(); - } - if (schemaRootPath.startsWith("/")) { - schemaRootPath = "file://" + schemaRootPath; - } - if (schemaRootPath.endsWith(".jar") && !schemaRootPath.startsWith("jar:")) { - schemaRootPath = "jar:" + schemaRootPath; - } - if (schemaRootPath.endsWith(".jar")) { - schemaRootPath += "!/" + GOLDEN_SCHEMA_SQL_PATH; - } else { - schemaRootPath += "/" + GOLDEN_SCHEMA_SQL_PATH; - } - return Optional.of(schemaRootPath); - } - - private String readInitialScript() { - Optional schemaUrlOverride = getInitScriptUrlOverride(); - if (!schemaUrlOverride.isPresent()) { - return readSqlInClassPath(initScriptPath); - } - try { - return Resources.toString(new URL(schemaUrlOverride.get()), StandardCharsets.UTF_8); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - private void executeSql(String dbName, String sqlScript) { try (Connection conn = createConnection(dbName); Statement statement = conn.createStatement()) { diff --git a/core/src/test/java/google/registry/model/transaction/JpaTransactionManagerRuleTest.java b/core/src/test/java/google/registry/model/transaction/JpaTransactionManagerRuleTest.java index a045bc25b..5ca719707 100644 --- a/core/src/test/java/google/registry/model/transaction/JpaTransactionManagerRuleTest.java +++ b/core/src/test/java/google/registry/model/transaction/JpaTransactionManagerRuleTest.java @@ -15,13 +15,10 @@ package google.registry.model.transaction; import static com.google.common.truth.Truth.assertThat; -import static com.google.common.truth.Truth8.assertThat; -import static google.registry.model.transaction.JpaTransactionManagerRule.GOLDEN_SCHEMA_RESOURCE_ROOT_PROP; import static google.registry.model.transaction.TransactionManagerFactory.jpaTm; import static google.registry.testing.JUnitBackports.assertThrows; import google.registry.model.ImmutableObject; -import google.registry.testing.SystemPropertyRule; import java.util.List; import javax.persistence.Entity; import javax.persistence.Id; @@ -41,8 +38,6 @@ public class JpaTransactionManagerRuleTest { .withEntityClass(TestEntity.class) .build(); - @Rule public final SystemPropertyRule systemPropertyRule = new SystemPropertyRule(); - @Test public void verifiesRuleWorks() { assertThrows( @@ -78,58 +73,6 @@ public class JpaTransactionManagerRuleTest { assertThat(retrieved).isEqualTo(original); } - @Test - public void testInitScriptUrl_noOverride() { - systemPropertyRule.setProperty(GOLDEN_SCHEMA_RESOURCE_ROOT_PROP, null); - assertThat(jpaTmRule.getInitScriptUrlOverride()).isEmpty(); - } - - @Test - public void testInitScriptUrl_localDir_noProtocol() { - systemPropertyRule.setProperty(GOLDEN_SCHEMA_RESOURCE_ROOT_PROP, "/path/to/resources"); - assertThat(jpaTmRule.getInitScriptUrlOverride()) - .hasValue("file:///path/to/resources/sql/schema/nomulus.golden.sql"); - } - - @Test - public void testInitScriptUrl_localDir_hasProtocol() { - systemPropertyRule.setProperty(GOLDEN_SCHEMA_RESOURCE_ROOT_PROP, "file:///path/to/resources"); - assertThat(jpaTmRule.getInitScriptUrlOverride()) - .hasValue("file:///path/to/resources/sql/schema/nomulus.golden.sql"); - } - - @Test - public void testInitScriptUrl_localJar_noProtocol() { - systemPropertyRule.setProperty( - GOLDEN_SCHEMA_RESOURCE_ROOT_PROP, "/path/to/resources/schema.jar"); - assertThat(jpaTmRule.getInitScriptUrlOverride()) - .hasValue("jar:file:///path/to/resources/schema.jar!/sql/schema/nomulus.golden.sql"); - } - - @Test - public void testInitScriptUrl_localJar_hasPartialProtocol() { - systemPropertyRule.setProperty( - GOLDEN_SCHEMA_RESOURCE_ROOT_PROP, "file:///path/to/resources/schema.jar"); - assertThat(jpaTmRule.getInitScriptUrlOverride()) - .hasValue("jar:file:///path/to/resources/schema.jar!/sql/schema/nomulus.golden.sql"); - } - - @Test - public void testInitScriptUrl_localJar_hasFullProtocol() { - systemPropertyRule.setProperty( - GOLDEN_SCHEMA_RESOURCE_ROOT_PROP, "jar:file:///path/to/resources/schema.jar"); - assertThat(jpaTmRule.getInitScriptUrlOverride()) - .hasValue("jar:file:///path/to/resources/schema.jar!/sql/schema/nomulus.golden.sql"); - } - - @Test - public void testInitScriptUrl_remoteJar() { - systemPropertyRule.setProperty( - GOLDEN_SCHEMA_RESOURCE_ROOT_PROP, "http://host/path/to/resources/schema.jar"); - assertThat(jpaTmRule.getInitScriptUrlOverride()) - .hasValue("jar:http://host/path/to/resources/schema.jar!/sql/schema/nomulus.golden.sql"); - } - @Entity(name = "TestEntity") // Specify name to avoid nested class naming issues. static class TestEntity extends ImmutableObject { @Id String key;