1 package com.tonbeller.jpivot.olap.model.impl; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import junit.framework.TestCase; 7 8 import com.tonbeller.jpivot.olap.model.Expression; 9 import com.tonbeller.jpivot.olap.model.ExpressionPrinter; 10 import com.tonbeller.jpivot.olap.model.Hierarchy; 11 import com.tonbeller.jpivot.olap.model.Level; 12 13 16 public class ExpressionPrinterTest extends TestCase { 17 18 MemberImpl m1; 19 MemberImpl m2; 20 LevelImpl level; 21 HierarchyImpl hier; 22 DimensionImpl dim; 23 24 public ExpressionPrinterTest(String arg0) { 25 super(arg0); 26 } 27 28 public void testCall() { 29 List args = new ArrayList (); 30 args.add(m1); 31 args.add(level); 32 args.add(hier); 33 args.add(dim); 34 FunCallExprImpl f = new FunCallExprImpl(); 35 f.setArgs(args); 36 f.setName("call"); 37 assertEquals("call([Member 1], [Level 1], [Hierarchy 1], [Dimension 1])", print(f)); 39 } 40 41 public void testProper() { 42 List args = new ArrayList (); 43 args.add(level); 44 FunCallExprImpl f = new FunCallExprImpl(); 45 f.setArgs(args); 46 f.setName(".members"); 47 assertEquals("[Level 1].members", print(f)); 48 } 49 50 public void testTupel() { 51 List args = new ArrayList (); 52 args.add(m1); 53 args.add(m2); 54 FunCallExprImpl f = new FunCallExprImpl(); 55 f.setArgs(args); 56 f.setName("()"); 57 assertEquals("([Member 1], [Member 2])", print(f)); 58 } 59 60 public void testSet() { 61 List args = new ArrayList (); 62 args.add(m1); 63 args.add(m2); 64 FunCallExprImpl f = new FunCallExprImpl(); 65 f.setArgs(args); 66 f.setName("{}"); 67 assertEquals("{[Member 1], [Member 2]}", print(f)); 68 } 69 70 public void testParam() { 71 ParameterExprImpl parm = new ParameterExprImpl(); 72 parm.setName("my name"); 73 parm.setLabel("my label"); 74 parm.setType(0); 75 parm.setValue(m1); 76 assertEquals("Parameter(\"RandomID\", STRING, \"my label\", [Member 1])", print(parm)); 78 } 79 80 private String print(Expression f) { 81 ExpressionPrinter ep = new ExpressionPrinter(); 82 f.accept(ep); 83 return ep.toString(); 84 } 85 86 protected void setUp() throws Exception { 87 m1 = new MemberImpl(); 88 m1.setLabel("Member 1"); 89 m2 = new MemberImpl(); 90 m2.setLabel("Member 2"); 91 level = new LevelImpl(); 92 level.setLabel("Level 1"); 93 m1.setLevel(level); 94 m2.setLevel(level); 95 hier = new HierarchyImpl(); 96 level.setHierarchy(hier); 97 hier.setLabel("Hierarchy 1"); 98 hier.setLevels(new Level[]{level}); 99 dim =new DimensionImpl(); 100 dim.setLabel("Dimension 1"); 101 dim.setHierarchies(new Hierarchy[]{hier}); 102 hier.setDimension(dim); 103 } 104 105 } 106 | Popular Tags |