Search in sources :

Example 1 with MemberEditCommand

use of mondrian.olap.CacheControl.MemberEditCommand in project mondrian by pentaho.

the class MemberCacheControlTest method testMoveFailBadLevel.

public void testMoveFailBadLevel() {
    final TestContext tc = getTestContext();
    final Connection conn = tc.getConnection();
    final CacheControl cc = conn.getCacheControl(null);
    final RolapCubeMember caCubeMember = (RolapCubeMember) findMember(tc, "Sales", "Retail", "CA");
    final RolapMember caMember = caCubeMember.member;
    final RolapHierarchy hierarchy = caMember.getHierarchy();
    final MemberReader memberReader = hierarchy.getMemberReader();
    final MemberCache memberCache = ((SmartMemberReader) memberReader).getMemberCache();
    final RolapMember sfMember = (RolapMember) hierarchy.createMember(caMember, caMember.getLevel().getChildLevel(), "San Francisco", null);
    final RolapMember storeMember = (RolapMember) hierarchy.createMember(sfMember, sfMember.getLevel().getChildLevel(), "Store 14", null);
    // test axis contents
    tc.assertAxisReturns("[Retail].[CA].Children", "[Retail].[CA].[Alameda]\n" + "[Retail].[CA].[Beverly Hills]\n" + "[Retail].[CA].[Los Angeles]\n" + "[Retail].[CA].[San Diego]\n" + "[Retail].[CA].[San Francisco]");
    tc.assertAxisReturns("[Retail].[CA].[San Francisco].Children", "[Retail].[CA].[San Francisco].[Store 14]");
    List<RolapMember> sfChildren = memberCache.getChildrenFromCache(sfMember, null);
    assertEquals(1, sfChildren.size());
    assertTrue(storeMember.getParentMember().equals(sfMember));
    // Now tell the cache that Store 14 moved to CA
    final MemberEditCommand command = cc.createMoveCommand(storeMember, caMember);
    try {
        cc.execute(command);
        fail("Should have failed due to improper level");
    } catch (MondrianException e) {
        assertEquals("new parent belongs to different level than old", e.getCause().getMessage());
    }
    // The list of SF children should still contain 1 element
    assertEquals(1, memberCache.getChildrenFromCache(sfMember, null).size());
    // test axis contents. should not have been modified
    tc.assertAxisReturns("[Retail].[CA].[San Francisco].Children", "[Retail].[CA].[San Francisco].[Store 14]");
    tc.assertAxisReturns("[Retail].[CA].Children", "[Retail].[CA].[Alameda]\n" + "[Retail].[CA].[Beverly Hills]\n" + "[Retail].[CA].[Los Angeles]\n" + "[Retail].[CA].[San Diego]\n" + "[Retail].[CA].[San Francisco]");
    // Test parent object. should be the same
    assertTrue(storeMember.getParentMember().equals(sfMember));
}
Also used : MemberEditCommand(mondrian.olap.CacheControl.MemberEditCommand)

Example 2 with MemberEditCommand

use of mondrian.olap.CacheControl.MemberEditCommand in project mondrian by pentaho.

the class MemberCacheControlTest method testMoveCommand.

public void testMoveCommand() {
    final TestContext tc = getTestContext();
    final Connection conn = tc.getConnection();
    final CacheControl cc = conn.getCacheControl(null);
    final RolapCubeMember caCubeMember = (RolapCubeMember) findMember(tc, "Sales", "Retail", "CA");
    final RolapMember caMember = caCubeMember.member;
    final RolapHierarchy hierarchy = caMember.getHierarchy();
    final MemberReader memberReader = hierarchy.getMemberReader();
    final MemberCache memberCache = ((SmartMemberReader) memberReader).getMemberCache();
    final RolapMember alamedaMember = (RolapMember) hierarchy.createMember(caMember, caMember.getLevel().getChildLevel(), "Alameda", null);
    final RolapMember sfMember = (RolapMember) hierarchy.createMember(caMember, caMember.getLevel().getChildLevel(), "San Francisco", null);
    final RolapMember storeMember = (RolapMember) hierarchy.createMember(sfMember, sfMember.getLevel().getChildLevel(), "Store 14", null);
    // test axis contents
    tc.assertAxisReturns("[Retail].[CA].Children", "[Retail].[CA].[Alameda]\n" + "[Retail].[CA].[Beverly Hills]\n" + "[Retail].[CA].[Los Angeles]\n" + "[Retail].[CA].[San Diego]\n" + "[Retail].[CA].[San Francisco]");
    tc.assertAxisReturns("[Retail].[CA].[Alameda].Children", "[Retail].[CA].[Alameda].[HQ]");
    tc.assertAxisReturns("[Retail].[CA].[San Francisco].Children", "[Retail].[CA].[San Francisco].[Store 14]");
    List<RolapMember> sfChildren = memberCache.getChildrenFromCache(sfMember, null);
    assertEquals(1, sfChildren.size());
    List<RolapMember> alamedaChildren = memberCache.getChildrenFromCache(alamedaMember, null);
    assertEquals(1, alamedaChildren.size());
    assertTrue(storeMember.getParentMember().equals(sfMember));
    // Now tell the cache that Store 14 moved to Alameda
    final MemberEditCommand command = cc.createMoveCommand(storeMember, alamedaMember);
    cc.execute(command);
    // The list of SF children should contain 0 elements
    assertEquals(0, memberCache.getChildrenFromCache(sfMember, null).size());
    // Check Alameda's children. It should be null as the parent's list
    // should be cleared.
    alamedaChildren = memberCache.getChildrenFromCache(alamedaMember, null);
    assertEquals(2, alamedaChildren.size());
    // test axis contents
    tc.assertAxisReturns("[Retail].[CA].[San Francisco].Children", "");
    tc.assertAxisReturns("[Retail].[CA].[Alameda].Children", "[Retail].[CA].[Alameda].[HQ]\n" + "[Retail].[CA].[Alameda].[Store 14]");
    // Test parent object
    assertTrue(storeMember.getParentMember().equals(alamedaMember));
}
Also used : MemberEditCommand(mondrian.olap.CacheControl.MemberEditCommand)

Aggregations

MemberEditCommand (mondrian.olap.CacheControl.MemberEditCommand)2