Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: java
dist: precise
jdk:
- oraclejdk7
- oraclejdk8
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/twingly/search/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public final class Constants {
/**
* The constant DATE_FORMAT.
*/
public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssX";
public static final String QUERY_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";
public static final String POST_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssX";

/**
* The constant TWINGLY_API_KEY_PROPERTY
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/twingly/search/DateAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
/**
* Custom XMLAdapter that processes XML String date to java.util.Date in correct format.
*
* @see Constants#DATE_FORMAT
* @see Constants#POST_DATE_FORMAT
*/
public class DateAdapter extends XmlAdapter<String, Date> {
private final SimpleDateFormat dateFormat = new SimpleDateFormat(Constants.DATE_FORMAT);
private final SimpleDateFormat dateFormat = new SimpleDateFormat(Constants.POST_DATE_FORMAT);

/**
* {@inheritDoc}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/twingly/search/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import java.util.Date;
import java.util.Objects;

import static com.twingly.search.Constants.DATE_FORMAT;
import com.twingly.search.Constants;

/**
* The type Query.
*/
public class Query {
private static final SimpleDateFormat QUERY_DATE_FORMAT = new SimpleDateFormat(DATE_FORMAT);
private static final SimpleDateFormat QUERY_DATE_FORMAT = new SimpleDateFormat(Constants.QUERY_DATE_FORMAT);
private Date startTime;
private Date endTime;
private String searchQuery;
Expand Down
32 changes: 16 additions & 16 deletions src/test/groovy/com/twingly/search/QueryBuilderSpockTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import spock.lang.Unroll

import java.text.SimpleDateFormat

import static com.twingly.search.Constants.DATE_FORMAT
import static com.twingly.search.Constants.QUERY_DATE_FORMAT

class QueryBuilderSpockTest extends Specification {
private static SDF = new SimpleDateFormat(DATE_FORMAT)
private static SDF = new SimpleDateFormat(QUERY_DATE_FORMAT)

@Unroll
def "should create #expectedQueryString for searchQuery=#sq, location=#loc, lang=#lang, startTime=#st and endTime=#et"() {
Expand All @@ -28,14 +28,14 @@ class QueryBuilderSpockTest extends Specification {
query.toStringRepresentation() == expectedQueryString
where:
sq | loc | lang | st | et || expectedQueryString
"sq" | "ua" | "uk" | SDF.parse("2017-05-10T01:26:53Z") | SDF.parse("2017-05-11T01:26:53Z") || String.format("sq lang:uk start-date:%s end-date:%s location:ua", SDF.format(st), SDF.format(et))
"sq" | "ua" | "uk" | SDF.parse("2017-05-10T01:26:53Z") | null || String.format("sq lang:uk start-date:%s location:ua", SDF.format(st))
"sq" | "ua" | "uk" | null | SDF.parse("2017-05-11T01:26:53Z") || String.format("sq lang:uk end-date:%s location:ua", SDF.format(et))
"sq" | "ua" | "uk" | SDF.parse("2017-05-10T01:26:53") | SDF.parse("2017-05-11T01:26:53") || String.format("sq lang:uk start-date:%s end-date:%s location:ua", SDF.format(st), SDF.format(et))
"sq" | "ua" | "uk" | SDF.parse("2017-05-10T01:26:53") | null || String.format("sq lang:uk start-date:%s location:ua", SDF.format(st))
"sq" | "ua" | "uk" | null | SDF.parse("2017-05-11T01:26:53") || String.format("sq lang:uk end-date:%s location:ua", SDF.format(et))
"sq" | "ua" | "uk" | null | null || "sq lang:uk location:ua"
"sq" | "ua" | null | null | null || "sq location:ua"
"sq" | null | null | null | null || "sq"
"sq" | "NO_SUCH_LOC" | "NO_SUCH_LANG" | null | null || "sq"
"sq" | Location.Ukraine | Language.Ukrainian | SDF.parse("2017-07-10T01:26:53Z") | SDF.parse("2017-05-11T01:26:53Z") || String.format("sq lang:uk start-date:%s location:ua", SDF.format(st))
"sq" | Location.Ukraine | Language.Ukrainian | SDF.parse("2017-07-10T01:26:53") | SDF.parse("2017-05-11T01:26:53") || String.format("sq lang:uk start-date:%s location:ua", SDF.format(st))
}

@Unroll
Expand All @@ -55,8 +55,8 @@ class QueryBuilderSpockTest extends Specification {

def "should convert Query to QueryBuilder and back"() {
given:
def startTime = SDF.parse("2016-03-03T15:30:45Z")
def endTime = SDF.parse("2016-05-03T15:30:45Z")
def startTime = SDF.parse("2016-03-03T15:30:45")
def endTime = SDF.parse("2016-05-03T15:30:45")
def searchQuery = "searchQuery"
def lang = "ua"
def location = "uk"
Expand Down Expand Up @@ -124,8 +124,8 @@ class QueryBuilderSpockTest extends Specification {

def "should set start time if it is before end time"() {
given:
def startTime = SDF.parse("2016-03-03T15:30:45Z")
def endTime = SDF.parse("2016-05-03T15:30:45Z")
def startTime = SDF.parse("2016-03-03T15:30:45")
def endTime = SDF.parse("2016-05-03T15:30:45")
when:
def query = QueryBuilder.create("pattern").startTime(startTime).endTime(endTime).build()
then:
Expand All @@ -135,8 +135,8 @@ class QueryBuilderSpockTest extends Specification {

def "should not set end time if it's before start time"() {
given:
def startTime = SDF.parse("2016-05-03T15:30:45Z")
def endTime = SDF.parse("2016-03-03T15:30:45Z")
def startTime = SDF.parse("2016-05-03T15:30:45")
def endTime = SDF.parse("2016-03-03T15:30:45")
when:
def query = QueryBuilder.create("pattern").startTime(startTime).endTime(endTime).build()
then:
Expand All @@ -146,8 +146,8 @@ class QueryBuilderSpockTest extends Specification {

def "should not set start time if it's after end time"() {
given:
def startTime = SDF.parse("2016-05-03T15:30:45Z")
def endTime = SDF.parse("2016-03-03T15:30:45Z")
def startTime = SDF.parse("2016-05-03T15:30:45")
def endTime = SDF.parse("2016-03-03T15:30:45")
when:
def query = QueryBuilder.create("pattern").endTime(endTime).startTime(startTime).build()
then:
Expand Down Expand Up @@ -181,8 +181,8 @@ class QueryBuilderSpockTest extends Specification {
given:
def searchPattern = "searchPattern"
def language = "en"
def startTime = SDF.parse("2016-04-03T15:30:45Z")
def endTime = SDF.parse("2016-05-03T15:30:45Z")
def startTime = SDF.parse("2016-04-03T15:30:45")
def endTime = SDF.parse("2016-05-03T15:30:45")
when:
def query = QueryBuilder.create(searchPattern).startTime(startTime).
endTime(endTime).lang(language).build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UrlConnectionClientFunctionSpockTest extends Specification {
@Rule
RecorderRule recorder = new RecorderRule(configuration)

@Betamax(tape = "search with filled coordinates", mode = TapeMode.READ_ONLY)
@Betamax(tape = "search with filled coordinates", mode = TapeMode.READ_WRITE)
def "search with filled coordinates"() {
given:
def apiKey = "API_KEY"
Expand All @@ -35,7 +35,7 @@ class UrlConnectionClientFunctionSpockTest extends Specification {
result.posts[0].id == "7533026945919130930"
}

@Betamax(tape = "search for spotify", mode = TapeMode.READ_ONLY)
@Betamax(tape = "search for spotify", mode = TapeMode.READ_WRITE)
def "search for spotify in English"() {
given:
def apiKey = "API_KEY"
Expand All @@ -48,7 +48,7 @@ class UrlConnectionClientFunctionSpockTest extends Specification {
result.getNumberOfMatchesReturned() == 10
}

@Betamax(tape = "search for google", mode = TapeMode.READ_ONLY)
@Betamax(tape = "search for google", mode = TapeMode.READ_WRITE)
def "search for google without compression in Ukraine and Belarus"() {
given:
def apiKey = "API_KEY"
Expand All @@ -62,7 +62,7 @@ class UrlConnectionClientFunctionSpockTest extends Specification {
result.getNumberOfMatchesReturned() == 100
}

@Betamax(tape = "search without valid API key", mode = TapeMode.READ_ONLY)
@Betamax(tape = "search without valid API key", mode = TapeMode.READ_WRITE)
def "search without valid api key"() {
given:
def apiKey = "API_KEY"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.text.SimpleDateFormat
class UrlConnectionClientSpockTest extends Specification {
private static final String API_KEY = "apiKey"
def packagePath = Paths.get("com", "twingly", "search", "client")
def sdf = new SimpleDateFormat(Constants.DATE_FORMAT)
def sdf = new SimpleDateFormat(Constants.POST_DATE_FORMAT)
def jaxbContext = Mock(JAXBContext)
def unmarschaller = Mock(Unmarshaller)
def urlStreamHandler
Expand Down
Loading