1 package com.tonbeller.jpivot.mondrian; 2 3 import java.util.List ; 4 5 import junit.framework.TestCase; 6 import mondrian.mdx.LevelExpr; 7 import mondrian.mdx.MemberExpr; 8 import mondrian.mdx.UnresolvedFunCall; 9 import mondrian.olap.Exp; 10 import mondrian.olap.FunCall; 11 import mondrian.olap.Literal; 12 import mondrian.olap.Syntax; 13 14 import com.tonbeller.jpivot.olap.model.Axis; 15 import com.tonbeller.jpivot.olap.model.Position; 16 import com.tonbeller.jpivot.olap.model.Result; 17 import com.tonbeller.jpivot.olap.navi.DrillExpandPosition; 18 import com.tonbeller.jpivot.olap.navi.PlaceHierarchiesOnAxes; 19 import com.tonbeller.jpivot.olap.query.DrillExpandPositionExt; 20 import com.tonbeller.jpivot.olap.query.ResultBase; 21 import com.tonbeller.jpivot.tags.MondrianModelFactory; 22 import com.tonbeller.wcf.bookmarks.Bookmarkable; 23 24 27 public class BookmarkTest extends TestCase { 28 29 33 public BookmarkTest(String arg0) { 34 super(arg0); 35 } 36 37 public void testTopCount() throws Exception { 38 39 45 String mdxQuery = "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} " 46 + "ON columns, " 47 + "{([Time].[1997],[Product].[All Products].[Food].[Produce].[Vegetables].[Fresh Vegetables].[Hermanos])}" 48 + " ON rows from [Sales]"; 49 50 String renderFile = null; int renderNum = 0; 52 53 Result result; 54 55 MondrianModel model = MondrianModelFactory.instance(); 56 model.setMdxQuery(mdxQuery); 57 TestConnection.initModel(model); 58 59 DrillExpandPositionExt mdep = (DrillExpandPositionExt) model 60 .getExtension(DrillExpandPosition.ID); 61 PlaceHierarchiesOnAxes placeHier = (PlaceHierarchiesOnAxes) model 62 .getExtension(PlaceHierarchiesOnAxes.ID); 63 65 result = model.getResult(); 67 if (renderFile != null) 68 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 69 70 assertPosition(result, 1, 0, new String [] { "1997"}); 71 72 Axis[] axes = result.getAxes(); 74 List positions = axes[1].getPositions(); 75 Position pos0 = (Position) positions.get(0); 76 MondrianMember allTime = (MondrianMember) pos0.getMembers()[0]; 77 Object exp1 = placeHier.createMemberExpression(allTime.getLevel().getHierarchy()); 78 MondrianMember hermanos = (MondrianMember) pos0.getMembers()[1]; 79 MondrianLevel brandLevel = (MondrianLevel) hermanos.getLevel(); 80 positions = axes[0].getPositions(); 81 pos0 = (Position) positions.get(0); 82 MondrianMember unitsales = (MondrianMember) pos0.getMembers()[0]; 83 UnresolvedFunCall brandNameMembers = new UnresolvedFunCall("members", Syntax.Property, new Exp[] { 85 new LevelExpr(brandLevel.getMonLevel())}); 86 87 UnresolvedFunCall funOrder = new UnresolvedFunCall("topcount", new Exp[] { brandNameMembers, 88 Literal.create(new Integer (5)), new MemberExpr(unitsales.getMonMember())}); 89 placeHier.setQueryAxis(axes[1], new Object [] { exp1, funOrder}); 90 result = model.getResult(); 91 if (renderFile != null) 92 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 93 assertPosition(result, 1, 1, new String [] { "1997", "Tell Tale"}); 94 95 axes = result.getAxes(); 97 positions = axes[1].getPositions(); 98 pos0 = (Position) positions.get(0); 99 mdep.expand(pos0, pos0.getMembers()[0]); result = model.getResult(); 101 if (renderFile != null) 102 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 103 104 assertPosition(result, 1, 5, new String [] { "Q1", "Hermanos"}); 105 106 Object bm = model.getBookmarkState(Bookmarkable.EXTENSIONAL); 108 109 model.setBookmarkState(bm); 110 result = model.getResult(); 111 if (renderFile != null) 112 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 113 assertPosition(result, 1, 7, new String [] { "Q1", "Ebony"}); 114 axes = result.getAxes(); 115 positions = axes[1].getPositions(); 116 Position pos = (Position) positions.get(1); 117 assertTrue(mdep.canExpand(pos, pos.getMembers()[1])); 118 } 119 120 123 private void assertPosition(Result result, int iAxis, int iPos, String [] posMembers) { 124 Position pos = (Position) result.getAxes()[iAxis].getPositions().get(iPos); 125 for (int i = 0; i < posMembers.length; i++) { 126 String str = pos.getMembers()[i].getLabel(); 127 assertEquals(str, posMembers[i]); 128 } 129 } 130 } | Popular Tags |