KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.tonbeller.jpivot.mondrian;
2
3 import java.util.List JavaDoc;
4
5 import junit.framework.TestCase;
6
7 import com.tonbeller.jpivot.olap.model.Position;
8 import com.tonbeller.jpivot.olap.model.Result;
9 import com.tonbeller.jpivot.olap.navi.DrillExpandPosition;
10 import com.tonbeller.jpivot.olap.query.DrillExpandPositionExt;
11 import com.tonbeller.jpivot.olap.query.ResultBase;
12 import com.tonbeller.jpivot.tags.MondrianModelFactory;
13
14 /**
15  * @author hh
16  *
17  * Test expand/collapse with position and member
18  */

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

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

37
38     String JavaDoc mdxQuery =
39       "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns,"
40         + "{([Gender].[All Gender], [Marital Status].[All Marital Status],"
41         + "[Customers].[All Customers],"
42         + "[Product].[All Products] ) } on rows "
43         + "from Sales where ([Time].[1997])";
44
45     String JavaDoc renderFile = null; // "c:\\x\\testExpandPosMem";
46
int renderNum = 0;
47
48     Result result;
49
50     MondrianModel model = MondrianModelFactory.instance();
51     model.setMdxQuery(mdxQuery);
52     TestConnection.initModel(model);
53
54     DrillExpandPositionExt mdep =
55       (DrillExpandPositionExt) model.getExtension(DrillExpandPosition.ID);
56
57     // first step
58
result = model.getResult();
59     if (renderFile != null)
60        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
61
62     List JavaDoc positions = result.getAxes()[1].getPositions();
63     // expand All Gender
64
Position pos = (Position) positions.get(0);
65     assertTrue(mdep.canExpand(pos, pos.getMembers()[0]));
66     mdep.expand(pos, pos.getMembers()[0]); // expand All Gender
67

68     result = model.getResult();
69     if (renderFile != null)
70        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
71
72     positions = result.getAxes()[1].getPositions();
73     assertPosition(
74       result,
75       1,
76       new String JavaDoc[] { "F", "All Marital Status", "All Customers", "All Products" });
77
78     // expand (F,,All Customers,)
79
pos = (Position) positions.get(1);
80     assertTrue(mdep.canExpand(pos, pos.getMembers()[2]));
81     mdep.expand(pos, pos.getMembers()[2]); // expand All Customers
82

83     result = model.getResult();
84     if (renderFile != null)
85        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
86
87     positions = result.getAxes()[1].getPositions();
88     assertPosition(result, 4, new String JavaDoc[] { "F", "All Marital Status", "USA", "All Products" });
89
90     // expand All Products
91
pos = (Position) positions.get(4);
92     assertTrue(mdep.canExpand(pos, pos.getMembers()[3]));
93     mdep.expand(pos, pos.getMembers()[3]); // expand F, All, USA, All Products
94

95     result = model.getResult();
96     if (renderFile != null)
97        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
98
99     positions = result.getAxes()[1].getPositions();
100     assertPosition(result, 5, new String JavaDoc[] { "F", "All Marital Status", "USA", "Drink" });
101
102     // expand USA
103
pos = (Position) positions.get(5);
104     assertTrue(mdep.canExpand(pos, pos.getMembers()[2]));
105     mdep.expand(pos, pos.getMembers()[2]); // expand F, All, USA
106

107     result = model.getResult();
108     if (renderFile != null)
109        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
110
111     positions = result.getAxes()[1].getPositions();
112
113     assertPosition(result, 9, new String JavaDoc[] { "F", "All Marital Status", "CA", "Drink" });
114     assertPosition(result, 14, new String JavaDoc[] { "F", "All Marital Status", "OR", "Food" });
115
116     // expand All Marital status under F
117
pos = (Position) positions.get(1);
118     assertTrue(mdep.canExpand(pos, pos.getMembers()[1]));
119     mdep.expand(pos, pos.getMembers()[1]); // expand All Marital Status
120

121     result = model.getResult();
122     if (renderFile != null)
123        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
124
125     positions = result.getAxes()[1].getPositions();
126
127     assertPosition(result, positions.size() - 2, new String JavaDoc[] { "F", "S", "WA", "Non-Consumable" });
128     assertPosition(result, positions.size() - 5, new String JavaDoc[] { "F", "S", "WA", "All Products" });
129
130     // Collapse all Products
131
pos = (Position) positions.get(positions.size() - 5);
132     assertTrue(mdep.canCollapse(pos, pos.getMembers()[3]));
133     mdep.collapse(pos, pos.getMembers()[3]); // "F", "S", "WA", "All Products"
134

135     result = model.getResult();
136     if (renderFile != null)
137        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
138
139     positions = result.getAxes()[1].getPositions();
140
141     assertPosition(result, positions.size() - 2, new String JavaDoc[] { "F", "S", "WA", "All Products" });
142
143     // collapse All Marital Status
144
pos = (Position) positions.get(1);
145     assertTrue(mdep.canCollapse(pos, pos.getMembers()[1]));
146     mdep.collapse(pos, pos.getMembers()[1]); // All Marital Status
147

148     result = model.getResult();
149     if (renderFile != null)
150        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
151
152     positions = result.getAxes()[1].getPositions();
153
154     assertPosition(result, 8, new String JavaDoc[] { "F", "All Marital Status", "CA", "All Products" });
155
156     // collapse All Gender
157
pos = (Position) positions.get(0);
158     assertTrue(mdep.canCollapse(pos, pos.getMembers()[0]));
159     mdep.collapse(pos, pos.getMembers()[0]); // All Gender
160

161     result = model.getResult();
162     if (renderFile != null)
163       ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
164
165     positions = result.getAxes()[1].getPositions();
166     assertEquals(positions.size(), 1);
167   }
168
169   /**
170    * assert position
171    */

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