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