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.Axis; 8 import com.tonbeller.jpivot.olap.model.Hierarchy; 9 import com.tonbeller.jpivot.olap.model.Position; 10 import com.tonbeller.jpivot.olap.model.Result; 11 import com.tonbeller.jpivot.olap.navi.DrillReplace; 12 import com.tonbeller.jpivot.olap.query.DrillReplaceExt; 13 import com.tonbeller.jpivot.olap.query.ResultBase; 14 import com.tonbeller.jpivot.tags.MondrianModelFactory; 15 16 21 public class DrillReplaceTest extends TestCase { 22 23 27 public DrillReplaceTest(String arg0) { 28 super(arg0); 29 } 30 31 public void testCrossJoin() throws Exception { 32 33 38 String mdxQuery = 39 "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns, " 40 + "CrossJoin( [Store].[USA].children, [Product].[All Products].[Drink].children) on rows " 41 + "from Sales where ([Time].[1997])"; 42 43 String renderFile = null; int renderNum = 0; 45 46 Result result; 47 48 MondrianModel model = MondrianModelFactory.instance(); 49 model.setMdxQuery(mdxQuery); 50 TestConnection.initModel(model); 51 52 result = model.getResult(); 54 if (renderFile != null) 55 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 56 57 assertPosition(result, 1, "CA", "Beverages"); 58 assertPosition(result, 6, "WA", "Alcoholic Beverages"); 59 60 DrillReplaceExt mdrep = (DrillReplaceExt) model.getExtension(DrillReplace.ID); 61 62 Axis[] axes = result.getAxes(); 64 List positions = axes[1].getPositions(); 65 Position pos1 = (Position) positions.get(1); 67 assertTrue(mdrep.canDrillDown(pos1.getMembers()[0])); 68 mdrep.drillDown(pos1.getMembers()[0]); 70 result = model.getResult(); 71 if (renderFile != null) 72 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 73 74 assertPosition(result, 6, "Los Angeles", "Alcoholic Beverages"); 75 assertPosition(result, 10, "San Diego", "Beverages"); 76 assertPosition(result, 14, "San Francisco", "Dairy"); 77 78 axes = result.getAxes(); 80 positions = axes[1].getPositions(); 81 Position pos0 = (Position) positions.get(0); Hierarchy hier = pos0.getMembers()[0].getLevel().getHierarchy(); 83 84 assertTrue(mdrep.canDrillUp(hier)); 85 mdrep.drillUp(hier); 87 result = model.getResult(); 88 if (renderFile != null) 89 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 90 91 assertPosition(result, 2, "CA", "Dairy"); 92 assertPosition(result, 7, "WA", "Beverages"); 93 94 axes = result.getAxes(); 96 positions = axes[1].getPositions(); 97 pos0 = (Position) positions.get(0); hier = pos0.getMembers()[0].getLevel().getHierarchy(); 99 100 assertTrue(mdrep.canDrillUp(hier)); 101 mdrep.drillUp(hier); 103 result = model.getResult(); 104 if (renderFile != null) 105 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 106 107 assertPosition(result, 7, "USA", "Beverages"); 108 109 axes = result.getAxes(); 111 positions = axes[1].getPositions(); 112 pos0 = (Position) positions.get(0); hier = pos0.getMembers()[0].getLevel().getHierarchy(); 114 115 assertTrue(mdrep.canDrillUp(hier)); 116 mdrep.drillUp(hier); 118 result = model.getResult(); 119 if (renderFile != null) 120 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 121 122 assertPosition(result, 2, "All Stores", "Dairy"); 123 124 assertTrue(!mdrep.canDrillUp(hier)); 126 127 } 128 129 public void testSingle() throws Exception { 130 131 136 String mdxQuery = 137 "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns, " 138 + "{ [Store].[USA].children } on rows " 139 + "from Sales where ([Time].[1997])"; 140 141 String renderFile = null; int renderNum = 0; 143 144 Result result; 145 146 MondrianModel model = MondrianModelFactory.instance(); 147 model.setMdxQuery(mdxQuery); 148 TestConnection.initModel(model); 149 150 result = model.getResult(); 152 if (renderFile != null) 153 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 154 155 assertPosition(result, 0, "CA", null); 156 assertPosition(result, 1, "OR", null); 157 158 DrillReplaceExt mdrep = (DrillReplaceExt) model.getExtension(DrillReplace.ID); 159 160 Axis[] axes = result.getAxes(); 162 List positions = axes[1].getPositions(); 163 Position pos = (Position) positions.get(0); assertTrue(mdrep.canDrillDown(pos.getMembers()[0])); 165 mdrep.drillDown(pos.getMembers()[0]); 167 result = model.getResult(); 168 if (renderFile != null) 169 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 170 171 assertPosition(result, 1, "Beverly Hills", null); 172 assertPosition(result, 3, "San Diego", null); 173 174 axes = result.getAxes(); 176 positions = axes[1].getPositions(); 177 pos = (Position) positions.get(3); 179 assertTrue(mdrep.canDrillDown(pos.getMembers()[0])); 180 mdrep.drillDown(pos.getMembers()[0]); 182 result = model.getResult(); 183 if (renderFile != null) 184 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 185 186 assertPosition(result, 0, "Store 24", null); 187 188 axes = result.getAxes(); 190 positions = axes[1].getPositions(); 191 pos = (Position) positions.get(0); 192 assertTrue(!mdrep.canDrillDown(pos.getMembers()[0])); 193 194 axes = result.getAxes(); 196 positions = axes[1].getPositions(); 197 pos = (Position) positions.get(0); Hierarchy hier = pos.getMembers()[0].getLevel().getHierarchy(); 199 200 assertTrue(mdrep.canDrillUp(hier)); 201 mdrep.drillUp(hier); 203 result = model.getResult(); 204 if (renderFile != null) 205 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 206 207 assertPosition(result, 2, "Los Angeles", null); 208 assertPosition(result, 4, "San Francisco", null); 209 210 assertTrue(mdrep.canDrillUp(hier)); 212 mdrep.drillUp(hier); 214 result = model.getResult(); 215 if (renderFile != null) 216 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 217 218 assertPosition(result, 2, "WA", null); 219 220 assertTrue(mdrep.canDrillUp(hier)); 222 mdrep.drillUp(hier); 224 result = model.getResult(); 225 if (renderFile != null) 226 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 227 228 assertPosition(result, 2, "USA", null); 229 230 assertTrue(mdrep.canDrillUp(hier)); 232 mdrep.drillUp(hier); 234 result = model.getResult(); 235 if (renderFile != null) 236 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 237 238 assertPosition(result, 0, "All Stores", null); 239 240 assertTrue(!mdrep.canDrillUp(hier)); 242 243 } 244 245 public void testTwoCrossjDown() throws Exception { 246 247 String mdxQuery = 248 "select {[Measures].[Sales Count]} on columns, " 249 + "{ CrossJoin( [Customers].[All Customers].[USA].[CA].children, [Product].[All Products].[Drink].children), " 250 + "CrossJoin( [Customers].[All Customers].[USA].[WA].children, [Product].[All Products].[Drink].children) } on rows " 251 + "from Sales where ([Time].[1997])"; 252 253 String renderFile = null; int renderNum = 0; 255 256 Result result; 257 258 MondrianModel model = MondrianModelFactory.instance(); 259 model.setMdxQuery(mdxQuery); 260 TestConnection.initModel(model); 261 262 result = model.getResult(); 264 if (renderFile != null) 265 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 266 267 assertPosition(result, 2, "Altadena", "Dairy"); 268 assertPosition(result, 9, "Berkeley", "Alcoholic Beverages"); 269 270 DrillReplaceExt mdrep = (DrillReplaceExt) model.getExtension(DrillReplace.ID); 271 272 Axis[] axes = result.getAxes(); 274 List positions = axes[1].getPositions(); 275 276 assertPosition(result, positions.size() - 1, "Yakima", "Dairy"); 278 Position pos = (Position) positions.get(0); Hierarchy hier = pos.getMembers()[0].getLevel().getHierarchy(); 280 assertTrue(mdrep.canDrillDown(pos.getMembers()[0])); 281 mdrep.drillDown(pos.getMembers()[0]); 283 result = model.getResult(); 284 if (renderFile != null) 285 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 286 287 axes = result.getAxes(); 288 positions = axes[1].getPositions(); 289 assertPosition(result, 10, "Angela Evans", "Beverages"); 290 assertPosition(result, positions.size() - 7, "Wendell Kersten", "Dairy"); 291 292 assertTrue(mdrep.canDrillUp(hier)); 294 mdrep.drillUp(hier); 296 result = model.getResult(); 297 if (renderFile != null) 298 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 299 300 axes = result.getAxes(); 301 positions = axes[1].getPositions(); 302 assertPosition(result, positions.size() - 1, "Woodland Hills", "Dairy"); } 304 305 public void testTwoCrossjUp() throws Exception { 306 307 313 314 String mdxQuery = 315 "select {[Measures].[Sales Count]} on columns, " 316 + "{ CrossJoin( [Customers].[All Customers].[USA].[CA].[Berkeley].children, [Product].[All Products].[Drink].children), " 317 + "CrossJoin( [Customers].[All Customers].[USA].[WA].[Seattle].children, [Product].[All Products].[Drink].children) } on rows " 318 + "from Sales where ([Time].[1997])"; 319 320 String renderFile = null; int renderNum = 0; 322 323 Result result; 324 325 MondrianModel model = MondrianModelFactory.instance(); 326 model.setMdxQuery(mdxQuery); 327 TestConnection.initModel(model); 328 329 result = model.getResult(); 331 if (renderFile != null) 332 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 333 334 Axis[] axes = result.getAxes(); 335 List positions = axes[1].getPositions(); 336 Position pos = (Position) positions.get(0); 337 Hierarchy hier = pos.getMembers()[0].getLevel().getHierarchy(); 338 339 assertPosition(result, 4, "Alma Shelton", "Beverages"); 340 assertPosition(result, positions.size() - 3, "Yvonne Rose", "Alcoholic Beverages"); 341 342 DrillReplaceExt mdrep = (DrillReplaceExt) model.getExtension(DrillReplace.ID); 343 344 assertTrue(mdrep.canDrillUp(hier)); 346 mdrep.drillUp(hier); 348 result = model.getResult(); 349 if (renderFile != null) 350 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 351 352 axes = result.getAxes(); 353 positions = axes[1].getPositions(); 354 355 assertPosition(result, 0, "Altadena", "Alcoholic Beverages"); assertPosition(result, positions.size() - 1, "Yakima", "Dairy"); 359 } 360 361 364 private void assertPosition(Result result, int iPos, String firstMember, String secondMember) { 365 Position pos = (Position) result.getAxes()[1].getPositions().get(iPos); 366 String s = pos.getMembers()[0].getLabel(); 367 assertEquals(s, firstMember); 368 if (secondMember != null) { 369 s = pos.getMembers()[1].getLabel(); 370 assertEquals(s, secondMember); 371 } 372 } 373 374 } | Popular Tags |