Beispiel #1
0
  @Test
  public void testParseFileWithEscaptedBrackets() {
    String file = "[when][]ATTRIBUTE \"{attr}\" IS IN \\[{list}\\]=Attribute( {attr} in ({list}) )";
    try {
      final Reader reader = new StringReader(file);
      this.file = new DSLTokenizedMappingFile();

      final boolean parsingResult = this.file.parseAndLoad(reader);
      reader.close();

      assertTrue(this.file.getErrors().toString(), parsingResult);
      assertTrue(this.file.getErrors().isEmpty());

      assertEquals(1, this.file.getMapping().getEntries().size());

      DSLMappingEntry entry = (DSLMappingEntry) this.file.getMapping().getEntries().get(0);

      assertEquals(DSLMappingEntry.CONDITION, entry.getSection());
      assertEquals(DSLMappingEntry.EMPTY_METADATA, entry.getMetaData());
      assertEquals("ATTRIBUTE \"{attr}\" IS IN \\[{list}\\]", entry.getMappingKey());
      assertEquals("Attribute( {attr} in ({list}) )", entry.getMappingValue());

    } catch (final IOException e) {
      e.printStackTrace();
      fail("Should not raise exception ");
    }
  }
Beispiel #2
0
  @Test
  @Ignore
  public void testParseFileWithEscaptedEquals() {
    String file = "[when][]something:\\={value}=Attribute( something == \"{value}\" )";
    try {
      final Reader reader = new StringReader(file);
      this.file = new DSLTokenizedMappingFile();

      final boolean parsingResult = this.file.parseAndLoad(reader);
      reader.close();

      assertTrue(this.file.getErrors().toString(), parsingResult);
      assertTrue(this.file.getErrors().isEmpty());

      assertEquals(1, this.file.getMapping().getEntries().size());

      DSLMappingEntry entry = (DSLMappingEntry) this.file.getMapping().getEntries().get(0);

      assertEquals(DSLMappingEntry.CONDITION, entry.getSection());
      assertEquals(DSLMappingEntry.EMPTY_METADATA, entry.getMetaData());
      assertEquals("something:={value}", entry.getMappingKey());
      assertEquals("Attribute( something == \"{value}\" )", entry.getMappingValue());

    } catch (final IOException e) {
      e.printStackTrace();
      fail("Should not raise exception ");
    }
  }
Beispiel #3
0
  @Test
  public void testEnum() {
    String file =
        "[when][]ATTRIBUTE {attr:ENUM:Attribute.value} in {list}=Attribute( {attr} in ({list}) )";
    try {
      final Reader reader = new StringReader(file);
      this.file = new DSLTokenizedMappingFile();

      final boolean parsingResult = this.file.parseAndLoad(reader);
      reader.close();

      assertTrue(this.file.getErrors().toString(), parsingResult);
      assertTrue(this.file.getErrors().isEmpty());

      assertEquals(1, this.file.getMapping().getEntries().size());

      DSLMappingEntry entry = (DSLMappingEntry) this.file.getMapping().getEntries().get(0);

      assertEquals(DSLMappingEntry.CONDITION, entry.getSection());
      assertEquals(DSLMappingEntry.EMPTY_METADATA, entry.getMetaData());
      System.out.println(entry.getValuePattern());
      System.out.println(entry.getVariables());
      assertEquals("ATTRIBUTE {attr:ENUM:Attribute.value} in {list}", entry.getMappingKey());
      assertEquals("Attribute( {attr} in ({list}) )", entry.getMappingValue());

      assertEquals(
          "(?:(?<=^)|(?<=\\W))ATTRIBUTE\\s+(.*?)\\s+in\\s+(.*?)$",
          entry.getKeyPattern().toString());

    } catch (final IOException e) {
      e.printStackTrace();
      fail("Should not raise exception ");
    }
  }
Beispiel #4
0
 public void buildTree(DSLMapping mapping) {
   for (DSLMappingEntry entry : mapping.getEntries()) {
     Section section = entry.getSection();
     String nl = entry.getMappingKey();
     String objname = entry.getMetaData().getMetaData();
     addEntry(section, nl, objname);
   }
 }
Beispiel #5
0
  @Test
  public void testParseFileWithEscaptedCurlyBrackets() {
    String file =
        "[consequence][$policy]Add surcharge {surcharge} to Policy=modify(policy) \\{price = {surcharge}\\}";
    try {
      final Reader reader = new StringReader(file);
      this.file = new DSLTokenizedMappingFile();

      final boolean parsingResult = this.file.parseAndLoad(reader);
      reader.close();

      assertTrue(this.file.getErrors().toString(), parsingResult);
      assertTrue(this.file.getErrors().isEmpty());

      assertEquals(1, this.file.getMapping().getEntries().size());

      DSLMappingEntry entry = (DSLMappingEntry) this.file.getMapping().getEntries().get(0);

      assertEquals(DSLMappingEntry.CONSEQUENCE, entry.getSection());
      assertEquals("$policy", entry.getMetaData().toString());
      assertEquals("Add surcharge {surcharge} to Policy", entry.getMappingKey());
      assertEquals("modify(policy) \\{price = {surcharge}\\}", entry.getMappingValue());

      String input =
          "rule x"
              + NL
              + "when"
              + NL
              + "then"
              + NL
              + "Add surcharge 300 to Policy"
              + NL
              + "end"
              + NL
              + "";
      String expected =
          "rule x"
              + NL
              + "when"
              + NL
              + "then"
              + NL
              + "modify(policy) {price = 300}"
              + NL
              + "end"
              + NL
              + "";

      DefaultExpander de = new DefaultExpander();
      de.addDSLMapping(this.file.getMapping());

      final String result = de.expand(input);

      //            String result = entry.getKeyPattern().matcher( input ).replaceAll(
      // entry.getValuePattern() );

      assertEquals(expected, result);

    } catch (final IOException e) {
      e.printStackTrace();
      fail("Should not raise exception ");
    }
  }