1 23 24 package org.objectweb.medor.optim.jorm; 25 26 import org.objectweb.medor.api.MedorException; 27 import org.objectweb.medor.filter.jorm.lib.SinglePName; 28 import org.objectweb.medor.filter.lib.BasicFieldOperand; 29 import org.objectweb.medor.expression.lib.BasicParameterOperand; 30 import org.objectweb.medor.query.TestQueryTreeHelper; 31 import org.objectweb.medor.query.api.QueryLeaf; 32 import org.objectweb.medor.query.api.QueryTreeField; 33 import org.objectweb.medor.query.lib.QueryTreePrinter; 34 import org.objectweb.medor.query.lib.SelectProject; 35 import org.objectweb.medor.type.lib.PTypeSpaceMedor; 36 import org.objectweb.util.monolog.api.BasicLevel; 37 38 import java.util.Collection ; 39 40 43 public abstract class TestJormLeafRewriter extends TestJormPDHelper { 44 45 public TestJormLeafRewriter(String testName, String loggerName) { 46 super(testName, loggerName); 47 } 48 49 protected abstract QueryLeaf getQueryLeaf_A() throws MedorException; 50 51 protected abstract QueryLeaf getQueryLeaf_One() throws MedorException; 52 53 public Example getExtent(Collection fileNames, 54 String className, 55 String pnameFieldName, 56 String [] fieldNames) { 57 Example e = super.getExtent(fileNames, className, pnameFieldName, fieldNames); 58 e.extent.setPMapper(mapper, PROJECT_NAME); 59 return e; 60 } 61 62 public void testA() { 63 checkRewrittenA(getRewrittenA()); 64 } 65 66 public void testOne() { 67 checkRewrittenOne(getRewrittenOne()); 68 } 69 70 public void testB() { 71 checkRewrittenB(getRewrittenB()); 72 } 73 74 public void testC() { 75 checkRewrittenC(getRewrittenC()); 76 } 77 78 public void testD() { 79 checkRewrittenD(getRewrittenD()); 80 } 81 82 public void checkRewrittenA(Example e) { 83 try { 84 String prefix = e.clazz.getFQName() + "."; 85 QueryLeaf ql = getQueryLeaf_A(); 86 QueryTreeField id = (QueryTreeField) 87 ql.getTupleStructure().getField(prefix + "id"); 88 QueryTreeField f1 = (QueryTreeField) 89 ql.getTupleStructure().getField(prefix + "field1"); 90 QueryTreeField f2 = (QueryTreeField) 91 ql.getTupleStructure().getField(prefix + "field2"); 92 93 SelectProject expected = new SelectProject(""); 94 SinglePName spn = new SinglePName( 95 new BasicFieldOperand(id), 96 new BasicParameterOperand( 97 PTypeSpaceMedor.NAMING_CONTEXT, prefix + "object"), 98 e.extent.getField(prefix + "object").getType()); 99 expected.addCalculatedField(prefix + "object", spn.getType(), spn); 100 expected.addPropagatedField( 101 prefix + "field1", f1.getType(), new QueryTreeField[]{f1}); 102 expected.addPropagatedField( 103 prefix + "field2", f2.getType(), new QueryTreeField[]{f2}); 104 105 logger.log(BasicLevel.DEBUG, "Expected QueryTree"); 106 QueryTreePrinter.printQueryTree(expected, logger); 107 108 TestQueryTreeHelper.equals("", expected, e.qt, logger); 109 } 110 catch (MedorException me) { 111 me.printStackTrace(); 112 fail(me.getMessage()); 113 } 114 } 115 116 public void checkRewrittenOne(Example e) { 117 try { 118 QueryLeaf ql = getQueryLeaf_One(); 119 String prefix = e.clazz.getFQName() + "."; 120 QueryTreeField id = (QueryTreeField) 121 ql.getTupleStructure().getField(prefix + "id"); 122 QueryTreeField f1 = (QueryTreeField) 123 ql.getTupleStructure().getField(prefix + "field1"); 124 QueryTreeField ida = (QueryTreeField) 125 ql.getTupleStructure().getField(prefix + "idA"); 126 127 SelectProject expected = new SelectProject(""); 128 SinglePName spn = new SinglePName( 129 new BasicFieldOperand(id), 130 new BasicParameterOperand( 131 PTypeSpaceMedor.NAMING_CONTEXT, prefix + "." + "object"), 132 e.extent.getField(prefix + "object").getType()); 133 expected.addCalculatedField(prefix + "object", spn.getType(), spn); 134 expected.addPropagatedField( 135 prefix + "field1", f1.getType(), new QueryTreeField[]{f1}); 136 String poName = prefix + "fieldA"; 137 spn = new SinglePName( 138 new BasicFieldOperand(id), 139 new BasicParameterOperand( 140 PTypeSpaceMedor.NAMING_CONTEXT, poName), 141 e.extent.getField(prefix + "fieldA").getType()); 142 expected.addCalculatedField(prefix + "fieldA", spn.getType(), spn); 143 144 logger.log(BasicLevel.DEBUG, "Expected QueryTree"); 145 QueryTreePrinter.printQueryTree(expected, logger); 146 147 TestQueryTreeHelper.equals("", expected, e.qt, logger); 148 } 149 catch (MedorException me) { 150 me.printStackTrace(); 151 fail(me.getMessage()); 152 } 153 } 154 155 public void checkRewrittenB(Example e) { 156 } 158 159 public void checkRewrittenC(Example e) { 160 } 162 163 public void checkRewrittenD(Example e) { 164 } 166 } 167 | Popular Tags |