Exemplo n.º 1
0
 /** Column headers must be valid. */
 @Test
 public void testBadColumnHeader() {
   try {
     makeRuleSet();
     makeRuleTable();
     makeRow(11, "Condition", "CONDITION", "A", "SMURF", "P");
     listener.finishSheet();
     fail("should have failed");
   } catch (DecisionTableParseException e) {
     String badCell = RuleSheetParserUtil.rc2name(11, 4);
     System.err.println(e.getMessage());
     assertTrue(e.getMessage().contains(badCell));
   }
 }
Exemplo n.º 2
0
 /** Duplications of several columns are not permitted : PRIORITY/P. */
 @Test
 public void testTooManyColumnsPriority() {
   try {
     makeRuleSet();
     makeRuleTable();
     makeRow(11, "C", "C", "A", "PRIORITY", "P");
     listener.finishSheet();
     fail("should have failed");
   } catch (DecisionTableParseException e) {
     String badCell = RuleSheetParserUtil.rc2name(11, 5);
     System.err.println(e.getMessage());
     assertTrue(e.getMessage().contains(badCell));
   }
 }
Exemplo n.º 3
0
 /** Must have a type for pattern below a condition, not a snippet. */
 @Test
 public void testMissingCondition() {
   try {
     makeRuleSet();
     makeRuleTable();
     makeRow(11, "C", "C", "C", "A", "A");
     makeRow(12, "attr == $param", "attr == $param", "attr == $param", "action();", "action();");
     listener.finishSheet();
     fail("should have failed");
   } catch (DecisionTableParseException e) {
     String badCell = RuleSheetParserUtil.rc2name(12, 1);
     System.err.println(e.getMessage());
     assertTrue(e.getMessage().contains(badCell));
   }
 }
Exemplo n.º 4
0
 /** Must not have snippet for attribute */
 @Test
 public void testSnippetForAttribute() {
   try {
     makeRuleSet();
     makeRuleTable();
     makeRow(11, "C", "A", "G");
     makeRow(12, "Foo", "Foo");
     makeRow(13, "attr == $param", "x", "XXX");
     makeRow(15, "1", "show()", "10");
     listener.finishSheet();
     fail("should have failed");
   } catch (DecisionTableParseException e) {
     String badCell = RuleSheetParserUtil.rc2name(13, 3);
     System.err.println(e.getMessage());
     assertTrue(e.getMessage().contains(badCell));
   }
 }
Exemplo n.º 5
0
 /** Spurious code snippet. */
 @Test
 public void testSpuriousCodeSnippet() {
   try {
     makeRuleSet();
     makeRuleTable();
     makeRow(11, "C", "C", "A");
     makeRow(12, "Foo", "Foo");
     makeRow(13, "attr == $param", "attr == $param", "action();", "attr > $param");
     makeRow(15, "1", "2", "");
     listener.finishSheet();
     fail("should have failed");
   } catch (DecisionTableParseException e) {
     String badCell = RuleSheetParserUtil.rc2name(13, 4);
     System.err.println(e.getMessage());
     assertTrue(e.getMessage().contains(badCell));
   }
 }
  @Override
  public void addTemplate(final int row, final int column, final String content) {
    // Validate column template
    if (valueBuilders.containsKey(column)) {
      final String message =
          "Internal error: Can't have a code snippet added twice to one spreadsheet column.";
      this.conversionResult.addMessage(message, ConversionMessageType.ERROR);
      return;
    }

    // Add new template
    final String template = content.trim();
    try {
      this.valueBuilders.put(column, getValueBuilder(template));
    } catch (DecisionTableParseException pe) {
      this.conversionResult.addMessage(pe.getMessage(), ConversionMessageType.WARNING);
    }
  }
Exemplo n.º 7
0
 /** Must have a code snippet in an action. */
 @Test
 public void testMissingCodeSnippetAction() {
   try {
     makeRuleSet();
     makeRuleTable();
     makeRow(11, "C", "A");
     makeRow(12, "foo: Foo", "Bar()");
     makeRow(13, "attr == $param");
     makeRow(15, "1", "1");
     makeRow(16, "2", "2");
     listener.finishSheet();
     Package p = listener.getRuleSet();
     DRLOutput dout = new DRLOutput();
     p.renderDRL(dout);
     String drl = dout.getDRL();
     System.out.println(drl);
     fail("should have failed");
   } catch (DecisionTableParseException e) {
     String badCell = RuleSheetParserUtil.rc2name(13, 2);
     System.err.println(e.getMessage());
     assertTrue(e.getMessage().contains(badCell));
   }
 }
Exemplo n.º 8
0
 /** Duplicate package level attribute */
 @Test
 public void testDuplicatePackageAttribute() {
   try {
     makeRuleSet();
     makeAttribute("agenda-group", "agroup"); // B3, C3
     makeAttribute("agenda-group", "bgroup"); // B3. B4
     makeRuleTable();
     makeRow(11, "C", "A", "P");
     makeRow(12, "Foo", "Foo");
     makeRow(13, "attr == $param", "x");
     makeRow(15, "1", "show()", "10");
     listener.finishSheet();
     Package p = listener.getRuleSet();
     DRLOutput dout = new DRLOutput();
     p.renderDRL(dout);
     String drl = dout.getDRL();
     // System.out.println( drl );
     fail("should have failed");
   } catch (DecisionTableParseException e) {
     System.err.println(e.getMessage());
     assertTrue(e.getMessage().contains("C3, C4"));
   }
 }