1 package com.tonbeller.jpivot.param; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.List ; 6 7 import javax.sql.DataSource ; 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 21 public class ClickableMemberTest extends TestCase { 22 23 class TestSqlAccess extends ExtensionSupport implements SqlAccess { 24 public DataSource getDataSource() { 25 return null; 26 } 27 public SessionParam createParameter(Member m, String 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 paramName, String 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 c = new ArrayList (); 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 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 |