# IGNITE-32 Test suite.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/af0d2850 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/af0d2850 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/af0d2850 Branch: refs/heads/ignite-54-55 Commit: af0d2850fb5507d3aba2f17737c004ce392b4515 Parents: 01b79bb Author: AKuznetsov <akuznet...@gridgain.com> Authored: Thu Feb 5 09:15:16 2015 +0700 Committer: AKuznetsov <akuznet...@gridgain.com> Committed: Thu Feb 5 09:15:16 2015 +0700 ---------------------------------------------------------------------- .../schema/load/AbstractSchemaLoaderTest.java | 134 +++++++++++++++++++ .../schema/load/BaseSchemaLoaderSelfTest.java | 134 ------------------- .../load/generator/PojoGeneratorSelfTest.java | 70 ---------- .../load/generator/PojoGeneratorTest.java | 70 ++++++++++ .../load/generator/XmlGeneratorSelfTest.java | 50 ------- .../schema/load/generator/XmlGeneratorTest.java | 50 +++++++ .../load/parser/DbMetadataParserSelfTest.java | 118 ---------------- .../load/parser/DbMetadataParserTest.java | 118 ++++++++++++++++ .../testsuites/IgniteSchemaLoadTestSuite.java | 42 ++++++ 9 files changed, 414 insertions(+), 372 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/af0d2850/modules/schema-load/src/test/java/org/apache/ignite/schema/load/AbstractSchemaLoaderTest.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/test/java/org/apache/ignite/schema/load/AbstractSchemaLoaderTest.java b/modules/schema-load/src/test/java/org/apache/ignite/schema/load/AbstractSchemaLoaderTest.java new file mode 100644 index 0000000..1822b0e --- /dev/null +++ b/modules/schema-load/src/test/java/org/apache/ignite/schema/load/AbstractSchemaLoaderTest.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.schema.load; + +import junit.framework.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.schema.model.PojoDescriptor; +import org.apache.ignite.schema.parser.DatabaseMetadataParser; +import org.apache.ignite.schema.ui.*; + +import java.io.*; +import java.sql.*; +import java.util.List; + +import static org.apache.ignite.schema.ui.MessageBox.Result.*; + +/** + * Base functional for ignite-schema-loader tests. + */ +public abstract class AbstractSchemaLoaderTest extends TestCase { + /** DB connection URL. */ + private static final String CONN_URL = "jdbc:h2:mem:autoCacheStore;DB_CLOSE_DELAY=-1"; + + /** Path to temp folder where generated POJOs will be saved. */ + protected static final String OUT_DIR_PATH = System.getProperty("java.io.tmpdir") + "/ignite-schema-loader/out"; + + /** Auto confirmation of file conflicts. */ + protected ConfirmCallable askOverwrite = new ConfirmCallable(null, "") { + @Override public MessageBox.Result confirm(String msg) { + return YES_TO_ALL; + } + }; + + /** List of generated for test database POJO objects. */ + protected List<PojoDescriptor> pojos; + + /** {@inheritDoc} */ + @Override public void setUp() throws Exception { + Class.forName("org.h2.Driver"); + + Connection conn = DriverManager.getConnection(CONN_URL, "sa", ""); + + Statement stmt = conn.createStatement(); + + stmt.executeUpdate("CREATE TABLE PRIMITIVES (pk INTEGER PRIMARY KEY, " + + " boolCol BOOLEAN NOT NULL," + + " byteCol TINYINT NOT NULL," + + " shortCol SMALLINT NOT NULL," + + " intCol INTEGER NOT NULL, " + + " longCol BIGINT NOT NULL," + + " floatCol REAL NOT NULL," + + " doubleCol DOUBLE NOT NULL," + + " doubleCol2 DOUBLE NOT NULL, " + + " bigDecimalCol DECIMAL(10, 0)," + + " strCol VARCHAR(10)," + + " dateCol DATE," + + " timeCol TIME," + + " tsCol TIMESTAMP, " + + " arrCol BINARY(10))"); + + stmt.executeUpdate("CREATE TABLE OBJECTS (pk INTEGER PRIMARY KEY, " + + " boolCol BOOLEAN," + + " byteCol TINYINT," + + " shortCol SMALLINT," + + " intCol INTEGER," + + " longCol BIGINT," + + " floatCol REAL," + + " doubleCol DOUBLE," + + " doubleCol2 DOUBLE," + + " bigDecimalCol DECIMAL(10, 0)," + + " strCol VARCHAR(10), " + + " dateCol DATE," + + " timeCol TIME," + + " tsCol TIMESTAMP," + + " arrCol BINARY(10))"); + + conn.commit(); + + U.closeQuiet(stmt); + + pojos = DatabaseMetadataParser.parse(conn, false); + + U.closeQuiet(conn); + } + + /** + * Compare files by lines. + * + * @param exp Stream to read of expected file from test resources. + * @param generated Generated file instance. + * @param excludePtrn Marker string to exclude lines from comparing. + * @return true if generated file correspond to expected. + */ + protected boolean compareFilesInt(InputStream exp, File generated, String excludePtrn) { + try (BufferedReader baseReader = new BufferedReader(new InputStreamReader(exp))) { + try (BufferedReader generatedReader = new BufferedReader(new FileReader(generated))) { + String baseLine; + + while ((baseLine = baseReader.readLine()) != null) { + String generatedLine = generatedReader.readLine(); + + if (!baseLine.equals(generatedLine) && !baseLine.contains(excludePtrn) + && !generatedLine.contains(excludePtrn)) { + System.out.println("Expected: " + baseLine); + System.out.println("Generated: " + generatedLine); + + return false; + } + } + + return true; + } + } catch (IOException e) { + e.printStackTrace(); + + return false; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/af0d2850/modules/schema-load/src/test/java/org/apache/ignite/schema/load/BaseSchemaLoaderSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/test/java/org/apache/ignite/schema/load/BaseSchemaLoaderSelfTest.java b/modules/schema-load/src/test/java/org/apache/ignite/schema/load/BaseSchemaLoaderSelfTest.java deleted file mode 100644 index 1ce0e63..0000000 --- a/modules/schema-load/src/test/java/org/apache/ignite/schema/load/BaseSchemaLoaderSelfTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.schema.load; - -import junit.framework.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.schema.model.PojoDescriptor; -import org.apache.ignite.schema.parser.DatabaseMetadataParser; -import org.apache.ignite.schema.ui.*; - -import java.io.*; -import java.sql.*; -import java.util.List; - -import static org.apache.ignite.schema.ui.MessageBox.Result.*; - -/** - * Base functional for ignite-schema-loader tests. - */ -public class BaseSchemaLoaderSelfTest extends TestCase { - /** DB connection URL. */ - private static final String CONN_URL = "jdbc:h2:mem:autoCacheStore;DB_CLOSE_DELAY=-1"; - - /** Path to temp folder where generated POJOs will be saved. */ - protected static final String OUT_DIR_PATH = System.getProperty("java.io.tmpdir") + "/ignite-schema-loader/out"; - - /** Auto confirmation of file conflicts. */ - protected ConfirmCallable askOverwrite = new ConfirmCallable(null, "") { - @Override public MessageBox.Result confirm(String msg) { - return YES_TO_ALL; - } - }; - - /** List of generated for test database POJO objects. */ - protected List<PojoDescriptor> pojos; - - /** {@inheritDoc} */ - @Override public void setUp() throws Exception { - Class.forName("org.h2.Driver"); - - Connection conn = DriverManager.getConnection(CONN_URL, "sa", ""); - - Statement stmt = conn.createStatement(); - - stmt.executeUpdate("CREATE TABLE PRIMITIVES (pk INTEGER PRIMARY KEY, " + - " boolCol BOOLEAN NOT NULL," + - " byteCol TINYINT NOT NULL," + - " shortCol SMALLINT NOT NULL," + - " intCol INTEGER NOT NULL, " + - " longCol BIGINT NOT NULL," + - " floatCol REAL NOT NULL," + - " doubleCol DOUBLE NOT NULL," + - " doubleCol2 DOUBLE NOT NULL, " + - " bigDecimalCol DECIMAL(10, 0)," + - " strCol VARCHAR(10)," + - " dateCol DATE," + - " timeCol TIME," + - " tsCol TIMESTAMP, " + - " arrCol BINARY(10))"); - - stmt.executeUpdate("CREATE TABLE OBJECTS (pk INTEGER PRIMARY KEY, " + - " boolCol BOOLEAN," + - " byteCol TINYINT," + - " shortCol SMALLINT," + - " intCol INTEGER," + - " longCol BIGINT," + - " floatCol REAL," + - " doubleCol DOUBLE," + - " doubleCol2 DOUBLE," + - " bigDecimalCol DECIMAL(10, 0)," + - " strCol VARCHAR(10), " + - " dateCol DATE," + - " timeCol TIME," + - " tsCol TIMESTAMP," + - " arrCol BINARY(10))"); - - conn.commit(); - - U.closeQuiet(stmt); - - pojos = DatabaseMetadataParser.parse(conn, false); - - U.closeQuiet(conn); - } - - /** - * Compare files by lines. - * - * @param exp Stream to read of expected file from test resources. - * @param generated Generated file instance. - * @param excludePtrn Marker string to exclude lines from comparing. - * @return true if generated file correspond to expected. - */ - protected boolean compareFilesInt(InputStream exp, File generated, String excludePtrn) { - try (BufferedReader baseReader = new BufferedReader(new InputStreamReader(exp))) { - try (BufferedReader generatedReader = new BufferedReader(new FileReader(generated))) { - String baseLine; - - while ((baseLine = baseReader.readLine()) != null) { - String generatedLine = generatedReader.readLine(); - - if (!baseLine.equals(generatedLine) && !baseLine.contains(excludePtrn) - && !generatedLine.contains(excludePtrn)) { - System.out.println("Expected: " + baseLine); - System.out.println("Generated: " + generatedLine); - - return false; - } - } - - return true; - } - } catch (IOException e) { - e.printStackTrace(); - - return false; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/af0d2850/modules/schema-load/src/test/java/org/apache/ignite/schema/load/generator/PojoGeneratorSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/test/java/org/apache/ignite/schema/load/generator/PojoGeneratorSelfTest.java b/modules/schema-load/src/test/java/org/apache/ignite/schema/load/generator/PojoGeneratorSelfTest.java deleted file mode 100644 index af30c62..0000000 --- a/modules/schema-load/src/test/java/org/apache/ignite/schema/load/generator/PojoGeneratorSelfTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.schema.load.generator; - -import org.apache.ignite.schema.generator.PojoGenerator; -import org.apache.ignite.schema.load.BaseSchemaLoaderSelfTest; -import org.apache.ignite.schema.model.PojoDescriptor; - -import java.io.File; - -/** - * Tests for POJO generator. - */ -public class PojoGeneratorSelfTest extends BaseSchemaLoaderSelfTest { - /** Marker string to skip date generation while comparing.*/ - private static final String GEN_PTRN = "Code generated by Apache Ignite Schema Load utility"; - - /** - * Test that POJOs generated correctly. - */ - public void testPojoGeneration() throws Exception { - String pkg = "org.apache.ignite.schema.load.model"; - String intPath = "org/apache/ignite/schema/load/model"; - - Boolean containsSchema = false; - - for (PojoDescriptor pojo : pojos) { - if (pojo.valueClassName().isEmpty()) - containsSchema = true; - else { - PojoGenerator.generate(pojo, OUT_DIR_PATH, pkg, true, true, askOverwrite); - - assertTrue("Generated key class POJO content is differ from expected for type " + pojo.keyClassName(), - compareFiles(pojo.keyClassName(), intPath, GEN_PTRN)); - - assertTrue("Generated value class POJO content is differ from expected for type " + pojo.valueClassName(), - compareFiles(pojo.valueClassName(), intPath, GEN_PTRN)); - } - } - - assertTrue("Generated POJOs does not contains schema.", containsSchema); - } - - /** - * @param typeName Type name. - * @param intPath Int path. - * @return {@code true} if generated POJO as expected. - */ - private boolean compareFiles(String typeName, String intPath, String excludePtrn) { - String relPath = intPath + "/" + typeName; - - return compareFilesInt(getClass().getResourceAsStream("/" + relPath + ".txt"), - new File(OUT_DIR_PATH + "/" + relPath + ".java"), excludePtrn); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/af0d2850/modules/schema-load/src/test/java/org/apache/ignite/schema/load/generator/PojoGeneratorTest.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/test/java/org/apache/ignite/schema/load/generator/PojoGeneratorTest.java b/modules/schema-load/src/test/java/org/apache/ignite/schema/load/generator/PojoGeneratorTest.java new file mode 100644 index 0000000..3162290 --- /dev/null +++ b/modules/schema-load/src/test/java/org/apache/ignite/schema/load/generator/PojoGeneratorTest.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.schema.load.generator; + +import org.apache.ignite.schema.generator.PojoGenerator; +import org.apache.ignite.schema.load.AbstractSchemaLoaderTest; +import org.apache.ignite.schema.model.PojoDescriptor; + +import java.io.File; + +/** + * Tests for POJO generator. + */ +public class PojoGeneratorTest extends AbstractSchemaLoaderTest { + /** Marker string to skip date generation while comparing.*/ + private static final String GEN_PTRN = "Code generated by Apache Ignite Schema Load utility"; + + /** + * Test that POJOs generated correctly. + */ + public void testPojoGeneration() throws Exception { + String pkg = "org.apache.ignite.schema.load.model"; + String intPath = "org/apache/ignite/schema/load/model"; + + Boolean containsSchema = false; + + for (PojoDescriptor pojo : pojos) { + if (pojo.valueClassName().isEmpty()) + containsSchema = true; + else { + PojoGenerator.generate(pojo, OUT_DIR_PATH, pkg, true, true, askOverwrite); + + assertTrue("Generated key class POJO content is differ from expected for type " + pojo.keyClassName(), + compareFiles(pojo.keyClassName(), intPath, GEN_PTRN)); + + assertTrue("Generated value class POJO content is differ from expected for type " + pojo.valueClassName(), + compareFiles(pojo.valueClassName(), intPath, GEN_PTRN)); + } + } + + assertTrue("Generated POJOs does not contains schema.", containsSchema); + } + + /** + * @param typeName Type name. + * @param intPath Internal path. + * @return {@code true} if generated POJO as expected. + */ + private boolean compareFiles(String typeName, String intPath, String excludePtrn) { + String relPath = intPath + "/" + typeName; + + return compareFilesInt(getClass().getResourceAsStream("/" + relPath + ".txt"), + new File(OUT_DIR_PATH + "/" + relPath + ".java"), excludePtrn); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/af0d2850/modules/schema-load/src/test/java/org/apache/ignite/schema/load/generator/XmlGeneratorSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/test/java/org/apache/ignite/schema/load/generator/XmlGeneratorSelfTest.java b/modules/schema-load/src/test/java/org/apache/ignite/schema/load/generator/XmlGeneratorSelfTest.java deleted file mode 100644 index 93022dc..0000000 --- a/modules/schema-load/src/test/java/org/apache/ignite/schema/load/generator/XmlGeneratorSelfTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.schema.load.generator; - -import org.apache.ignite.schema.generator.*; -import org.apache.ignite.schema.load.*; -import org.apache.ignite.schema.model.*; - -import java.io.*; -import java.util.*; - -/** - * Tests for XML generator. - */ -public class XmlGeneratorSelfTest extends BaseSchemaLoaderSelfTest { - /** - * Test that XML generated correctly. - */ - public void testXmlGeneration() throws Exception { - Collection<PojoDescriptor> all = new ArrayList<>(); - - for (PojoDescriptor pojo : pojos) - if (pojo.parent() != null) - all.add(pojo); - - String fileName = "Ignite.xml"; - - XmlGenerator.generate("org.apache.ignite.schema.load.model", all, true, new File(OUT_DIR_PATH, fileName), - askOverwrite); - - assertTrue("Generated XML file content is differ from expected one", - compareFilesInt(getClass().getResourceAsStream("/org/apache/ignite/schema/load/model/" + fileName), - new File(OUT_DIR_PATH + "/" + fileName), "XML generated by Apache Ignite Schema Load utility")); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/af0d2850/modules/schema-load/src/test/java/org/apache/ignite/schema/load/generator/XmlGeneratorTest.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/test/java/org/apache/ignite/schema/load/generator/XmlGeneratorTest.java b/modules/schema-load/src/test/java/org/apache/ignite/schema/load/generator/XmlGeneratorTest.java new file mode 100644 index 0000000..027f64f --- /dev/null +++ b/modules/schema-load/src/test/java/org/apache/ignite/schema/load/generator/XmlGeneratorTest.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.schema.load.generator; + +import org.apache.ignite.schema.generator.*; +import org.apache.ignite.schema.load.*; +import org.apache.ignite.schema.model.*; + +import java.io.*; +import java.util.*; + +/** + * Tests for XML generator. + */ +public class XmlGeneratorTest extends AbstractSchemaLoaderTest { + /** + * Test that XML generated correctly. + */ + public void testXmlGeneration() throws Exception { + Collection<PojoDescriptor> all = new ArrayList<>(); + + for (PojoDescriptor pojo : pojos) + if (pojo.parent() != null) + all.add(pojo); + + String fileName = "Ignite.xml"; + + XmlGenerator.generate("org.apache.ignite.schema.load.model", all, true, new File(OUT_DIR_PATH, fileName), + askOverwrite); + + assertTrue("Generated XML file content is differ from expected one", + compareFilesInt(getClass().getResourceAsStream("/org/apache/ignite/schema/load/model/" + fileName), + new File(OUT_DIR_PATH + "/" + fileName), "XML generated by Apache Ignite Schema Load utility")); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/af0d2850/modules/schema-load/src/test/java/org/apache/ignite/schema/load/parser/DbMetadataParserSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/test/java/org/apache/ignite/schema/load/parser/DbMetadataParserSelfTest.java b/modules/schema-load/src/test/java/org/apache/ignite/schema/load/parser/DbMetadataParserSelfTest.java deleted file mode 100644 index 024a411..0000000 --- a/modules/schema-load/src/test/java/org/apache/ignite/schema/load/parser/DbMetadataParserSelfTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.schema.load.parser; - -import org.apache.ignite.schema.load.*; -import org.apache.ignite.schema.model.*; - -import java.math.*; -import java.sql.Date; -import java.sql.*; -import java.util.*; - -/** - * Tests for metadata parsing. - */ -public class DbMetadataParserSelfTest extends BaseSchemaLoaderSelfTest { - /** - * Check that field is correspond to expected. - * - * @param field Field descriptor. - * @param name Expected field name. - * @param primitive Expected field primitive type. - * @param cls Expected field type. - */ - private void checkField(PojoField field, String name, boolean primitive, Class<?> cls) { - assertEquals("Name of field should be " + name, name, field.javaName()); - - assertEquals("Type of field should be " + cls.getName(), cls.getName(), field.javaTypeName()); - - assertEquals("Field primitive should be " + primitive, primitive, field.primitive()); - } - - /** - * Check that type is correspond to expected. - * - * @param type Type descriptor. - */ - private void checkType(PojoDescriptor type) { - assertFalse("Type key class name should be defined", type.keyClassName().isEmpty()); - - assertFalse("Type value class name should be defined", type.valueClassName().isEmpty()); - - Collection<PojoField> keyFields = type.keyFields(); - - assertEquals("Key type should have 1 field", 1, keyFields.size()); - - checkField(keyFields.iterator().next(), "pk", true, int.class); - - List<PojoField> fields = type.fields(); - - assertEquals("Value type should have 15 fields", 15, fields.size()); - - Iterator<PojoField> fieldsIt = fields.iterator(); - - checkField(fieldsIt.next(), "pk", true, int.class); - - if ("Objects".equals(type.valueClassName())) { - checkField(fieldsIt.next(), "boolcol", false, Boolean.class); - checkField(fieldsIt.next(), "bytecol", false, Byte.class); - checkField(fieldsIt.next(), "shortcol", false, Short.class); - checkField(fieldsIt.next(), "intcol", false, Integer.class); - checkField(fieldsIt.next(), "longcol", false, Long.class); - checkField(fieldsIt.next(), "floatcol", false, Float.class); - checkField(fieldsIt.next(), "doublecol", false, Double.class); - checkField(fieldsIt.next(), "doublecol2", false, Double.class); - } - else { - checkField(fieldsIt.next(), "boolcol", true, boolean.class); - checkField(fieldsIt.next(), "bytecol", true, byte.class); - checkField(fieldsIt.next(), "shortcol", true, short.class); - checkField(fieldsIt.next(), "intcol", true, int.class); - checkField(fieldsIt.next(), "longcol", true, long.class); - checkField(fieldsIt.next(), "floatcol", true, float.class); - checkField(fieldsIt.next(), "doublecol", true, double.class); - checkField(fieldsIt.next(), "doublecol2", true, double.class); - } - - checkField(fieldsIt.next(), "bigdecimalcol", false, BigDecimal.class); - checkField(fieldsIt.next(), "strcol", false, String.class); - checkField(fieldsIt.next(), "datecol", false, Date.class); - checkField(fieldsIt.next(), "timecol", false, Time.class); - checkField(fieldsIt.next(), "tscol", false, Timestamp.class); - checkField(fieldsIt.next(), "arrcol", false, Object.class); - } - - /** - * Test that metadata generated correctly. - */ - public void testCheckMetadata() { - assertEquals("Metadata should contain 3 element", 3, pojos.size()); - - Iterator<PojoDescriptor> it = pojos.iterator(); - - PojoDescriptor schema = it.next(); - - assertTrue("First element is schema description. Its class name should be empty", - schema.valueClassName().isEmpty()); - - checkType(it.next()); - - checkType(it.next()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/af0d2850/modules/schema-load/src/test/java/org/apache/ignite/schema/load/parser/DbMetadataParserTest.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/test/java/org/apache/ignite/schema/load/parser/DbMetadataParserTest.java b/modules/schema-load/src/test/java/org/apache/ignite/schema/load/parser/DbMetadataParserTest.java new file mode 100644 index 0000000..aaec75c --- /dev/null +++ b/modules/schema-load/src/test/java/org/apache/ignite/schema/load/parser/DbMetadataParserTest.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.schema.load.parser; + +import org.apache.ignite.schema.load.*; +import org.apache.ignite.schema.model.*; + +import java.math.*; +import java.sql.Date; +import java.sql.*; +import java.util.*; + +/** + * Tests for metadata parsing. + */ +public class DbMetadataParserTest extends AbstractSchemaLoaderTest { + /** + * Check that field is correspond to expected. + * + * @param field Field descriptor. + * @param name Expected field name. + * @param primitive Expected field primitive type. + * @param cls Expected field type. + */ + private void checkField(PojoField field, String name, boolean primitive, Class<?> cls) { + assertEquals("Name of field should be " + name, name, field.javaName()); + + assertEquals("Type of field should be " + cls.getName(), cls.getName(), field.javaTypeName()); + + assertEquals("Field primitive should be " + primitive, primitive, field.primitive()); + } + + /** + * Check that type is correspond to expected. + * + * @param type Type descriptor. + */ + private void checkType(PojoDescriptor type) { + assertFalse("Type key class name should be defined", type.keyClassName().isEmpty()); + + assertFalse("Type value class name should be defined", type.valueClassName().isEmpty()); + + Collection<PojoField> keyFields = type.keyFields(); + + assertEquals("Key type should have 1 field", 1, keyFields.size()); + + checkField(keyFields.iterator().next(), "pk", true, int.class); + + List<PojoField> fields = type.fields(); + + assertEquals("Value type should have 15 fields", 15, fields.size()); + + Iterator<PojoField> fieldsIt = fields.iterator(); + + checkField(fieldsIt.next(), "pk", true, int.class); + + if ("Objects".equals(type.valueClassName())) { + checkField(fieldsIt.next(), "boolcol", false, Boolean.class); + checkField(fieldsIt.next(), "bytecol", false, Byte.class); + checkField(fieldsIt.next(), "shortcol", false, Short.class); + checkField(fieldsIt.next(), "intcol", false, Integer.class); + checkField(fieldsIt.next(), "longcol", false, Long.class); + checkField(fieldsIt.next(), "floatcol", false, Float.class); + checkField(fieldsIt.next(), "doublecol", false, Double.class); + checkField(fieldsIt.next(), "doublecol2", false, Double.class); + } + else { + checkField(fieldsIt.next(), "boolcol", true, boolean.class); + checkField(fieldsIt.next(), "bytecol", true, byte.class); + checkField(fieldsIt.next(), "shortcol", true, short.class); + checkField(fieldsIt.next(), "intcol", true, int.class); + checkField(fieldsIt.next(), "longcol", true, long.class); + checkField(fieldsIt.next(), "floatcol", true, float.class); + checkField(fieldsIt.next(), "doublecol", true, double.class); + checkField(fieldsIt.next(), "doublecol2", true, double.class); + } + + checkField(fieldsIt.next(), "bigdecimalcol", false, BigDecimal.class); + checkField(fieldsIt.next(), "strcol", false, String.class); + checkField(fieldsIt.next(), "datecol", false, Date.class); + checkField(fieldsIt.next(), "timecol", false, Time.class); + checkField(fieldsIt.next(), "tscol", false, Timestamp.class); + checkField(fieldsIt.next(), "arrcol", false, Object.class); + } + + /** + * Test that metadata generated correctly. + */ + public void testCheckMetadata() { + assertEquals("Metadata should contain 3 element", 3, pojos.size()); + + Iterator<PojoDescriptor> it = pojos.iterator(); + + PojoDescriptor schema = it.next(); + + assertTrue("First element is schema description. Its class name should be empty", + schema.valueClassName().isEmpty()); + + checkType(it.next()); + + checkType(it.next()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/af0d2850/modules/schema-load/src/test/java/org/apache/ignite/schema/load/testsuites/IgniteSchemaLoadTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/test/java/org/apache/ignite/schema/load/testsuites/IgniteSchemaLoadTestSuite.java b/modules/schema-load/src/test/java/org/apache/ignite/schema/load/testsuites/IgniteSchemaLoadTestSuite.java new file mode 100644 index 0000000..26c90c1 --- /dev/null +++ b/modules/schema-load/src/test/java/org/apache/ignite/schema/load/testsuites/IgniteSchemaLoadTestSuite.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.schema.load.testsuites; + +import junit.framework.*; +import org.apache.ignite.schema.load.generator.*; +import org.apache.ignite.schema.load.parser.*; + +/** + * Ignite Schema Load Utility Tests. + */ +public class IgniteSchemaLoadTestSuite { + /** + * @return Test suite. + * @throws Exception Thrown in case of the failure. + */ + public static TestSuite suite() throws Exception { + TestSuite suite = new TestSuite("Ignite Apache Schema Load Utility Test Suite"); + + suite.addTestSuite(PojoGeneratorTest.class); + suite.addTestSuite(XmlGeneratorTest.class); + suite.addTestSuite(DbMetadataParserTest.class); + + return suite; + } + +}