use of mondrian.test.TestContext in project mondrian by pentaho.
the class NonEmptyTest method testFilterChildlessSnowflakeMembers.
public void testFilterChildlessSnowflakeMembers() {
propSaver.set(MondrianProperties.instance().FilterChildlessSnowflakeMembers, false);
SqlPattern[] patterns = { new SqlPattern(Dialect.DatabaseProduct.MYSQL, "select `product_class`.`product_family` as `c0` " + "from `product_class` as `product_class` " + "group by `product_class`.`product_family` " + (TestContext.instance().getDialect().requiresOrderByAlias() ? "order by ISNULL(`c0`) ASC," + " `c0` ASC" : "order by ISNULL(`product_class`.`product_family`) ASC," + " `product_class`.`product_family` ASC"), null) };
final TestContext context = getTestContext().withFreshConnection();
try {
assertQuerySql(context, "select [Product].[Product Family].Members on 0\n" + "from [Sales]", patterns);
// note that returns an extra member,
// [Product].[Drink].[Baking Goods]
context.assertQueryReturns("select [Product].[Drink].Children on 0\n" + "from [Sales]", "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Product].[Drink].[Alcoholic Beverages]}\n" + "{[Product].[Drink].[Baking Goods]}\n" + "{[Product].[Drink].[Beverages]}\n" + "{[Product].[Drink].[Dairy]}\n" + "Row #0: 6,838\n" + "Row #0: \n" + "Row #0: 13,573\n" + "Row #0: 4,186\n");
// [Product].[Drink].[Baking Goods] has one child, but no fact data
context.assertQueryReturns("select [Product].[Drink].[Baking Goods].Children on 0\n" + "from [Sales]", "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Product].[Drink].[Baking Goods].[Dry Goods]}\n" + "Row #0: \n");
// NON EMPTY filters out that child
context.assertQueryReturns("select non empty [Product].[Drink].[Baking Goods].Children on 0\n" + "from [Sales]", "Axis #0:\n" + "{}\n" + "Axis #1:\n");
// [Product].[Drink].[Baking Goods].[Dry Goods] has one child, but
// no fact data
context.assertQueryReturns("select [Product].[Drink].[Baking Goods].[Dry Goods].Children on 0\n" + "from [Sales]", "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Product].[Drink].[Baking Goods].[Dry Goods].[Coffee]}\n" + "Row #0: \n");
// NON EMPTY filters out that child
context.assertQueryReturns("select non empty [Product].[Drink].[Baking Goods].[Dry Goods].Children on 0\n" + "from [Sales]", "Axis #0:\n" + "{}\n" + "Axis #1:\n");
// [Coffee] has no children
context.assertQueryReturns("select [Product].[Drink].[Baking Goods].[Dry Goods].[Coffee].Children on 0\n" + "from [Sales]", "Axis #0:\n" + "{}\n" + "Axis #1:\n");
context.assertQueryReturns("select [Measures].[Unit Sales] on 0,\n" + " [Product].[Product Family].Members on 1\n" + "from [Sales]", "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Measures].[Unit Sales]}\n" + "Axis #2:\n" + "{[Product].[Drink]}\n" + "{[Product].[Food]}\n" + "{[Product].[Non-Consumable]}\n" + "Row #0: 24,597\n" + "Row #1: 191,940\n" + "Row #2: 50,236\n");
} finally {
context.close();
}
}
use of mondrian.test.TestContext in project mondrian by pentaho.
the class OrderKeyOneToOneCheckTest method getTestContext.
@Override
public TestContext getTestContext() {
TestContext testContext = super.getTestContext().withFreshConnection();
testContext.flushSchemaCache();
return testContext.withSchema("" + "<?xml version=\"1.0\"?>\n" + "<Schema name=\"FoodMart 2358\">\n" + " <Dimension name=\"Time\" type=\"TimeDimension\">\n" + " <Hierarchy hasAll=\"false\" primaryKey=\"time_id\">\n" + " <Table name=\"time_by_day\"/>\n" + " <Level name=\"Year\" column=\"the_year\" type=\"Numeric\" uniqueMembers=\"true\"\n" + " levelType=\"TimeYears\"/> \n" + " <Level name=\"Quarter\" column=\"quarter\" ordinalColumn=\"month_of_year\" uniqueMembers=\"false\" levelType=\"TimeQuarters\"/> \n" + " <Level name=\"Month\" column=\"month_of_year\" uniqueMembers=\"false\" type=\"Numeric\"\n" + " levelType=\"TimeMonths\"/>\n" + " </Hierarchy>\n" + " </Dimension>\n" + "<Cube name=\"Sales\" defaultMeasure=\"Unit Sales\">\n" + " <Table name=\"sales_fact_1997\"/>\n" + " <DimensionUsage name=\"Time\" source=\"Time\" foreignKey=\"time_id\"/>\n" + " <Measure name=\"Unit Sales\" column=\"unit_sales\" aggregator=\"sum\"\n" + " formatString=\"Standard\"/>\n" + "</Cube>\n" + "</Schema>");
}
use of mondrian.test.TestContext in project mondrian by pentaho.
the class RolapCubeTest method testGetCalculatedMembersReturnsOnlyAccessibleMembers.
public void testGetCalculatedMembersReturnsOnlyAccessibleMembers() {
String[] expectedCalculatedMembers = { "[Measures].[Profit]", "[Measures].[Profit last Period]", "[Measures].[Profit Growth]", "[Product].[~Missing]" };
TestContext testContext = createTestContextWithAdditionalMembersAndARole();
Connection connection = testContext.getConnection();
try {
Cube salesCube = cubeByName(connection, "Sales");
SchemaReader schemaReader = salesCube.getSchemaReader(connection.getRole());
List<Member> calculatedMembers = schemaReader.getCalculatedMembers();
assertEquals(expectedCalculatedMembers.length, calculatedMembers.size());
assertCalculatedMemberExists(expectedCalculatedMembers, calculatedMembers);
} finally {
connection.close();
}
}
use of mondrian.test.TestContext in project mondrian by pentaho.
the class RolapCubeTest method testNonJoiningDimensions.
public void testNonJoiningDimensions() {
TestContext testContext = this.getTestContext();
Connection connection = testContext.getConnection();
try {
RolapCube salesCube = (RolapCube) cubeByName(connection, "Sales");
RolapCube warehouseAndSalesCube = (RolapCube) cubeByName(connection, "Warehouse and Sales");
SchemaReader readerWarehouseAndSales = warehouseAndSalesCube.getSchemaReader().withLocus();
List<Member> members = new ArrayList<Member>();
List<Member> warehouseMembers = warehouseMembersCanadaMexicoUsa(readerWarehouseAndSales);
Dimension warehouseDim = warehouseMembers.get(0).getDimension();
members.addAll(warehouseMembers);
List<Member> storeMembers = storeMembersCAAndOR(readerWarehouseAndSales).slice(0);
Dimension storeDim = storeMembers.get(0).getDimension();
members.addAll(storeMembers);
Set<Dimension> nonJoiningDims = salesCube.nonJoiningDimensions(members.toArray(new Member[0]));
assertFalse(nonJoiningDims.contains(storeDim));
assertTrue(nonJoiningDims.contains(warehouseDim));
} finally {
connection.close();
}
}
use of mondrian.test.TestContext in project mondrian by pentaho.
the class RolapNativeSqlInjectionTest method testMondrian2436.
public void testMondrian2436() {
String mdxQuery = "" + "select {[Measures].[Store Sales]} on columns, " + "filter([Customers].[Name].Members, (([Measures].[Store Sales]) > '(select 1000)')) on rows " + "from [Sales]";
TestContext context = getTestContext().withFreshConnection();
try {
context.executeQuery(mdxQuery);
} catch (MondrianException e) {
assertNotNull("MondrianEvaluationException is expected on invalid filter condition", e.getCause());
assertEquals("Expected to get decimal, but got (select 1000)", e.getCause().getMessage());
return;
} finally {
context.close();
}
fail("[Store Sales] filtering should not work for non-valid decimals");
}
Aggregations