From 497e3ddc588ecc49facfe38449efe652920662ef Mon Sep 17 00:00:00 2001 From: terrymanu Date: Thu, 3 May 2018 23:27:04 +0800 Subject: [PATCH] for #601: remove assert.path from env config --- .../dbtest/IntegrateTestEnvironment.java | 3 --- .../java/io/shardingjdbc/dbtest/StartTest.java | 12 ++++++++---- .../io/shardingjdbc/dbtest/common/PathUtil.java | 16 ++-------------- .../src/test/resources/integrate/env.properties | 1 - 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/IntegrateTestEnvironment.java b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/IntegrateTestEnvironment.java index 5b8f7b7873db9..3930fd10ace50 100644 --- a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/IntegrateTestEnvironment.java +++ b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/IntegrateTestEnvironment.java @@ -37,8 +37,6 @@ public final class IntegrateTestEnvironment { private final boolean initialized; - private final String assertPath; - private final Collection databaseTypes; private IntegrateTestEnvironment() { @@ -49,7 +47,6 @@ private IntegrateTestEnvironment() { ex.printStackTrace(); } initialized = Boolean.valueOf(prop.getProperty("initialized", Boolean.FALSE.toString())); - assertPath = prop.getProperty("assert.path"); databaseTypes = new LinkedList<>(); for (String each : prop.getProperty("databases", DatabaseType.H2.name()).split(",")) { databaseTypes.add(DatabaseType.valueOf(each.trim())); diff --git a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java index 37f306df3a5df..3795b6ed43c2e 100644 --- a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java +++ b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java @@ -19,7 +19,6 @@ import io.shardingjdbc.dbtest.asserts.AssertEngine; import io.shardingjdbc.dbtest.common.FileUtil; -import io.shardingjdbc.dbtest.common.PathUtil; import io.shardingjdbc.dbtest.config.AnalyzeConfig; import io.shardingjdbc.dbtest.config.bean.AssertDDLDefinition; import io.shardingjdbc.dbtest.config.bean.AssertDMLDefinition; @@ -40,14 +39,19 @@ import javax.xml.bind.JAXBException; import java.io.File; import java.io.IOException; +import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import static org.junit.Assert.assertNotNull; + @RunWith(Parameterized.class) @RequiredArgsConstructor public final class StartTest { + private static final String INTEGRATION_RESOURCES_PATH = "asserts"; + private static boolean isInitialized = IntegrateTestEnvironment.getInstance().isInitialized(); private static boolean isCleaned = IntegrateTestEnvironment.getInstance().isInitialized(); @@ -60,9 +64,9 @@ public final class StartTest { @Parameters(name = "{0} ({2}) -> {1}") public static Collection getParameters() throws IOException, JAXBException { - String assertPath = IntegrateTestEnvironment.getInstance().getAssertPath(); - assertPath = PathUtil.getPath(assertPath); - List paths = FileUtil.getAllFilePaths(new File(assertPath), "assert-", "xml"); + URL integrateResources = StartTest.class.getClassLoader().getResource(INTEGRATION_RESOURCES_PATH); + assertNotNull(integrateResources); + List paths = FileUtil.getAllFilePaths(new File(integrateResources.getPath()), "assert-", "xml"); for (String each : paths) { AssertsDefinition assertsDefinition = AnalyzeConfig.analyze(each); if (StringUtils.isNotBlank(assertsDefinition.getBaseConfig())) { diff --git a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/common/PathUtil.java b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/common/PathUtil.java index 4f28628702e0e..970c2fc15737b 100644 --- a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/common/PathUtil.java +++ b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/common/PathUtil.java @@ -21,7 +21,7 @@ public class PathUtil { - private static final String BASEPATH = PathUtil.class.getClassLoader().getResource("").getPath(); + private static final String BASE_PATH = PathUtil.class.getClassLoader().getResource("").getPath(); /** * Get the resource path. @@ -34,11 +34,10 @@ public static String getPath(final String path, final String parent) { if (path == null) { throw new DbTestException("The path cannot be empty"); } - String result = path; if (result.startsWith("classpath:")) { result = result.substring("classpath:".length()); - result = BASEPATH + result; + result = BASE_PATH + result; return result; } if (parent != null) { @@ -46,15 +45,4 @@ public static String getPath(final String path, final String parent) { } return result; } - - /** - * Get the resource path. - * - * @param path path - * @return path - */ - public static String getPath(final String path) { - return getPath(path, null); - } - } diff --git a/sharding-jdbc-core/src/test/resources/integrate/env.properties b/sharding-jdbc-core/src/test/resources/integrate/env.properties index bca0b65d822ab..07bbedf768d75 100644 --- a/sharding-jdbc-core/src/test/resources/integrate/env.properties +++ b/sharding-jdbc-core/src/test/resources/integrate/env.properties @@ -1,4 +1,3 @@ initialized=false -assert.path=classpath:asserts #databases=H2,MySQL,Oracle,SQLServer,PostgreSQL databases=H2