Search in sources :

Example 1 with DiffRepository

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();
}
Also used : DiffRepository(mondrian.test.DiffRepository)

Example 2 with DiffRepository

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);
}
Also used : DiffRepository(mondrian.test.DiffRepository) StringRepositoryContentFinder(mondrian.server.StringRepositoryContentFinder)

Example 3 with DiffRepository

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);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) PropertyList(mondrian.olap.Util.PropertyList) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) DiffRepository(mondrian.test.DiffRepository) Properties(java.util.Properties) RolapConnectionProperties(mondrian.rolap.RolapConnectionProperties)

Example 4 with DiffRepository

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;
}
Also used : Pattern(java.util.regex.Pattern) DiffRepository(mondrian.test.DiffRepository)

Example 5 with DiffRepository

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()][]);
}
Also used : DiffRepository(mondrian.test.DiffRepository) URL(java.net.URL)

Aggregations

DiffRepository (mondrian.test.DiffRepository)5 URL (java.net.URL)1 Properties (java.util.Properties)1 Pattern (java.util.regex.Pattern)1 Transformer (javax.xml.transform.Transformer)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 PropertyList (mondrian.olap.Util.PropertyList)1 RolapConnectionProperties (mondrian.rolap.RolapConnectionProperties)1 StringRepositoryContentFinder (mondrian.server.StringRepositoryContentFinder)1