1 package com.tonbeller.jpivot.xmla; 2 3 import java.net.URL ; 4 import java.util.List ; 5 6 import junit.framework.TestCase; 7 8 import com.tonbeller.jpivot.core.ModelFactory; 9 import com.tonbeller.jpivot.olap.model.Axis; 10 import com.tonbeller.jpivot.olap.model.Hierarchy; 11 import com.tonbeller.jpivot.olap.model.Position; 12 import com.tonbeller.jpivot.olap.model.Result; 13 import com.tonbeller.jpivot.olap.navi.DrillReplace; 14 import com.tonbeller.jpivot.olap.query.DrillReplaceExt; 15 import com.tonbeller.jpivot.olap.query.ResultBase; 16 17 22 public class DrillReplaceTest extends TestCase { 23 24 28 public DrillReplaceTest(String arg0) { 29 super(arg0); 30 } 31 32 public void testCrossJoin() throws Exception { 33 34 39 String mdxQuery = 40 "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns, " 41 + "CrossJoin( [Store].[USA].children, [Product].[All Products].[Drink].children) on rows " 42 + "from Sales where ([Time].[1997])"; 43 44 String renderFile = null; int renderNum = 0; 46 47 Result result; 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 result = model.getResult(); 56 if (renderFile != null) 57 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 58 59 assertPosition(result, 1, "CA", "Beverages"); 60 assertPosition(result, 6, "WA", "Alcoholic Beverages"); 61 62 DrillReplaceExt mdrep = (DrillReplaceExt) model.getExtension(DrillReplace.ID); 63 64 Axis[] axes = result.getAxes(); 66 List positions = axes[1].getPositions(); 67 Position pos1 = (Position) positions.get(1); 69 assertTrue(mdrep.canDrillDown(pos1.getMembers()[0])); 70 mdrep.drillDown(pos1.getMembers()[0]); 72 result = model.getResult(); 73 if (renderFile != null) 74 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 75 76 assertPosition(result, 6, "Los Angeles", "Alcoholic Beverages"); 77 assertPosition(result, 10, "San Diego", "Beverages"); 78 assertPosition(result, 14, "San Francisco", "Dairy"); 79 80 axes = result.getAxes(); 82 positions = axes[1].getPositions(); 83 Position pos0 = (Position) positions.get(0); Hierarchy hier = pos0.getMembers()[0].getLevel().getHierarchy(); 85 86 assertTrue(mdrep.canDrillUp(hier)); 87 mdrep.drillUp(hier); 89 result = model.getResult(); 90 if (renderFile != null) 91 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 92 93 assertPosition(result, 2, "CA", "Dairy"); 94 assertPosition(result, 7, "WA", "Beverages"); 95 96 axes = result.getAxes(); 98 positions = axes[1].getPositions(); 99 pos0 = (Position) positions.get(0); hier = pos0.getMembers()[0].getLevel().getHierarchy(); 101 102 assertTrue(mdrep.canDrillUp(hier)); 103 mdrep.drillUp(hier); 105 result = model.getResult(); 106 if (renderFile != null) 107 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 108 109 assertPosition(result, 7, "USA", "Beverages"); 110 111 axes = result.getAxes(); 113 positions = axes[1].getPositions(); 114 pos0 = (Position) positions.get(0); hier = pos0.getMembers()[0].getLevel().getHierarchy(); 116 117 assertTrue(mdrep.canDrillUp(hier)); 118 mdrep.drillUp(hier); 120 result = model.getResult(); 121 if (renderFile != null) 122 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 123 124 assertPosition(result, 2, "All Stores", "Dairy"); 125 126 assertTrue(!mdrep.canDrillUp(hier)); 128 129 } 130 131 public void testSingle() throws Exception { 132 133 138 String mdxQuery = 139 "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns, " 140 + "{ [Store].[USA].children } on rows " 141 + "from Sales where ([Time].[1997])"; 142 143 String renderFile = null; int renderNum = 0; 145 146 Result result; 147 148 URL confUrl = XMLA_Model.class.getResource("config.xml"); 149 XMLA_Model model = (XMLA_Model) ModelFactory.instance(confUrl); 150 151 model.setMdxQuery(mdxQuery); 152 TestConnection.initModel(model); 153 154 result = model.getResult(); 156 if (renderFile != null) 157 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 158 159 assertPosition(result, 0, "CA", null); 160 assertPosition(result, 1, "OR", null); 161 162 DrillReplaceExt mdrep = (DrillReplaceExt) model.getExtension(DrillReplace.ID); 163 164 Axis[] axes = result.getAxes(); 166 List positions = axes[1].getPositions(); 167 Position pos = (Position) positions.get(0); assertTrue(mdrep.canDrillDown(pos.getMembers()[0])); 169 mdrep.drillDown(pos.getMembers()[0]); 171 result = model.getResult(); 172 if (renderFile != null) 173 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 174 175 assertPosition(result, 1, "Beverly Hills", null); 176 assertPosition(result, 3, "San Diego", null); 177 178 axes = result.getAxes(); 180 positions = axes[1].getPositions(); 181 pos = (Position) positions.get(3); 183 assertTrue(mdrep.canDrillDown(pos.getMembers()[0])); 184 mdrep.drillDown(pos.getMembers()[0]); 186 result = model.getResult(); 187 if (renderFile != null) 188 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 189 190 assertPosition(result, 0, "Store 24", null); 191 192 axes = result.getAxes(); 194 positions = axes[1].getPositions(); 195 pos = (Position) positions.get(0); 196 assertTrue(!mdrep.canDrillDown(pos.getMembers()[0])); 197 198 axes = result.getAxes(); 200 positions = axes[1].getPositions(); 201 pos = (Position) positions.get(0); Hierarchy hier = pos.getMembers()[0].getLevel().getHierarchy(); 203 204 assertTrue(mdrep.canDrillUp(hier)); 205 mdrep.drillUp(hier); 207 result = model.getResult(); 208 if (renderFile != null) 209 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 210 211 assertPosition(result, 2, "Los Angeles", null); 212 assertPosition(result, 4, "San Francisco", null); 213 214 assertTrue(mdrep.canDrillUp(hier)); 216 mdrep.drillUp(hier); 218 result = model.getResult(); 219 if (renderFile != null) 220 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 221 222 assertPosition(result, 2, "WA", null); 223 224 assertTrue(mdrep.canDrillUp(hier)); 226 mdrep.drillUp(hier); 228 result = model.getResult(); 229 if (renderFile != null) 230 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 231 232 assertPosition(result, 2, "USA", null); 233 234 assertTrue(mdrep.canDrillUp(hier)); 236 mdrep.drillUp(hier); 238 result = model.getResult(); 239 if (renderFile != null) 240 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 241 242 assertPosition(result, 0, "All Stores", null); 243 244 assertTrue(!mdrep.canDrillUp(hier)); 246 247 } 248 249 public void testTwoCrossjDown() throws Exception { 250 251 String mdxQuery = 252 "select {[Measures].[Sales Count]} on columns, " 253 + "{ CrossJoin( [Customers].[All Customers].[USA].[CA].children, [Product].[All Products].[Drink].children), " 254 + "CrossJoin( [Customers].[All Customers].[USA].[WA].children, [Product].[All Products].[Drink].children) } on rows " 255 + "from Sales where ([Time].[1997])"; 256 257 String renderFile = null; int renderNum = 0; 259 260 Result result; 261 262 URL confUrl = XMLA_Model.class.getResource("config.xml"); 263 XMLA_Model model = (XMLA_Model) ModelFactory.instance(confUrl); 264 265 model.setMdxQuery(mdxQuery); 266 TestConnection.initModel(model); 267 268 result = model.getResult(); 270 if (renderFile != null) 271 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 272 273 assertPosition(result, 2, "Altadena", "Dairy"); 274 assertPosition(result, 9, "Berkeley", "Alcoholic Beverages"); 275 276 DrillReplaceExt mdrep = (DrillReplaceExt) model.getExtension(DrillReplace.ID); 277 278 Axis[] axes = result.getAxes(); 280 List positions = axes[1].getPositions(); 281 282 assertPosition(result, positions.size() - 1, "Yakima", "Dairy"); 284 Position pos = (Position) positions.get(0); Hierarchy hier = pos.getMembers()[0].getLevel().getHierarchy(); 286 assertTrue(mdrep.canDrillDown(pos.getMembers()[0])); 287 mdrep.drillDown(pos.getMembers()[0]); 289 result = model.getResult(); 290 if (renderFile != null) 291 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 292 293 axes = result.getAxes(); 294 positions = axes[1].getPositions(); 295 assertPosition(result, 10, "Angela Evans", "Beverages"); 296 assertPosition(result, positions.size() - 7, "Wendell Kersten", "Dairy"); 297 298 assertTrue(mdrep.canDrillUp(hier)); 300 mdrep.drillUp(hier); 302 result = model.getResult(); 303 if (renderFile != null) 304 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 305 306 axes = result.getAxes(); 307 positions = axes[1].getPositions(); 308 assertPosition(result, positions.size() - 1, "Woodland Hills", "Dairy"); } 310 311 public void testTwoCrossjUp() throws Exception { 312 313 319 320 String mdxQuery = 321 "select {[Measures].[Sales Count]} on columns, " 322 + "{ CrossJoin( [Customers].[All Customers].[USA].[CA].[Berkeley].children, [Product].[All Products].[Drink].children), " 323 + "CrossJoin( [Customers].[All Customers].[USA].[WA].[Seattle].children, [Product].[All Products].[Drink].children) } on rows " 324 + "from Sales where ([Time].[1997])"; 325 326 String renderFile = null; int renderNum = 0; 328 329 Result result; 330 331 URL confUrl = XMLA_Model.class.getResource("config.xml"); 332 XMLA_Model model = (XMLA_Model) ModelFactory.instance(confUrl); 333 334 model.setMdxQuery(mdxQuery); 335 TestConnection.initModel(model); 336 337 result = model.getResult(); 339 if (renderFile != null) 340 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 341 342 Axis[] axes = result.getAxes(); 343 List positions = axes[1].getPositions(); 344 Position pos = (Position) positions.get(0); 345 Hierarchy hier = pos.getMembers()[0].getLevel().getHierarchy(); 346 347 assertPosition(result, 4, "Alma Shelton", "Beverages"); 348 assertPosition(result, positions.size() - 3, "Yvonne Rose", "Alcoholic Beverages"); 349 350 DrillReplaceExt mdrep = (DrillReplaceExt) model.getExtension(DrillReplace.ID); 351 352 assertTrue(mdrep.canDrillUp(hier)); 354 mdrep.drillUp(hier); 356 result = model.getResult(); 357 if (renderFile != null) 358 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 359 360 axes = result.getAxes(); 361 positions = axes[1].getPositions(); 362 363 assertPosition(result, 0, "Altadena", "Alcoholic Beverages"); assertPosition(result, positions.size() - 1, "Yakima", "Dairy"); 367 } 368 369 372 private void assertPosition(Result result, int iPos, String firstMember, String secondMember) { 373 Position pos = (Position) result.getAxes()[1].getPositions().get(iPos); 374 String s = pos.getMembers()[0].getLabel(); 375 assertEquals(s, firstMember); 376 if (secondMember != null) { 377 s = pos.getMembers()[1].getLabel(); 378 assertEquals(s, secondMember); 379 } 380 } 381 382 } | Popular Tags |