Skip to content

Commit

Permalink
MONDRIAN: Don't throw NPE if tests invoked in wrong directory;
Browse files Browse the repository at this point in the history
	CSV tests now recuse themselves if invoked against Access.

[git-p4: depot-paths = "//open/mondrian/": change = 7903]
  • Loading branch information
julianhyde committed Oct 11, 2006
1 parent 43f2cd7 commit e92a328
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 50 deletions.
9 changes: 9 additions & 0 deletions src/main/mondrian/rolap/sql/SqlQuery.java
Expand Up @@ -1121,6 +1121,15 @@ private static String guessSqlType(
return "INTEGER";
}
}

/**
* Returns whether this dialect supports common SQL Data Definition
* Language (DDL) statements such as <code>CREATE TABLE</code> and
* <code>DROP INDEX</code>.
*/
public boolean allowsDdl() {
return !isAccess();
}
}

/**
Expand Down
41 changes: 28 additions & 13 deletions testsrc/main/mondrian/rolap/aggmatcher/BUG_1541077.java
Expand Up @@ -9,20 +9,16 @@
*/
package mondrian.rolap.aggmatcher;

import mondrian.olap.*;
import mondrian.rolap.RolapConnection;
import mondrian.test.FoodMartTestCase;
import mondrian.test.TestContext;
import mondrian.test.loader.CsvDBLoader;
import java.sql.Connection;
import java.io.File;
import mondrian.olap.MondrianProperties;
import mondrian.olap.Result;

/**
* This is a concrete class used to test Bug 1541077 as well as a couple of
* other aggregate table ExplicitRecognizer conditions.
* Testcase for
* <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1541077&group_id=35302&atid=414613">bug 1541077<a>
* and a couple of other aggregate table ExplicitRecognizer conditions.
*
* @author <a>Richard M. Emberson</a>
* @version
* @author Richard M. Emberson
* @version $Id$
*/
public class BUG_1541077 extends AggTableTestCase {

Expand All @@ -36,6 +32,10 @@ public BUG_1541077(String name) {
}

public void testStoreCount() throws Exception {
if (!isApplicable()) {
return;
}

MondrianProperties props = MondrianProperties.instance();

// get value without aggregates
Expand All @@ -52,7 +52,12 @@ public void testStoreCount() throws Exception {

assertTrue(v.equals(v1));
}

public void testSalesCount() throws Exception {
if (!isApplicable()) {
return;
}

MondrianProperties props = MondrianProperties.instance();

// get value without aggregates
Expand All @@ -69,7 +74,12 @@ public void testSalesCount() throws Exception {

assertTrue(v.equals(v1));
}

public void testTotalAmount() throws Exception {
if (!isApplicable()) {
return;
}

MondrianProperties props = MondrianProperties.instance();

// get value without aggregates
Expand All @@ -86,7 +96,11 @@ public void testTotalAmount() throws Exception {

assertTrue(v.equals(v1));
}

public void testBug1541077() throws Exception {
if (!isApplicable()) {
return;
}

MondrianProperties props = MondrianProperties.instance();

Expand All @@ -110,6 +124,7 @@ public void testBug1541077() throws Exception {
protected String getFileName() {
return BUG_1541077;
}

protected String getCubeDescription() {
return "<Cube name='Cheques'>\n" +
"<Table name='cheques'>\n" +
Expand Down Expand Up @@ -187,6 +202,6 @@ protected String getCubeDescription() {
"</Cube>";

}


}

// End BUG_1541077.java
27 changes: 14 additions & 13 deletions testsrc/main/mondrian/test/comp/ResultComparatorTest.java
Expand Up @@ -138,21 +138,22 @@ public static TestSuite suite() {
final Pattern pattern = filePattern == null ? null : Pattern.compile(filePattern);
final String directory = fileDirectory == null ? "testsrc" + File.separatorChar + "queryFiles" : fileDirectory;

File[] files = new File(directory).listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
if (name.startsWith("query") && name.endsWith(".xml")) {
if (pattern == null) {
return true;
}
else {
return pattern.matcher(name).matches();
File[] files = new File(directory).listFiles(
new FilenameFilter() {
public boolean accept(File dir, String name) {
if (name.startsWith("query") && name.endsWith(".xml")) {
if (pattern == null) {
return true;
} else {
return pattern.matcher(name).matches();
}
}
return false;
}

return false;
}
});

});
if (files == null) {
files = new File[0];
}
for (int idx = 0; idx < files.length; idx++) {
suite.addTest(new ResultComparatorTest(files[idx]));
}
Expand Down
46 changes: 34 additions & 12 deletions testsrc/main/mondrian/test/loader/CsvDBLoader.java
Expand Up @@ -10,7 +10,6 @@

package mondrian.test.loader;

import mondrian.olap.Util;
import java.io.FileInputStream;
import java.io.File;
import java.io.IOException;
Expand All @@ -21,14 +20,16 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* This concrete subclass of DBLoader gets its Tables by reading CSV files
* using the CsvLoader class and is the loader use for CSV junit tests.
* Implementation of {@link DBLoader} which gets its Tables by reading CSV files
* using the {@link CsvLoader} class and is the loader use for CSV junit tests.
*
* <p>
* This class requires that the CSV files have a specific format as defined:
* <code>CsvDBLoader</code> requires that the CSV files have a specific format
* as defined:
*
* <blockquote><pre>
* list_of_csv_files : (csv_file)+
* csv_file: table_definitions
Expand Down Expand Up @@ -65,8 +66,8 @@
* for an example.
*
*
* @author <a>Richard M. Emberson</a>
* @version
* @author Richard M. Emberson
* @version $Id$
*/
public class CsvDBLoader extends DBLoader {

Expand All @@ -85,27 +86,35 @@ public class CsvDBLoader extends DBLoader {
public CsvDBLoader() {
super();
}

public void setInputDirectory(File inputDirectory) {
this.inputDirectory = inputDirectory;
}

public File getInputDirectory() {
return this.inputDirectory;
}

public void setInputDirectoryRegex(String inputDirectoryRegex) {
this.inputDirectoryRegex = inputDirectoryRegex;
}

public String getInputDirectoryRegex() {
return this.inputDirectoryRegex;
}

public void setInputFiles(File[] inputFiles) {
this.inputFiles = inputFiles;
}

public File[] getInputFiles() {
return this.inputFiles;
}

public void setInputFile(File inputFile) {
this.inputFile = inputFile;
}

public File getInputFile() {
return this.inputFile;
}
Expand All @@ -123,6 +132,7 @@ public Table[] getTables() throws Exception {
return new Table[0];
}
}

public Table[] getTablesFromDirectory() throws Exception {
File[] files;
if (this.inputDirectoryRegex == null) {
Expand All @@ -136,17 +146,23 @@ public boolean accept(File dir, String name) {
}
}
);
if (files == null) {
files = new File[0];
}
}
return getTables(files);
}

public Table[] getTablesFromFiles() throws Exception {
return getTables(this.inputFiles);
}

public Table[] getTablesFromFile() throws Exception {
List list = new ArrayList();
loadTables(this.inputFile, list);
return (Table[]) list.toArray(new Table[list.size()]);
}

public Table[] getTables(File[] files) throws Exception {
List list = new ArrayList();
for (int i = 0; i < files.length; i++) {
Expand All @@ -171,6 +187,7 @@ public Iterator iterator() {
return this.list.iterator();
}
}

public static class CsvLoaderRowStream implements RowStream {
private final CsvLoader csvloader;
CsvLoaderRowStream(CsvLoader csvloader) {
Expand Down Expand Up @@ -199,6 +216,7 @@ public void remove() { }
};
}
}

public void loadTables(File file, List tableList) throws Exception {
//System.out.println("CsvLoader.loadTables: TOP:");
CsvLoader csvloader = null;
Expand All @@ -214,7 +232,6 @@ public void loadTables(File file, List tableList) throws Exception {
Reader reader = new FileReader(file);
csvloader = new CsvLoader(reader);
int lineNos = 0;
LOOP:
while (csvloader.hasNextLine()) {
String[] values = csvloader.nextLine();
lineNos++;
Expand Down Expand Up @@ -418,7 +435,7 @@ public void loadTables(File file, List tableList) throws Exception {
new CsvLoaderRowStream(csvloader);
controller.setRowStream(rowStream);
csvloader = null;
break LOOP;
break;
}

}
Expand All @@ -430,9 +447,11 @@ public void loadTables(File file, List tableList) throws Exception {
}
//System.out.println("CsvLoader.loadTables: BOTTOM:");
}
protected Column[] loadColumns(String[] columnNames,
String[] columnTypes, int lineNos)
throws Exception {

protected Column[] loadColumns(
String[] columnNames, String[] columnTypes, int lineNos)
throws Exception
{
List list = new ArrayList();
for (int i = 0; i < columnNames.length; i++) {
String columnName = columnNames[i];
Expand Down Expand Up @@ -577,6 +596,7 @@ protected static void usage(String msg) {
System.out.println(buf.toString());
System.exit((msg == null) ? 0 : 1);
}

public static void main(String[] args) throws Exception {
String propFile = null;
String jdbcDrivers = null;
Expand Down Expand Up @@ -797,3 +817,5 @@ public static void main(String[] args) throws Exception {
loader.executeStatements(tables);
}
}

// End CsvDBLoader.java

0 comments on commit e92a328

Please sign in to comment.