1 package com.tonbeller.jpivot.xmla; 2 3 import java.net.URL ; 4 5 import junit.framework.TestCase; 6 7 import com.tonbeller.jpivot.core.ModelFactory; 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.JunitUtil; 12 import com.tonbeller.jpivot.olap.model.Member; 13 import com.tonbeller.jpivot.olap.model.Position; 14 import com.tonbeller.jpivot.olap.model.Result; 15 import com.tonbeller.jpivot.olap.navi.PlaceHierarchiesOnAxes; 16 import com.tonbeller.jpivot.olap.query.ResultBase; 17 18 21 public class ExpandAllTest extends TestCase { 22 23 27 public ExpandAllTest(String arg0) { 28 super(arg0); 29 } 30 31 public void testExpandAllMember() throws Exception { 32 33 37 String mdxQuery = "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} " 38 + "ON columns, " + "{[Product].[All Products]} ON rows from [Sales]"; 39 40 String renderFile = null; int renderNum = 0; 42 43 Result result; 44 45 URL confUrl = XMLA_Model.class.getResource("config.xml"); 46 XMLA_Model model = (XMLA_Model) ModelFactory.instance(confUrl); 47 48 model.setMdxQuery(mdxQuery); 49 TestConnection.initModel(model); 50 51 TestConnection.initModel(model); 52 PlaceHierarchiesOnAxes placeHier = (PlaceHierarchiesOnAxes) model 53 .getExtension(PlaceHierarchiesOnAxes.ID); 54 55 placeHier.setExpandAllMember(true); 57 58 result = model.getResult(); 60 if (renderFile != null) 61 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 62 63 JunitUtil.assertPosition(result, 1, 0, new String [] { "All Products"}, new String [] { "266773.00", 64 "225627.23", "565238.13"}); 65 66 Dimension[] dims = model.getDimensions(); 68 Dimension custoDim = null; 69 for (int i = 0; i < dims.length; i++) { 70 if ((dims[i]).getLabel().equals("Customers")) { 71 custoDim = dims[i]; 72 break; 73 } 74 } 75 Axis[] axes = result.getAxes(); 76 Position pos0 = (Position) axes[1].getPositions().get(0); 77 Member[] mems = pos0.getMembers(); 78 Object [] ohiers = new Object [mems.length +1]; 79 for (int i = 0; i < mems.length; i++) { 80 Hierarchy hier = mems[i].getLevel().getHierarchy(); 81 ohiers[i] = placeHier.createMemberExpression(hier); 82 } 83 Object oCust = placeHier.createMemberExpression(custoDim.getHierarchies()[0]); 84 ohiers[mems.length] = oCust; 85 placeHier.setQueryAxis(axes[1], ohiers); 86 87 result = model.getResult(); 89 if (renderFile != null) 90 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 91 92 JunitUtil.assertPosition(result, 1, 3, new String [] { "All Products", "USA"}, new String [] { "266773.00", 93 "225627.23", "565238.13"}); 94 95 } 96 97 } | Popular Tags |