KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > xmla > CoSalUniTest


1 package com.tonbeller.jpivot.xmla;
2
3 import java.net.URL JavaDoc;
4 import java.util.List JavaDoc;
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 /**
18  * make sure that the measures "Store Cost,Store Sales, Unit Sales"
19  * are NOT "hierarchized".
20  */

21 public class CoSalUniTest extends TestCase {
22
23   /**
24    * Constructor
25    * @param arg0
26    */

27   public CoSalUniTest(String JavaDoc arg0) {
28     super(arg0);
29   }
30
31   public void testCoSalUni() throws Exception JavaDoc {
32
33     /*
34      select Crossjoin({[Store Size in SQFT].[All Store Size in SQFT]},
35      Crossjoin({[Store Type].[All Store Type]},
36      {[Measures].[Store Cost], [Measures].[Store Sales], [Measures].[Unit Sales]})) ON columns,
37      {[Product].[All Products]} ON rows
38      from [Sales]
39      where [Time].[1997]
40      */

41     String JavaDoc 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 JavaDoc renderFile = null; // "c:\\x\\testCoSalUni";
47
int renderNum = 0;
48
49     Result result;
50
51     URL JavaDoc 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     // first step
58
result = model.getResult();
59     if (renderFile != null)
60       ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html");
61
62     assertPosition(result, 2, new String JavaDoc[] { "All Store Size in SQFT", "All Store Type",
63         "Unit Sales"});
64
65     DrillExpandPositionExt mdep = (DrillExpandPositionExt) model
66         .getExtension(DrillExpandPosition.ID);
67
68     // Drill down All Store Size
69
Axis[] axes = result.getAxes();
70     List JavaDoc positions = axes[0].getPositions();
71     Position pos0 = (Position) positions.get(0); // Drill down All Store Size
72

73     assertTrue(mdep.canExpand(pos0, pos0.getMembers()[0]));
74     mdep.expand(pos0, pos0.getMembers()[0]); // drilldown All Store Size
75

76     result = model.getResult();
77     if (renderFile != null)
78       ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html");
79
80     // null comes before any number in xmla (different from mondrian)
81
assertPosition(result, 7, new String JavaDoc[] { "20319", "All Store Type", "Store Sales"});
82
83     // drill down All Store Types below 20319.0
84
axes = result.getAxes();
85     positions = axes[0].getPositions();
86     Position pos4 = (Position) positions.get(7); // "20319.0", "All Store Types"
87
mdep.expand(pos4, pos4.getMembers()[1]); // drilldown All Store Size
88
result = model.getResult();
89     if (renderFile != null)
90       ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html");
91
92     assertPosition(result, 24, new String JavaDoc[] { "20319", "Supermarket", "Store Cost"});
93
94     // save bookmark and reload
95
// make sure, that "." in member name does not cause problem
96
Object JavaDoc 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 JavaDoc[] { "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 JavaDoc[] { "20319", "Supermarket", "Store Cost"});
111
112   }
113
114   /**
115    * assert position
116    */

117   private void assertPosition(Result result, int iPos, String JavaDoc[] posMembers) {
118     Position pos = (Position) result.getAxes()[0].getPositions().get(iPos);
119     for (int i = 0; i < posMembers.length; i++) {
120       String JavaDoc str = pos.getMembers()[i].getLabel();
121       assertEquals(str, posMembers[i]);
122     }
123   }
124 } // CoSalUni
125
Popular Tags