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.Position; 9 import com.tonbeller.jpivot.olap.model.Result; 10 import com.tonbeller.jpivot.olap.navi.DrillExpandMember; 11 import com.tonbeller.jpivot.olap.navi.DrillExpandPosition; 12 import com.tonbeller.jpivot.olap.query.DrillExpandMemberExt; 13 import com.tonbeller.jpivot.olap.query.DrillExpandPositionExt; 14 import com.tonbeller.jpivot.olap.query.ResultBase; 15 import com.tonbeller.jpivot.tags.MondrianModelFactory; 16 17 22 public class ExpandCollapseTest extends TestCase { 23 24 28 public ExpandCollapseTest(String arg0) { 29 super(arg0); 30 } 31 32 public void testExpandPosMem() 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 49 MondrianModel model = MondrianModelFactory.instance(); 50 model.setMdxQuery(mdxQuery); 51 TestConnection.initModel(model); 52 53 result = model.getResult(); 55 if (renderFile != null) 56 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 57 58 assertPosition(result, 1, "CA", "Beverages"); 59 assertPosition(result, 6, "WA", "Alcoholic Beverages"); 60 61 DrillExpandPositionExt mdep = 62 (DrillExpandPositionExt) model.getExtension(DrillExpandPosition.ID); 63 64 66 Axis[] axes = result.getAxes(); 67 List positions = axes[1].getPositions(); 68 Position pos = (Position) positions.get(1); 70 assertTrue(mdep.canExpand(pos, pos.getMembers()[0])); 71 mdep.expand(pos, pos.getMembers()[0]); 73 result = model.getResult(); 74 if (renderFile != null) 75 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 76 77 positions = result.getAxes()[1].getPositions(); 78 assertPosition(result, 6, "Beverly Hills", "Alcoholic Beverages"); 79 assertPosition(result, 10, "Los Angeles", "Beverages"); 80 assertPosition(result, 17, "San Francisco", "Dairy"); 81 assertPosition(result, positions.size() - 1, "WA", "Dairy"); 82 83 pos = (Position) positions.get(1); assertTrue(mdep.canExpand(pos, pos.getMembers()[1])); 86 mdep.expand(pos, pos.getMembers()[1]); 88 result = model.getResult(); 89 if (renderFile != null) 90 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 91 92 positions = result.getAxes()[1].getPositions(); 93 assertPosition(result, 2, "CA", "Carbonated Beverages"); 94 assertPosition(result, 5, "CA", "Pure Juice Beverages"); 95 assertPosition(result, 10, "Beverly Hills", "Alcoholic Beverages"); 96 assertPosition(result, positions.size() - 4, "OR", "Dairy"); 97 98 100 pos = (Position) positions.get(14); assertTrue(mdep.canExpand(pos, pos.getMembers()[1])); 102 mdep.expand(pos, pos.getMembers()[1]); 104 result = model.getResult(); 105 if (renderFile != null) 106 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 107 108 positions = result.getAxes()[1].getPositions(); 109 assertPosition(result, 15, "Los Angeles", "Carbonated Beverages"); 110 assertPosition(result, 17, "Los Angeles", "Hot Beverages"); 111 assertPosition(result, 21, "San Diego", "Beverages"); 112 113 pos = (Position) positions.get(1); assertTrue(mdep.canCollapse(pos, pos.getMembers()[0])); 116 mdep.collapse(pos, pos.getMembers()[0]); 118 result = model.getResult(); 119 if (renderFile != null) 120 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 121 122 positions = result.getAxes()[1].getPositions(); 123 assertPosition(result, 0, "CA", "Alcoholic Beverages"); 124 assertPosition(result, 5, "CA", "Pure Juice Beverages"); 125 assertPosition(result, 10, "WA", "Alcoholic Beverages"); 126 127 pos = (Position) positions.get(1); assertTrue(mdep.canCollapse(pos, pos.getMembers()[1])); 130 mdep.collapse(pos, pos.getMembers()[1]); 132 result = model.getResult(); 133 if (renderFile != null) 134 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 135 136 positions = result.getAxes()[1].getPositions(); 137 assertPosition(result, 8, "WA", "Dairy"); 138 assertEquals(positions.size(), 9); 139 140 } 141 142 public void testExpandMem() throws Exception { 143 148 149 String mdxQuery = 150 "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns, " 151 + "CrossJoin( [Store].[USA].children, [Product].[All Products].[Drink].children) on rows " 152 + "from Sales where ([Time].[1997])"; 153 154 String renderFile = null; int renderNum = 0; 156 157 Result result; 158 159 MondrianModel model = MondrianModelFactory.instance(); 160 model.setMdxQuery(mdxQuery); 161 TestConnection.initModel(model); 162 163 result = model.getResult(); 165 if (renderFile != null) 166 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 167 168 assertPosition(result, 1, "CA", "Beverages"); 169 assertPosition(result, 6, "WA", "Alcoholic Beverages"); 170 171 DrillExpandMemberExt mdem = 172 (DrillExpandMemberExt) model.getExtension(DrillExpandMember.ID); 173 174 176 Axis[] axes = result.getAxes(); 177 List positions = axes[1].getPositions(); 178 Position pos = (Position) positions.get(1); 180 assertTrue(mdem.canExpand(pos.getMembers()[0])); mdem.expand(pos.getMembers()[0]); 183 result = model.getResult(); 184 if (renderFile != null) 185 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 186 187 assertPosition(result, 8, "Beverly Hills", "Dairy"); 188 assertPosition(result, 12, "San Diego", "Alcoholic Beverages"); 189 assertPosition(result, 16, "San Francisco", "Beverages"); 190 191 positions = result.getAxes()[1].getPositions(); 193 pos = (Position) positions.get(1); assertTrue(mdem.canExpand(pos.getMembers()[1])); 195 mdem.expand(pos.getMembers()[1]); 197 result = model.getResult(); 198 if (renderFile != null) 199 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 200 201 assertPosition(result, 2, "CA", "Carbonated Beverages"); 202 assertPosition(result, 5, "CA", "Pure Juice Beverages"); 203 assertPosition(result, 24, "Los Angeles", "Drinks"); 204 assertPosition(result, 32, "San Diego", "Hot Beverages"); 205 assertPosition(result, 44, "OR", "Carbonated Beverages"); 206 207 209 positions = result.getAxes()[1].getPositions(); 210 pos = (Position) positions.get(21); assertTrue(mdem.canExpand(pos.getMembers()[0])); mdem.expand(pos.getMembers()[0]); 214 result = model.getResult(); 215 if (renderFile != null) 216 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 217 218 assertPosition(result, 30, "Store 7", "Carbonated Beverages"); 219 220 positions = result.getAxes()[1].getPositions(); 222 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]); 228 result = model.getResult(); 229 if (renderFile != null) 230 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 231 232 assertPosition(result, 4, "CA", "Hot Beverages"); 233 assertPosition(result, 12, "OR", "Pure Juice Beverages"); 234 assertPosition(result, 14, "WA", "Alcoholic Beverages"); 235 236 positions = result.getAxes()[1].getPositions(); 238 pos = (Position) positions.get(1); assertTrue(mdem.canCollapse(pos.getMembers()[1])); mdem.collapse(pos.getMembers()[1]); 242 result = model.getResult(); 243 if (renderFile != null) 244 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 245 246 positions = result.getAxes()[1].getPositions(); 247 assertPosition(result, 8, "WA", "Dairy"); 248 assertEquals(positions.size(), 9); 249 250 } 251 252 public void testMixedMode() throws Exception { 253 254 String mdxQuery = 255 " select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} ON columns, " 256 + "CrossJoin( {[Promotion Media].[All Media]}," 257 + " {[Product].[All Products].[Drink].children} ) ON rows " 258 + "from [Sales] where ([Time].[1997]) "; 259 260 String renderFile = null; int renderNum = 0; 262 263 Result result; 264 265 MondrianModel model = MondrianModelFactory.instance(); 266 model.setMdxQuery(mdxQuery); 267 TestConnection.initModel(model); 268 269 result = model.getResult(); 271 if (renderFile != null) 272 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 273 274 assertPosition(result, 2, "All Media", "Dairy"); 275 276 DrillExpandMemberExt mdem = 277 (DrillExpandMemberExt) model.getExtension(DrillExpandMember.ID); 278 DrillExpandPositionExt mdep = 279 (DrillExpandPositionExt) model.getExtension(DrillExpandPosition.ID); 280 281 Axis[] axes = result.getAxes(); 283 List positions = axes[1].getPositions(); 284 Position pos = (Position) positions.get(1); 286 assertTrue(mdem.canExpand(pos.getMembers()[0])); mdem.expand(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, 3, "Bulk Mail", "Alcoholic Beverages"); 296 assertPosition(result, 10, "Daily Paper", "Beverages"); 297 assertPosition(result, 28, "Radio", "Beverages"); 298 assertPosition(result, 44, "TV", "Dairy"); 299 300 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]); 306 result = model.getResult(); 307 if (renderFile != null) 308 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 309 310 assertPosition(result, 28, "Radio", "Beer and Wine"); 311 axes = result.getAxes(); 312 positions = axes[1].getPositions(); 313 314 pos = (Position) positions.get(2); assertTrue(mdem.canExpand(pos.getMembers()[1])); mdem.expand(pos.getMembers()[1]); 319 result = model.getResult(); 320 if (renderFile != null) 321 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 322 323 axes = result.getAxes(); 324 positions = axes[1].getPositions(); 325 assertEquals(positions.size(), 61); 326 327 pos = (Position) positions.get(0); assertTrue(mdem.canCollapse(pos.getMembers()[0])); mdem.collapse(pos.getMembers()[0]); 332 result = model.getResult(); 333 if (renderFile != null) 334 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 335 axes = result.getAxes(); 336 positions = axes[1].getPositions(); 337 assertEquals(positions.size(), 4); 338 339 pos = (Position) positions.get(2); assertTrue(mdep.canCollapse(pos, pos.getMembers()[1])); mdep.collapse(pos, pos.getMembers()[1]); 343 344 result = model.getResult(); 345 if (renderFile != null) 346 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html"); 347 axes = result.getAxes(); 348 positions = axes[1].getPositions(); 349 assertEquals(positions.size(), 3); 350 } 351 352 355 private void assertPosition(Result result, int iPos, String firstMember, String secondMember) { 356 Position pos = (Position) result.getAxes()[1].getPositions().get(iPos); 357 String s = pos.getMembers()[0].getLabel(); 358 assertEquals(s, firstMember); 359 s = pos.getMembers()[1].getLabel(); 360 assertEquals(s, secondMember); 361 } 362 363 } | Popular Tags |