From c6103c7c9a6b6971d2aa0b8e3997608cb5f2c36f Mon Sep 17 00:00:00 2001 From: lresende Date: Mon, 2 Nov 2009 22:22:29 +0000 Subject: Move the das folder as new trunk for das sub project git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@832144 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tuscany/das/rdb/test/DBToXSDTests.java | 142 +++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 das-java/trunk/tools/src/test/java/org/apache/tuscany/das/rdb/test/DBToXSDTests.java (limited to 'das-java/trunk/tools/src/test/java/org/apache/tuscany/das/rdb/test/DBToXSDTests.java') diff --git a/das-java/trunk/tools/src/test/java/org/apache/tuscany/das/rdb/test/DBToXSDTests.java b/das-java/trunk/tools/src/test/java/org/apache/tuscany/das/rdb/test/DBToXSDTests.java new file mode 100644 index 0000000000..aba4eba68f --- /dev/null +++ b/das-java/trunk/tools/src/test/java/org/apache/tuscany/das/rdb/test/DBToXSDTests.java @@ -0,0 +1,142 @@ +/* + * 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.tuscany.das.rdb.test; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +import junit.framework.TestCase; + +import org.apache.tuscany.das.rdb.dbconfig.DBInitializer; +import org.apache.tuscany.das.rdb.util.DBToXSDGenerator; +/** + * Tests the DB Schema to Model XSD converter tool + */ +public class DBToXSDTests extends TestCase { + protected void setUp() throws Exception { + super.setUp(); + DBInitializer dbInitializer = new DBInitializer("dbConfig.xml"); + dbInitializer.initializeDatabase(true); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + static public String getContents(File aFile) { + //...checks on aFile are elided + StringBuffer contents = new StringBuffer(); + + //declared here only to make visible to finally clause + BufferedReader input = null; + try { + //use buffering, reading one line at a time + //FileReader always assumes default encoding is OK! + input = new BufferedReader( new FileReader(aFile) ); + String line = null; //not declared within while loop + /* + * readLine is a bit quirky : + * it returns the content of a line MINUS the newline. + * it returns null only for the END of the stream. + * it returns an empty String if two newlines appear in a row. + */ + while (( line = input.readLine()) != null){ + contents.append(line); + contents.append(System.getProperty("line.separator")); + } + } + catch (FileNotFoundException ex) { + ex.printStackTrace(); + } + catch (IOException ex){ + ex.printStackTrace(); + } + finally { + try { + if (input!= null) { + //flush and close both "input" and its underlying FileReader + input.close(); + } + } + catch (IOException ex) { + ex.printStackTrace(); + } + } + return contents.toString(); + } + + String compare1 = ""; + String compare2 = "
"; + String compare3 = ""; + String compare4 = ""; + + public void testDBToSchemaFile() throws Exception { + DBToXSDGenerator.getSchemaFileFromDB("DBConnectionConfig.xml"); + File file = new File("target/dbSchema.txt"); + if(file.isFile()) { + String schemaContent = getContents(file); + if(schemaContent.indexOf(compare1) != -1 && schemaContent.indexOf(compare2) != -1) { + assertTrue(true); + } + } else { + fail("SchemaFile does not exists or has improper contents!"); + } + } + + public void testSchemaFileToXSD() throws Exception { + DBToXSDGenerator.getModelFileFromSchemaFile("target/dbSchema.txt", "target/schemaModel.xsd"); + + File modelfile = new File("target/schemaModel.xsd"); + if(modelfile.isFile()) { + String modelContent = getContents(modelfile); + if(modelContent.indexOf(compare3) != -1 && modelContent.indexOf(compare4) != -1) { + assertTrue(true); + } + } else { + fail("ModelFile does not exists or has improper contents!"); + } + } + + public void testDBToXSD() throws Exception { + DBToXSDGenerator.getModelFileFromDB("DBConnectionConfig.xml"); + + File file = new File("target/dbSchema.txt"); + if(file.isFile()) { + String schemaContent = getContents(file); + if(schemaContent.indexOf(compare1) != -1 && schemaContent.indexOf(compare2) != -1) { + assertTrue(true); + } + } else { + fail("SchemaFile does not exists or has improper contents!"); + } + + File modelfile = new File("target/schemaModel.xsd"); + if(modelfile.isFile()) { + String modelContent = getContents(modelfile); + if(modelContent.indexOf(compare3) != -1 && modelContent.indexOf(compare4) != -1) { + assertTrue(true); + } + } else { + fail("ModelFile does not exists or has improper contents!"); + } + } +} -- cgit v1.2.3