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.Position; 11 import com.tonbeller.jpivot.olap.model.Result; 12 import com.tonbeller.jpivot.olap.navi.DrillExpandMember; 13 import com.tonbeller.jpivot.olap.navi.DrillExpandPosition; 14 import com.tonbeller.jpivot.olap.query.DrillExpandMemberExt; 15 import com.tonbeller.jpivot.olap.query.DrillExpandPositionExt; 16 import com.tonbeller.jpivot.olap.query.ResultBase; 17 18 23 public class ExpandCollapseTest extends TestCase { 24 25 29 public ExpandCollapseTest(String arg0) { 30 super(arg0); 31 } 32 33 public void testExpandPosMem() throws Exception { 34 35 40 String mdxQuery = 41 "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns, " 42 + "CrossJoin( [Store].[USA].children, [Product].[All Products].[Drink].children) on rows " 43 + "from Sales where ([Time].[1997])"; 44 45 String renderFile = null; int renderNum = 0; 47 48 Result result; 49 50 URL confUrl = XMLA_Model.class.getResource("config.xml"); 51 XMLA_Model model = (XMLA_Model) ModelFactory.instance(confUrl); 52 53 model.setMdxQuery(mdxQuery); 54 TestConnection.initModel(model); 55 56 result = model.getResult(); 58 if (renderFile != null) 59 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 60 61 assertPosition(result, 1, "CA", "Beverages"); 62 assertPosition(result, 6, "WA", "Alcoholic Beverages"); 63 64 DrillExpandPositionExt mdep = 65 (DrillExpandPositionExt) model.getExtension(DrillExpandPosition.ID); 66 67 69 Axis[] axes = result.getAxes(); 70 List positions = axes[1].getPositions(); 71 Position pos = (Position) positions.get(1); 73 assertTrue(mdep.canExpand(pos, pos.getMembers()[0])); 74 mdep.expand(pos, pos.getMembers()[0]); 76 result = model.getResult(); 77 if (renderFile != null) 78 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 79 80 positions = result.getAxes()[1].getPositions(); 81 assertPosition(result, 6, "Beverly Hills", "Alcoholic Beverages"); 82 assertPosition(result, 10, "Los Angeles", "Beverages"); 83 assertPosition(result, 17, "San Francisco", "Dairy"); 84 assertPosition(result, positions.size() - 1, "WA", "Dairy"); 85 86 pos = (Position) positions.get(1); assertTrue(mdep.canExpand(pos, pos.getMembers()[1])); 89 mdep.expand(pos, pos.getMembers()[1]); 91 result = model.getResult(); 92 if (renderFile != null) 93 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 94 95 positions = result.getAxes()[1].getPositions(); 96 assertPosition(result, 2, "CA", "Carbonated Beverages"); 97 assertPosition(result, 5, "CA", "Pure Juice Beverages"); 98 assertPosition(result, 10, "Beverly Hills", "Alcoholic Beverages"); 99 assertPosition(result, positions.size() - 4, "OR", "Dairy"); 100 101 103 pos = (Position) positions.get(14); assertTrue(mdep.canExpand(pos, pos.getMembers()[1])); 105 mdep.expand(pos, pos.getMembers()[1]); 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 assertPosition(result, 15, "Los Angeles", "Carbonated Beverages"); 113 assertPosition(result, 17, "Los Angeles", "Hot Beverages"); 114 assertPosition(result, 21, "San Diego", "Beverages"); 115 116 pos = (Position) positions.get(1); assertTrue(mdep.canCollapse(pos, pos.getMembers()[0])); 119 mdep.collapse(pos, pos.getMembers()[0]); 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 assertPosition(result, 0, "CA", "Alcoholic Beverages"); 127 assertPosition(result, 5, "CA", "Pure Juice Beverages"); 128 assertPosition(result, 10, "WA", "Alcoholic Beverages"); 129 130 pos = (Position) positions.get(1); assertTrue(mdep.canCollapse(pos, pos.getMembers()[1])); 133 mdep.collapse(pos, pos.getMembers()[1]); 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 assertPosition(result, 8, "WA", "Dairy"); 141 assertEquals(positions.size(), 9); 142 143 } 144 145 public void testExpandMem() throws Exception { 146 151 152 String mdxQuery = 153 "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns, " 154 + "CrossJoin( [Store].[USA].children, [Product].[All Products].[Drink].children) on rows " 155 + "from Sales where ([Time].[1997])"; 156 157 String renderFile = null; int renderNum = 0; 159 160 Result result; 161 162 URL confUrl = XMLA_Model.class.getResource("config.xml"); 163 XMLA_Model model = (XMLA_Model) ModelFactory.instance(confUrl); 164 165 model.setMdxQuery(mdxQuery); 166 TestConnection.initModel(model); 167 168 result = model.getResult(); 170 if (renderFile != null) 171 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 172 173 assertPosition(result, 1, "CA", "Beverages"); 174 assertPosition(result, 6, "WA", "Alcoholic Beverages"); 175 176 DrillExpandMemberExt mdem = 177 (DrillExpandMemberExt) model.getExtension(DrillExpandMember.ID); 178 179 181 Axis[] axes = result.getAxes(); 182 List positions = axes[1].getPositions(); 183 Position pos = (Position) positions.get(1); 185 assertTrue(mdem.canExpand(pos.getMembers()[0])); mdem.expand(pos.getMembers()[0]); 188 result = model.getResult(); 189 if (renderFile != null) 190 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 191 192 assertPosition(result, 8, "Beverly Hills", "Dairy"); 193 assertPosition(result, 12, "San Diego", "Alcoholic Beverages"); 194 assertPosition(result, 16, "San Francisco", "Beverages"); 195 196 positions = result.getAxes()[1].getPositions(); 198 pos = (Position) positions.get(1); assertTrue(mdem.canExpand(pos.getMembers()[1])); 200 mdem.expand(pos.getMembers()[1]); 202 result = model.getResult(); 203 if (renderFile != null) 204 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 205 206 assertPosition(result, 2, "CA", "Carbonated Beverages"); 207 assertPosition(result, 5, "CA", "Pure Juice Beverages"); 208 assertPosition(result, 24, "Los Angeles", "Drinks"); 209 assertPosition(result, 32, "San Diego", "Hot Beverages"); 210 assertPosition(result, 44, "OR", "Carbonated Beverages"); 211 212 214 positions = result.getAxes()[1].getPositions(); 215 pos = (Position) positions.get(21); assertTrue(mdem.canExpand(pos.getMembers()[0])); mdem.expand(pos.getMembers()[0]); 219 result = model.getResult(); 220 if (renderFile != null) 221 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 222 223 assertPosition(result, 30, "Store 7", "Carbonated Beverages"); 224 225 positions = result.getAxes()[1].getPositions(); 227 pos = (Position) positions.get(21); assertTrue(mdem.canCollapse(pos.getMembers()[0])); pos = (Position) positions.get(2); assertTrue(mdem.canCollapse(pos.getMembers()[0])); mdem.collapse(pos.getMembers()[0]); 233 result = model.getResult(); 234 if (renderFile != null) 235 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 236 237 assertPosition(result, 4, "CA", "Hot Beverages"); 238 assertPosition(result, 12, "OR", "Pure Juice Beverages"); 239 assertPosition(result, 14, "WA", "Alcoholic Beverages"); 240 241 positions = result.getAxes()[1].getPositions(); 243 pos = (Position) positions.get(1); assertTrue(mdem.canCollapse(pos.getMembers()[1])); mdem.collapse(pos.getMembers()[1]); 247 result = model.getResult(); 248 if (renderFile != null) 249 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 250 251 positions = result.getAxes()[1].getPositions(); 252 assertPosition(result, 8, "WA", "Dairy"); 253 assertEquals(positions.size(), 9); 254 255 } 256 257 public void testMixedMode() throws Exception { 258 259 String mdxQuery = 260 " select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} ON columns, " 261 + "CrossJoin( {[Promotion Media].[All Media]}," 262 + " {[Product].[All Products].[Drink].children} ) ON rows " 263 + "from [Sales] where ([Time].[1997]) "; 264 265 String renderFile = null; int renderNum = 0; 267 268 Result result; 269 270 URL confUrl = XMLA_Model.class.getResource("config.xml"); 271 XMLA_Model model = (XMLA_Model) ModelFactory.instance(confUrl); 272 273 model.setMdxQuery(mdxQuery); 274 TestConnection.initModel(model); 275 276 result = model.getResult(); 278 if (renderFile != null) 279 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 280 281 assertPosition(result, 2, "All Media", "Dairy"); 282 283 DrillExpandMemberExt mdem = 284 (DrillExpandMemberExt) model.getExtension(DrillExpandMember.ID); 285 DrillExpandPositionExt mdep = 286 (DrillExpandPositionExt) model.getExtension(DrillExpandPosition.ID); 287 288 Axis[] axes = result.getAxes(); 290 List positions = axes[1].getPositions(); 291 Position pos = (Position) positions.get(1); 293 assertTrue(mdem.canExpand(pos.getMembers()[0])); mdem.expand(pos.getMembers()[0]); 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, 3, "Bulk Mail", "Alcoholic Beverages"); 303 assertPosition(result, 10, "Daily Paper", "Beverages"); 304 assertPosition(result, 28, "Radio", "Beverages"); 305 assertPosition(result, 44, "TV", "Dairy"); 306 307 pos = (Position) positions.get(27); assertTrue(!mdep.canExpand(pos, pos.getMembers()[0])); assertTrue(mdep.canExpand(pos, pos.getMembers()[1])); mdep.expand(pos, pos.getMembers()[1]); 313 result = model.getResult(); 314 if (renderFile != null) 315 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 316 317 assertPosition(result, 28, "Radio", "Beer and Wine"); 318 axes = result.getAxes(); 319 positions = axes[1].getPositions(); 320 321 pos = (Position) positions.get(2); assertTrue(mdem.canExpand(pos.getMembers()[1])); mdem.expand(pos.getMembers()[1]); 326 result = model.getResult(); 327 if (renderFile != null) 328 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 329 330 axes = result.getAxes(); 331 positions = axes[1].getPositions(); 332 assertEquals(positions.size(), 61); 333 334 pos = (Position) positions.get(0); assertTrue(mdem.canCollapse(pos.getMembers()[0])); mdem.collapse(pos.getMembers()[0]); 339 result = model.getResult(); 340 if (renderFile != null) 341 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 342 axes = result.getAxes(); 343 positions = axes[1].getPositions(); 344 assertEquals(positions.size(), 4); 345 346 pos = (Position) positions.get(2); assertTrue(mdep.canCollapse(pos, pos.getMembers()[1])); mdep.collapse(pos, pos.getMembers()[1]); 350 351 result = model.getResult(); 352 if (renderFile != null) 353 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 354 axes = result.getAxes(); 355 positions = axes[1].getPositions(); 356 assertEquals(positions.size(), 3); 357 } 358 359 362 private void assertPosition(Result result, int iPos, String firstMember, String secondMember) { 363 Position pos = (Position) result.getAxes()[1].getPositions().get(iPos); 364 String s = pos.getMembers()[0].getLabel(); 365 assertEquals(s, firstMember); 366 s = pos.getMembers()[1].getLabel(); 367 assertEquals(s, secondMember); 368 } 369 370 } | Popular Tags |