KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.tonbeller.jpivot.mondrian;
2
3 import junit.framework.TestCase;
4
5 import com.tonbeller.jpivot.olap.model.Axis;
6 import com.tonbeller.jpivot.olap.model.Dimension;
7 import com.tonbeller.jpivot.olap.model.Hierarchy;
8 import com.tonbeller.jpivot.olap.model.JunitUtil;
9 import com.tonbeller.jpivot.olap.model.Member;
10 import com.tonbeller.jpivot.olap.model.Position;
11 import com.tonbeller.jpivot.olap.model.Result;
12 import com.tonbeller.jpivot.olap.navi.PlaceHierarchiesOnAxes;
13 import com.tonbeller.jpivot.olap.query.ResultBase;
14 import com.tonbeller.jpivot.tags.MondrianModelFactory;
15
16 /**
17  * Test the "expand All member" of the PlaceHierarchies extension
18  */

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

25   public ExpandAllTest(String JavaDoc arg0) {
26     super(arg0);
27   }
28
29   public void testExpandAllMember() throws Exception JavaDoc {
30
31     /*
32      select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} ON columns,
33      {[Product].[All Products]} ON rows from [Sales]
34      */

35     String JavaDoc mdxQuery = "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} "
36         + "ON columns, " + "{[Product].[All Products]} ON rows from [Sales]";
37
38     String JavaDoc renderFile = null; //"c:\\x\\testExpandAllMember";
39
int renderNum = 0;
40
41     Result result;
42
43     MondrianModel model = MondrianModelFactory.instance();
44     model.setMdxQuery(mdxQuery);
45     TestConnection.initModel(model);
46     PlaceHierarchiesOnAxes placeHier = (PlaceHierarchiesOnAxes) model
47         .getExtension(PlaceHierarchiesOnAxes.ID);
48
49     // set the "Expand All member" feature
50
placeHier.setExpandAllMember(true);
51     
52     // first step
53
result = model.getResult();
54     if (renderFile != null)
55       ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html");
56
57     JunitUtil.assertPosition(result, 1, 0, new String JavaDoc[] { "All Products"}, new String JavaDoc[] { "266773",
58         "225627.23", "565238.13"});
59
60     // get Customers Hierarchy and add it to axis 1
61
Dimension[] dims = model.getDimensions();
62     Dimension custoDim = null;
63     for (int i = 0; i < dims.length; i++) {
64       if ((dims[i]).getLabel().equals("Customers")) {
65         custoDim = dims[i];
66         break;
67       }
68     }
69     Axis[] axes = result.getAxes();
70     Position pos0 = (Position) axes[1].getPositions().get(0);
71     Member[] mems = pos0.getMembers();
72     Object JavaDoc[] ohiers = new Object JavaDoc[mems.length +1];
73     for (int i = 0; i < mems.length; i++) {
74       Hierarchy hier = mems[i].getLevel().getHierarchy();
75       ohiers[i] = placeHier.createMemberExpression(hier);
76     }
77     Object JavaDoc oCust = placeHier.createMemberExpression(custoDim.getHierarchies()[0]);
78     ohiers[mems.length] = oCust;
79     placeHier.setQueryAxis(axes[1], ohiers);
80
81     // expect "All Customers" to be expanded
82
result = model.getResult();
83     if (renderFile != null)
84       ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html");
85
86     JunitUtil.assertPosition(result, 1, 3, new String JavaDoc[] { "All Products", "USA"}, new String JavaDoc[] { "266773",
87         "225627.23", "565238.13"});
88
89   }
90
91 }
Popular Tags