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.DrillExpandPosition; 13 import com.tonbeller.jpivot.olap.query.DrillExpandPositionExt; 14 import com.tonbeller.jpivot.olap.query.ResultBase; 15 import com.tonbeller.wcf.bookmarks.Bookmarkable; 16 17 21 public class CoSalUniTest extends TestCase { 22 23 27 public CoSalUniTest(String arg0) { 28 super(arg0); 29 } 30 31 public void testCoSalUni() throws Exception { 32 33 41 String mdxQuery = "select Crossjoin({[Store Size in SQFT].[All Store Size in SQFT]}, " 42 + "Crossjoin({[Store Type].[All Store Type]}, " 43 + "{[Measures].[Store Cost], [Measures].[Store Sales], [Measures].[Unit Sales]})) ON columns, " 44 + "{[Product].[All Products]} ON rows 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 result = model.getResult(); 59 if (renderFile != null) 60 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 61 62 assertPosition(result, 2, new String [] { "All Store Size in SQFT", "All Store Type", 63 "Unit Sales"}); 64 65 DrillExpandPositionExt mdep = (DrillExpandPositionExt) model 66 .getExtension(DrillExpandPosition.ID); 67 68 Axis[] axes = result.getAxes(); 70 List positions = axes[0].getPositions(); 71 Position pos0 = (Position) positions.get(0); 73 assertTrue(mdep.canExpand(pos0, pos0.getMembers()[0])); 74 mdep.expand(pos0, pos0.getMembers()[0]); 76 result = model.getResult(); 77 if (renderFile != null) 78 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 79 80 assertPosition(result, 7, new String [] { "20319", "All Store Type", "Store Sales"}); 82 83 axes = result.getAxes(); 85 positions = axes[0].getPositions(); 86 Position pos4 = (Position) positions.get(7); mdep.expand(pos4, pos4.getMembers()[1]); result = model.getResult(); 89 if (renderFile != null) 90 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 91 92 assertPosition(result, 24, new String [] { "20319", "Supermarket", "Store Cost"}); 93 94 Object state = model.getBookmarkState(Bookmarkable.EXTENSIONAL); 97 result = model.getResult(); 98 if (renderFile != null) 99 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 100 101 assertPosition(result, 1, new String [] { "All Store Size in SQFT", "All Store Type", 102 "Store Sales"}); 103 104 model.setMdxQuery(mdxQuery); 105 model.setBookmarkState(state); 106 result = model.getResult(); 107 if (renderFile != null) 108 ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html"); 109 110 assertPosition(result, 24, new String [] { "20319", "Supermarket", "Store Cost"}); 111 112 } 113 114 117 private void assertPosition(Result result, int iPos, String [] posMembers) { 118 Position pos = (Position) result.getAxes()[0].getPositions().get(iPos); 119 for (int i = 0; i < posMembers.length; i++) { 120 String str = pos.getMembers()[i].getLabel(); 121 assertEquals(str, posMembers[i]); 122 } 123 } 124 } | Popular Tags |