This repository was archived by the owner on Jun 2, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
main/java/com/nflabs/Grok
test/java/com/nflabs/Grok Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,14 @@ public String toJson(){
120
120
121
121
}
122
122
123
+ /**
124
+ *
125
+ * @return java map object from the matched element in the text
126
+ */
127
+ public Map <String , String > toMap (){
128
+ return _capture ;
129
+ }
130
+
123
131
/**
124
132
*
125
133
*/
Original file line number Diff line number Diff line change
1
+ package com .nflabs .Grok ;
2
+
3
+ import java .util .Map ;
4
+
5
+ import junit .framework .TestCase ;
6
+
7
+ public class GrokTest extends TestCase {
8
+
9
+ protected void setUp () throws Exception {
10
+ super .setUp ();
11
+ }
12
+
13
+ protected void tearDown () throws Exception {
14
+ super .tearDown ();
15
+ }
16
+
17
+ /**
18
+ * Do some basic test
19
+ *
20
+ * @throws Throwable
21
+ */
22
+ public void testGrok () throws Throwable {
23
+ Grok g = new Grok ();
24
+
25
+ g .addPatternFromFile ("patterns/base" );
26
+
27
+ g .compile ("%{URI}" );
28
+
29
+ Match gm = g .match ("http://www.google.com/search=lol" );
30
+ gm .captures ();
31
+
32
+ Map <String , String > map = gm .toMap ();
33
+ assertEquals ("www.google.com" , map .get ("HOSTNAME" ));
34
+ assertEquals ("www.google.com" , map .get ("host" ));
35
+ assertEquals ("http" , map .get ("proto" ));
36
+ assertEquals (null , map .get ("port" ));
37
+ assertEquals ("/search=lol" , map .get ("params" ));
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments