use of mondrian.test.DiffRepository in project mondrian by pentaho.
the class XmlaTest method tearDown.
// implement TestCase
protected void tearDown() throws Exception {
DiffRepository diffRepos = getDiffRepos();
diffRepos.setCurrentTestCaseName(null);
server.shutdown();
server = null;
handler = null;
super.tearDown();
}
use of mondrian.test.DiffRepository in project mondrian by pentaho.
the class XmlaTest method setUp.
// implement TestCase
protected void setUp() throws Exception {
super.setUp();
DiffRepository diffRepos = getDiffRepos();
diffRepos.setCurrentTestCaseName(getName());
server = MondrianServer.createWithRepository(new StringRepositoryContentFinder(context.getDataSourcesString()), XmlaTestContext.CATALOG_LOCATOR);
handler = new XmlaHandler((XmlaHandler.ConnectionFactory) server, "xmla");
XMLUnit.setIgnoreWhitespace(false);
}
use of mondrian.test.DiffRepository in project mondrian by pentaho.
the class XmlaTest method runTest.
protected void runTest() throws Exception {
if (!MondrianProperties.instance().SsasCompatibleNaming.get() && getName().equals("mdschemaLevelsCubeDimRestrictions")) {
// fixed by a few sed-like comparisons.
return;
}
DiffRepository diffRepos = getDiffRepos();
String request = diffRepos.expand(null, "${request}");
String expectedResponse = diffRepos.expand(null, "${response}");
Properties props = new Properties();
XmlaTestContext s = new XmlaTestContext();
String con = s.getConnectString().replaceAll("&", "&");
PropertyList pl = Util.parseConnectString(con);
pl.remove(RolapConnectionProperties.Jdbc.name());
pl.remove(RolapConnectionProperties.JdbcUser.name());
pl.remove(RolapConnectionProperties.JdbcPassword.name());
props.setProperty(DATA_SOURCE_INFO_RESPONSE_PROP, pl.toString());
expectedResponse = Util.replaceProperties(expectedResponse, Util.toMap(props));
Element requestElem = XmlaUtil.text2Element(XmlaTestContext.xmlFromTemplate(request, XmlaTestContext.ENV));
Element responseElem = ignoreLastUpdateDate(executeRequest(requestElem));
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
StringWriter bufWriter = new StringWriter();
transformer.transform(new DOMSource(responseElem), new StreamResult(bufWriter));
bufWriter.write(Util.nl);
String actualResponse = TestContext.instance().upgradeActual(bufWriter.getBuffer().toString());
try {
// Start with a purely logical XML diff to avoid test noise
// from non-determinism in XML generation.
XMLAssert.assertXMLEqual(expectedResponse, actualResponse);
} catch (AssertionFailedError e) {
// In case of failure, re-diff using DiffRepository's comparison
// method. It may have noise due to physical vs logical structure,
// but it will maintain the expected/actual, and some IDEs can even
// display visual diffs.
diffRepos.assertEquals("response", "${response}", actualResponse);
}
}
use of mondrian.test.DiffRepository in project mondrian by pentaho.
the class XmlaTest method suite.
public static TestSuite suite() {
TestSuite suite = new TestSuite();
DiffRepository diffRepos = getDiffRepos();
MondrianProperties properties = MondrianProperties.instance();
String filePattern = properties.QueryFilePattern.get();
final Pattern pattern = filePattern == null ? null : Pattern.compile(filePattern);
List<String> testCaseNames = diffRepos.getTestCaseNames();
if (pattern != null) {
Iterator<String> iter = testCaseNames.iterator();
while (iter.hasNext()) {
String name = iter.next();
if (!pattern.matcher(name).matches()) {
iter.remove();
}
}
}
LOGGER.debug("Found " + testCaseNames.size() + " XML/A test cases");
for (String name : testCaseNames) {
suite.addTest(new XmlaTest(name));
}
suite.addTestSuite(OtherTest.class);
return suite;
}
use of mondrian.test.DiffRepository in project mondrian by pentaho.
the class XmlaTestContext method defaultRequests.
/**
* Returns a list of sample XML requests.
*
* <p>Each item is a pair of strings: {test name, request}.
*
* <p>NOTE: This method is called from <code>xmlaTest.jsp</code>. Do not
* remove it if you can't find calls from Java.
*
* @return List of sample XML requests
*/
public String[][] defaultRequests() {
// Assume that the ref file is in the same tree (WEB-INF/classes) as
// DiffRepository.class.
URL refUrl = DiffRepository.class.getClassLoader().getResource("mondrian/xmla/test/XmlaTest.ref.xml");
DiffRepository diffRepos = new DiffRepository(refUrl);
List<String[]> stringList = new ArrayList<String[]>();
for (String testName : diffRepos.getTestCaseNames()) {
String templateRequest = diffRepos.get(testName, "request");
String request = xmlFromTemplate(templateRequest, ENV);
stringList.add(new String[] { testName, request });
}
return stringList.toArray(new String[stringList.size()][]);
}
Aggregations