Skip to content

Commit

Permalink
Upgrade to natty 0.11
Browse files Browse the repository at this point in the history
Fixes #1226
  • Loading branch information
Jochen Schalanda committed Jun 8, 2015
1 parent 9a01820 commit f3ab9e2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 35 deletions.
19 changes: 1 addition & 18 deletions graylog2-server/pom.xml
Expand Up @@ -215,7 +215,7 @@
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.graylog2.repackaged</groupId> <groupId>com.joestelmach</groupId>
<artifactId>natty</artifactId> <artifactId>natty</artifactId>
</dependency> </dependency>


Expand Down Expand Up @@ -313,23 +313,6 @@
</dependency> </dependency>
</dependencies> </dependencies>


<dependencyManagement>
<dependencies>
<!-- Getting rid of commons-logging in a transitive dependency of com.joestelmach:natty -->
<dependency>
<groupId>org.mnode.ical4j</groupId>
<artifactId>ical4j</artifactId>
<version>1.0.2</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>

<build> <build>
<plugins> <plugins>
<plugin> <plugin>
Expand Down
Expand Up @@ -16,48 +16,65 @@
*/ */
package org.graylog2.utilities.date; package org.graylog2.utilities.date;


import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;


import static org.assertj.jodatime.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;


public class NaturalDateParserTest { public class NaturalDateParserTest {
private NaturalDateParser naturalDateParser;


@Test @Before
public void testParse() throws Exception, NaturalDateParser.DateNotParsableException { public void setUp() {
NaturalDateParser p = new NaturalDateParser(); naturalDateParser = new NaturalDateParser();
}


NaturalDateParser.Result today = p.parse("today"); @Test
public void testParse() throws Exception {
NaturalDateParser.Result today = naturalDateParser.parse("today");
assertNotNull(today.getFrom()); assertNotNull(today.getFrom());
assertNotNull(today.getTo()); assertNotNull(today.getTo());


// It's enough if this does not throw exceptions because we are not testing the underlying library. // It's enough if this does not throw exceptions because we are not testing the underlying library.
p.parse("today"); naturalDateParser.parse("today");
p.parse("last week to today"); naturalDateParser.parse("last week to today");
} }


@Test(expected = NaturalDateParser.DateNotParsableException.class) @Test(expected = NaturalDateParser.DateNotParsableException.class)
public void testParseFailsOnUnparsableDate() throws Exception, NaturalDateParser.DateNotParsableException { public void testParseFailsOnUnparsableDate() throws Exception {
new NaturalDateParser().parse("LOLWUT"); naturalDateParser.parse("LOLWUT");
} }


@Test(expected = NaturalDateParser.DateNotParsableException.class) @Test(expected = NaturalDateParser.DateNotParsableException.class)
public void testParseFailsOnEmptyDate() throws Exception, NaturalDateParser.DateNotParsableException { public void testParseFailsOnEmptyDate() throws Exception {
new NaturalDateParser().parse(""); naturalDateParser.parse("");
} }


@Test @Test
@Ignore @Ignore
public void testTemporalOrder() throws Exception, NaturalDateParser.DateNotParsableException { public void testTemporalOrder() throws Exception {
NaturalDateParser p = new NaturalDateParser(); NaturalDateParser p = new NaturalDateParser();


NaturalDateParser.Result result1 = p.parse("last hour"); NaturalDateParser.Result result1 = p.parse("last hour");
assertTrue(result1.getFrom().compareTo(result1.getTo()) < 0); assertTrue(result1.getFrom().compareTo(result1.getTo()) < 0);


NaturalDateParser.Result result2 = p.parse("last one hour"); NaturalDateParser.Result result2 = p.parse("last one hour");
assertTrue(result2.getFrom().compareTo(result2.getTo()) < 0); assertTrue(result2.getFrom().compareTo(result2.getTo()) < 0);
}

// https://github.com/Graylog2/graylog2-server/issues/1226
@Test
public void issue1226() throws Exception {
NaturalDateParser.Result result99days = naturalDateParser.parse("last 99 days");
assertThat(result99days.getFrom()).isEqualToIgnoringMillis(result99days.getTo().minusDays(99));


NaturalDateParser.Result result100days = naturalDateParser.parse("last 100 days");
assertThat(result100days.getFrom()).isEqualToIgnoringMillis(result100days.getTo().minusDays(100));


NaturalDateParser.Result result101days = naturalDateParser.parse("last 101 days");
assertThat(result101days.getFrom()).isEqualToIgnoringMillis(result101days.getTo().minusDays(101));
} }
} }
15 changes: 9 additions & 6 deletions pom.xml
Expand Up @@ -566,14 +566,17 @@
<version>2.3</version> <version>2.3</version>
</dependency> </dependency>


<!--
This is required because natty currently doesn't work with
newer antlr-runtime versions, see https://github.com/joestelmach/natty/issues/60
-->
<dependency> <dependency>
<groupId>org.graylog2.repackaged</groupId> <groupId>com.joestelmach</groupId>
<artifactId>natty</artifactId> <artifactId>natty</artifactId>
<version>0.8-1</version> <version>0.11</version>
<exclusions>
<!-- Getting rid of commons-logging in a transitive dependency of com.joestelmach:natty -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>


<dependency> <dependency>
Expand Down

0 comments on commit f3ab9e2

Please sign in to comment.