DataProviderCompiler { public String compile(final DataProvider dataProvider, final String template) { final InputStream templateStream = this.getClass().getResourceAsStream(template); return compile(dataProvider, templateStream); }  String compile(final DataProvider dataProvider,
                          final String template); String compile(final DataProvider dataProvider,
                          final InputStream templateStream); String compile(final DataProvider dataProvider,
                          final TemplateDataListener listener); String compile(final DataProvider dataProvider,
                          final String template,
                          boolean replaceOptionals); String compile(final DataProvider dataProvider,
                          final InputStream templateStream,
                          boolean replaceOptionals); String compile(final DataProvider dataProvider,
                          final TemplateDataListener listener,
                          boolean replaceOptionals); void newCell(List<DataListener> listeners,
                        int row,
                        int column,
                        String value,
                        int mergedColStart);  }
@Test public void testCompiler() throws Exception { TestDataProvider tdp = new TestDataProvider(rows); final DataProviderCompiler converter = new DataProviderCompiler(); final String drl = converter.compile(tdp, "/templates/rule_template_1.drl"); Assertions.assertThat(EXPECTED_RULES.toString()).isEqualToIgnoringWhitespace(drl); }
@Test public void testCompileIndentedKeywords() throws Exception { TestDataProvider tdp = new TestDataProvider( rows ); final DataProviderCompiler converter = new DataProviderCompiler(); final String drl = converter.compile( tdp, "/templates/rule_template_indented.drl" ); Assertions.assertThat(EXPECTED_RULES.toString()).isEqualToIgnoringWhitespace(drl); }
@Test public void testCompilerMaps() throws Exception { Collection<Map<String, Object>> maps = new ArrayList<Map<String, Object>>(); final ObjectDataCompiler converter = new ObjectDataCompiler(); InputStream templateStream = this.getClass().getResourceAsStream("/templates/rule_template_1.drl"); TemplateContainer tc = new DefaultTemplateContainer(templateStream); Column[] columns = tc.getColumns(); for (String[] row : rows) { Map<String, Object> map = new HashMap<String, Object>(); for (int icol = 0; icol < columns.length; icol++) { Object value = row[icol]; if (value != null) { map.put(columns[icol].getName(), value); } } maps.add(map); } templateStream = this.getClass().getResourceAsStream("/templates/rule_template_1.drl"); final String drl = converter.compile(maps, templateStream); Assertions.assertThat(EXPECTED_RULES.toString()).isEqualToIgnoringWhitespace(drl); }
@Test public void testCompilerObjs() throws Exception { Collection<Object> objs = new ArrayList<Object>(); final ObjectDataCompiler converter = new ObjectDataCompiler(); final InputStream templateStream = this.getClass().getResourceAsStream("/templates/rule_template_1.drl"); for (String[] row : rows) { OBJ obj = new OBJ(row); objs.add(obj); } final String drl = converter.compile(objs, templateStream); Assertions.assertThat(EXPECTED_RULES.toString()).isEqualToIgnoringWhitespace(drl); }