001: /*
002: * WbSchemaDiffTest.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.sql.wbcommands;
013:
014: import java.io.File;
015: import java.sql.SQLException;
016: import java.sql.Statement;
017: import workbench.TestUtil;
018: import workbench.db.WbConnection;
019: import workbench.sql.StatementRunnerResult;
020: import workbench.util.SqlUtil;
021:
022: /**
023: *
024: * @author support@sql-workbench.net
025: */
026: public class WbSchemaDiffTest extends junit.framework.TestCase {
027:
028: private WbConnection source;
029: private WbConnection target;
030: private TestUtil util;
031:
032: public WbSchemaDiffTest(String testName) {
033: super (testName);
034: }
035:
036: public void tearDown() {
037: try {
038: source.disconnect();
039: } catch (Throwable th) {
040: }
041: try {
042: target.disconnect();
043: } catch (Throwable th) {
044: }
045: }
046:
047: public void testBaseDiff() {
048: try {
049: setupDatabase();
050: WbSchemaDiff diff = new WbSchemaDiff();
051: File output = new File(util.getBaseDir(), "diffTest.xml");
052: output.delete();
053: StatementRunnerResult result = diff
054: .execute("WbSchemaDiff -file='"
055: + output.getAbsolutePath()
056: + "' -includeForeignKeys=false -includePrimaryKeys=false -includeIndex=false -referenceProfile=source -targetProfile=target");
057: assertTrue(result.isSuccess());
058: assertTrue("File not created", output.exists());
059:
060: if (!output.delete()) {
061: fail("could not delete output file");
062: }
063: } catch (Exception e) {
064: e.printStackTrace();
065: fail(e.getMessage());
066: }
067: }
068:
069: private void setupDatabase() throws SQLException,
070: ClassNotFoundException {
071: util = new TestUtil("schemaDiffTest");
072: this .source = util.getConnection("source");
073: this .target = util.getConnection("target");
074:
075: Statement stmt = null;
076:
077: try {
078: stmt = source.createStatement();
079: stmt
080: .executeUpdate("create table person (person_id integer primary key, firstname varchar(100), lastname varchar(100))");
081: stmt
082: .executeUpdate("create table address (address_id integer primary key, street varchar(50), city varchar(100), phone varchar(50), email varchar(50))");
083: stmt
084: .executeUpdate("create table person_address (person_id integer, address_id integer, primary key (person_id, address_id))");
085: stmt
086: .executeUpdate("alter table person_address add constraint fk_pa_person foreign key (person_id) references person(person_id)");
087: stmt
088: .executeUpdate("alter table person_address add constraint fk_pa_address foreign key (address_id) references address(address_id)");
089:
090: stmt
091: .executeUpdate("CREATE VIEW v_person AS SELECT * FROM person");
092: stmt.executeUpdate("CREATE sequence seq_one");
093: stmt
094: .executeUpdate("CREATE sequence seq_two increment by 5");
095: stmt.executeUpdate("CREATE sequence seq_three");
096: SqlUtil.closeStatement(stmt);
097:
098: stmt = target.createStatement();
099: stmt
100: .executeUpdate("create table person (person_id integer primary key, firstname varchar(50), lastname varchar(100))");
101: stmt
102: .executeUpdate("create table address (address_id integer primary key, street varchar(10), city varchar(100), pone varchar(50), remark varchar(500))");
103: stmt
104: .executeUpdate("create table person_address (person_id integer, address_id integer, primary key (person_id, address_id))");
105: stmt
106: .executeUpdate("alter table person_address add constraint fk_pa_person foreign key (person_id) references person(person_id)");
107:
108: stmt
109: .executeUpdate("CREATE VIEW something AS SELECT * FROM address");
110:
111: stmt.executeUpdate("CREATE sequence seq_one");
112: stmt.executeUpdate("CREATE sequence seq_two");
113: stmt.executeUpdate("CREATE sequence seq_to_be_deleted");
114: } finally {
115: SqlUtil.closeStatement(stmt);
116: }
117:
118: }
119: }
|