From 7e7c8a1efe01acb8b2f9421705fd0a0668b94535 Mon Sep 17 00:00:00 2001 From: Julian Hyde Date: Fri, 18 Mar 2005 12:12:55 -0800 Subject: [PATCH] MONDRIAN: Enable XML/A test. Make the "mondrian.catalogURL" property (used by both CmdRunner and XmlaTest) behave a little more like other properties. [git-p4: depot-paths = "//open/mondrian/": change = 3384] --- .../mondrian/olap/MondrianProperties.java | 77 +++++++++--------- src/main/mondrian/tui/CmdRunner.java | 13 +-- testsrc/main/mondrian/test/Main.java | 2 +- testsrc/main/mondrian/xmla/XmlaTest.java | 80 ++++++------------- 4 files changed, 67 insertions(+), 105 deletions(-) diff --git a/src/main/mondrian/olap/MondrianProperties.java b/src/main/mondrian/olap/MondrianProperties.java index ac82ad60ce..de3b089d52 100644 --- a/src/main/mondrian/olap/MondrianProperties.java +++ b/src/main/mondrian/olap/MondrianProperties.java @@ -80,15 +80,15 @@ public void populate(ServletContext servletContext) { load(url); } } catch (MalformedURLException e) { - LOGGER.error("Mondrian: file '" - + file.getAbsolutePath() - + "' could not be loaded (" - + e + LOGGER.error("Mondrian: file '" + + file.getAbsolutePath() + + "' could not be loaded (" + + e + ")"); } } else if (populateCount == 0 && false) { - LOGGER.warn("Mondrian: Warning: file '" - + file.getAbsolutePath() + LOGGER.warn("Mondrian: Warning: file '" + + file.getAbsolutePath() + "' not found"); } @@ -102,14 +102,14 @@ public void populate(ServletContext servletContext) { load(resourceUrl); } else if (populateCount == 0 && false) { - LOGGER.warn("Mondrian: Warning: servlet resource '" - + mondrianDotProperties + LOGGER.warn("Mondrian: Warning: servlet resource '" + + mondrianDotProperties + "' not found"); } } catch (MalformedURLException e) { - LOGGER.error("Mondrian: '" + mondrianDotProperties - + "' could not be loaded from servlet context (" - + e + LOGGER.error("Mondrian: '" + mondrianDotProperties + + "' could not be loaded from servlet context (" + + e + ")"); } } @@ -125,8 +125,8 @@ else if (populateCount == 0 && false) { } } if (populateCount++ == 0) { - LOGGER.info("Mondrian: loaded " - + count + LOGGER.info("Mondrian: loaded " + + count + " system properties"); } } @@ -137,16 +137,16 @@ private void load(final URL url) { try { load(url.openStream()); if (populateCount == 0) { - LOGGER.info("Mondrian: properties loaded from '" - + url + LOGGER.info("Mondrian: properties loaded from '" + + url + "'"); } } catch (IOException e) { - LOGGER.error("Mondrian: error while loading properties " - + "from '" - + url - + "' (" - + e + LOGGER.error("Mondrian: error while loading properties " + + "from '" + + url + + "' (" + + e + ")"); } } @@ -179,10 +179,10 @@ public String getJdbcDrivers() { /** Property {@value}. */ public static final String JdbcDrivers = "mondrian.jdbcDrivers"; /** Values is {@value}. */ - public static final String JdbcDrivers_Default = - "sun.jdbc.odbc.JdbcOdbcDriver," - + "org.hsqldb.jdbcDriver," - + "oracle.jdbc.OracleDriver," + public static final String JdbcDrivers_Default = + "sun.jdbc.odbc.JdbcOdbcDriver," + + "org.hsqldb.jdbcDriver," + + "oracle.jdbc.OracleDriver," + "com.mysql.jdbc.Driver"; /** Retrieves the value of the {@link #ResultLimit} property. */ @@ -209,7 +209,7 @@ public boolean getPrintCacheablesAfterQuery() { return getBooleanProperty(PrintCacheablesAfterQuery); } /** Property {@value}. */ - public static final String PrintCacheablesAfterQuery = + public static final String PrintCacheablesAfterQuery = "mondrian.rolap.RolapResult.printCacheables"; /** Retrieves the value of the {@link #FlushAfterQuery} property. */ @@ -217,7 +217,7 @@ public boolean getFlushAfterQuery() { return getBooleanProperty(FlushAfterQuery); } /** Property {@value}. */ - public static final String FlushAfterQuery = + public static final String FlushAfterQuery = "mondrian.rolap.RolapResult.flushAfterEachQuery"; // mondrian.test properties @@ -255,7 +255,7 @@ public String getTestConnectString() { return getProperty(TestConnectString); } /** Property {@value} */ - public static final String TestConnectString = + public static final String TestConnectString = "mondrian.test.connectString"; @@ -284,7 +284,7 @@ public int getLargeDimensionThreshold() { return getIntProperty(LargeDimensionThreshold, LargeDimensionThreshold_Default); } /** Property {@value}. */ - public static final String LargeDimensionThreshold = + public static final String LargeDimensionThreshold = "mondrian.rolap.LargeDimensionThreshold"; /** Value is {@value}. */ public static final int LargeDimensionThreshold_Default = 100; @@ -316,7 +316,7 @@ public int getSparseSegmentCountThreshold() { return getIntProperty(SparseSegmentCountThreshold, SparseSegmentCountThreshold_Default); } /** Property {@value}. */ - public static final String SparseSegmentCountThreshold = + public static final String SparseSegmentCountThreshold = "mondrian.rolap.SparseSegmentValueThreshold"; /** Value is {@value}. */ public static final int SparseSegmentCountThreshold_Default = 1000; @@ -327,18 +327,18 @@ public double getSparseSegmentDensityThreshold() { return getDoubleProperty(SparseSegmentDensityThreshold, SparseSegmentDensityThreshold_Default); } /** Property {@value}. */ - public static final String SparseSegmentDensityThreshold = + public static final String SparseSegmentDensityThreshold = "mondrian.rolap.SparseSegmentDensityThreshold"; /** Value is {@value}. */ public static final double SparseSegmentDensityThreshold_Default = 0.5; - public static final String QueryFilePattern = + public static final String QueryFilePattern = "mondrian.test.QueryFilePattern"; public String getQueryFilePattern() { return getProperty(QueryFilePattern); } - public static final String QueryFileDirectory = + public static final String QueryFileDirectory = "mondrian.test.QueryFileDirectory"; public String getQueryFileDirectory() { return getProperty(QueryFileDirectory); @@ -370,13 +370,16 @@ public boolean getWarmup() { } /** - * Retrieves the URL of the catalog to be used by CmdRunner. - * - *

The value always comes from {@link System#props}, but the property is - * declared in the {@link MondrianProperties} class for uniformity. + * Retrieves the URL of the catalog to be used by CmdRunner and XML/A Test. */ public String getCatalogURL() { - return System.getProperty(CatalogUrl); + return getProperty("mondrian.catalogURL"); + } + /** + * Sets the catalog URL. Writes to {@link System#getProperties()}. + */ + public void setCatalogURL() { + } /** Property {@value}. */ public static final String CatalogUrl = "mondrian.catalogURL"; diff --git a/src/main/mondrian/tui/CmdRunner.java b/src/main/mondrian/tui/CmdRunner.java index 3eefe875f3..9b97964b55 100644 --- a/src/main/mondrian/tui/CmdRunner.java +++ b/src/main/mondrian/tui/CmdRunner.java @@ -111,11 +111,7 @@ public static void listPropertiesAll(StringBuffer buf) { } private static String getPropertyValue(String propertyName) { - if (propertyName.equals(MondrianProperties.CatalogUrl)) { - return System.getProperty(MondrianProperties.CatalogUrl); - } else { - return MondrianProperties.instance().getProperty(propertyName); - } + return MondrianProperties.instance().getProperty(propertyName); } public static void listProperty(String propertyName, StringBuffer buf) { @@ -134,11 +130,7 @@ public static boolean isProperty(String propertyName) { public static boolean setProperty(String name, String value) { String oldValue = getPropertyValue(name); if (! Util.equals(oldValue, value)) { - if (name.equals(MondrianProperties.CatalogUrl)) { - System.setProperty(MondrianProperties.CatalogUrl, value); - } else { - MondrianProperties.instance().setProperty(name, value); - } + MondrianProperties.instance().setProperty(name, value); return true; } else { return false; @@ -1037,7 +1029,6 @@ protected String executeFunc(String mdxCmd) { } else if (tokens.length == 2) { String funcname = tokens[1]; List funInfoList = FunTable.instance().getFunInfoList(); - Category cat = Category.instance(); List matches = new ArrayList(); Iterator it = funInfoList.iterator(); diff --git a/testsrc/main/mondrian/test/Main.java b/testsrc/main/mondrian/test/Main.java index ad22315270..da481f4771 100644 --- a/testsrc/main/mondrian/test/Main.java +++ b/testsrc/main/mondrian/test/Main.java @@ -127,7 +127,7 @@ public static Test suite() throws Exception { suite.addTestSuite(AccessControlTest.class); suite.addTestSuite(ParserTest.class); suite.addTestSuite(ParentChildHierarchyTest.class); - if (false) suite.addTestSuite(XmlaTest.class); + suite.addTestSuite(XmlaTest.class); if (isRunOnce()) suite.addTestSuite(TestCalculatedMembers.class); suite.addTestSuite(RaggedHierarchyTest.class); } diff --git a/testsrc/main/mondrian/xmla/XmlaTest.java b/testsrc/main/mondrian/xmla/XmlaTest.java index dc824e1d12..1fafa07640 100644 --- a/testsrc/main/mondrian/xmla/XmlaTest.java +++ b/testsrc/main/mondrian/xmla/XmlaTest.java @@ -14,10 +14,15 @@ import junit.framework.TestCase; import java.io.StringWriter; +import java.io.File; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import java.util.regex.Pattern; +import java.net.URL; + +import mondrian.olap.MondrianProperties; +import mondrian.olap.Util; /** * Unit test for Mondrian's XML for Analysis API (package @@ -29,8 +34,6 @@ **/ public class XmlaTest extends TestCase { private static final String nl = System.getProperty("line.separator"); - //private static final String dataSource = "Provider=MSOLAP;Data Source=local;"; - private static final String FOODMART_CATALOG_URL = "mondrian.test.foodmart.catalogURL"; private static String catalogName; private static String dataSource; @@ -42,12 +45,23 @@ public class XmlaTest extends TestCase { public XmlaTest(String s) { super(s); - if( System.getProperty(FOODMART_CATALOG_URL) != null ) - catalogName = System.getProperty(FOODMART_CATALOG_URL); - else - catalogName = "file:/E:/mondrian/demo/FoodMart.xml"; - dataSource = "Provider=Mondrian;Jdbc=jdbc:odbc:MondrianFoodMart;Catalog=" + catalogName + ";JdbcDrivers=sun.jdbc.odbc.JdbcOdbcDriver;"; + } + protected void setUp() throws Exception { + super.setUp(); + + catalogName = MondrianProperties.instance().getCatalogURL(); + if (catalogName == null) { + final File file = new File("demo/FoodMart.xml"); + if (!file.exists()) { + throw new RuntimeException("CatalogURL must be specified"); + } + final URL url = Util.toURL(file); + catalogName = url.toString(); + } + dataSource = + "Provider=Mondrian;Jdbc=jdbc:odbc:MondrianFoodMart;Catalog=" + + catalogName + ";JdbcDrivers=sun.jdbc.odbc.JdbcOdbcDriver;"; } /** @@ -204,7 +218,7 @@ public void testDiscoverCatalogs() { } public void testDiscoverCubes() { - assertRequestYields(wrap( + assertRequestMatches(wrap( "" + nl + " MDSCHEMA_CUBES" + nl + @@ -222,13 +236,7 @@ public void testDiscoverCubes() { " " + nl + ""), - "" + nl + - "" + nl + - " " + nl + - " " + nl + - " " + nl + - " " + nl + - " " + nl + + "(?s).*" + nl + " " + nl + " " + catalogName + "" + nl + " FoodMart" + nl + @@ -238,47 +246,7 @@ public void testDiscoverCubes() { " false" + nl + " false" + nl + " " + nl + - " " + nl + - " " + catalogName + "" + nl + - " FoodMart" + nl + - " Warehouse and Sales" + nl + - " true" + nl + - " false" + nl + - " false" + nl + - " false" + nl + - " " + nl + - " " + nl + - " " + catalogName + "" + nl + - " FoodMart" + nl + - " Sales" + nl + - " true" + nl + - " false" + nl + - " false" + nl + - " false" + nl + - " " + nl + - " " + nl + - " " + catalogName + "" + nl + - " FoodMart" + nl + - " HR" + nl + - " true" + nl + - " false" + nl + - " false" + nl + - " false" + nl + - " " + nl + - " " + nl + - " " + catalogName + "" + nl + - " FoodMart" + nl + - " Warehouse" + nl + - " true" + nl + - " false" + nl + - " false" + nl + - " false" + nl + - " " + nl + - " " + nl + - " " + nl + - " " + nl + - " " + nl + - ""); + ".*"); } public void testDiscoverCubesRestricted() {