KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > table > span > ScopedPropertyMetaSetTest


1 package com.tonbeller.jpivot.table.span;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.HashSet JavaDoc;
5 import java.util.List JavaDoc;
6 import java.util.Set JavaDoc;
7
8 import junit.framework.TestCase;
9
10 import com.tonbeller.jpivot.olap.model.Level;
11 import com.tonbeller.jpivot.olap.model.MemberPropertyMeta;
12 import com.tonbeller.jpivot.olap.model.impl.HierarchyImpl;
13 import com.tonbeller.jpivot.olap.model.impl.LevelImpl;
14 import com.tonbeller.jpivot.olap.model.impl.MemberImpl;
15 import com.tonbeller.jpivot.olap.model.impl.PropertyImpl;
16
17 /**
18  * @author av
19  */

20 public class ScopedPropertyMetaSetTest extends TestCase {
21   private TestMemberProperties extension;
22
23   MemberPropertyMetaFilter allFilter = new ScopedPropertyMetaSet.AllFilter();
24
25   public void testLevelScope() {
26     List JavaDoc vp = new ArrayList JavaDoc();
27     vp.add(new MemberPropertyMeta("1label", "a", "l1"));
28     vp.add(new MemberPropertyMeta("2label", "a", "l2"));
29     vp.add(new MemberPropertyMeta("3label", "b", "l1"));
30     vp.add(new MemberPropertyMeta("4label", "c", "l2"));
31
32     ScopedPropertyMetaSet vpl = new ScopedPropertyMetaSet(null);
33     vpl.addAll(vp);
34
35     assertTrue(vpl.contains(new MemberPropertyMeta(null, "a", "l1")));
36     assertTrue(vpl.contains(new MemberPropertyMeta(null, "a", "l2")));
37     assertFalse(vpl.contains(new MemberPropertyMeta(null, "a", "l3")));
38
39     assertTrue(vpl.contains(new MemberPropertyMeta(null, "b", "l1")));
40     assertFalse(vpl.contains(new MemberPropertyMeta(null, "b", "l2")));
41     assertFalse(vpl.contains(new MemberPropertyMeta(null, "b", "l3")));
42
43     assertFalse(vpl.contains(new MemberPropertyMeta(null, "c", "l1")));
44     assertTrue(vpl.contains(new MemberPropertyMeta(null, "c", "l2")));
45     assertFalse(vpl.contains(new MemberPropertyMeta(null, "c", "l3")));
46
47     assertFalse(vpl.contains(new MemberPropertyMeta(null, "d", "l1")));
48     assertFalse(vpl.contains(new MemberPropertyMeta(null, "d", "l2")));
49     assertFalse(vpl.contains(new MemberPropertyMeta(null, "d", "l3")));
50
51     String JavaDoc[] allNames = vpl.getAllNames();
52     assertEquals(3, allNames.length);
53     assertEquals("a", allNames[0]);
54     assertEquals("b", allNames[1]);
55     assertEquals("c", allNames[2]);
56
57     vpl.remove(new MemberPropertyMeta(null, "a", "l3"));
58     assertEquals(4, vpl.metaList(allFilter).size());
59     vpl.remove(new MemberPropertyMeta(null, "a", "l1"));
60     assertEquals(3, vpl.metaList(allFilter).size());
61
62   }
63
64   String JavaDoc scope(Level l) {
65     return extension.getPropertyScope(l);
66   }
67
68   public void testHierarchyScope() {
69     List JavaDoc vp = new ArrayList JavaDoc();
70
71     LevelImpl l1 = new LevelImpl();
72     l1.setLabel("l1");
73     LevelImpl l2 = new LevelImpl();
74     l2.setLabel("l2");
75     LevelImpl l3 = new LevelImpl();
76     l3.setLabel("l3");
77
78     HierarchyImpl h1 = new HierarchyImpl();
79     h1.setLabel("h1");
80     HierarchyImpl h2 = new HierarchyImpl();
81     h2.setLabel("h2");
82     l1.setHierarchy(h1);
83     l2.setHierarchy(h1);
84     l3.setHierarchy(h2);
85
86     vp.add(new MemberPropertyMeta("1label", "a", scope(l1)));
87     vp.add(new MemberPropertyMeta("2label", "b", scope(l2)));
88     vp.add(new MemberPropertyMeta("3label", "c", scope(l3)));
89
90     ScopedPropertyMetaSet vpl = new ScopedPropertyMetaSet(null);
91     vpl.addAll(vp);
92     assertEquals(3, vpl.metaList(allFilter).size());
93     vp.add(new MemberPropertyMeta("1label", "a", scope(l1)));
94     assertEquals(3, vpl.metaList(allFilter).size());
95     vp.add(new MemberPropertyMeta("1label", "a", scope(l2)));
96     assertEquals(3, vpl.metaList(allFilter).size());
97
98     assertEquals(scope(l1), scope(l1));
99     assertEquals(scope(l1), scope(l2));
100     assertNotSame(scope(l1), scope(l3));
101     assertEquals(scope(l2), scope(l2));
102     assertNotSame(scope(l2), scope(l3));
103     assertEquals(scope(l3), scope(l3));
104
105     assertTrue(vpl.contains(new MemberPropertyMeta(null, "a", scope(l1))));
106     assertTrue(vpl.contains(new MemberPropertyMeta(null, "a", scope(l2))));
107     assertFalse(vpl.contains(new MemberPropertyMeta(null, "a", scope(l3))));
108
109     assertTrue(vpl.contains(new MemberPropertyMeta(null, "b", scope(l1))));
110     assertTrue(vpl.contains(new MemberPropertyMeta(null, "b", scope(l2))));
111     assertFalse(vpl.contains(new MemberPropertyMeta(null, "b", scope(l3))));
112
113     assertFalse(vpl.contains(new MemberPropertyMeta(null, "c", scope(l1))));
114     assertFalse(vpl.contains(new MemberPropertyMeta(null, "c", scope(l2))));
115     assertTrue(vpl.contains(new MemberPropertyMeta(null, "c", scope(l3))));
116
117     assertFalse(vpl.contains(new MemberPropertyMeta(null, "d", scope(l1))));
118     assertFalse(vpl.contains(new MemberPropertyMeta(null, "d", scope(l2))));
119     assertFalse(vpl.contains(new MemberPropertyMeta(null, "d", scope(l3))));
120
121     String JavaDoc[] allNames = vpl.getAllNames();
122     assertEquals(3, allNames.length);
123     assertEquals("a", allNames[0]);
124     assertEquals("b", allNames[1]);
125     assertEquals("c", allNames[2]);
126
127     Set JavaDoc scopes = new HashSet JavaDoc();
128     scopes.add(scope(l1));
129     MemberPropertyMetaFilter filter = vpl.createScopesFilter(scopes);
130     ScopedPropertyMetaSet sub = vpl.metaSet(filter);
131     assertEquals(2, sub.metaList(allFilter).size());
132     assertTrue(sub.contains(new MemberPropertyMeta(null, "a", scope(l1))));
133     assertTrue(sub.contains(new MemberPropertyMeta(null, "b", scope(l2))));
134     assertFalse(sub.contains(new MemberPropertyMeta(null, "c", scope(l3))));
135
136     scopes.clear();
137     scopes.add(scope(l2));
138     filter = vpl.createScopesFilter(scopes);
139     sub = vpl.metaSet(filter);
140     assertEquals(2, sub.metaList(allFilter).size());
141     assertTrue(sub.contains(new MemberPropertyMeta(null, "a", scope(l1))));
142     assertTrue(sub.contains(new MemberPropertyMeta(null, "b", scope(l2))));
143     assertFalse(sub.contains(new MemberPropertyMeta(null, "c", scope(l3))));
144
145     scopes.clear();
146     scopes.add(scope(l3));
147     filter = vpl.createScopesFilter(scopes);
148     sub = vpl.metaSet(filter);
149     assertEquals(1, sub.metaList(allFilter).size());
150     assertFalse(sub.contains(new MemberPropertyMeta(null, "a", scope(l1))));
151     assertFalse(sub.contains(new MemberPropertyMeta(null, "b", scope(l2))));
152     assertTrue(sub.contains(new MemberPropertyMeta(null, "c", scope(l3))));
153
154     vpl.remove(new MemberPropertyMeta(null, "a", scope(l3)));
155     assertEquals(3, vpl.metaList(allFilter).size());
156     vpl.remove(new MemberPropertyMeta(null, "a", scope(l1)));
157     assertEquals(2, vpl.metaList(allFilter).size());
158
159   }
160
161
162   public void testIntersectList() {
163     extension.setLevelScope(true);
164     LevelImpl level = new LevelImpl();
165     level.setLabel("level");
166     List JavaDoc abc = new ArrayList JavaDoc();
167     abc.add(new MemberPropertyMeta("1label", "a", scope(level)));
168     abc.add(new MemberPropertyMeta("2label", "b", scope(level)));
169     abc.add(new MemberPropertyMeta("4label", "c", scope(level)));
170
171     List JavaDoc abd = new ArrayList JavaDoc();
172     abd.add(new MemberPropertyMeta("1label", "a", scope(level)));
173     abd.add(new MemberPropertyMeta("2label", "b", scope(level)));
174     abd.add(new MemberPropertyMeta("4label", "d", scope(level)));
175
176     ScopedPropertyMetaSet set = new ScopedPropertyMetaSet(extension);
177     set.addAll(abc);
178     List JavaDoc ab = set.intersectList(abd);
179     assertEquals(2, ab.size());
180   }
181
182   public void testAddMember() {
183     MemberImpl m = new MemberImpl();
184     m.addProperty(new PropertyImpl("a", "av"));
185     m.addProperty(new PropertyImpl("b", "bv"));
186     LevelImpl l = new LevelImpl();
187     l.setLabel("l");
188     m.setLevel(l);
189     HierarchyImpl h = new HierarchyImpl();
190     h.setLabel("h");
191     l.setHierarchy(h);
192
193     extension.setLevelScope(true);
194     ScopedPropertyMetaSet set = new ScopedPropertyMetaSet(extension);
195     set.addMember(m);
196     assertTrue(set.contains(new MemberPropertyMeta("a", "a", "l")));
197
198     extension.setLevelScope(false);
199     set = new ScopedPropertyMetaSet(extension);
200     set.addMember(m);
201     assertTrue(set.contains(new MemberPropertyMeta("a", "a", "h")));
202   }
203
204   public ScopedPropertyMetaSetTest(String JavaDoc arg0) {
205     super(arg0);
206   }
207
208   protected void setUp() throws Exception JavaDoc {
209     extension = new TestMemberProperties();
210   }
211
212 }
213
Popular Tags