1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.rat.configuration.builders;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertNotNull;
21
22 import java.io.StringReader;
23 import java.util.SortedSet;
24
25 import org.apache.rat.analysis.IHeaderMatcher;
26 import org.apache.rat.analysis.matchers.FullTextMatcher;
27 import org.apache.rat.analysis.matchers.NotMatcher;
28 import org.apache.rat.configuration.XMLConfigurationReader;
29 import org.apache.rat.license.ILicense;
30 import org.junit.jupiter.api.Test;
31
32 public class NotBuilderTest {
33
34 @Test
35 public void xmlTest() {
36 String configStr = "<rat-config>"
37 + " <families>"
38 + " <family id='newFam' name='my new family' />"
39 + " </families>"
40 + " <licenses>"
41 + " <license family='newFam' id='EXAMPLE' name='Example License'>"
42 + " <not>"
43 + " <text>The text to match</text>"
44 + " </not>"
45 + " </license>"
46 + " </licenses>"
47 + " </rat-config>";
48
49 XMLConfigurationReader reader = new XMLConfigurationReader();
50 reader.read(new StringReader(configStr));
51 SortedSet<ILicense> licenses = reader.readLicenses();
52 assertEquals(1, licenses.size());
53 IHeaderMatcher matcher = licenses.first().getMatcher();
54 assertEquals(NotMatcher.class, matcher.getClass());
55 NotMatcher result = (NotMatcher) matcher;
56 assertNotNull(result.getEnclosed());
57 assertEquals(FullTextMatcher.class, result.getEnclosed().getClass());
58 }
59
60 @Test
61 public void xmlIdTest() {
62 String configStr = "<rat-config>"
63 + " <families>"
64 + " <family id='newFam' name='my new family' />"
65 + " </families>"
66 + " <licenses>"
67 + " <license family='newFam' id='EXAMPLE' name='Example License'>"
68 + " <not id='foo'>"
69 + " <text>The text to match</text>"
70 + " </not>"
71 + " </license>"
72 + " </licenses>"
73 + " </rat-config>";
74
75 XMLConfigurationReader reader = new XMLConfigurationReader();
76 reader.read(new StringReader(configStr));
77 SortedSet<ILicense> licenses = reader.readLicenses();
78 assertEquals(1, licenses.size());
79 IHeaderMatcher matcher = licenses.first().getMatcher();
80 assertEquals("foo", matcher.getId());
81 assertEquals(NotMatcher.class, matcher.getClass());
82 NotMatcher result = (NotMatcher) matcher;
83 assertNotNull(result.getEnclosed());
84 assertEquals(FullTextMatcher.class, result.getEnclosed().getClass());
85 }
86 }