Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# IGNITE-32: Tests for db metadata parsing and XML generation.
- Loading branch information
1 parent
e28ddd2
commit e716d82
Showing
8 changed files
with
606 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
...les/schema-load/src/test/java/org/apache/ignite/schema/load/BaseSchemaLoaderSelfTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* | ||
* 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 { | ||
/** Default connection URL (value is <tt>jdbc:h2:mem:jdbcCacheStore;DB_CLOSE_DELAY=-1</tt>). */ | ||
private static final String DFLT_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 = | ||
String.format("%s/ignite-schema-loader/out", System.getProperty("java.io.tmpdir")); | ||
|
||
/** 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> pojoLst; | ||
|
||
/** {@inheritDoc} */ | ||
@Override public void setUp() throws Exception { | ||
Class.forName("org.h2.Driver"); | ||
|
||
Connection conn = DriverManager.getConnection(DFLT_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); | ||
|
||
pojoLst = 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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.