GuidedDecisionTableSourceService extends BaseSourceService<GuidedDecisionTable52> { @Override public String getSource(final Path path, final GuidedDecisionTable52 model) throws SourceGenerationFailedException { try { final String dslr = GuidedDTDRLPersistence.getInstance().marshal(model); final Expander expander = getDSLExpander(path); final String drl = expander.expand(dslr); return drl; } catch (Exception e) { throw new SourceGenerationFailedException(e.getMessage()); } } @Inject  GuidedDecisionTableSourceService(final GuidedDTableResourceTypeDefinition resourceType,
                                            final GuidedDecisionTableEditorService guidedDecisionTableEditorService,
                                            final @Named("ioStrategy") IOService ioService,
                                            final FileDiscoveryService fileDiscoveryService,
                                            final KieModuleService moduleService); @Override String getPattern(); @Override String getSource(final Path path,
                            final GuidedDecisionTable52 model); @Override String getSource(final Path path);  }
@Test public void testOtherwise() throws Exception { addRow(1, "John", false); addRow(2, "Peter", false); addRow(3, null, true); model.setData(data); String source = service.getSource(path, model); assertTrue("Expected: name == \"John\"", source.contains("$p : Person( name == \"John\" )")); assertTrue("Expected: name == \"Peter\"", source.contains("$p : Person( name == \"Peter\" )")); assertTrue("Expected: name not in ( \"John\", \"Peter\" )", source.contains("$p : Person( name not in ( \"John\", \"Peter\" )")); }
@Test public void testOtherwiseTwoSameValues() throws Exception { addRow(1, "John", false); addRow(2, "John", false); addRow(3, null, true); model.setData(data); String source = service.getSource(path, model); assertTrue("Expected: name not in ( \"John\" )", source.contains("$p : Person( name not in ( \"John\" )")); }
@Test public void testOtherwiseEmptyValue() throws Exception { addRow(1, "John", false); addRow(2, "", false); addRow(3, null, true); model.setData(data); String source = service.getSource(path, model); assertTrue("Expected: name not in ( \"John\", \"\" )", source.contains("$p : Person( name not in ( \"John\", \"\" )")); }
@Test public void testOtherwiseEmptyAndNullValue() throws Exception { addRow(1, "", false); addRow(2, null, false); addRow(3, null, true); model.setData(data); String source = service.getSource(path, model); assertTrue("Expected: name not in ( \"\" )", source.contains("$p : Person( name not in ( \"\" )")); }
@Test public void testOtherwiseTwoTimes() throws Exception { addRow(1, "John", false); addRow(2, null, true); addRow(3, "Peter", false); addRow(4, null, true); model.setData(data); String source = service.getSource(path, model); assertTrue("Expected: name not in ( \"John\", \"Peter\" )", source.contains("$p : Person( name not in ( \"John\", \"Peter\" )")); source.replaceFirst("John", ""); assertTrue("Expected: name not in ( \"John\", \"Peter\" )", source.contains("$p : Person( name not in ( \"John\", \"Peter\" )")); }
@Test public void testCustomRuleName() throws Exception { adRowWithCustomRuleName(1, "John is important", "John"); model.setData(data); String source = service.getSource(path, model); assertTrue("Expected custom rule name to be present", source.contains("rule \"John is important\"\n")); }
@Test public void testFormulaFieldBinding() throws Exception { final ConditionCol52 ageEqualToFormulaCondition = new ConditionCol52(); ageEqualToFormulaCondition.setConstraintValueType(BaseSingleFieldConstraint.TYPE_RET_VALUE); ageEqualToFormulaCondition.setHeader("age equals to"); ageEqualToFormulaCondition.setFactField("age"); ageEqualToFormulaCondition.setOperator("=="); ageEqualToFormulaCondition.setBinding("$age"); pattern.setChildColumns(Arrays.asList(ageEqualToFormulaCondition)); model.setConditionPatterns(Arrays.asList(pattern)); addRow(1, "1 + 1"); model.setData(data); final String source = service.getSource(path, model); assertTrue(source.contains("$p : Person( $age : age == ( 1 + 1 ) )")); }