KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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