TemplateModel extends RuleModel { public InterpolationVariable[] getInterpolationVariablesList() { Map<InterpolationVariable, Integer> vars = getInterpolationVariables(); InterpolationVariable[] ret = new InterpolationVariable[vars.size() - 1]; for (Map.Entry<InterpolationVariable, Integer> entry : vars.entrySet()) { if (!ID_COLUMN_NAME.equals(entry.getKey().getVarName())) { ret[entry.getValue()] = entry.getKey(); } } return ret; }  String addRow(int index,
                         String[] row); String addRow(String[] row); void clearRows(); int getColsCount(); InterpolationVariable[] getInterpolationVariablesList(); int getRowsCount(); Map<String, List<String>> getTable(); String[][] getTableAsArray(); void putInSync(); void removeRow(int row); boolean removeRowById(String rowId); void setValue(String varName,
                         int rowIndex,
                         String newValue); void setIdCol(final int idCol); static final String ID_COLUMN_NAME; }
@Test public void sameFieldSameVariable() throws Exception { TemplateModel m = new TemplateModel(); m.name = "t1"; m.lhs = new IPattern[1]; FactPattern factPattern = new FactPattern(); m.lhs[0] = factPattern; factPattern.addConstraint(makeConstraint("Applicant", "age", "Integer", "$default", "==")); factPattern.addConstraint(makeConstraint("Applicant", "age", "Integer", "$default", "==")); assertEquals(1, m.getInterpolationVariablesList().length); assertEquals("Integer", m.getInterpolationVariablesList()[0].getDataType()); }
@Test public void sameVariableFroTwoDifferentTypes() throws Exception { TemplateModel m = new TemplateModel(); m.name = "t1"; m.lhs = new IPattern[1]; FactPattern factPattern = new FactPattern(); m.lhs[0] = factPattern; factPattern.addConstraint(makeConstraint("Applicant", "age", "Integer", "$default", "==")); factPattern.addConstraint(makeConstraint("Applicant", "name", "String", "$default", "==")); assertEquals(1, m.getInterpolationVariablesList().length); assertEquals(TemplateModel.DEFAULT_TYPE, m.getInterpolationVariablesList()[0].getDataType()); }
@Test public void sameVariableFroTwoDifferentOperatorsSameType() throws Exception { TemplateModel m = new TemplateModel(); m.name = "t1"; m.lhs = new IPattern[1]; FactPattern factPattern = new FactPattern(); m.lhs[0] = factPattern; factPattern.addConstraint(makeConstraint("Applicant", "age", "Integer", "$default", "==")); factPattern.addConstraint(makeConstraint("Applicant", "name", "Integer", "$default", "!=")); assertEquals(1, m.getInterpolationVariablesList().length); assertEquals(TemplateModel.DEFAULT_TYPE, m.getInterpolationVariablesList()[0].getDataType()); }
@Test public void sameVariableFroTwoDifferentOperatorsDifferentType() throws Exception { TemplateModel m = new TemplateModel(); m.name = "t1"; m.lhs = new IPattern[1]; FactPattern factPattern = new FactPattern(); m.lhs[0] = factPattern; factPattern.addConstraint(makeConstraint("Applicant", "age", "Integer", "$default", "==")); factPattern.addConstraint(makeConstraint("Applicant", "name", "String", "$default", "!=")); assertEquals(1, m.getInterpolationVariablesList().length); assertEquals(TemplateModel.DEFAULT_TYPE, m.getInterpolationVariablesList()[0].getDataType()); }
@Test public void separateVariableNames() throws Exception { TemplateModel m = new TemplateModel(); m.name = "t1"; m.lhs = new IPattern[1]; FactPattern factPattern = new FactPattern(); m.lhs[0] = factPattern; factPattern.addConstraint(makeConstraint("Applicant", "age", "Integer", "$default", "==")); factPattern.addConstraint(makeConstraint("Applicant", "name", "String", "$other", "==")); assertEquals(2, m.getInterpolationVariablesList().length); assertEquals("Integer", m.getInterpolationVariablesList()[0].getDataType()); assertEquals("String", m.getInterpolationVariablesList()[1].getDataType()); }