ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [4/5] incubator-ignite git commit: # IGNITE-330 Generate snippets classes.
Date Fri, 20 Mar 2015 19:25:14 GMT
# IGNITE-330 Generate snippets classes.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/c493225f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/c493225f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/c493225f

Branch: refs/heads/ignite-45
Commit: c493225f8314af823c416e14b4a89a2d8fd4ebfb
Parents: 7676613
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Sat Mar 21 02:17:11 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Sat Mar 21 02:17:11 2015 +0700

----------------------------------------------------------------------
 .../ignite/schema/generator/CodeGenerator.java  | 581 +++++++++++++++++++
 .../ignite/schema/generator/PojoGenerator.java  | 414 -------------
 .../schema/generator/SnippetGenerator.java      | 144 -----
 .../ignite/schema/ui/SchemaImportApp.java       |   4 +-
 .../test/generator/CodeGeneratorTest.java       |  70 +++
 .../test/generator/PojoGeneratorTest.java       |  70 ---
 .../testsuites/IgniteSchemaImportTestSuite.java |   2 +-
 7 files changed, 654 insertions(+), 631 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c493225f/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
new file mode 100644
index 0000000..29e0824
--- /dev/null
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
@@ -0,0 +1,581 @@
+/*
+ * 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.generator;
+
+import org.apache.ignite.schema.model.*;
+import org.apache.ignite.schema.ui.*;
+
+import java.io.*;
+import java.text.*;
+import java.util.*;
+
+import static org.apache.ignite.schema.ui.MessageBox.Result.*;
+
+/**
+ * Code generator of POJOs for key and value classes and configuration snippets.
+ */
+public class CodeGenerator {
+    /** */
+    private static final String TAB = "    ";
+    /** */
+    private static final String TAB2 = TAB + TAB;
+    /** */
+    private static final String TAB3 = TAB + TAB + TAB;
+
+    /**
+     * Add line to source code without indent.
+     *
+     * @param src Source code.
+     * @param line Code line.
+     */
+    private static void add0(Collection<String> src, String line) {
+        src.add(line);
+    }
+
+    /**
+     * Add line to source code with one indent.
+     *
+     * @param src Source code.
+     * @param line Code line.
+     */
+    private static void add1(Collection<String> src, String line) {
+        src.add(TAB + line);
+    }
+
+    /**
+     * Add line to source code with two indents.
+     *
+     * @param src Source code.
+     * @param line Code line.
+     */
+    private static void add2(Collection<String> src, String line) {
+        src.add(TAB2 + line);
+    }
+
+    /**
+     * Add line to source code with two indents.
+     *
+     * @param src Source code.
+     * @param fmt Code line with format placeholders.
+     * @param args Format arguments.
+     */
+    private static void add2Fmt(Collection<String> src, String fmt, Object... args) {
+        add2(src, String.format(fmt, args));
+    }
+
+    /**
+     * Add line to source code with three indents.
+     *
+     * @param src Source code.
+     * @param line Code line.
+     */
+    private static void add3(Collection<String> src, String line) {
+        src.add(TAB3 + line);
+    }
+
+    /**
+     * @param str Source string.
+     * @return String with first letters in upper case.
+     */
+    private static String capitalizeFirst(String str) {
+        return Character.toUpperCase(str.charAt(0)) + str.substring(1);
+    }
+
+    /**
+     * @param field POJO field descriptor.
+     * @return Field java type name.
+     */
+    private static String javaTypeName(PojoField field) {
+        String javaTypeName = field.javaTypeName();
+
+        return javaTypeName.startsWith("java.lang.") ? javaTypeName.substring(10) : javaTypeName;
+    }
+
+    /**
+     * Generate class header.
+     *
+     * @param src Source code.
+     * @param pkg Package name.
+     * @param imports Optional imports.
+     * @param desc Class description.
+     * @param cls Class declaration.
+     */
+    private static void header(Collection<String> src, String pkg, String imports, String desc, String cls) {
+        // License.
+        add0(src, "/*");
+        add0(src, " * Licensed to the Apache Software Foundation (ASF) under one or more");
+        add0(src, " * contributor license agreements.  See the NOTICE file distributed with");
+        add0(src, " * this work for additional information regarding copyright ownership.");
+        add0(src, " * The ASF licenses this file to You under the Apache License, Version 2.0");
+        add0(src, " * (the \"License\"); you may not use this file except in compliance with");
+        add0(src, " * the License.  You may obtain a copy of the License at");
+        add0(src, " *");
+        add0(src, " *      http://www.apache.org/licenses/LICENSE-2.0");
+        add0(src, " *");
+        add0(src, " * Unless required by applicable law or agreed to in writing, software");
+        add0(src, " * distributed under the License is distributed on an \"AS IS\" BASIS,");
+        add0(src, " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
+        add0(src, " * See the License for the specific language governing permissions and");
+        add0(src, " * limitations under the License.");
+        add0(src, " */");
+        add0(src, "");
+
+        // Package.
+        add0(src, "package " + pkg + ";");
+        add0(src, "");
+
+        // Imports.
+        if (!imports.isEmpty()) {
+            for (String imp : imports.split(";"))
+                if (imp.isEmpty())
+                    add0(src, "");
+                else
+                    add0(src, "import " + imp + ";");
+
+            add0(src, "");
+        }
+
+        // Class.
+        add0(src, "/**");
+        add0(src, " * " + desc + " definition.");
+        add0(src, " *");
+        add0(src, " * Code generated by Apache Ignite Schema Import utility: "
+            + new SimpleDateFormat("MM/dd/yyyy").format(new Date()) + ".");
+        add0(src, " */");
+        add0(src, "public class " + cls + " {");
+    }
+
+    /**
+     * Write source code to file.
+     *
+     * @param src Source code.
+     * @param out Target file.
+     * @throws IOException If failed to write source code to file.
+     */
+    private static void write(Collection<String> src, File out) throws IOException {
+        // Write generated code to file.
+        try (Writer writer = new BufferedWriter(new FileWriter(out))) {
+            for (String line : src)
+                writer.write(line + '\n');
+        }
+    }
+
+    /**
+     * Generate java class code.
+     *
+     * @param pojo POJO descriptor.
+     * @param key {@code true} if key class should be generated.
+     * @param pkg Package name.
+     * @param pkgFolder Folder where to save generated class.
+     * @param constructor {@code true} if empty and full constructors should be generated.
+     * @param includeKeys {@code true} if key fields should be included into value class.
+     * @param askOverwrite Callback to ask user to confirm file overwrite.
+     * @throws IOException If failed to write generated code into file.
+     */
+    private static void generateCode(PojoDescriptor pojo, boolean key, String pkg, File pkgFolder,
+        boolean constructor, boolean includeKeys, ConfirmCallable askOverwrite) throws IOException {
+        String type = key ? pojo.keyClassName() : pojo.valueClassName();
+
+        File out = new File(pkgFolder, type + ".java");
+
+        if (out.exists()) {
+            MessageBox.Result choice = askOverwrite.confirm(out.getName());
+
+            if (CANCEL == choice)
+                throw new IllegalStateException("POJO generation was canceled!");
+
+            if (NO == choice || NO_TO_ALL == choice)
+                return;
+        }
+
+        Collection<String> src = new ArrayList<>(256);
+
+        header(src, pkg, "java.io.*", type, type + " implements Serializable");
+
+        add1(src, "/** */");
+        add1(src, "private static final long serialVersionUID = 0L;");
+        add0(src, "");
+
+        Collection<PojoField> fields = key ? pojo.keyFields() : pojo.valueFields(includeKeys);
+
+        // Generate fields declaration.
+        for (PojoField field : fields) {
+            String fldName = field.javaName();
+
+            add1(src, "/** Value for " + fldName + ". */");
+
+            if (key && field.affinityKey())
+                add1(src, "@CacheAffinityKeyMapped");
+
+            add1(src, "private " + javaTypeName(field) + " " + fldName + ";");
+            add0(src, "");
+        }
+
+        // Generate constructors.
+        if (constructor) {
+            add1(src, "/**");
+            add1(src, " * Empty constructor.");
+            add1(src, " */");
+            add1(src, "public " + type + "() {");
+            add2(src, "// No-op.");
+            add1(src, "}");
+
+            add0(src, "");
+
+            add1(src, "/**");
+            add1(src, " * Full constructor.");
+            add1(src, " */");
+            add1(src, "public " + type + "(");
+
+            Iterator<PojoField> it = fields.iterator();
+
+            while (it.hasNext()) {
+                PojoField field = it.next();
+
+                add2(src, javaTypeName(field) + " " + field.javaName() + (it.hasNext() ? "," : ""));
+            }
+            add1(src, ") {");
+
+            for (PojoField field : fields)
+                add2Fmt(src, "this.%1$s = %1$s;", field.javaName());
+
+            add1(src, "}");
+            add0(src, "");
+        }
+
+        // Generate getters and setters methods.
+        for (PojoField field : fields) {
+            String fldName = field.javaName();
+
+            String fldType = javaTypeName(field);
+
+            String mtdName = capitalizeFirst(fldName);
+
+            add1(src, "/**");
+            add1(src, " * Gets " + fldName + ".");
+            add1(src, " *");
+            add1(src, " * @return Value for " + fldName + ".");
+            add1(src, " */");
+            add1(src, "public " + fldType + " get" + mtdName + "() {");
+            add2(src, "return " + fldName + ";");
+            add1(src, "}");
+            add0(src, "");
+
+            add1(src, "/**");
+            add1(src, " * Sets " + fldName + ".");
+            add1(src, " *");
+            add1(src, " * @param " + fldName + " New value for " + fldName + ".");
+            add1(src, " */");
+            add1(src, "public void set" + mtdName + "(" + fldType + " " + fldName + ") {");
+            add2(src, "this." + fldName + " = " + fldName + ";");
+            add1(src, "}");
+            add0(src, "");
+        }
+
+        // Generate equals() method.
+        add1(src, "/** {@inheritDoc} */");
+        add1(src, "@Override public boolean equals(Object o) {");
+        add2(src, "if (this == o)");
+        add3(src, "return true;");
+        add0(src, "");
+
+        add2(src, "if (!(o instanceof " + type + "))");
+        add3(src, "return false;");
+        add0(src, "");
+
+        add2Fmt(src, "%1$s that = (%1$s)o;", type);
+
+        for (PojoField field : fields) {
+            add0(src, "");
+
+            String javaName = field.javaName();
+
+            if (field.primitive()) {
+                switch (field.javaTypeName()) {
+                    case "float":
+                        add2Fmt(src, "if (Float.compare(%1$s, that.%1$s) != 0)", javaName);
+                        break;
+
+                    case "double":
+                        add2Fmt(src, "if (Double.compare(%1$s, that.%1$s) != 0)", javaName);
+                        break;
+
+                    default:
+                        add2Fmt(src, "if (%1$s != that.%1$s)", javaName);
+                }
+            }
+            else
+                add2Fmt(src, "if (%1$s != null ? !%1$s.equals(that.%1$s) : that.%1$s != null)", javaName);
+
+            add3(src, "return false;");
+        }
+
+        add0(src, "");
+        add2(src, "return true;");
+        add1(src, "}");
+        add0(src, "");
+
+        // Generate hashCode() method.
+        add1(src, "/** {@inheritDoc} */");
+        add1(src, "@Override public int hashCode() {");
+
+        List<String> hash = new ArrayList<>(fields.size() * 2);
+
+        boolean first = true;
+        boolean tempVar = false;
+
+        for (PojoField field : fields) {
+            String javaName = field.javaName();
+
+            if (!first)
+                add0(hash, "");
+
+            if (field.primitive()) {
+                switch (field.javaTypeName()) {
+                    case "boolean":
+                        add2Fmt(hash, first ? "int res = %s ? 1 : 0;" : "res = 31 * res + (%s ? 1 : 0);", javaName);
+                        break;
+
+                    case "byte":
+                    case "short":
+                        add2Fmt(hash, first ? "int res = (int)%s;" : "res = 31 * res + (int)%s;", javaName);
+                        break;
+
+                    case "int":
+                        add2Fmt(hash, first ? "int res = %s;" : "res = 31 * res + %s;", javaName);
+                        break;
+
+                    case "long":
+                        add2Fmt(hash, first
+                            ? "int res = (int)(%1$s ^ (%1$s >>> 32));"
+                            : "res = 31 * res + (int)(%1$s ^ (%1$s >>> 32));", javaName);
+                        break;
+
+                    case "float":
+                        add2Fmt(hash, first
+                            ? "int res = %1$s != +0.0f ? Float.floatToIntBits(%1$s) : 0;"
+                            : "res = 31 * res + (%1$s != +0.0f ? Float.floatToIntBits(%1$s) : 0);", javaName);
+                        break;
+
+                    case "double":
+                        add2Fmt(hash, (tempVar ? "ig_hash_temp" : "long ig_hash_temp") +
+                            " = Double.doubleToLongBits(%s);", javaName);
+
+                        add0(hash, "");
+
+                        add2Fmt(hash, first
+                            ? "int res = (int)(ig_hash_temp ^ (ig_hash_temp >>> 32));"
+                            : "res = 31 * res + (int)(ig_hash_temp ^ (ig_hash_temp >>> 32));", javaName);
+
+                        tempVar = true;
+                        break;
+                }
+            }
+            else
+                add2Fmt(hash, first ? "int res = %1$s != null ? %1$s.hashCode() : 0;"
+                    : "res = 31 * res + (%1$s != null ? %1$s.hashCode() : 0);", javaName);
+
+            first = false;
+        }
+
+        for (String line : hash)
+            add0(src, line);
+
+        add0(src, "");
+        add2(src, "return res;");
+        add1(src, "}");
+        add0(src, "");
+
+        // Generate toString() method.
+        add1(src, "/** {@inheritDoc} */");
+        add1(src, "@Override public String toString() {");
+
+        Iterator<PojoField> it = fields.iterator();
+
+        add2Fmt(src, "return \"%1$s [%2$s=\" + %2$s +", type, it.next().javaName());
+
+        while (it.hasNext())
+            add3(src, String.format("\", %1$s=\" + %1$s +", it.next().javaName()));
+
+        add3(src, "\"]\";");
+        add1(src, "}");
+
+        add0(src, "}");
+        add0(src, "");
+
+        // Write generated code to file.
+        write(src, out);
+    }
+
+    /**
+     * Generate source code for type by its metadata.
+     *
+     * @param pojo POJO descriptor.
+     * @param outFolder Output folder.
+     * @param pkg Types package.
+     * @param constructor {@code true} if empty and full constructors should be generated.
+     * @param includeKeys {@code true} if key fields should be included into value class.
+     * @param askOverwrite Callback to ask user to confirm file overwrite.
+     * @throws IOException If failed to write generated code into file.
+     */
+    public static void pojos(PojoDescriptor pojo, String outFolder, String pkg, boolean constructor,
+        boolean includeKeys, ConfirmCallable askOverwrite) throws IOException {
+        File pkgFolder = new File(outFolder, pkg.replace('.', File.separatorChar));
+
+        if (!pkgFolder.exists() && !pkgFolder.mkdirs())
+            throw new IOException("Failed to create folders for package: " + pkg);
+
+        generateCode(pojo, true, pkg, pkgFolder, constructor, false, askOverwrite);
+
+        generateCode(pojo, false, pkg, pkgFolder, constructor, includeKeys, askOverwrite);
+    }
+
+    /**
+     * Add type fields.
+     *
+     * @param src Source code lines.
+     * @param owner Fields owner collection.
+     * @param fields Fields metadata.
+     */
+    private static void addFields(Collection<String> src, String owner, Collection<PojoField> fields) {
+        for (PojoField field : fields) {
+            String javaTypeName = field.javaTypeName();
+
+            if (javaTypeName.startsWith("java.lang."))
+                javaTypeName = javaTypeName.substring(10);
+
+            src.add(owner + ".add(new CacheTypeFieldMetadata(\"" + field.dbName() + "\", " +
+                "Types." + field.dbTypeName() + ", \"" +
+                field.javaName() + "\", " + javaTypeName + ".class));");
+        }
+    }
+
+    /**
+     * Generate java snippets for cache configuration with JDBC store and types metadata.
+     *
+     * @param pojos POJO descriptors.
+     * @param pkg Types package.
+     * @param includeKeys {@code true} if key fields should be included into value class.
+     * @param outFolder Output folder.
+     * @param askOverwrite Callback to ask user to confirm file overwrite.
+     * @throws IOException If generation failed.
+     */
+    public static void snippets(Collection<PojoDescriptor> pojos, String pkg, boolean includeKeys,
+        String outFolder, ConfirmCallable askOverwrite) throws IOException {
+        File pkgFolder = new File(outFolder, pkg.replace('.', File.separatorChar));
+
+        File cacheStoreSnippet = new File(pkgFolder, "CacheStoreSnippet.java");
+
+        if (cacheStoreSnippet.exists()) {
+            MessageBox.Result choice = askOverwrite.confirm(cacheStoreSnippet.getName());
+
+            if (CANCEL == choice)
+                throw new IllegalStateException("Java snippets generation was canceled!");
+
+            if (NO == choice || NO_TO_ALL == choice)
+                return;
+        }
+
+        Collection<String> src = new ArrayList<>(256);
+
+        header(src, pkg, "org.apache.ignite.cache.store.jdbc.*;org.apache.ignite.configuration.*;;" +
+            "javax.cache.configuration.*;javax.sql.*", "CacheStoreSnippet", "CacheStoreSnippet");
+
+        add1(src, "/** Configure cache store. */");
+        add1(src, "public static void configure(CacheConfiguration ccfg) {");
+        add2(src, "DataSource dataSource = null; // TODO create data source.");
+        add0(src, "");
+        add2(src, "// Create store. ");
+        add2(src, "CacheJdbcPojoStore store = new CacheJdbcPojoStore();");
+        add2(src, "store.setDataSource(dataSource);");
+        add0(src, "");
+        add2(src, "// Create store factory. ");
+        add2(src, "ccfg.setCacheStoreFactory(new FactoryBuilder.SingletonFactory<>(store));");
+        add0(src, "");
+        add2(src, "// Configure cache to use store. ");
+        add2(src, "ccfg.setReadThrough(true);");
+        add2(src, "ccfg.setWriteThrough(true);");
+        add1(src, "}");
+
+        add0(src, "}");
+
+        write(src, cacheStoreSnippet);
+
+        File cacheTypeMetadataSnippet = new File(pkgFolder, "CacheTypeMetadataSnippet.java");
+
+        if (cacheTypeMetadataSnippet.exists()) {
+            MessageBox.Result choice = askOverwrite.confirm(cacheTypeMetadataSnippet.getName());
+
+            if (CANCEL == choice)
+                throw new IllegalStateException("Java snippets generation was canceled!");
+
+            if (NO == choice || NO_TO_ALL == choice)
+                return;
+        }
+
+        src.clear();
+
+        header(src, pkg, "org.apache.ignite.cache.*;;org.apache.ignite.configuration.*;java.sql.Types;java.util.*",
+            "CacheTypeMetadataSnippet", "CacheTypeMetadataSnippet");
+
+        add1(src, "/** Configure cache types metadata. */");
+        add1(src, "public static void configure(CacheConfiguration ccfg) {");
+
+        add2(src, "// Configure cache types. ");
+        add2(src, "Collection<CacheTypeMetadata> meta = new ArrayList<>();");
+        add0(src, "");
+
+        boolean first = true;
+
+        for (PojoDescriptor pojo : pojos) {
+            String tbl = pojo.table();
+
+            add2(src, "// " + tbl + ".");
+            add2(src, (first ? "CacheTypeMetadata " : "") + "type = new CacheTypeMetadata();");
+            add2(src, "type.setDatabaseSchema(\"" + pojo.schema() + "\");");
+            add2(src, "type.setDatabaseTable(\"" + tbl + "\");");
+            add2(src, "type.setKeyType(\"" + pkg + "." + pojo.keyClassName() + "\");");
+            add2(src, "type.setValueType(\"" + pkg + "." + pojo.valueClassName() + "\");");
+            add0(src, "");
+
+            add2(src, "meta.add(type);");
+            add0(src, "");
+
+            add2(src, "// Key fields for " + tbl + ".");
+            add2(src, (first ? "Collection<CacheTypeFieldMetadata> " : "") + "keys = new ArrayList<>();");
+            addFields(src, "keys", pojo.keyFields());
+            add2(src, "type.setKeyFields(keys);");
+            add0(src, "");
+
+            add2(src, "// Value fields for " + tbl + ".");
+            add2(src, (first ? "Collection<CacheTypeFieldMetadata> " : "") + "vals = new ArrayList<>();");
+            addFields(src, "vals", pojo.valueFields(includeKeys));
+            add2(src, "type.setValueFields(vals);");
+            add0(src, "");
+
+            first = false;
+        }
+        add0(src, "");
+        add2(src, "ccfg.setTypeMetadata(meta);");
+        add1(src, "}");
+
+        add0(src, "}");
+
+        write(src, cacheTypeMetadataSnippet);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c493225f/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/PojoGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/PojoGenerator.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/PojoGenerator.java
deleted file mode 100644
index 6a8eef6..0000000
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/PojoGenerator.java
+++ /dev/null
@@ -1,414 +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.generator;
-
-import org.apache.ignite.schema.model.*;
-import org.apache.ignite.schema.ui.*;
-
-import java.io.*;
-import java.text.*;
-import java.util.*;
-
-import static org.apache.ignite.schema.ui.MessageBox.Result.*;
-
-/**
- * POJO generator for key and value classes.
- */
-public class PojoGenerator {
-    /** */
-    private static final String TAB = "    ";
-    /** */
-    private static final String TAB2 = TAB + TAB;
-    /** */
-    private static final String TAB3 = TAB + TAB + TAB;
-
-    /**
-     * Add line to source code without indent.
-     *
-     * @param src Source code.
-     * @param line Code line.
-     */
-    private static void add0(Collection<String> src, String line) {
-        src.add(line);
-    }
-
-    /**
-     * Add line to source code with one indent.
-     *
-     * @param src Source code.
-     * @param line Code line.
-     */
-    private static void add1(Collection<String> src, String line) {
-        src.add(TAB + line);
-    }
-
-    /**
-     * Add line to source code with two indents.
-     *
-     * @param src Source code.
-     * @param line Code line.
-     */
-    private static void add2(Collection<String> src, String line) {
-        src.add(TAB2 + line);
-    }
-
-    /**
-     * Add line to source code with two indents.
-     *
-     * @param src Source code.
-     * @param fmt Code line with format placeholders.
-     * @param args Format arguments.
-     */
-    private static void add2Fmt(Collection<String> src, String fmt, Object... args) {
-        add2(src, String.format(fmt, args));
-    }
-
-    /**
-     * Add line to source code with three indents.
-     *
-     * @param src Source code.
-     * @param line Code line.
-     */
-    private static void add3(Collection<String> src, String line) {
-        src.add(TAB3 + line);
-    }
-
-    /**
-     * @param str Source string.
-     * @return String with first letters in upper case.
-     */
-    private static String capitalizeFirst(String str) {
-        return Character.toUpperCase(str.charAt(0)) + str.substring(1);
-    }
-
-    /**
-     * @param field POJO field descriptor.
-     * @return Field java type name.
-     */
-    private static String javaTypeName(PojoField field) {
-        String javaTypeName = field.javaTypeName();
-
-        return javaTypeName.startsWith("java.lang.") ? javaTypeName.substring(10) : javaTypeName;
-    }
-
-    /**
-     * Generate java class code.
-     *
-     * @param pojo POJO descriptor.
-     * @param key {@code true} if key class should be generated.
-     * @param pkg Package name.
-     * @param pkgFolder Folder where to save generated class.
-     * @param constructor {@code true} if empty and full constructors should be generated.
-     * @param includeKeys {@code true} if key fields should be included into value class.
-     * @param askOverwrite Callback to ask user to confirm file overwrite.
-     * @throws IOException If failed to write generated code into file.
-     */
-    private static void generateCode(PojoDescriptor pojo, boolean key, String pkg, File pkgFolder,
-        boolean constructor, boolean includeKeys, ConfirmCallable askOverwrite) throws IOException {
-        String type = key ? pojo.keyClassName() : pojo.valueClassName();
-
-        File out = new File(pkgFolder, type + ".java");
-
-        if (out.exists()) {
-            MessageBox.Result choice = askOverwrite.confirm(out.getName());
-
-            if (CANCEL == choice)
-                throw new IllegalStateException("POJO generation was canceled!");
-
-            if (NO == choice || NO_TO_ALL == choice)
-                return;
-        }
-
-        Collection<String> src = new ArrayList<>(256);
-
-        // License.
-        add0(src, "/*");
-        add0(src, " * Licensed to the Apache Software Foundation (ASF) under one or more");
-        add0(src, " * contributor license agreements.  See the NOTICE file distributed with");
-        add0(src, " * this work for additional information regarding copyright ownership.");
-        add0(src, " * The ASF licenses this file to You under the Apache License, Version 2.0");
-        add0(src, " * (the \"License\"); you may not use this file except in compliance with");
-        add0(src, " * the License.  You may obtain a copy of the License at");
-        add0(src, " *");
-        add0(src, " *      http://www.apache.org/licenses/LICENSE-2.0");
-        add0(src, " *");
-        add0(src, " * Unless required by applicable law or agreed to in writing, software");
-        add0(src, " * distributed under the License is distributed on an \"AS IS\" BASIS,");
-        add0(src, " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
-        add0(src, " * See the License for the specific language governing permissions and");
-        add0(src, " * limitations under the License.");
-        add0(src, " */");
-        add0(src, "");
-
-        // Package.
-        add0(src, "package " + pkg + ";");
-        add0(src, "");
-
-        // Imports.
-        add0(src, "import java.io.*;");
-        add0(src, "");
-
-        // Class.
-        add0(src, "/**");
-        add0(src, " * " + type + " definition.");
-        add0(src, " *");
-        add0(src, " * Code generated by Apache Ignite Schema Import utility: " + new SimpleDateFormat("MM/dd/yyyy").format(new Date()) + ".");
-        add0(src, " */");
-        add0(src, "public class " + type + " implements Serializable {");
-
-        add1(src, "/** */");
-        add1(src, "private static final long serialVersionUID = 0L;");
-        add0(src, "");
-
-        Collection<PojoField> fields = key ? pojo.keyFields() : pojo.valueFields(includeKeys);
-
-        // Generate fields declaration.
-        for (PojoField field : fields) {
-            String fldName = field.javaName();
-
-            add1(src, "/** Value for " + fldName + ". */");
-
-            if (key && field.affinityKey())
-                add1(src, "@CacheAffinityKeyMapped");
-
-            add1(src, "private " + javaTypeName(field) + " " + fldName + ";");
-            add0(src, "");
-        }
-
-        // Generate constructors.
-        if (constructor) {
-            add1(src, "/**");
-            add1(src, " * Empty constructor.");
-            add1(src, " */");
-            add1(src, "public " + type + "() {");
-            add2(src, "// No-op.");
-            add1(src, "}");
-
-            add0(src, "");
-
-            add1(src, "/**");
-            add1(src, " * Full constructor.");
-            add1(src, " */");
-            add1(src, "public " + type + "(");
-
-            Iterator<PojoField> it = fields.iterator();
-
-            while (it.hasNext()) {
-                PojoField field = it.next();
-
-                add2(src, javaTypeName(field) + " " + field.javaName() + (it.hasNext() ? "," : ""));
-            }
-            add1(src, ") {");
-
-            for (PojoField field : fields)
-                add2Fmt(src, "this.%1$s = %1$s;", field.javaName());
-
-            add1(src, "}");
-            add0(src, "");
-        }
-
-        // Generate getters and setters methods.
-        for (PojoField field : fields) {
-            String fldName = field.javaName();
-
-            String fldType = javaTypeName(field);
-
-            String mtdName = capitalizeFirst(fldName);
-
-            add1(src, "/**");
-            add1(src, " * Gets " + fldName + ".");
-            add1(src, " *");
-            add1(src, " * @return Value for " + fldName + ".");
-            add1(src, " */");
-            add1(src, "public " + fldType + " get" + mtdName + "() {");
-            add2(src, "return " + fldName + ";");
-            add1(src, "}");
-            add0(src, "");
-
-            add1(src, "/**");
-            add1(src, " * Sets " + fldName + ".");
-            add1(src, " *");
-            add1(src, " * @param " + fldName + " New value for " + fldName + ".");
-            add1(src, " */");
-            add1(src, "public void set" + mtdName + "(" + fldType + " " + fldName + ") {");
-            add2(src, "this." + fldName + " = " + fldName + ";");
-            add1(src, "}");
-            add0(src, "");
-        }
-
-        // Generate equals() method.
-        add1(src, "/** {@inheritDoc} */");
-        add1(src, "@Override public boolean equals(Object o) {");
-        add2(src, "if (this == o)");
-        add3(src, "return true;");
-        add0(src, "");
-
-        add2(src, "if (!(o instanceof " + type + "))");
-        add3(src, "return false;");
-        add0(src, "");
-
-        add2Fmt(src, "%1$s that = (%1$s)o;", type);
-
-        for (PojoField field : fields) {
-            add0(src, "");
-
-            String javaName = field.javaName();
-
-            if (field.primitive()) {
-                switch (field.javaTypeName()) {
-                    case "float":
-                        add2Fmt(src, "if (Float.compare(%1$s, that.%1$s) != 0)", javaName);
-                        break;
-
-                    case "double":
-                        add2Fmt(src, "if (Double.compare(%1$s, that.%1$s) != 0)", javaName);
-                        break;
-
-                    default:
-                        add2Fmt(src, "if (%1$s != that.%1$s)", javaName);
-                }
-            }
-            else
-                add2Fmt(src, "if (%1$s != null ? !%1$s.equals(that.%1$s) : that.%1$s != null)", javaName);
-
-            add3(src, "return false;");
-        }
-
-        add0(src, "");
-        add2(src, "return true;");
-        add1(src, "}");
-        add0(src, "");
-
-        // Generate hashCode() method.
-        add1(src, "/** {@inheritDoc} */");
-        add1(src, "@Override public int hashCode() {");
-
-        List<String> hash = new ArrayList<>(fields.size() * 2);
-
-        boolean first = true;
-        boolean tempVar = false;
-
-        for (PojoField field : fields) {
-            String javaName = field.javaName();
-
-            if (!first)
-                add0(hash, "");
-
-            if (field.primitive()) {
-                switch (field.javaTypeName()) {
-                    case "boolean":
-                        add2Fmt(hash, first ? "int res = %s ? 1 : 0;" : "res = 31 * res + (%s ? 1 : 0);", javaName);
-                        break;
-
-                    case "byte":
-                    case "short":
-                        add2Fmt(hash, first ? "int res = (int)%s;" : "res = 31 * res + (int)%s;", javaName);
-                        break;
-
-                    case "int":
-                        add2Fmt(hash, first ? "int res = %s;" : "res = 31 * res + %s;", javaName);
-                        break;
-
-                    case "long":
-                        add2Fmt(hash, first
-                            ? "int res = (int)(%1$s ^ (%1$s >>> 32));"
-                            : "res = 31 * res + (int)(%1$s ^ (%1$s >>> 32));", javaName);
-                        break;
-
-                    case "float":
-                        add2Fmt(hash, first
-                            ? "int res = %1$s != +0.0f ? Float.floatToIntBits(%1$s) : 0;"
-                            : "res = 31 * res + (%1$s != +0.0f ? Float.floatToIntBits(%1$s) : 0);", javaName);
-                        break;
-
-                    case "double":
-                        add2Fmt(hash, (tempVar ? "ig_hash_temp" : "long ig_hash_temp") +
-                            " = Double.doubleToLongBits(%s);", javaName);
-
-                        add0(hash, "");
-
-                        add2Fmt(hash, first
-                            ? "int res = (int)(ig_hash_temp ^ (ig_hash_temp >>> 32));"
-                            : "res = 31 * res + (int)(ig_hash_temp ^ (ig_hash_temp >>> 32));", javaName);
-
-                        tempVar = true;
-                        break;
-                }
-            }
-            else
-                add2Fmt(hash, first ? "int res = %1$s != null ? %1$s.hashCode() : 0;"
-                    : "res = 31 * res + (%1$s != null ? %1$s.hashCode() : 0);", javaName);
-
-            first = false;
-        }
-
-        for (String line : hash)
-            add0(src, line);
-
-        add0(src, "");
-        add2(src, "return res;");
-        add1(src, "}");
-        add0(src, "");
-
-        // Generate toString() method.
-        add1(src, "/** {@inheritDoc} */");
-        add1(src, "@Override public String toString() {");
-
-        Iterator<PojoField> it = fields.iterator();
-
-        add2Fmt(src, "return \"%1$s [%2$s=\" + %2$s +", type, it.next().javaName());
-
-        while (it.hasNext())
-            add3(src, String.format("\", %1$s=\" + %1$s +", it.next().javaName()));
-
-        add3(src, "\"]\";");
-        add1(src, "}");
-
-        add0(src, "}");
-        add0(src, "");
-
-        // Write generated code to file.
-        try (Writer writer = new BufferedWriter(new FileWriter(out))) {
-            for (String line : src)
-                writer.write(line + '\n');
-        }
-    }
-
-    /**
-     * Generate source code for type by its metadata.
-     *
-     * @param pojo POJO descriptor.
-     * @param outFolder Output folder.
-     * @param pkg Types package.
-     * @param constructor {@code true} if empty and full constructors should be generated.
-     * @param includeKeys {@code true} if key fields should be included into value class.
-     * @param askOverwrite Callback to ask user to confirm file overwrite.
-     * @throws IOException If failed to write generated code into file.
-     */
-    public static void generate(PojoDescriptor pojo, String outFolder, String pkg, boolean constructor,
-        boolean includeKeys, ConfirmCallable askOverwrite) throws IOException {
-        File pkgFolder = new File(outFolder, pkg.replace('.', File.separatorChar));
-
-        if (!pkgFolder.exists() && !pkgFolder.mkdirs())
-            throw new IOException("Failed to create folders for package: " + pkg);
-
-        generateCode(pojo, true, pkg, pkgFolder, constructor, false, askOverwrite);
-
-        generateCode(pojo, false, pkg, pkgFolder, constructor, includeKeys, askOverwrite);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c493225f/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/SnippetGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/SnippetGenerator.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/SnippetGenerator.java
deleted file mode 100644
index 084601a..0000000
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/SnippetGenerator.java
+++ /dev/null
@@ -1,144 +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.generator;
-
-import org.apache.ignite.schema.model.*;
-import org.apache.ignite.schema.ui.*;
-
-import java.io.*;
-import java.util.*;
-
-import static org.apache.ignite.schema.ui.MessageBox.Result.*;
-
-/**
- * Cache configuration snippet generator.
- */
-public class SnippetGenerator {
-    /**
-     * Add type fields.
-     *
-     * @param src Source code lines.
-     * @param owner Fields owner collection.
-     * @param fields Fields metadata.
-     */
-    private static void addFields(Collection<String> src, String owner, Collection<PojoField> fields) {
-        for (PojoField field : fields) {
-            String javaTypeName = field.javaTypeName();
-
-            if (javaTypeName.startsWith("java.lang."))
-                javaTypeName = javaTypeName.substring(10);
-
-            src.add(owner + ".add(new CacheTypeFieldMetadata(\"" + field.dbName() + "\", " +
-                "java.sql.Types." + field.dbTypeName() + ", \"" +
-                field.javaName() + "\", " + javaTypeName + ".class));");
-        }
-    }
-
-    /**
-     * Generate java snippet for cache configuration with JDBC store.
-     *
-     * @param pojos POJO descriptors.
-     * @param pkg Types package.
-     * @param includeKeys {@code true} if key fields should be included into value class.
-     * @param out File to output snippet.
-     * @param askOverwrite Callback to ask user to confirm file overwrite.
-     * @throws IOException If generation failed.
-     */
-    public static void generate(Collection<PojoDescriptor> pojos, String pkg, boolean includeKeys, File out,
-        ConfirmCallable askOverwrite) throws IOException {
-        if (out.exists()) {
-            MessageBox.Result choice = askOverwrite.confirm(out.getName());
-
-            if (CANCEL == choice)
-                throw new IllegalStateException("Java configuration snippet generation was canceled!");
-
-            if (NO == choice || NO_TO_ALL == choice)
-                return;
-        }
-
-        Collection<String> src = new ArrayList<>(256);
-
-        src.add("// Code snippet for cache configuration.");
-        src.add("");
-        src.add("IgniteConfiguration cfg = new IgniteConfiguration();");
-        src.add("");
-        src.add("CacheConfiguration ccfg = new CacheConfiguration<>();");
-        src.add("");
-        src.add("DataSource dataSource = null; // TODO: Create data source for your database.");
-        src.add("");
-        src.add("// Create store. ");
-        src.add("CacheJdbcPojoStore store = new CacheJdbcPojoStore();");
-        src.add("store.setDataSource(dataSource);");
-        src.add("");
-        src.add("// Create store factory. ");
-        src.add("ccfg.setCacheStoreFactory(new FactoryBuilder.SingletonFactory<>(store));");
-        src.add("");
-        src.add("// Configure cache to use store. ");
-        src.add("ccfg.setReadThrough(true);");
-        src.add("ccfg.setWriteThrough(true);");
-        src.add("");
-        src.add("// Configure cache types. ");
-        src.add("Collection<CacheTypeMetadata> meta = new ArrayList<>();");
-        src.add("");
-
-        boolean first = true;
-
-        for (PojoDescriptor pojo : pojos) {
-            String tbl = pojo.table();
-
-            src.add("// " + tbl + ".");
-            src.add((first ? "CacheTypeMetadata " : "") +  "type = new CacheTypeMetadata();");
-            src.add("type.setDatabaseSchema(\"" + pojo.schema() + "\");");
-            src.add("type.setDatabaseTable(\"" + tbl + "\");");
-            src.add("type.setKeyType(\"" + pkg + "." + pojo.keyClassName() + "\");");
-            src.add("type.setValueType(\"" +  pkg + "." + pojo.valueClassName() + "\");");
-            src.add("");
-
-            src.add("meta.add(type);");
-            src.add("");
-
-            src.add("// Key fields for " + tbl + ".");
-            src.add((first ? "Collection<CacheTypeFieldMetadata> " : "") + "keys = new ArrayList<>();");
-            addFields(src, "keys", pojo.keyFields());
-            src.add("type.setKeyFields(keys);");
-            src.add("");
-
-            src.add("// Value fields for " + tbl + ".");
-            src.add((first ? "Collection<CacheTypeFieldMetadata> " : "") + "vals = new ArrayList<>();");
-            addFields(src, "vals", pojo.valueFields(includeKeys));
-            src.add("type.setValueFields(vals);");
-            src.add("");
-
-            first = false;
-        }
-        src.add("");
-        src.add("ccfg.setTypeMetadata(meta);");
-
-        src.add("");
-        src.add("cfg.setCacheConfiguration(ccfg);");
-
-        src.add("// Start Ignite node.");
-        src.add("Ignition.start(cfg);");
-
-        // Write generated code to file.
-        try (Writer writer = new BufferedWriter(new FileWriter(out))) {
-            for (String line : src)
-                writer.write(line + '\n');
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c493225f/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
index a3b46dc..ca63772 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
@@ -478,13 +478,13 @@ public class SchemaImportApp extends Application {
                         XmlGenerator.generate(pkg, pojo, includeKeys, new File(destFolder, pojo.table() + ".xml"),
                             askOverwrite);
 
-                    PojoGenerator.generate(pojo, outFolder, pkg, constructor, includeKeys, askOverwrite);
+                    CodeGenerator.pojos(pojo, outFolder, pkg, constructor, includeKeys, askOverwrite);
                 }
 
                 if (singleXml)
                     XmlGenerator.generate(pkg, all, includeKeys, new File(outFolder, "Ignite.xml"), askOverwrite);
 
-                SnippetGenerator.generate(all, pkg, includeKeys, new File(outFolder, "Ignite.snippet"), askOverwrite);
+                CodeGenerator.snippets(all, pkg, includeKeys, outFolder, askOverwrite);
 
                 perceptualDelay(started);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c493225f/modules/schema-import/src/test/java/org/apache/ignite/schema/test/generator/CodeGeneratorTest.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/generator/CodeGeneratorTest.java b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/generator/CodeGeneratorTest.java
new file mode 100644
index 0000000..c458aad
--- /dev/null
+++ b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/generator/CodeGeneratorTest.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.test.generator;
+
+import org.apache.ignite.schema.generator.CodeGenerator;
+import org.apache.ignite.schema.test.AbstractSchemaImportTest;
+import org.apache.ignite.schema.model.PojoDescriptor;
+
+import java.io.File;
+
+/**
+ * Tests for POJO generator.
+ */
+public class CodeGeneratorTest extends AbstractSchemaImportTest {
+    /** Marker string to skip date generation while comparing.*/
+    private static final String GEN_PTRN = "Code generated by Apache Ignite Schema Import utility";
+
+    /**
+     * Test that POJOs generated correctly.
+     */
+    public void testPojoGeneration() throws Exception {
+        String pkg = "org.apache.ignite.schema.test.model";
+        String intPath = "org/apache/ignite/schema/test/model";
+
+        Boolean containsSchema = false;
+
+        for (PojoDescriptor pojo : pojos) {
+            if (pojo.valueClassName().isEmpty())
+                containsSchema = true;
+            else {
+                CodeGenerator.pojos(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/c493225f/modules/schema-import/src/test/java/org/apache/ignite/schema/test/generator/PojoGeneratorTest.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/generator/PojoGeneratorTest.java b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/generator/PojoGeneratorTest.java
deleted file mode 100644
index a7de8f8..0000000
--- a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/generator/PojoGeneratorTest.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.test.generator;
-
-import org.apache.ignite.schema.generator.PojoGenerator;
-import org.apache.ignite.schema.test.AbstractSchemaImportTest;
-import org.apache.ignite.schema.model.PojoDescriptor;
-
-import java.io.File;
-
-/**
- * Tests for POJO generator.
- */
-public class PojoGeneratorTest extends AbstractSchemaImportTest {
-    /** Marker string to skip date generation while comparing.*/
-    private static final String GEN_PTRN = "Code generated by Apache Ignite Schema Import utility";
-
-    /**
-     * Test that POJOs generated correctly.
-     */
-    public void testPojoGeneration() throws Exception {
-        String pkg = "org.apache.ignite.schema.test.model";
-        String intPath = "org/apache/ignite/schema/test/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/c493225f/modules/schema-import/src/test/java/org/apache/ignite/schema/test/testsuites/IgniteSchemaImportTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/testsuites/IgniteSchemaImportTestSuite.java b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/testsuites/IgniteSchemaImportTestSuite.java
index dce63a4..571264e 100644
--- a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/testsuites/IgniteSchemaImportTestSuite.java
+++ b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/testsuites/IgniteSchemaImportTestSuite.java
@@ -32,7 +32,7 @@ public class IgniteSchemaImportTestSuite {
     public static TestSuite suite() throws Exception {
         TestSuite suite = new TestSuite("Ignite Apache Schema Import Utility Test Suite");
 
-        suite.addTestSuite(PojoGeneratorTest.class);
+        suite.addTestSuite(CodeGeneratorTest.class);
         suite.addTestSuite(XmlGeneratorTest.class);
         suite.addTestSuite(DbMetadataParserTest.class);
 


Mime
View raw message