From f4e09ae0caa4167c9c53714eb0d39eddb6c6c9af Mon Sep 17 00:00:00 2001 From: terrymanu Date: Fri, 4 May 2018 17:36:35 +0800 Subject: [PATCH] for #601: refactor collateData --- .../io/shardingjdbc/dbtest/StartTest.java | 41 ++++++------------- .../dbtest/config/bean/AssertsDefinition.java | 8 ++-- 2 files changed, 17 insertions(+), 32 deletions(-) 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 c9cb8d73f13f6..77447f7d7860b 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 @@ -18,12 +18,8 @@ package io.shardingjdbc.dbtest; import io.shardingjdbc.dbtest.asserts.AssertEngine; -import io.shardingjdbc.dbtest.config.bean.AssertDDLDefinition; -import io.shardingjdbc.dbtest.config.bean.AssertDMLDefinition; -import io.shardingjdbc.dbtest.config.bean.AssertDQLDefinition; import io.shardingjdbc.dbtest.config.bean.AssertDefinition; import io.shardingjdbc.dbtest.config.bean.AssertsDefinition; -import io.shardingjdbc.dbtest.exception.DbTestException; import io.shardingjdbc.dbtest.init.InItCreateSchema; import lombok.RequiredArgsConstructor; import org.junit.AfterClass; @@ -46,7 +42,6 @@ import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; import java.util.List; @@ -63,8 +58,6 @@ public final class StartTest { private static boolean isCleaned = IntegrateTestEnvironment.getInstance().isInitialized(); - private static final List RESULT_ASSERT = new ArrayList<>(); - private final String path; private final String id; @@ -73,21 +66,27 @@ public final class StartTest { public static Collection getParameters() throws IOException, JAXBException, URISyntaxException { URL integrateResources = StartTest.class.getClassLoader().getResource(INTEGRATION_RESOURCES_PATH); assertNotNull(integrateResources); + List result = new LinkedList<>(); for (String each : getAssertFiles(integrateResources)) { AssertsDefinition assertsDefinition = unmarshal(each); String[] dbs = assertsDefinition.getBaseConfig().split(","); for (String db : dbs) { InItCreateSchema.addDatabase(db); } - List assertDQLs = assertsDefinition.getAssertDQL(); - collateData(RESULT_ASSERT, each, assertDQLs); - List assertDMLs = assertsDefinition.getAssertDML(); - collateData(RESULT_ASSERT, each, assertDMLs); - List assertDDLs = assertsDefinition.getAssertDDL(); - collateData(RESULT_ASSERT, each, assertDDLs); + result.addAll(getParameters(each, assertsDefinition.getAssertDQL())); + result.addAll(getParameters(each, assertsDefinition.getAssertDML())); + result.addAll(getParameters(each, assertsDefinition.getAssertDDL())); AssertEngine.addAssertDefinition(each, assertsDefinition); } - return RESULT_ASSERT; + return result; + } + + private static Collection getParameters(final String path, final List asserts) { + Collection result = new LinkedList<>(); + for (AssertDefinition each : asserts) { + result.add(new String[] {path, each.getId()}); + } + return result; } private static List getAssertFiles(final URL integrateResources) throws IOException, URISyntaxException { @@ -112,20 +111,6 @@ private static AssertsDefinition unmarshal(final String assertFilePath) throws I } } - private static void collateData(final List result, final String path, final List asserts) { - if (asserts == null) { - return; - } - List assertDefinitions = new ArrayList<>(asserts.size()); - for (AssertDefinition each : asserts) { - if (assertDefinitions.contains(each.getId())) { - throw new DbTestException("ID can't be repeated"); - } - assertDefinitions.add(each.getId()); - result.add(new String[]{path, each.getId()}); - } - } - @BeforeClass public static void beforeClass() { if (isInitialized) { diff --git a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/config/bean/AssertsDefinition.java b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/config/bean/AssertsDefinition.java index e9ef2573d1804..ad0138e60715c 100644 --- a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/config/bean/AssertsDefinition.java +++ b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/config/bean/AssertsDefinition.java @@ -22,7 +22,7 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; @Getter @@ -45,12 +45,12 @@ public class AssertsDefinition { private String initDataFile; @XmlElement(name = "assertDQL") - private List assertDQL = new ArrayList<>(); + private List assertDQL = new LinkedList<>(); @XmlElement(name = "assertDML") - private List assertDML = new ArrayList<>(); + private List assertDML = new LinkedList<>(); @XmlElement(name = "assertDDL") - private List assertDDL = new ArrayList<>(); + private List assertDDL = new LinkedList<>(); }