1 package com.tonbeller.jpivot.mondrian; 2 3 import java.util.Iterator ; 4 import java.util.List ; 5 6 import junit.framework.TestCase; 7 8 import com.tonbeller.jpivot.olap.model.Axis; 9 import com.tonbeller.jpivot.olap.model.Dimension; 10 import com.tonbeller.jpivot.olap.model.Hierarchy; 11 import com.tonbeller.jpivot.olap.model.Position; 12 import com.tonbeller.jpivot.olap.model.Result; 13 import com.tonbeller.jpivot.olap.navi.DrillExpandPosition; 14 import com.tonbeller.jpivot.olap.navi.PlaceHierarchiesOnAxes; 15 import com.tonbeller.jpivot.olap.navi.PlaceMembersOnAxes; 16 import com.tonbeller.jpivot.olap.query.DrillExpandPositionExt; 17 import com.tonbeller.jpivot.olap.query.ResultBase; 18 import com.tonbeller.jpivot.tags.MondrianModelFactory; 19 20 23 public class VariousTest extends TestCase { 24 25 29 public VariousTest(String arg0) { 30 super(arg0); 31 } 32 33 public void testSetCollapse() throws Exception { 34 35 39 String mdxQuery = "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} " 40 + "ON columns, " + "{[Product].[All Products]} ON rows from [Sales]"; 41 42 String renderFile = null; int renderNum = 0; 44 45 Result result; 46 47 MondrianModel model = MondrianModelFactory.instance(); 48 model.setMdxQuery(mdxQuery); 49 TestConnection.initModel(model); 50 51 DrillExpandPositionExt mdep = (DrillExpandPositionExt) model 52 .getExtension(DrillExpandPosition.ID); 53 PlaceHierarchiesOnAxes placeHier = (PlaceHierarchiesOnAxes) model 54 .getExtension(PlaceHierarchiesOnAxes.ID); 55 PlaceMembersOnAxes placeMem = (PlaceMembersOnAxes) model.getExtension(PlaceMembersOnAxes.ID); 56 57 result = model.getResult(); 59 if (renderFile != null) 60 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 61 62 assertPosition(result, 1, 0, new String [] { "All Products"}); 63 64 Axis[] axes = result.getAxes(); 66 List positions = axes[1].getPositions(); 67 Position pos0 = (Position) positions.get(0); Hierarchy hierProduct = pos0.getMembers()[0].getLevel().getHierarchy(); 69 mdep.expand(pos0, pos0.getMembers()[0]); result = model.getResult(); 71 if (renderFile != null) 72 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 73 74 axes = result.getAxes(); 75 positions = axes[1].getPositions(); 76 Position pos3 = (Position) positions.get(3); assertPosition(result, 1, 3, new String [] { "Non-Consumable"}); 78 MondrianMember nonCons = (MondrianMember) pos3.getMembers()[0]; 79 80 List mList = placeMem.findVisibleMembers(hierProduct); 81 for (Iterator iter = mList.iterator(); iter.hasNext();) { 83 MondrianMember m = (MondrianMember) iter.next(); 84 if (m.equals(nonCons)) 85 iter.remove(); 86 } 87 Dimension[] dims = model.getDimensions(); 89 Dimension timeDim = null; 90 for (int i = 0; i < dims.length; i++) { 91 if (((MondrianDimension) dims[i]).getLabel().equals("Time")) { 92 timeDim = dims[i]; 93 break; 94 } 95 } 96 Object oTime = placeHier.createMemberExpression(timeDim.getHierarchies()[0]); 97 Object oSet = placeMem.createMemberExpression(mList); 98 placeHier.setQueryAxis(axes[1], new Object [] { oSet, oTime}); 99 100 result = model.getResult(); 101 if (renderFile != null) 102 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 103 axes = result.getAxes(); 104 positions = axes[1].getPositions(); 105 106 assertPosition(result, 1, 0, new String [] { "All Products", "1997"}); 108 pos0 = (Position) positions.get(0); 109 mdep.expand(pos0, pos0.getMembers()[1]); 110 111 result = model.getResult(); 112 if (renderFile != null) 113 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 114 115 assertPosition(result, 1, 4, new String [] { "All Products", "Q4"}); 116 117 axes = result.getAxes(); 119 positions = axes[1].getPositions(); 120 Position pos4 = (Position) positions.get(4); mdep.collapse(pos4, pos4.getMembers()[0]); 122 result = model.getResult(); 123 if (renderFile != null) 124 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 125 126 axes = result.getAxes(); 127 positions = axes[1].getPositions(); 128 assertPosition(result, 1, 1, new String [] { "All Products", "Q1"}); 129 assertEquals(positions.size(), 6); 130 } 131 132 135 private void assertPosition(Result result, int iAxis, int iPos, String [] posMembers) { 136 Position pos = (Position) result.getAxes()[iAxis].getPositions().get(iPos); 137 for (int i = 0; i < posMembers.length; i++) { 138 String str = pos.getMembers()[i].getLabel(); 139 assertEquals(str, posMembers[i]); 140 } 141 } 142 } | Popular Tags |