Skip to content

Commit

Permalink
Fix more tests for dbcp.
Browse files Browse the repository at this point in the history
git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@84 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Apr 2, 2008
1 parent 2496cad commit f537684
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
20 changes: 15 additions & 5 deletions testsrc/org/olap4j/MetadataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public class MetadataTest extends TestCase {
private static final String NL = System.getProperty("line.separator");

private final TestContext.Tester tester;
private final Connection connection;
private final String catalogName;
private final OlapConnection olapConnection;
private final OlapDatabaseMetaData olapDatabaseMetaData;
private Connection connection;
private String catalogName;
private OlapConnection olapConnection;
private OlapDatabaseMetaData olapDatabaseMetaData;
private final String propertyNamePattern = null;
private final String dataSourceName = "xx";

Expand All @@ -49,13 +49,23 @@ public class MetadataTest extends TestCase {

public MetadataTest() throws SQLException {
tester = TestContext.instance().getTester();
}

protected void setUp() throws SQLException {
connection = tester.createConnection();
catalogName = connection.getCatalog();
olapConnection =
((OlapWrapper) connection).unwrap(OlapConnection.class);
tester.getWrapper().unwrap(connection, OlapConnection.class);
olapDatabaseMetaData = olapConnection.getMetaData();
}

protected void tearDown() throws Exception {
if (connection != null && !connection.isClosed()) {
connection.close();
connection = null;
}
}

// ~ Helper methods ----------

private void assertContains(String seek, String s) {
Expand Down
28 changes: 22 additions & 6 deletions testsrc/org/olap4j/test/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.olap4j.Axis;

import java.sql.SQLException;
import java.sql.Connection;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -36,14 +37,31 @@ public class ParserTest extends TestCase {
Pattern.compile(
"(?s)From line ([0-9]+), column ([0-9]+) to line ([0-9]+), column ([0-9]+): (.*)");

final TestContext testContext = TestContext.instance();
private Connection connection;

public ParserTest(String name) {
super(name);
}

protected OlapConnection getOlapConnection() throws SQLException {
if (connection == null) {
connection = testContext.getTester().createConnection();
}
return testContext.getTester().getWrapper().unwrap(
connection, OlapConnection.class);
}

protected void tearDown() throws Exception {
if (connection != null && !connection.isClosed()) {
connection.close();
connection = null;
}
}

private MdxParser createParser() {
try {
OlapConnection olapConnection =
TestContext.instance().getOlapConnection();
OlapConnection olapConnection = getOlapConnection();
return olapConnection.getParserFactory()
.createMdxParser(olapConnection);
} catch (SQLException e) {
Expand Down Expand Up @@ -185,9 +203,7 @@ public void testUnparse() {

private void checkUnparse(String queryString, final String expected) {
try {
final TestContext testContext = TestContext.instance();

OlapConnection olapConnection = testContext.getOlapConnection();
OlapConnection olapConnection = getOlapConnection();
MdxParser mdxParser =
olapConnection.getParserFactory()
.createMdxParser(olapConnection);
Expand Down Expand Up @@ -528,7 +544,7 @@ public void testId() {

// todo: enable this
public void _testCloneQuery() throws SQLException {
OlapConnection olapConnection = TestContext.instance().getOlapConnection();
OlapConnection olapConnection = getOlapConnection();
MdxParser mdxParser =
olapConnection.getParserFactory()
.createMdxParser(olapConnection);
Expand Down
11 changes: 0 additions & 11 deletions testsrc/org/olap4j/test/TestContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,6 @@ public static TestContext instance() {
return INSTANCE;
}

/**
* Creates a connection to the test's default OLAP server.
*
* @return connection
* @throws SQLException on error
*/
public OlapConnection getOlapConnection() throws SQLException {
java.sql.Connection connection = tester.createConnection();
return ((OlapWrapper) connection).unwrap(OlapConnection.class);
}

/**
* Checks that an actual string matches an expected string. If they do not,
* throws a {@link junit.framework.ComparisonFailure} and prints the
Expand Down

0 comments on commit f537684

Please sign in to comment.