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