01: /*
02: * WbLoadPkMappingTest.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.sql.wbcommands;
13:
14: import java.io.File;
15: import java.io.FileWriter;
16: import java.io.PrintWriter;
17: import java.util.Map;
18: import workbench.TestUtil;
19: import workbench.WbTestCase;
20: import workbench.db.ConnectionMgr;
21: import workbench.sql.DefaultStatementRunner;
22: import workbench.sql.SqlCommand;
23: import workbench.sql.StatementRunnerResult;
24: import workbench.storage.PkMapping;
25:
26: /**
27: *
28: * @author support@sql-workbench.net
29: */
30: public class WbLoadPkMappingTest extends WbTestCase {
31:
32: public WbLoadPkMappingTest(String testName) {
33: super (testName);
34: }
35:
36: public void testExecute() throws Exception {
37: TestUtil util = getTestUtil();
38: DefaultStatementRunner runner;
39:
40: try {
41: util.prepareEnvironment();
42: runner = util.createConnectedStatementRunner();
43:
44: File f = new File(util.getBaseDir(), "pkmapping.def");
45: PrintWriter w = new PrintWriter(new FileWriter(f));
46: w.println("junitpk=id,name");
47: w.close();
48:
49: String sql = "-- load mapping from a file \n "
50: + WbLoadPkMapping.FORMATTED_VERB + "\n -file='"
51: + f.getAbsolutePath() + "'";
52: SqlCommand command = runner.getCommandToUse(sql);
53: assertTrue(command instanceof WbLoadPkMapping);
54: runner.runStatement(sql, -1, -1);
55: StatementRunnerResult result = runner.getResult();
56: assertEquals("Loading not successful", true, result
57: .isSuccess());
58:
59: Map mapping = PkMapping.getInstance().getMapping();
60: String cols = (String) mapping.get("junitpk");
61: assertEquals("Wrong pk mapping stored", "id,name", cols);
62:
63: } catch (Exception e) {
64: e.printStackTrace();
65: fail(e.getMessage());
66: } finally {
67: ConnectionMgr.getInstance().disconnectAll();
68: }
69: }
70:
71: }
|