1 package com.tonbeller.jpivot.mondrian; 2 3 import junit.framework.TestCase; 4 5 import com.tonbeller.jpivot.olap.model.Axis; 6 import com.tonbeller.jpivot.olap.model.Dimension; 7 import com.tonbeller.jpivot.olap.model.Hierarchy; 8 import com.tonbeller.jpivot.olap.model.JunitUtil; 9 import com.tonbeller.jpivot.olap.model.Member; 10 import com.tonbeller.jpivot.olap.model.Position; 11 import com.tonbeller.jpivot.olap.model.Result; 12 import com.tonbeller.jpivot.olap.navi.PlaceHierarchiesOnAxes; 13 import com.tonbeller.jpivot.olap.query.ResultBase; 14 import com.tonbeller.jpivot.tags.MondrianModelFactory; 15 16 19 public class ExpandAllTest extends TestCase { 20 21 25 public ExpandAllTest(String arg0) { 26 super(arg0); 27 } 28 29 public void testExpandAllMember() throws Exception { 30 31 35 String mdxQuery = "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} " 36 + "ON columns, " + "{[Product].[All Products]} ON rows from [Sales]"; 37 38 String renderFile = null; int renderNum = 0; 40 41 Result result; 42 43 MondrianModel model = MondrianModelFactory.instance(); 44 model.setMdxQuery(mdxQuery); 45 TestConnection.initModel(model); 46 PlaceHierarchiesOnAxes placeHier = (PlaceHierarchiesOnAxes) model 47 .getExtension(PlaceHierarchiesOnAxes.ID); 48 49 placeHier.setExpandAllMember(true); 51 52 result = model.getResult(); 54 if (renderFile != null) 55 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 56 57 JunitUtil.assertPosition(result, 1, 0, new String [] { "All Products"}, new String [] { "266773", 58 "225627.23", "565238.13"}); 59 60 Dimension[] dims = model.getDimensions(); 62 Dimension custoDim = null; 63 for (int i = 0; i < dims.length; i++) { 64 if ((dims[i]).getLabel().equals("Customers")) { 65 custoDim = dims[i]; 66 break; 67 } 68 } 69 Axis[] axes = result.getAxes(); 70 Position pos0 = (Position) axes[1].getPositions().get(0); 71 Member[] mems = pos0.getMembers(); 72 Object [] ohiers = new Object [mems.length +1]; 73 for (int i = 0; i < mems.length; i++) { 74 Hierarchy hier = mems[i].getLevel().getHierarchy(); 75 ohiers[i] = placeHier.createMemberExpression(hier); 76 } 77 Object oCust = placeHier.createMemberExpression(custoDim.getHierarchies()[0]); 78 ohiers[mems.length] = oCust; 79 placeHier.setQueryAxis(axes[1], ohiers); 80 81 result = model.getResult(); 83 if (renderFile != null) 84 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 85 86 JunitUtil.assertPosition(result, 1, 3, new String [] { "All Products", "USA"}, new String [] { "266773", 87 "225627.23", "565238.13"}); 88 89 } 90 91 } | Popular Tags |