Search in sources :

Example 11 with Hierarchy

use of mondrian.olap.Hierarchy in project pentaho-platform by pentaho.

the class MDXMetaDataTest method mockMember.

private Member mockMember(String caption, String name) {
    Level level = mockLevel(name);
    Dimension dimension = mockDimension(name);
    Hierarchy hierarchy = mockHierarchy(name, caption);
    Member member = mock(Member.class);
    when(member.getCaption()).thenReturn(caption);
    when(member.getHierarchy()).thenReturn(hierarchy);
    when(member.getDimension()).thenReturn(dimension);
    when(member.getLevel()).thenReturn(level);
    return member;
}
Also used : Hierarchy(mondrian.olap.Hierarchy) Level(mondrian.olap.Level) Dimension(mondrian.olap.Dimension) Member(mondrian.olap.Member)

Example 12 with Hierarchy

use of mondrian.olap.Hierarchy in project mondrian by pentaho.

the class SqlConstraintUtilsTest method testRemoveCalculatedAndDefaultMembers.

public void testRemoveCalculatedAndDefaultMembers() {
    Hierarchy hierarchy = mock(Hierarchy.class);
    // create members
    List<Member> members = new ArrayList<Member>();
    // 0:passed
    members.add(createMemberMock(false, false, hierarchy));
    // 1:not passed
    members.add(createMemberMock(true, false, hierarchy));
    // 2:passed
    members.add(createMemberMock(true, true, hierarchy));
    // 3:passed
    members.add(createMemberMock(false, true, hierarchy));
    // 4:default,
    members.add(createMemberMock(false, true, hierarchy));
    // not passed
    // 5:passed
    members.add(createMemberMock(false, false, hierarchy));
    // 6:not passed
    members.add(createMemberMock(true, false, hierarchy));
    when(hierarchy.getDefaultMember()).thenReturn(members.get(4));
    List<Member> newMembers = SqlConstraintUtils.removeCalculatedAndDefaultMembers(members);
    assertEquals(4, newMembers.size());
    assertTrue(newMembers.contains(members.get(0)));
    assertTrue(newMembers.contains(members.get(2)));
    assertTrue(newMembers.contains(members.get(3)));
    assertTrue(newMembers.contains(members.get(5)));
}
Also used : Hierarchy(mondrian.olap.Hierarchy) ArrayList(java.util.ArrayList) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember)

Example 13 with Hierarchy

use of mondrian.olap.Hierarchy in project mondrian by pentaho.

the class RestrictedMemberReaderTest method testDefaultMember_noDefaultMember_roleAccess.

public void testDefaultMember_noDefaultMember_roleAccess() {
    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();
    List<RolapMember> rootMembers = Arrays.asList(new RolapMember[] { member0 });
    RolapMember hierDefaultMember = null;
    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(null).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertSame("on Access is null", member0, rmr.getDefaultMember());
    Mockito.doReturn(Access.ALL).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertSame("on Access.ALL", member0, rmr.getDefaultMember());
    Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertSame("on Access.CUSTOM", member0, rmr.getDefaultMember());
    Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertNotSame("on Access.NONE", member0, rmr.getDefaultMember());
    Assert.assertTrue(rmr.getDefaultMember() instanceof MultiCardinalityDefaultMember);
}
Also used : Role(mondrian.olap.Role) Hierarchy(mondrian.olap.Hierarchy) MultiCardinalityDefaultMember(mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember) HierarchyAccess(mondrian.olap.Role.HierarchyAccess)

Example 14 with Hierarchy

use of mondrian.olap.Hierarchy in project mondrian by pentaho.

the class RestrictedMemberReaderTest method testDefaultMember_roleAccess.

public void testDefaultMember_roleAccess() {
    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();
    List<RolapMember> rootMembers = Arrays.asList(new RolapMember[] { member0 });
    RolapMember hierDefaultMember = member0;
    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(null).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertSame("on Access is null", hierDefaultMember, rmr.getDefaultMember());
    Mockito.doReturn(Access.ALL).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertSame("on Access.ALL", hierDefaultMember, rmr.getDefaultMember());
    Mockito.doReturn(Access.CUSTOM).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertSame("on Access.CUSTOM", hierDefaultMember, rmr.getDefaultMember());
    Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertNotSame("on Access.NONE", hierDefaultMember, rmr.getDefaultMember());
    Assert.assertTrue(rmr.getDefaultMember() instanceof MultiCardinalityDefaultMember);
}
Also used : Role(mondrian.olap.Role) Hierarchy(mondrian.olap.Hierarchy) MultiCardinalityDefaultMember(mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember) HierarchyAccess(mondrian.olap.Role.HierarchyAccess)

Example 15 with Hierarchy

use of mondrian.olap.Hierarchy in project mondrian by pentaho.

the class RestrictedMemberReaderTest method testDefaultMember_multiRootMeasure.

public void testDefaultMember_multiRootMeasure() {
    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(true).when(member0).isMeasure();
    Mockito.doReturn(true).when(member1).isMeasure();
    Mockito.doReturn(true).when(member1).isMeasure();
    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.assertSame("on Access C-N-C", member0, rmr.getDefaultMember());
    Mockito.doReturn(Access.NONE).when(roleAccess).getAccess(anyRolapMember());
    Assert.assertTrue("on Access.NONE", rmr.getDefaultMember() instanceof MultiCardinalityDefaultMember);
}
Also used : Role(mondrian.olap.Role) Hierarchy(mondrian.olap.Hierarchy) MultiCardinalityDefaultMember(mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember) HierarchyAccess(mondrian.olap.Role.HierarchyAccess)

Aggregations

Hierarchy (mondrian.olap.Hierarchy)27 Level (mondrian.olap.Level)9 Member (mondrian.olap.Member)8 Role (mondrian.olap.Role)8 HierarchyAccess (mondrian.olap.Role.HierarchyAccess)7 MultiCardinalityDefaultMember (mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember)6 MondrianDef (mondrian.olap.MondrianDef)5 DataSource (javax.sql.DataSource)4 Dimension (mondrian.olap.Dimension)4 mondrian.olap (mondrian.olap)3 Schema (mondrian.olap.Schema)3 RolapCube (mondrian.rolap.RolapCube)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Axis (mondrian.olap.Axis)2 RelationOrJoin (mondrian.olap.MondrianDef.RelationOrJoin)2 LimitedRollupMember (mondrian.rolap.RolapHierarchy.LimitedRollupMember)2 Level (org.apache.log4j.Level)2