1
1
package org .graylog2 .syslog4j .server .impl .event .structured ;
2
2
3
3
import org .joda .time .DateTime ;
4
+ import org .joda .time .DateTimeZone ;
4
5
import org .junit .Test ;
5
6
6
7
import java .net .InetAddress ;
7
8
import java .net .InetSocketAddress ;
9
+ import java .time .ZoneId ;
10
+ import java .time .ZoneOffset ;
11
+ import java .time .ZonedDateTime ;
8
12
import java .util .HashMap ;
9
13
import java .util .Map ;
10
14
11
15
import static org .junit .Assert .assertEquals ;
12
16
13
17
14
18
public class StructuredSyslogServerEventTest {
19
+ public static final DateTimeZone MST = DateTimeZone .forID ("MST" );
15
20
private final InetAddress INET_ADDR = new InetSocketAddress (514 ).getAddress ();
16
21
17
22
private StructuredSyslogServerEvent buildEvent (String message ) {
@@ -223,4 +228,24 @@ public void testStructuredSyslogNgNoMillisecTimestamp() throws Exception {
223
228
assertEquals (null , event .getStructuredMessage ().getMessageId ());
224
229
assertEquals ("syslog-ng starting up; version='3.5.3'" , event .getStructuredMessage ().getMessage ());
225
230
}
226
- }
231
+
232
+ @ Test
233
+ public void testDefaultTimeZoneNotSet () throws Exception {
234
+ // Message from: https://github.com/Graylog2/graylog2-server/issues/845
235
+ final String messageWithoutZone = "<45>1 2014-10-21T10:21:09 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\" 1\" ] syslog-ng starting up; version='3.5.3'" ;
236
+ final String messageWithZone = "<45>1 2014-10-21T10:21:09-07:00 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\" 1\" ] syslog-ng starting up; version='3.5.3'" ;
237
+
238
+ assertEquals (new DateTime ("2014-10-21T10:21:09.000" ), buildEvent (messageWithoutZone ).getDateTime ());
239
+ assertEquals (new DateTime ("2014-10-21T10:21:09.000-07:00" ), buildEvent (messageWithZone ).getDateTime ());
240
+ }
241
+
242
+ @ Test
243
+ public void testDefaultTimeZoneSet () throws Exception {
244
+ // Message from: https://github.com/Graylog2/graylog2-server/issues/845
245
+ final String messageWithoutZone = "<45>1 2014-10-21T10:21:09 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\" 1\" ] syslog-ng starting up; version='3.5.3'" ;
246
+ final String messageWithZone = "<45>1 2014-10-21T10:21:09+01:00 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\" 1\" ] syslog-ng starting up; version='3.5.3'" ;
247
+ ZonedDateTime of = ZonedDateTime .of (2014 , 10 , 21 , 10 , 21 , 9 , 0 , MST .toTimeZone ().toZoneId ());
248
+ assertEquals (new DateTime ("2014-10-21T10:21:09.000-07:00" , MST ), new StructuredSyslogServerEvent (messageWithoutZone , INET_ADDR , MST ).getDateTime ());
249
+ assertEquals (new DateTime ("2014-10-21T10:21:09.000+01:00" ), new StructuredSyslogServerEvent (messageWithZone , INET_ADDR , MST ).getDateTime ());
250
+ }
251
+ }
0 commit comments