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.Position; 8 import com.tonbeller.jpivot.olap.model.Result; 9 import com.tonbeller.jpivot.olap.navi.DrillExpandPosition; 10 import com.tonbeller.jpivot.olap.query.DrillExpandPositionExt; 11 import com.tonbeller.jpivot.olap.query.ResultBase; 12 import com.tonbeller.jpivot.tags.MondrianModelFactory; 13 14 19 public class ExpandPositionSpanTest extends TestCase { 20 21 25 public ExpandPositionSpanTest(String arg0) { 26 super(arg0); 27 } 28 29 public void testExpandPositionSpan() throws Exception { 30 37 38 String mdxQuery = 39 "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns," 40 + "{([Gender].[All Gender], [Marital Status].[All Marital Status]," 41 + "[Customers].[All Customers]," 42 + "[Product].[All Products] ) } on rows " 43 + "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 DrillExpandPositionExt mdep = 55 (DrillExpandPositionExt) model.getExtension(DrillExpandPosition.ID); 56 57 result = model.getResult(); 59 if (renderFile != null) 60 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 61 62 List positions = result.getAxes()[1].getPositions(); 63 Position pos = (Position) positions.get(0); 65 assertTrue(mdep.canExpand(pos, pos.getMembers()[0])); 66 mdep.expand(pos, pos.getMembers()[0]); 68 result = model.getResult(); 69 if (renderFile != null) 70 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 71 72 positions = result.getAxes()[1].getPositions(); 73 assertPosition( 74 result, 75 1, 76 new String [] { "F", "All Marital Status", "All Customers", "All Products" }); 77 78 pos = (Position) positions.get(1); 80 assertTrue(mdep.canExpand(pos, pos.getMembers()[2])); 81 mdep.expand(pos, pos.getMembers()[2]); 83 result = model.getResult(); 84 if (renderFile != null) 85 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 86 87 positions = result.getAxes()[1].getPositions(); 88 assertPosition(result, 4, new String [] { "F", "All Marital Status", "USA", "All Products" }); 89 90 pos = (Position) positions.get(4); 92 assertTrue(mdep.canExpand(pos, pos.getMembers()[3])); 93 mdep.expand(pos, pos.getMembers()[3]); 95 result = model.getResult(); 96 if (renderFile != null) 97 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 98 99 positions = result.getAxes()[1].getPositions(); 100 assertPosition(result, 5, new String [] { "F", "All Marital Status", "USA", "Drink" }); 101 102 pos = (Position) positions.get(5); 104 assertTrue(mdep.canExpand(pos, pos.getMembers()[2])); 105 mdep.expand(pos, pos.getMembers()[2]); 107 result = model.getResult(); 108 if (renderFile != null) 109 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 110 111 positions = result.getAxes()[1].getPositions(); 112 113 assertPosition(result, 9, new String [] { "F", "All Marital Status", "CA", "Drink" }); 114 assertPosition(result, 14, new String [] { "F", "All Marital Status", "OR", "Food" }); 115 116 pos = (Position) positions.get(1); 118 assertTrue(mdep.canExpand(pos, pos.getMembers()[1])); 119 mdep.expand(pos, pos.getMembers()[1]); 121 result = model.getResult(); 122 if (renderFile != null) 123 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 124 125 positions = result.getAxes()[1].getPositions(); 126 127 assertPosition(result, positions.size() - 2, new String [] { "F", "S", "WA", "Non-Consumable" }); 128 assertPosition(result, positions.size() - 5, new String [] { "F", "S", "WA", "All Products" }); 129 130 pos = (Position) positions.get(positions.size() - 5); 132 assertTrue(mdep.canCollapse(pos, pos.getMembers()[3])); 133 mdep.collapse(pos, pos.getMembers()[3]); 135 result = model.getResult(); 136 if (renderFile != null) 137 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 138 139 positions = result.getAxes()[1].getPositions(); 140 141 assertPosition(result, positions.size() - 2, new String [] { "F", "S", "WA", "All Products" }); 142 143 pos = (Position) positions.get(1); 145 assertTrue(mdep.canCollapse(pos, pos.getMembers()[1])); 146 mdep.collapse(pos, pos.getMembers()[1]); 148 result = model.getResult(); 149 if (renderFile != null) 150 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 151 152 positions = result.getAxes()[1].getPositions(); 153 154 assertPosition(result, 8, new String [] { "F", "All Marital Status", "CA", "All Products" }); 155 156 pos = (Position) positions.get(0); 158 assertTrue(mdep.canCollapse(pos, pos.getMembers()[0])); 159 mdep.collapse(pos, pos.getMembers()[0]); 161 result = model.getResult(); 162 if (renderFile != null) 163 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 164 165 positions = result.getAxes()[1].getPositions(); 166 assertEquals(positions.size(), 1); 167 } 168 169 172 private void assertPosition(Result result, int iPos, String [] posMembers) { 173 Position pos = (Position) result.getAxes()[1].getPositions().get(iPos); 174 for (int i = 0; i < posMembers.length; i++) { 175 String str = pos.getMembers()[i].getLabel(); 176 assertEquals(str, posMembers[i]); 177 } 178 } 179 180 } | Popular Tags |