KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > test > olap > ModelFactoryTest


1 package com.tonbeller.jpivot.test.olap;
2
3 import java.net.URL JavaDoc;
4
5 import junit.framework.TestCase;
6
7 import com.tonbeller.jpivot.core.Extension;
8 import com.tonbeller.jpivot.core.ModelChangeEvent;
9 import com.tonbeller.jpivot.core.ModelChangeListener;
10 import com.tonbeller.jpivot.core.ModelFactory;
11 import com.tonbeller.jpivot.olap.model.Axis;
12 import com.tonbeller.jpivot.olap.model.Cell;
13 import com.tonbeller.jpivot.olap.model.Member;
14 import com.tonbeller.jpivot.olap.model.Position;
15 import com.tonbeller.jpivot.olap.model.Result;
16 import com.tonbeller.jpivot.olap.navi.DrillExpandMember;
17 import com.tonbeller.jpivot.tags.TestOlapModelTag;
18
19 public class ModelFactoryTest extends TestCase {
20
21   private TestOlapModel model;
22   int count = 0;
23   
24   /**
25    * Constructor for ModelFactoryTest.
26    * @param arg0
27    */

28   public ModelFactoryTest(String JavaDoc arg0) {
29     super(arg0);
30   }
31   
32
33   public void testInstance() throws Exception JavaDoc {
34     assertNotNull(model);
35     Extension ext = model.getExtension(DrillExpandMember.ID);
36     assertNotNull(ext);
37     assertNull(model.getExtension("xx"));
38   }
39   
40   public void testResult() throws Exception JavaDoc {
41     // assert !crash
42
Result res = model.getResult();
43   }
44   
45   public void testListener() {
46     ModelChangeListener listener = new ModelChangeListener () {
47       public void modelChanged(ModelChangeEvent e) {
48         count += 1;
49       }
50
51       public void structureChanged(ModelChangeEvent e) {
52       }
53     };
54     model.addModelChangeListener(listener);
55     count = 0;
56     model.fireModelChanged();
57     assertEquals(count, 1);
58   }
59
60   public void testDrillExpand() throws Exception JavaDoc {
61     Axis axis = model.getResult().getAxes()[1];
62     int l0 = axis.getPositions().size();
63     Position p = (Position)axis.getPositions().get(0);
64     Member m = p.getMembers()[0];
65     DrillExpandMember de = (DrillExpandMember)model.getExtension(DrillExpandMember.ID);
66     assertTrue(!de.canCollapse(m));
67     assertTrue(de.canExpand(m));
68     
69     de.expand(m);
70     assertTrue(de.canCollapse(m));
71     assertTrue(!de.canExpand(m));
72     axis = model.getResult().getAxes()[1];
73     int l1 = axis.getPositions().size();
74     assertTrue(l0 < l1);
75     
76     de.collapse(m);
77     assertTrue(!de.canCollapse(m));
78     assertTrue(de.canExpand(m));
79     axis = model.getResult().getAxes()[1];
80     int l2 = axis.getPositions().size();
81     assertEquals(l0, l2);
82   }
83   
84   public void testTestable() throws Exception JavaDoc {
85     // random numbers are no good for testing
86
Cell c1 = (Cell)model.getResult().getCells().get(1);
87     Cell c2 = (Cell)model.getResult().getCells().get(1);
88     assertEquals(c1.getValue(), c2.getValue());
89   }
90   
91   public void testTestable2() throws Exception JavaDoc {
92     model.expand0();
93     assertTrue(model.getResult().getAxes()[1].getPositions().size() > 1);
94   }
95   
96   /**
97    * @see junit.framework.TestCase#setUp()
98    */

99   protected void setUp() throws Exception JavaDoc {
100     URL JavaDoc url = TestOlapModelTag.class.getResource("/com/tonbeller/jpivot/test/olap/config.xml");
101     model = (TestOlapModel) ModelFactory.instance(url);
102   }
103
104 }
105
Popular Tags