|
50 | 50 |
|
51 | 51 | import static org.junit.jupiter.api.Assertions.assertEquals; |
52 | 52 |
|
| 53 | +import org.junit.jupiter.api.Assertions; |
53 | 54 | import org.junit.jupiter.params.ParameterizedTest; |
54 | 55 | import org.junit.jupiter.params.provider.ValueSource; |
55 | 56 | import org.w3c.dom.NodeList; |
56 | 57 |
|
57 | | -public class FieldsSyntaxTests { |
| 58 | +public final class FieldsSyntaxTests { |
58 | 59 | @ParameterizedTest(name = "{index} command=''{0}''") |
59 | 60 | @ValueSource(strings = { |
60 | 61 | "fields", |
61 | 62 | "fields2", |
| 63 | + "fields_wildcard" |
62 | 64 | }) |
63 | | - public void fieldsSyntaxParseTest(String arg) throws Exception { |
64 | | - String fileName = "src/test/resources/antlr4/commands/fields/" + arg + ".txt"; |
65 | | - ParserSyntaxTestingUtility parserSyntaxTestingUtility |
| 65 | + void fieldsSyntaxParseTest(final String arg) throws Exception { |
| 66 | + final String fileName = "src/test/resources/antlr4/commands/fields/" + arg + ".txt"; |
| 67 | + final ParserSyntaxTestingUtility parserSyntaxTestingUtility |
66 | 68 | = new ParserSyntaxTestingUtility(fileName, false); |
67 | 69 | parserSyntaxTestingUtility.syntaxParseTest(arg); |
68 | 70 | } |
69 | 71 | @ParameterizedTest |
70 | 72 | @ValueSource(strings = { |
71 | 73 | "fields", |
| 74 | + "fields2", |
| 75 | + "fields_wildcard" |
72 | 76 | }) |
73 | | - void xpathTest1(String arg) throws Exception { |
74 | | - ParserStructureTestingUtility pstu = new ParserStructureTestingUtility(); |
75 | | - String fileName = "src/test/resources/antlr4/commands/fields/" + arg + ".txt"; |
76 | | - String xpathExp = "/root/transformStatement/fieldsTransformation"; |
| 77 | + void testFieldsTransformationExists(final String arg) throws Exception { |
| 78 | + final ParserStructureTestingUtility pstu = new ParserStructureTestingUtility(); |
| 79 | + final String fileName = "src/test/resources/antlr4/commands/fields/" + arg + ".txt"; |
| 80 | + final String xpathExp = "/root/transformStatement/fieldsTransformation"; |
77 | 81 |
|
78 | | - NodeList nodesA = (NodeList) pstu.xpathQueryFile(fileName, xpathExp, false); |
| 82 | + final NodeList nodesA = (NodeList) pstu.xpathQueryFile(fileName, xpathExp, false); |
79 | 83 | // Check that 1 found |
80 | | - assertEquals(1,nodesA.getLength()); |
| 84 | + Assertions.assertEquals(1,nodesA.getLength()); |
81 | 85 | } |
82 | 86 | @ParameterizedTest |
83 | 87 | @ValueSource(strings = { |
84 | 88 | "fields", |
85 | 89 | }) |
86 | | - void xpathTest2(String arg) throws Exception { |
87 | | - ParserStructureTestingUtility pstu = new ParserStructureTestingUtility(); |
88 | | - String fileName = "src/test/resources/antlr4/commands/fields/" + arg + ".txt"; |
89 | | - String xpathExp = "/root/transformStatement/fieldsTransformation/fieldListType/fieldType[1]/value"; |
| 90 | + void testFieldsInPlusMode(final String arg) throws Exception { |
| 91 | + final ParserStructureTestingUtility pstu = new ParserStructureTestingUtility(); |
| 92 | + final String fileName = "src/test/resources/antlr4/commands/fields/" + arg + ".txt"; |
| 93 | + final String xpathExp = "/root/transformStatement/fieldsTransformation/fieldListType/fieldType"; |
90 | 94 |
|
91 | | - NodeList nodesA = (NodeList) pstu.xpathQueryFile(fileName, xpathExp, false); |
92 | | - // Check that 1 found |
93 | | - assertEquals(1,nodesA.getLength()); |
| 95 | + final NodeList nodesA = (NodeList) pstu.xpathQueryFile(fileName, xpathExp, false); |
| 96 | + // Check that 3 found |
| 97 | + Assertions.assertEquals(3,nodesA.getLength()); |
| 98 | + Assertions.assertEquals("foo_*",nodesA.item(0).getTextContent()); |
| 99 | + Assertions.assertEquals("bar_*",nodesA.item(1).getTextContent()); |
| 100 | + Assertions.assertEquals("eawg",nodesA.item(2).getTextContent()); |
| 101 | + |
| 102 | + final String xpathExpPlus = "/root/transformStatement/fieldsTransformation/value"; |
| 103 | + |
| 104 | + final NodeList nodesB = (NodeList) pstu.xpathQueryFile(fileName, xpathExpPlus, false); |
| 105 | + Assertions.assertEquals(2,nodesB.getLength()); |
| 106 | + Assertions.assertEquals("fields",nodesB.item(0).getTextContent()); |
| 107 | + Assertions.assertEquals("+",nodesB.item(1).getTextContent()); |
94 | 108 | } |
95 | 109 | @ParameterizedTest |
96 | 110 | @ValueSource(strings = { |
97 | 111 | "fields2", |
98 | 112 | }) |
99 | | - void xpathTest3(String arg) throws Exception { |
100 | | - ParserStructureTestingUtility pstu = new ParserStructureTestingUtility(); |
101 | | - String fileName = "src/test/resources/antlr4/commands/fields/" + arg + ".txt"; |
102 | | - String xpathExp = "/root/transformStatement/fieldsTransformation/fieldListType/fieldType[1]/value"; |
| 113 | + void testFieldsInMinusMode(final String arg) throws Exception { |
| 114 | + final ParserStructureTestingUtility pstu = new ParserStructureTestingUtility(); |
| 115 | + final String fileName = "src/test/resources/antlr4/commands/fields/" + arg + ".txt"; |
| 116 | + final String xpathExp = "/root/transformStatement/fieldsTransformation/fieldListType/fieldType"; |
103 | 117 |
|
104 | | - NodeList nodesA = (NodeList) pstu.xpathQueryFile(fileName, xpathExp, false); |
105 | | - // Check that 1 found |
106 | | - assertEquals(1,nodesA.getLength()); |
| 118 | + final NodeList nodesA = (NodeList) pstu.xpathQueryFile(fileName, xpathExp, false); |
| 119 | + // Check that 2 found |
| 120 | + Assertions.assertEquals(2,nodesA.getLength()); |
| 121 | + Assertions.assertEquals("host",nodesA.item(0).getTextContent()); |
| 122 | + Assertions.assertEquals("ip",nodesA.item(1).getTextContent()); |
| 123 | + |
| 124 | + final String xpathExpPlus = "/root/transformStatement/fieldsTransformation/value"; |
| 125 | + |
| 126 | + final NodeList nodesB = (NodeList) pstu.xpathQueryFile(fileName, xpathExpPlus, false); |
| 127 | + Assertions.assertEquals(2,nodesB.getLength()); |
| 128 | + Assertions.assertEquals("fields",nodesB.item(0).getTextContent()); |
| 129 | + Assertions.assertEquals("-",nodesB.item(1).getTextContent()); |
| 130 | + } |
| 131 | + |
| 132 | + @ParameterizedTest |
| 133 | + @ValueSource(strings = { |
| 134 | + "fields_wildcard", |
| 135 | + }) |
| 136 | + void testFieldsWithLonelyWildcard(final String arg) throws Exception { |
| 137 | + final ParserStructureTestingUtility pstu = new ParserStructureTestingUtility(); |
| 138 | + final String fileName = "src/test/resources/antlr4/commands/fields/" + arg + ".txt"; |
| 139 | + final String xpathExp = "/root/transformStatement/fieldsTransformation/fieldListType/fieldType"; |
| 140 | + |
| 141 | + final NodeList nodesA = (NodeList) pstu.xpathQueryFile(fileName, xpathExp, false); |
| 142 | + // Check that 3 found |
| 143 | + Assertions.assertEquals(3,nodesA.getLength()); |
| 144 | + Assertions.assertEquals("*",nodesA.item(0).getTextContent()); |
| 145 | + Assertions.assertEquals("*_foo",nodesA.item(1).getTextContent()); |
| 146 | + Assertions.assertEquals("bar",nodesA.item(2).getTextContent()); |
| 147 | + |
| 148 | + final String xpathExpPlus = "/root/transformStatement/fieldsTransformation/value"; |
| 149 | + |
| 150 | + final NodeList nodesB = (NodeList) pstu.xpathQueryFile(fileName, xpathExpPlus, false); |
| 151 | + Assertions.assertEquals(1,nodesB.getLength()); |
| 152 | + Assertions.assertEquals("fields",nodesB.item(0).getTextContent()); |
107 | 153 | } |
108 | 154 | } |
0 commit comments