Esempio n. 1
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 ");
    }
  }