Skip to content

Commit

Permalink
MONDRIAN: Added tests for compatibility of Mondrian XMLA with Cognos8…
Browse files Browse the repository at this point in the history
….2 connected via Simba O2X bridge

[git-p4: depot-paths = "//open/mondrian/": change = 9277]
  • Loading branch information
thiyagu committed May 17, 2007
1 parent bdc5042 commit 748805a
Show file tree
Hide file tree
Showing 5 changed files with 6,412 additions and 207 deletions.
2 changes: 2 additions & 0 deletions testsrc/main/mondrian/test/Main.java
Expand Up @@ -42,6 +42,7 @@
import mondrian.xmla.XmlaExcel2000Test;
import mondrian.xmla.XmlaExcelXPTest;
import mondrian.xmla.XmlaErrorTest;
import mondrian.xmla.XmlaCognosTest;
import mondrian.xmla.impl.DynamicDatasourceXmlaServletTest;
import mondrian.xmla.test.XmlaTest;
import mondrian.test.clearview.*;
Expand Down Expand Up @@ -198,6 +199,7 @@ public static Test suite() throws Exception {
suite.addTestSuite(XmlaErrorTest.class);
suite.addTestSuite(XmlaExcel2000Test.class);
suite.addTestSuite(XmlaExcelXPTest.class);
suite.addTestSuite(XmlaCognosTest.class);
suite.addTestSuite(DynamicDatasourceXmlaServletTest.class);
suite.addTest(XmlaTest.suite());
if (isRunOnce()) suite.addTestSuite(TestCalculatedMembers.class);
Expand Down
205 changes: 205 additions & 0 deletions testsrc/main/mondrian/xmla/XmlaBaseTestCase.java
Expand Up @@ -13,18 +13,23 @@
import mondrian.test.DiffRepository;
import mondrian.test.TestContext;
import mondrian.tui.XmlaSupport;
import mondrian.tui.XmlUtil;
import mondrian.olap.Util;
import mondrian.rolap.RolapConnectionProperties;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import org.custommonkey.xmlunit.XMLAssert;

import javax.servlet.ServletException;
import javax.servlet.Servlet;
import java.io.IOException;
import java.io.ByteArrayInputStream;
import java.util.*;

import junit.framework.AssertionFailedError;

/**
* Extends FoodMartTestCase, adding support for testing XMLA specific
* functionality, for example LAST_SCHEMA_UPDATE
Expand All @@ -45,6 +50,18 @@ public abstract class XmlaBaseTestCase extends FoodMartTestCase {
new HashMap<String, String>();
// session id property
public static final String SESSION_ID_PROP = "session.id";
// request.type
public static final String REQUEST_TYPE_PROP = "request.type";// data.source.info
public static final String DATA_SOURCE_INFO_PROP = "data.source.info";
public static final String DATA_SOURCE_INFO = "MondrianFoodMart";// catalog
public static final String CATALOG_PROP = "catalog";
public static final String CATALOG_NAME_PROP= "catalog.name";
public static final String CATALOG = "FoodMart";// cube
public static final String CUBE_NAME_PROP = "cube.name";
public static final String SALES_CUBE = "Sales";// format
public static final String FORMAT_PROP = "format";
public static final String FORMAT_MULTI_DIMENSIONAL = "Multidimensional";
private static final boolean DEBUG = false;

public XmlaBaseTestCase() {
}
Expand Down Expand Up @@ -111,6 +128,194 @@ protected void setUp() throws Exception {
protected void tearDown() throws Exception {
}

protected Properties getDefaultRequestProperties(String requestType) {
Properties props = new Properties();
props.setProperty(REQUEST_TYPE_PROP, requestType);
props.setProperty(CATALOG_PROP, CATALOG);
props.setProperty(CATALOG_NAME_PROP, CATALOG);
props.setProperty(CUBE_NAME_PROP, SALES_CUBE);
props.setProperty(FORMAT_PROP, FORMAT_MULTI_DIMENSIONAL);
props.setProperty(DATA_SOURCE_INFO_PROP, DATA_SOURCE_INFO);
return props;
}

protected Document fileToDocument(String filename)
throws IOException , SAXException {
String s = getDiffRepos().expand(null, filename);
if (s.equals(filename)) {
s = "<?xml version='1.0'?><Empty/>";
}
Document doc = XmlUtil.parse(new ByteArrayInputStream(s.getBytes()));
return doc;
}

/**
* Executes an XMLA request, reading the text of the request and the
* response from attributes in {@link #getDiffRepos()}.
*
* @param requestType Request type: "DISCOVER_DATASOURCES", "EXECUTE", etc.
* @param props Properties for request
* @param testContext Test context
*/
public void doTest(
String requestType,
Properties props,
TestContext testContext) throws Exception {

String requestText = fileToString("request");
doTestInline(
requestType, requestText, "${response}", props, testContext);
}

public void doTestInline(
String requestType,
String requestText,
String respFileName,
Properties props,
TestContext testContext)
throws Exception
{
Document responseDoc = (respFileName != null)
? fileToDocument(respFileName)
: null;

String connectString = testContext.getConnectString();
Map<String,String> catalogNameUrls = getCatalogNameUrls(testContext);

Document expectedDoc;

// Test 'schemadata' first, so that if it fails, we will be able to
// amend the ref file with the fullest XML response.
final String ns = "cxmla";
expectedDoc = (responseDoc != null)
? XmlaSupport.transformSoapXmla(
responseDoc, new String[][] {{"content", "schemadata"}}, ns)
: null;
doTests(
requestText, props, null, connectString, catalogNameUrls,
expectedDoc, XmlaBasicTest.CONTENT_SCHEMADATA);

if (requestType.equals("EXECUTE")) {
return;
}

expectedDoc = (responseDoc != null)
? XmlaSupport.transformSoapXmla(
responseDoc, new String[][] {{"content", "none"}}, ns)
: null;

doTests(requestText, props, null, connectString, catalogNameUrls,
expectedDoc, XmlaBasicTest.CONTENT_NONE);

expectedDoc = (responseDoc != null)
? XmlaSupport.transformSoapXmla(
responseDoc, new String[][] {{"content", "data"}}, ns)
: null;
doTests(requestText, props, null, connectString, catalogNameUrls,
expectedDoc, XmlaBasicTest.CONTENT_DATA);

expectedDoc = (responseDoc != null)
? XmlaSupport.transformSoapXmla(
responseDoc, new String[][] {{"content", "schema"}}, ns)
: null;
doTests(requestText, props, null, connectString, catalogNameUrls,
expectedDoc, XmlaBasicTest.CONTENT_SCHEMA);
}

protected void doTests(
String soapRequestText,
Properties props,
String soapResponseText,
String connectString,
Map<String, String> catalogNameUrls,
Document expectedDoc,
String content) throws Exception {

if (content != null) {
props.setProperty(XmlaBasicTest.CONTENT_PROP, content);
}
soapRequestText = Util.replaceProperties(
soapRequestText, Util.toMap(props));

if (DEBUG) {
System.out.println("soapRequestText="+soapRequestText);
}
Document soapReqDoc = XmlUtil.parseString(soapRequestText);

Document xmlaReqDoc = XmlaSupport.extractBodyFromSoap(soapReqDoc);

// do XMLA
byte[] bytes =
XmlaSupport.processXmla(xmlaReqDoc, connectString, catalogNameUrls);
String response = new String(bytes);
if (DEBUG) {
System.out.println("xmla response="+response);
}
if (XmlUtil.supportsValidation()) {
if (XmlaSupport.validateXmlaUsingXpath(bytes)) {
if (DEBUG) {
System.out.println("XML Data is Valid");
}
}
}

// do SOAP-XMLA
bytes = XmlaSupport.processSoapXmla(soapReqDoc, connectString, catalogNameUrls, null);
response = new String(bytes);
if (DEBUG) {
System.out.println("soap response="+response);
}
if (XmlUtil.supportsValidation()) {
if (XmlaSupport.validateSoapXmlaUsingXpath(bytes)) {
if (DEBUG) {
System.out.println("XML Data is Valid");
}
}
}

Document gotDoc = ignoreLastUpdateDate(XmlUtil.parse(bytes));
String gotStr = XmlUtil.toString(gotDoc, true);
gotStr = Util.maskVersion(gotStr);
if (expectedDoc != null) {
String expectedStr = XmlUtil.toString(expectedDoc, true);
if (DEBUG) {
System.out.println("GOT:\n"+gotStr);
System.out.println("EXPECTED:\n"+expectedStr);
System.out.println("XXXXXXX");
}
try {
XMLAssert.assertXMLEqual(expectedStr, gotStr);
} catch (AssertionFailedError e) {
if (content.equals(XmlaBasicTest.CONTENT_SCHEMADATA)) {
// Let DiffRepository do the comparison. It will output
// a textual difference, and will update the logfile,
// XmlaBasicTest.log.xml. If you agree with the change,
// copy this file to XmlaBasicTest.ref.xml.
getDiffRepos().assertEquals("response", "${response}", gotStr);
} else {
throw e;
}
}
} else {
if (content.equals(XmlaBasicTest.CONTENT_SCHEMADATA)) {
getDiffRepos().amend("${response}", gotStr);
}
}
}

private Document ignoreLastUpdateDate(Document document) {
NodeList elements = document.getElementsByTagName("LAST_SCHEMA_UPDATE");
for (int i = elements.getLength(); i > 0; i--) {
removeNode(elements.item(i-1));
}
return document;
}

private void removeNode(Node node) {
Node parentNode = node.getParentNode();
parentNode.removeChild(node);
}

enum Action {
CREATE,
QUERY,
Expand Down

0 comments on commit 748805a

Please sign in to comment.