KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.tonbeller.jpivot.mondrian;
2
3 import java.net.URL 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.query.ResultBase;
10 import com.tonbeller.jpivot.tags.MondrianModelFactory;
11
12 /**
13  * Time dimension compatibility Test for "old" Schema files
14  */

15 public class TimeSchemaTest extends TestCase {
16
17   /**
18    * Constructor
19    *
20    * @param arg0
21    */

22   public TimeSchemaTest(String JavaDoc arg0) {
23     super(arg0);
24   }
25
26   /**
27    * test time dimension having Non Time Level
28    *
29    * @throws Exception
30    */

31   public void testTimeDimNonTimeLev() throws Exception JavaDoc {
32
33     String JavaDoc mdxQuery = "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns, "
34         + "Crossjoin([Time].[Quartale].members, [Customers].[All Customers].[USA].children) on rows "
35         + "from Sales";
36
37     String JavaDoc renderFile = null; //"c:\\x\\testTimeDimNonTimeLev";
38
int renderNum = 0;
39
40     Result result;
41
42     MondrianModel model = MondrianModelFactory.instance();
43     model.setMdxQuery(mdxQuery);
44
45     // the catalog file is TestSchema.xml in "this" directory
46
// URL url = this.getClass().getResource("TestSchema.xml");
47
// String catUri = "file://" + url.getFile();
48

49     URL JavaDoc url = this.getClass().getResource("TestSchema.xml");
50     String JavaDoc connectString = TestConnection.getConnectString(url.toExternalForm());
51     model.setConnectString(connectString);
52     String JavaDoc jdbcDriver = TestConnection.getJdbcDriver();
53     model.setJdbcDriver(jdbcDriver);
54     model.initialize();
55
56     result = model.getResult();
57     if (renderFile != null)
58       ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ + ".html");
59
60     //assertPosition(result, 2, "Q1", "WA");
61
}
62
63   /**
64    * assert position
65    */

66   private void assertPosition(Result result, int iPos, String JavaDoc firstMember, String JavaDoc secondMember) {
67     Position pos = (Position) result.getAxes()[1].getPositions().get(iPos);
68     String JavaDoc s = pos.getMembers()[0].getLabel();
69     assertEquals(s, firstMember);
70     if (secondMember != null) {
71       s = pos.getMembers()[1].getLabel();
72       assertEquals(s, secondMember);
73     }
74   }
75
76 } // TimeSchemaTest
77
Popular Tags