|
9 | 9 | import java.io.FileReader;
|
10 | 10 | import java.util.*;
|
11 | 11 |
|
| 12 | +import static org.hamcrest.CoreMatchers.containsString; |
12 | 13 | import static org.junit.Assert.*;
|
13 | 14 |
|
14 | 15 |
|
@@ -525,15 +526,42 @@ public void test017_nonMachingList() throws GrokException {
|
525 | 526 | @Test
|
526 | 527 | public void test021_postfix_patterns() throws Throwable {
|
527 | 528 | final Grok grok = Grok.create("patterns/postfix");
|
| 529 | + grok.addPatternFromFile("patterns/patterns"); |
528 | 530 | grok.compile("%{POSTFIX_SMTPD}", false);
|
529 | 531 |
|
530 | 532 | assertTrue(grok.getPatterns().containsKey("POSTFIX_SMTPD"));
|
531 | 533 | }
|
532 | 534 | @Test
|
533 | 535 | public void test022_postfix_patterns_with_named_captures_only() throws Throwable {
|
534 | 536 | final Grok grok = Grok.create("patterns/postfix");
|
| 537 | + grok.addPatternFromFile("patterns/patterns"); |
535 | 538 | grok.compile("%{POSTFIX_SMTPD}", true);
|
536 | 539 |
|
537 | 540 | assertTrue(grok.getPatterns().containsKey("POSTFIX_SMTPD"));
|
538 | 541 | }
|
| 542 | + |
| 543 | + @Test |
| 544 | + public void test023_named_captures_with_missing_definition() throws Throwable { |
| 545 | + |
| 546 | + ensureAbortsWithDefinitionMissing("FOO %{BAR}", "%{FOO}", true); |
| 547 | + } |
| 548 | + @Test |
| 549 | + public void test024_named_captures_with_missing_definition() throws Throwable { |
| 550 | + ensureAbortsWithDefinitionMissing("FOO %{BAR}", "%{FOO:name}", false); |
| 551 | + |
| 552 | + } |
| 553 | + @Test |
| 554 | + public void test025_captures_with_missing_definition() throws Throwable { |
| 555 | + ensureAbortsWithDefinitionMissing("FOO %{BAR}", "%{FOO}", false); |
| 556 | + } |
| 557 | + |
| 558 | + private void ensureAbortsWithDefinitionMissing(String pattern, String compilePattern, boolean namedOnly) { |
| 559 | + try { |
| 560 | + final Grok grok = Grok.create(ResourceManager.PATTERNS, pattern); |
| 561 | + grok.compile(compilePattern, namedOnly); |
| 562 | + fail("should abort due to missing definition"); |
| 563 | + } catch (GrokException e) { |
| 564 | + assertThat(e.getMessage(), containsString("No definition for key")); |
| 565 | + } |
| 566 | + } |
539 | 567 | }
|
0 commit comments