KickJava   Java API By Example, From Geeks To Geeks.

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


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.Axis;
8 import com.tonbeller.jpivot.olap.model.Position;
9 import com.tonbeller.jpivot.olap.model.Result;
10 import com.tonbeller.jpivot.olap.navi.DrillExpandPosition;
11 import com.tonbeller.jpivot.olap.query.DrillExpandPositionExt;
12 import com.tonbeller.jpivot.olap.query.ResultBase;
13 import com.tonbeller.jpivot.tags.MondrianModelFactory;
14 import com.tonbeller.wcf.bookmarks.Bookmarkable;
15
16 /**
17  * make sure that the measures "Store Cost,Store Sales, Unit Sales"
18  * are NOT "hierarchized".
19  */

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

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

40     String JavaDoc mdxQuery = "select Crossjoin({[Store Size in SQFT].[All Store Size in SQFTs]}, "
41         + "Crossjoin({[Store Type].[All Store Types]}, "
42         + "{[Measures].[Store Cost], [Measures].[Store Sales], [Measures].[Unit Sales]})) ON columns, "
43         + "{[Product].[All Products]} ON rows from [Sales] where [Time].[1997]";
44
45     String JavaDoc renderFile = null; //"c:\\x\\testCoSalUni";
46
int renderNum = 0;
47
48     Result result;
49
50     MondrianModel model = MondrianModelFactory.instance();
51     model.setMdxQuery(mdxQuery);
52     TestConnection.initModel(model);
53
54     // first step
55
result = model.getResult();
56     if (renderFile != null)
57       ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html");
58
59     assertPosition(result, 2, new String JavaDoc[] { "All Store Size in SQFTs", "All Store Types",
60         "Unit Sales"});
61
62     DrillExpandPositionExt mdep = (DrillExpandPositionExt) model
63         .getExtension(DrillExpandPosition.ID);
64
65     // Drill down All Store Size
66
Axis[] axes = result.getAxes();
67     List JavaDoc positions = axes[0].getPositions();
68     Position pos0 = (Position) positions.get(0); // Drill down All Store Size
69

70     assertTrue(mdep.canExpand(pos0, pos0.getMembers()[0]));
71     mdep.expand(pos0, pos0.getMembers()[0]); // drilldown All Store Size
72

73     result = model.getResult();
74     if (renderFile != null)
75       ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html");
76
77     assertPosition(result, 7, new String JavaDoc[] { "20319", "All Store Types", "Store Sales"});
78
79     // drill down All Store Types below 20319.0
80
axes = result.getAxes();
81     positions = axes[0].getPositions();
82     Position pos7 = (Position) positions.get(7); // "20319.0", "All Store Types"
83
mdep.expand(pos7, pos7.getMembers()[1]); // drilldown All Store Size
84
result = model.getResult();
85     if (renderFile != null)
86       ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html");
87
88     assertPosition(result, 24, new String JavaDoc[] { "20319", "Supermarket", "Store Cost"});
89
90     // save bookmark and reload
91
Object JavaDoc state = model.getBookmarkState(Bookmarkable.EXTENSIONAL);
92     result = model.getResult();
93     if (renderFile != null)
94       ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html");
95
96     assertPosition(result, 1, new String JavaDoc[] { "All Store Size in SQFTs", "All Store Types",
97         "Store Sales"});
98
99     model.setMdxQuery(mdxQuery);
100     model.setBookmarkState(state);
101     result = model.getResult();
102     if (renderFile != null)
103       ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html");
104
105     assertPosition(result, 24, new String JavaDoc[] { "20319", "Supermarket", "Store Cost"});
106
107   }
108
109   /**
110    * assert position
111    */

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