KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 /**
16  * @author hh
17  *
18  * Test expand/collapse with position and member
19  */

20 public class ExpandPositionSpanTest extends TestCase {
21
22   /**
23    * Constructor for ExpandCollapse.
24    * @param arg0
25    */

26   public ExpandPositionSpanTest(String JavaDoc arg0) {
27     super(arg0);
28   }
29
30   public void testExpandPositionSpan() throws Exception JavaDoc {
31     /*
32     select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns,
33     {([Gender].[All Gender], [Marital Status].[All Marital Status],
34     [Customers].[All Customers],
35     [Product].[All Products] ) } on rows
36     from Sales where ([Time].[1997])
37     */

38
39     String JavaDoc 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 JavaDoc renderFile = null; // "c:\\x\\testExpandPosMem";
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     DrillExpandPositionExt mdep =
58       (DrillExpandPositionExt) model.getExtension(DrillExpandPosition.ID);
59
60     // first step
61
result = model.getResult();
62     if (renderFile != null)
63        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
64
65     List JavaDoc positions = result.getAxes()[1].getPositions();
66     // expand All Gender
67
Position pos = (Position) positions.get(0);
68     assertTrue(mdep.canExpand(pos, pos.getMembers()[0]));
69     mdep.expand(pos, pos.getMembers()[0]); // expand All Gender
70

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 JavaDoc[] { "F", "All Marital Status", "All Customers", "All Products" });
80
81     // expand (F,,All Customers,)
82
pos = (Position) positions.get(1);
83     assertTrue(mdep.canExpand(pos, pos.getMembers()[2]));
84     mdep.expand(pos, pos.getMembers()[2]); // expand All Customers
85

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 JavaDoc[] { "F", "All Marital Status", "USA", "All Products" });
92
93     // expand All Products
94
pos = (Position) positions.get(4);
95     assertTrue(mdep.canExpand(pos, pos.getMembers()[3]));
96     mdep.expand(pos, pos.getMembers()[3]); // expand F, All, USA, All Products
97

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 JavaDoc[] { "F", "All Marital Status", "USA", "Drink" });
104
105     // expand USA
106
pos = (Position) positions.get(5);
107     assertTrue(mdep.canExpand(pos, pos.getMembers()[2]));
108     mdep.expand(pos, pos.getMembers()[2]); // expand F, All, USA
109

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 JavaDoc[] { "F", "All Marital Status", "CA", "Drink" });
117     assertPosition(result, 14, new String JavaDoc[] { "F", "All Marital Status", "OR", "Food" });
118
119     // expand All Marital status under F
120
pos = (Position) positions.get(1);
121     assertTrue(mdep.canExpand(pos, pos.getMembers()[1]));
122     mdep.expand(pos, pos.getMembers()[1]); // expand All Marital Status
123

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 JavaDoc[] { "F", "S", "WA", "Non-Consumable" });
131     assertPosition(result, positions.size() - 5, new String JavaDoc[] { "F", "S", "WA", "All Products" });
132
133     // Collapse all Products
134
pos = (Position) positions.get(positions.size() - 5);
135     assertTrue(mdep.canCollapse(pos, pos.getMembers()[3]));
136     mdep.collapse(pos, pos.getMembers()[3]); // "F", "S", "WA", "All Products"
137

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 JavaDoc[] { "F", "S", "WA", "All Products" });
145
146     // collapse All Marital Status
147
pos = (Position) positions.get(1);
148     assertTrue(mdep.canCollapse(pos, pos.getMembers()[1]));
149     mdep.collapse(pos, pos.getMembers()[1]); // All Marital Status
150

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 JavaDoc[] { "F", "All Marital Status", "CA", "All Products" });
158
159     // collapse All Gender
160
pos = (Position) positions.get(0);
161     assertTrue(mdep.canCollapse(pos, pos.getMembers()[0]));
162     mdep.collapse(pos, pos.getMembers()[0]); // All Gender
163

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   /**
173    * assert position
174    */

175   private void assertPosition(Result result, int iPos, String JavaDoc[] posMembers) {
176     Position pos = (Position) result.getAxes()[1].getPositions().get(iPos);
177     for (int i = 0; i < posMembers.length; i++) {
178       String JavaDoc str = pos.getMembers()[i].getLabel();
179       assertEquals(str, posMembers[i]);
180     }
181   }
182
183 } // End ExpandPositionSpanTest
184
Popular Tags