KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > param > ClickableMemberTest


1 package com.tonbeller.jpivot.param;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.List JavaDoc;
6
7 import javax.sql.DataSource JavaDoc;
8
9 import junit.framework.TestCase;
10
11 import com.tonbeller.jpivot.core.ExtensionSupport;
12 import com.tonbeller.jpivot.olap.model.Member;
13 import com.tonbeller.jpivot.olap.model.Property;
14 import com.tonbeller.jpivot.olap.model.impl.MemberImpl;
15 import com.tonbeller.jpivot.olap.model.impl.PropertyImpl;
16 import com.tonbeller.wcf.param.SessionParam;
17
18 /**
19  * @author av
20  */

21 public class ClickableMemberTest extends TestCase {
22
23   class TestSqlAccess extends ExtensionSupport implements SqlAccess {
24     public DataSource JavaDoc getDataSource() {
25       return null;
26     }
27     public SessionParam createParameter(Member m, String JavaDoc paramName) {
28       SessionParam p = new SessionParam();
29       p.setName(paramName);
30       p.setSqlValue(paramName);
31       return p;
32     }
33
34     public SessionParam createParameter(Member m, String JavaDoc paramName, String JavaDoc propertyName) {
35       SessionParam p = new SessionParam();
36       p.setName(paramName);
37       p.setSqlValue(propertyName);
38       return p;
39     }
40   }
41   public void testMemberInstance() {
42
43     MemberImpl m = new MemberImpl();
44     Property[] props = new Property[5];
45     for (int i = 0; i < props.length; i++) {
46       PropertyImpl pi = new PropertyImpl("prefix" + i, "value" + i);
47       props[i] = pi;
48     }
49     m.setProperties(props);
50     SqlAccess sa = new TestSqlAccess();
51
52     List JavaDoc c = new ArrayList JavaDoc();
53     AbstractParamProvider pp = new MemberParamProvider("param1");
54     pp.addMemberParams(c, sa, null);
55     assertEquals(1, c.size());
56     SessionParam sp = (SessionParam)c.iterator().next();
57     assertEquals("param1", sp.getName());
58     assertEquals("param1", sp.getSqlValue());
59
60     c.clear();
61     pp = new PropertyParamProvider("param2", "prop2");
62     pp.addMemberParams(c, sa, null);
63     assertEquals(1, c.size());
64     sp = (SessionParam)c.iterator().next();
65     assertEquals("param2", sp.getName());
66     assertEquals("prop2", sp.getSqlValue());
67
68     c.clear();
69     pp = new PropertyPrefixParamProvider("prefix");
70     pp.addMemberParams(c, sa, m);
71     assertEquals(props.length, c.size());
72     Iterator JavaDoc it = c.iterator();
73     sp = (SessionParam)it.next();
74     assertEquals("0", sp.getName());
75     assertEquals("prefix0", sp.getSqlValue());
76     sp = (SessionParam)it.next();
77     assertEquals("1", sp.getName());
78     assertEquals("prefix1", sp.getSqlValue());
79     
80   }
81 }
82
Popular Tags