use of mondrian.olap.Hierarchy in project mondrian by pentaho.
the class RestrictedMemberReaderTest method testDefaultMember_multiRoot.
public void testDefaultMember_multiRoot() {
RolapHierarchy hierarchy = Mockito.mock(RolapHierarchy.class);
MemberReader delegateMemberReader = Mockito.mock(MemberReader.class);
HierarchyAccess roleAccess = Mockito.mock(HierarchyAccess.class);
Role role = Mockito.mock(Role.class);
RolapMember member0 = mockMember();
RolapMember member1 = mockMember();
RolapMember member2 = mockMember();
List<RolapMember> rootMembers = Arrays.asList(new RolapMember[] { member0, member1, member2 });
RolapMember hierDefaultMember = member1;
Mockito.doReturn(roleAccess).when(role).getAccessDetails(Mockito.any(Hierarchy.class));
Mockito.doReturn(hierarchy).when(delegateMemberReader).getHierarchy();
Mockito.doReturn(hierDefaultMember).when(hierarchy).getDefaultMember();
rmr = Mockito.spy(new RestrictedMemberReader(delegateMemberReader, role));
Mockito.doReturn(rootMembers).when(rmr).getRootMembers();
Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(member0);
Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(member1);
Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(member2);
Assert.assertSame("on Access C-N-N", member0, rmr.getDefaultMember());
Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(member0);
Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(member1);
Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(member2);
Assert.assertSame("on Access N-N-C", member2, rmr.getDefaultMember());
Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(member0);
Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(member1);
Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(member2);
Assert.assertSame("on Access C-C-C", hierDefaultMember, rmr.getDefaultMember());
Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(member0);
Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(member1);
Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(member2);
Assert.assertTrue("on Access C-N-C", rmr.getDefaultMember() instanceof MultiCardinalityDefaultMember);
Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(anyRolapMember());
Assert.assertTrue("on Access.NONE", rmr.getDefaultMember() instanceof MultiCardinalityDefaultMember);
}
use of mondrian.olap.Hierarchy in project mondrian by pentaho.
the class RolapCubeHierarchyTest method testInit_FactCube_FactTableDiffers.
public void testInit_FactCube_FactTableDiffers() {
RolapCubeDimension cubeDimension = mock(RolapCubeDimension.class);
RolapCube cubeDimension_cube = mock(RolapCube.class);
boolean cubeDimension_cube_isVirtual = true;
String cubeDimension_uniqueName = "TheDimUniqueName";
RolapSchema cubeDimension_schema = mock(RolapSchema.class);
RolapConnection cubeDimension_schema_connection = mock(RolapConnection.class);
DataSource cubeDimension_schema_connection_DS = mock(DataSource.class);
MondrianDef.CubeDimension cubeDim = null;
RolapHierarchy rolapHierarchy = mock(RolapHierarchy.class);
Hierarchy rolapHierarchy_hierarchy = null;
String rolapHierarchy_uniqueName = "TheDimUniqueName";
Level[] rolapHierarchy_levels = new Level[] {};
RelationOrJoin rolapHierarchy_relation = mock(Relation.class);
String subName = null;
int ordinal = 0;
RolapCube factCube = mock(RolapCube.class);
RelationOrJoin factCube_Fact = mock(Relation.class);
boolean factCube_Fact_equals = false;
// check
assertEquals(factCube_Fact_equals, factCube_Fact.equals(rolapHierarchy_relation));
assertEquals(factCube_Fact_equals, rolapHierarchy_relation.equals(factCube_Fact));
doReturn(cubeDimension_cube).when(cubeDimension).getCube();
doReturn(cubeDimension_cube_isVirtual).when(cubeDimension_cube).isVirtual();
doReturn(cubeDimension_schema).when(cubeDimension).getSchema();
doReturn(cubeDimension_schema_connection).when(cubeDimension_schema).getInternalConnection();
doReturn(cubeDimension_schema_connection_DS).when(cubeDimension_schema_connection).getDataSource();
doReturn(cubeDimension_uniqueName).when(cubeDimension).getUniqueName();
doReturn(rolapHierarchy_hierarchy).when(rolapHierarchy).getHierarchy();
doReturn(rolapHierarchy_levels).when(rolapHierarchy).getLevels();
doReturn(rolapHierarchy_uniqueName).when(rolapHierarchy).getUniqueName();
doReturn(rolapHierarchy_relation).when(rolapHierarchy).getRelation();
doReturn(factCube_Fact).when(factCube).getFact();
RolapCubeHierarchy rch = new RolapCubeHierarchy(cubeDimension, cubeDim, rolapHierarchy, subName, ordinal, factCube);
assertEquals(false, rch.isUsingCubeFact());
}
use of mondrian.olap.Hierarchy in project mondrian by pentaho.
the class RolapCubeHierarchyTest method testInit_FactCube_NoFactTable.
public void testInit_FactCube_NoFactTable() {
RolapCubeDimension cubeDimension = mock(RolapCubeDimension.class);
RolapCube cubeDimension_cube = mock(RolapCube.class);
boolean cubeDimension_cube_isVirtual = true;
String cubeDimension_uniqueName = "TheDimUniqueName";
RolapSchema cubeDimension_schema = mock(RolapSchema.class);
RolapConnection cubeDimension_schema_connection = mock(RolapConnection.class);
DataSource cubeDimension_schema_connection_DS = mock(DataSource.class);
MondrianDef.CubeDimension cubeDim = null;
RolapHierarchy rolapHierarchy = mock(RolapHierarchy.class);
Hierarchy rolapHierarchy_hierarchy = null;
String rolapHierarchy_uniqueName = "TheDimUniqueName";
Level[] rolapHierarchy_levels = new Level[] {};
String subName = null;
int ordinal = 0;
RolapCube factCube = mock(RolapCube.class);
RolapCube factCube_Fact = null;
doReturn(cubeDimension_cube).when(cubeDimension).getCube();
doReturn(cubeDimension_cube_isVirtual).when(cubeDimension_cube).isVirtual();
doReturn(cubeDimension_schema).when(cubeDimension).getSchema();
doReturn(cubeDimension_schema_connection).when(cubeDimension_schema).getInternalConnection();
doReturn(cubeDimension_schema_connection_DS).when(cubeDimension_schema_connection).getDataSource();
doReturn(cubeDimension_uniqueName).when(cubeDimension).getUniqueName();
doReturn(rolapHierarchy_hierarchy).when(rolapHierarchy).getHierarchy();
doReturn(rolapHierarchy_levels).when(rolapHierarchy).getLevels();
doReturn(rolapHierarchy_uniqueName).when(rolapHierarchy).getUniqueName();
doReturn(factCube_Fact).when(factCube).getFact();
RolapCubeHierarchy rch = new RolapCubeHierarchy(cubeDimension, cubeDim, rolapHierarchy, subName, ordinal, factCube);
assertEquals(true, rch.isUsingCubeFact());
}
use of mondrian.olap.Hierarchy in project mondrian by pentaho.
the class RolapCubeHierarchyTest method testInit_NoFactCube.
public void testInit_NoFactCube() {
RolapCubeDimension cubeDimension = mock(RolapCubeDimension.class);
RolapCube cubeDimension_cube = mock(RolapCube.class);
boolean cubeDimension_cube_isVirtual = true;
String cubeDimension_uniqueName = "TheDimUniqueName";
RolapSchema cubeDimension_schema = mock(RolapSchema.class);
RolapConnection cubeDimension_schema_connection = mock(RolapConnection.class);
DataSource cubeDimension_schema_connection_DS = mock(DataSource.class);
MondrianDef.CubeDimension cubeDim = null;
RolapHierarchy rolapHierarchy = mock(RolapHierarchy.class);
Hierarchy rolapHierarchy_hierarchy = null;
String rolapHierarchy_uniqueName = "TheDimUniqueName";
Level[] rolapHierarchy_levels = new Level[] {};
String subName = null;
int ordinal = 0;
RolapCube factCube = null;
doReturn(cubeDimension_cube).when(cubeDimension).getCube();
doReturn(cubeDimension_cube_isVirtual).when(cubeDimension_cube).isVirtual();
doReturn(cubeDimension_schema).when(cubeDimension).getSchema();
doReturn(cubeDimension_schema_connection).when(cubeDimension_schema).getInternalConnection();
doReturn(cubeDimension_schema_connection_DS).when(cubeDimension_schema_connection).getDataSource();
doReturn(cubeDimension_uniqueName).when(cubeDimension).getUniqueName();
doReturn(rolapHierarchy_hierarchy).when(rolapHierarchy).getHierarchy();
doReturn(rolapHierarchy_levels).when(rolapHierarchy).getLevels();
doReturn(rolapHierarchy_uniqueName).when(rolapHierarchy).getUniqueName();
RolapCubeHierarchy rch = new RolapCubeHierarchy(cubeDimension, cubeDim, rolapHierarchy, subName, ordinal, factCube);
assertEquals("If factCube is null", true, rch.isUsingCubeFact());
rch = new RolapCubeHierarchy(cubeDimension, cubeDim, rolapHierarchy, subName, ordinal);
assertEquals("If factCube is not specified", true, rch.isUsingCubeFact());
}
use of mondrian.olap.Hierarchy in project mondrian by pentaho.
the class ExistingFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
final IterCalc setArg = compiler.compileIter(call.getArg(0));
final Type myType = call.getArg(0).getType();
return new AbstractListCalc(call, new Calc[] { setArg }) {
public boolean dependsOn(Hierarchy hierarchy) {
return myType.usesHierarchy(hierarchy, false);
}
public TupleList evaluateList(Evaluator evaluator) {
TupleIterable setTuples = setArg.evaluateIterable(evaluator);
TupleList result = TupleCollections.createList(setTuples.getArity());
List<Member> contextMembers = Arrays.asList(evaluator.getMembers());
List<Hierarchy> argDims = null;
List<Hierarchy> contextDims = getHierarchies(contextMembers);
for (List<Member> tuple : setTuples) {
if (argDims == null) {
argDims = getHierarchies(tuple);
}
if (existsInTuple(tuple, contextMembers, argDims, contextDims, evaluator)) {
result.add(tuple);
}
}
return result;
}
};
}
Aggregations