1 package com.tonbeller.jpivot.mondrian; 2 3 import java.util.List ; 4 5 import junit.framework.TestCase; 6 7 import com.tonbeller.jpivot.olap.model.Axis; 8 import com.tonbeller.jpivot.olap.model.Position; 9 import com.tonbeller.jpivot.olap.model.Result; 10 import com.tonbeller.jpivot.olap.navi.DrillExpandPosition; 11 import com.tonbeller.jpivot.olap.query.DrillExpandPositionExt; 12 import com.tonbeller.jpivot.olap.query.ResultBase; 13 import com.tonbeller.jpivot.tags.MondrianModelFactory; 14 import com.tonbeller.wcf.bookmarks.Bookmarkable; 15 16 20 public class CoSalUniTest extends TestCase { 21 22 26 public CoSalUniTest(String arg0) { 27 super(arg0); 28 } 29 30 public void testCoSalUni() throws Exception { 31 32 40 String mdxQuery = "select Crossjoin({[Store Size in SQFT].[All Store Size in SQFTs]}, " 41 + "Crossjoin({[Store Type].[All Store Types]}, " 42 + "{[Measures].[Store Cost], [Measures].[Store Sales], [Measures].[Unit Sales]})) ON columns, " 43 + "{[Product].[All Products]} ON rows from [Sales] where [Time].[1997]"; 44 45 String renderFile = null; int renderNum = 0; 47 48 Result result; 49 50 MondrianModel model = MondrianModelFactory.instance(); 51 model.setMdxQuery(mdxQuery); 52 TestConnection.initModel(model); 53 54 result = model.getResult(); 56 if (renderFile != null) 57 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 58 59 assertPosition(result, 2, new String [] { "All Store Size in SQFTs", "All Store Types", 60 "Unit Sales"}); 61 62 DrillExpandPositionExt mdep = (DrillExpandPositionExt) model 63 .getExtension(DrillExpandPosition.ID); 64 65 Axis[] axes = result.getAxes(); 67 List positions = axes[0].getPositions(); 68 Position pos0 = (Position) positions.get(0); 70 assertTrue(mdep.canExpand(pos0, pos0.getMembers()[0])); 71 mdep.expand(pos0, pos0.getMembers()[0]); 73 result = model.getResult(); 74 if (renderFile != null) 75 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 76 77 assertPosition(result, 7, new String [] { "20319", "All Store Types", "Store Sales"}); 78 79 axes = result.getAxes(); 81 positions = axes[0].getPositions(); 82 Position pos7 = (Position) positions.get(7); mdep.expand(pos7, pos7.getMembers()[1]); result = model.getResult(); 85 if (renderFile != null) 86 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 87 88 assertPosition(result, 24, new String [] { "20319", "Supermarket", "Store Cost"}); 89 90 Object state = model.getBookmarkState(Bookmarkable.EXTENSIONAL); 92 result = model.getResult(); 93 if (renderFile != null) 94 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 95 96 assertPosition(result, 1, new String [] { "All Store Size in SQFTs", "All Store Types", 97 "Store Sales"}); 98 99 model.setMdxQuery(mdxQuery); 100 model.setBookmarkState(state); 101 result = model.getResult(); 102 if (renderFile != null) 103 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 104 105 assertPosition(result, 24, new String [] { "20319", "Supermarket", "Store Cost"}); 106 107 } 108 109 112 private void assertPosition(Result result, int iPos, String [] posMembers) { 113 Position pos = (Position) result.getAxes()[0].getPositions().get(iPos); 114 for (int i = 0; i < posMembers.length; i++) { 115 String str = pos.getMembers()[i].getLabel(); 116 assertEquals(str, posMembers[i]); 117 } 118 } 119 } | Popular Tags |