GH-7: Add checkstyle and javaformat plugins

Fixes: #7

* Run `./gradlew format`
* Updates from PR review suggestions
This commit is contained in:
Chris Bono
2023-12-29 21:08:58 -06:00
committed by Artem Bilan
parent 84e732da08
commit 836708f0f2
357 changed files with 4344 additions and 4519 deletions

View File

@@ -36,7 +36,6 @@ import org.springframework.context.annotation.Import;
import org.springframework.messaging.Message;
/**
*
* @author Christian Tzolov
*/
@Configuration
@@ -103,11 +102,10 @@ public class TwitterGeoFunctionConfiguration {
}
@Bean
public Function<Message<?>, Message<byte[]>> twitterGeoFunction(
Function<Message<?>, GeoQuery> toGeoQuery,
Function<GeoQuery, List<Place>> places,
Function<Object, Message<byte[]>> managedJson) {
public Function<Message<?>, Message<byte[]>> twitterGeoFunction(Function<Message<?>, GeoQuery> toGeoQuery,
Function<GeoQuery, List<Place>> places, Function<Object, Message<byte[]>> managedJson) {
return toGeoQuery.andThen(places).andThen(managedJson)::apply;
}
}

View File

@@ -24,7 +24,6 @@ import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.validation.annotation.Validated;
/**
* @author Christian Tzolov
*/
@@ -35,8 +34,10 @@ public class TwitterGeoFunctionProperties {
private static final Expression DEFAULT_EXPRESSION = new SpelExpressionParser().parseExpression("payload");
public enum GeoType {
/** Geo retrieval type. */
reverse, search
}
/**
@@ -56,22 +57,24 @@ public class TwitterGeoFunctionProperties {
private Location location = new Location();
/**
* Hints for the number of results to return. This does not guarantee that the number of results
* returned will equal max_results, but instead informs how many 'nearby' results to return.
* Hints for the number of results to return. This does not guarantee that the number
* of results returned will equal max_results, but instead informs how many 'nearby'
* results to return.
*/
private int maxResults = -1;
/**
* Sets a hint on the 'region' in which to search. If a number, then this is a radius in meters, but it
* can also take a string that is suffixed with ft to specify feet. If this is not passed in, then it is
* assumed to be 0m. If coming from a device, in practice, this value is whatever accuracy the device
* has measuring its location (whether it be coming from a GPS, WiFi triangulation, etc.).
* Sets a hint on the 'region' in which to search. If a number, then this is a radius
* in meters, but it can also take a string that is suffixed with ft to specify feet.
* If this is not passed in, then it is assumed to be 0m. If coming from a device, in
* practice, this value is whatever accuracy the device has measuring its location
* (whether it be coming from a GPS, WiFi triangulation, etc.).
*/
private String accuracy = null;
/**
* Minimal granularity of data to return. If this is not passed in, then neighborhood is assumed.
* City can also be passed.
* Minimal granularity of data to return. If this is not passed in, then neighborhood
* is assumed. City can also be passed.
*/
private String granularity = null;
@@ -125,7 +128,8 @@ public class TwitterGeoFunctionProperties {
@AssertTrue(message = "Either the IP or the Location must be set")
public boolean isAtLeastOne() {
return this.getSearch().getIp() == null ^ (this.getLocation().getLat() == null && this.getLocation().getLon() == null);
return this.getSearch().getIp() == null
^ (this.getLocation().getLat() == null && this.getLocation().getLon() == null);
}
@AssertTrue(message = "The IP parameter is applicable only for 'Search' GeoType")
@@ -137,9 +141,10 @@ public class TwitterGeoFunctionProperties {
}
public static class Search {
/**
* An IP address. Used when attempting to fix geolocation based off of the user's IP address.
* Applicable only for 'search' geo type.
* An IP address. Used when attempting to fix geolocation based off of the user's
* IP address. Applicable only for 'search' geo type.
*/
private Expression ip = null;
@@ -163,6 +168,7 @@ public class TwitterGeoFunctionProperties {
public void setQuery(Expression query) {
this.query = query;
}
}
public static class Location {
@@ -177,7 +183,6 @@ public class TwitterGeoFunctionProperties {
*/
private Expression lon;
public Expression getLat() {
return lat;
}
@@ -193,5 +198,7 @@ public class TwitterGeoFunctionProperties {
public void setLon(Expression lon) {
this.lon = lon;
}
}
}

View File

@@ -59,8 +59,8 @@ public class TwitterTrendFunctionConfiguration {
}
@Bean
public Function<Message<?>, List<Location>> closestOrAvailableTrends(
TwitterTrendFunctionProperties properties, Twitter twitter) {
public Function<Message<?>, List<Location>> closestOrAvailableTrends(TwitterTrendFunctionProperties properties,
Twitter twitter) {
return message -> {
try {
if (properties.getClosest().getLat() != null && properties.getClosest().getLon() != null) {
@@ -80,12 +80,12 @@ public class TwitterTrendFunctionConfiguration {
}
@Bean
public Function<Message<?>, Message<byte[]>> twitterTrendFunction(
Function<Object, Message<byte[]>> managedJson, Function<Message<?>, Trends> trend,
TwitterTrendFunctionProperties properties, Function<Message<?>,
List<Location>> closestOrAvailableTrends) {
public Function<Message<?>, Message<byte[]>> twitterTrendFunction(Function<Object, Message<byte[]>> managedJson,
Function<Message<?>, Trends> trend, TwitterTrendFunctionProperties properties,
Function<Message<?>, List<Location>> closestOrAvailableTrends) {
return (properties.getTrendQueryType() == TwitterTrendFunctionProperties.TrendQueryType.trend) ?
trend.andThen(managedJson) : closestOrAvailableTrends.andThen(managedJson);
return (properties.getTrendQueryType() == TwitterTrendFunctionProperties.TrendQueryType.trend)
? trend.andThen(managedJson) : closestOrAvailableTrends.andThen(managedJson);
}
}

View File

@@ -33,10 +33,12 @@ public class TwitterTrendFunctionProperties {
private static final Expression DEFAULT_EXPRESSION = new SpelExpressionParser().parseExpression("payload");
enum TrendQueryType {
/** Retrieve trending places. */
trend,
/** Retrieve the Locations of trending places. */
trendLocation
}
private TrendQueryType trendQueryType = TrendQueryType.trend;
@@ -74,17 +76,18 @@ public class TwitterTrendFunctionProperties {
}
public static class Closest {
/**
* If provided with a long parameter the available trend locations will be sorted by distance, nearest
* to furthest, to the co-ordinate pair.
* The valid ranges for longitude is -180.0 to +180.0 (West is negative, East is positive) inclusive.
* If provided with a long parameter the available trend locations will be sorted
* by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for
* longitude is -180.0 to +180.0 (West is negative, East is positive) inclusive.
*/
private Expression lat;
/**
* If provided with a lat parameter the available trend locations will be sorted by distance, nearest to
* furthest, to the co-ordinate pair. The valid ranges for longitude is -180.0 to +180.0 (West is negative,
* East is positive) inclusive.
* If provided with a lat parameter the available trend locations will be sorted
* by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for
* longitude is -180.0 to +180.0 (West is negative, East is positive) inclusive.
*/
private Expression lon;
@@ -103,5 +106,7 @@ public class TwitterTrendFunctionProperties {
public void setLon(Expression lon) {
this.lon = lon;
}
}
}

View File

@@ -35,7 +35,6 @@ import org.springframework.context.annotation.Import;
import org.springframework.messaging.Message;
/**
*
* @author Christian Tzolov
*/
@Configuration
@@ -88,11 +87,12 @@ public class TwitterUsersFunctionConfiguration {
@Bean
/**
* queryUsers - depends on the `twitter.users.type` property is either userSearch or userLookup.
* managedJson - converts Users into JSON message payload.
* queryUsers - depends on the `twitter.users.type` property is either userSearch or
* userLookup. managedJson - converts Users into JSON message payload.
*/
public Function<Message<?>, Message<byte[]>> twitterUsersFunction(Function<Message<?>, List<User>> queryUsers,
Function<Object, Message<byte[]>> managedJson) {
return queryUsers.andThen(managedJson);
}
}

View File

@@ -34,8 +34,10 @@ public class TwitterUsersFunctionProperties {
private static final Expression DEFAULT_EXPRESSION = new SpelExpressionParser().parseExpression("payload");
public enum UserQueryType {
/** User retrieval types. */
search, lookup
}
/**
@@ -45,14 +47,14 @@ public class TwitterUsersFunctionProperties {
private UserQueryType type = UserQueryType.search;
/**
* Returns fully-hydrated user objects for specified by comma-separated values passed to the user_id and/or
* screen_name parameters.
* Returns fully-hydrated user objects for specified by comma-separated values passed
* to the user_id and/or screen_name parameters.
*/
private final Lookup lookup = new Lookup();
/**
* relevance-based search interface for querying by topical interest, full name, company name, location,
* or other criteria.
* relevance-based search interface for querying by topical interest, full name,
* company name, location, or other criteria.
*/
private final Search search = new Search();
@@ -85,6 +87,7 @@ public class TwitterUsersFunctionProperties {
}
public static class Lookup {
/**
* A comma separated list of user IDs, up to 100 are allowed in a single request.
* You are strongly encouraged to use a POST for larger requests.
@@ -92,8 +95,9 @@ public class TwitterUsersFunctionProperties {
private Expression userId;
/**
* A comma separated list of screen names, up to 100 are allowed in a single request.
* You are strongly encouraged to use a POST for larger (up to 100 screen names) requests.
* A comma separated list of screen names, up to 100 are allowed in a single
* request. You are strongly encouraged to use a POST for larger (up to 100 screen
* names) requests.
*/
private Expression screenName;
@@ -112,9 +116,11 @@ public class TwitterUsersFunctionProperties {
public void setScreenName(Expression screenName) {
this.screenName = screenName;
}
}
public static class Search {
/**
* The search query to run against people search.
*/
@@ -140,5 +146,7 @@ public class TwitterUsersFunctionProperties {
public void setPage(int page) {
this.page = page;
}
}
}

View File

@@ -58,14 +58,10 @@ import static org.mockserver.verify.VerificationTimes.once;
/**
* @author Christian Tzolov
*/
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.NONE,
properties = {
"twitter.connection.consumerKey=consumerKey666",
"twitter.connection.consumerSecret=consumerSecret666",
"twitter.connection.accessToken=accessToken666",
"twitter.connection.accessTokenSecret=accessTokenSecret666"
})
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE,
properties = { "twitter.connection.consumerKey=consumerKey666",
"twitter.connection.consumerSecret=consumerSecret666", "twitter.connection.accessToken=accessToken666",
"twitter.connection.accessTokenSecret=accessTokenSecret666" })
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public abstract class TwitterGeoFunctionTest {
@@ -83,18 +79,12 @@ public abstract class TwitterGeoFunctionTest {
public static void recordRequestExpectation(Map<String, List<String>> parameters) {
mockClient
.when(
request()
.withMethod("GET")
.withPath("/geo/search.json")
.withQueryStringParameters(parameters),
unlimited())
.respond(
response()
.withStatusCode(200)
.withHeader("Content-Type", "application/json; charset=utf-8")
.withBody(TwitterTestUtils.asString("classpath:/response/search_places_amsterdam.json"))
.withDelay(TimeUnit.SECONDS, 1));
.when(request().withMethod("GET").withPath("/geo/search.json").withQueryStringParameters(parameters),
unlimited())
.respond(response().withStatusCode(200)
.withHeader("Content-Type", "application/json; charset=utf-8")
.withBody(TwitterTestUtils.asString("classpath:/response/search_places_amsterdam.json"))
.withDelay(TimeUnit.SECONDS, 1));
}
@@ -109,10 +99,8 @@ public abstract class TwitterGeoFunctionTest {
mockServer.stop();
}
@TestPropertySource(properties = {
"twitter.geo.search.ip='127.0.0.1'",
"twitter.geo.search.query=payload.toUpperCase()"
})
@TestPropertySource(
properties = { "twitter.geo.search.ip='127.0.0.1'", "twitter.geo.search.query=payload.toUpperCase()" })
public static class TwitterGeoSearchByIPAndQueryTests extends TwitterGeoFunctionTest {
@Test
@@ -128,12 +116,10 @@ public abstract class TwitterGeoFunctionTest {
Message<?> received = twitterUsersFunction.apply(MessageBuilder.withPayload(inPayload).build());
mockClient.verify(request()
.withMethod("GET")
.withPath("/geo/search.json")
.withQueryStringParameter("ip", "127.0.0.1")
.withQueryStringParameter("query", "AMSTERDAM"),
once());
mockClient.verify(request().withMethod("GET")
.withPath("/geo/search.json")
.withQueryStringParameter("ip", "127.0.0.1")
.withQueryStringParameter("query", "AMSTERDAM"), once());
String outPayload = new String((byte[]) received.getPayload());
@@ -142,13 +128,11 @@ public abstract class TwitterGeoFunctionTest {
List places = new ObjectMapper().readValue(outPayload, List.class);
assertThat(places).hasSize(12);
}
}
@TestPropertySource(properties = {
"twitter.geo.location.lat='52.378'",
"twitter.geo.location.lon='4.9'",
"twitter.geo.search.query=payload.toUpperCase()"
})
@TestPropertySource(properties = { "twitter.geo.location.lat='52.378'", "twitter.geo.location.lon='4.9'",
"twitter.geo.search.query=payload.toUpperCase()" })
public static class TwitterGeoSearchByLocationTests extends TwitterGeoFunctionTest {
@Test
@@ -165,13 +149,11 @@ public abstract class TwitterGeoFunctionTest {
Message<?> received = twitterUsersFunction.apply(MessageBuilder.withPayload(inPayload).build());
mockClient.verify(request()
.withMethod("GET")
.withPath("/geo/search.json")
.withQueryStringParameter("lat", "52.378")
.withQueryStringParameter("long", "4.9")
.withQueryStringParameter("query", "Amsterdam"),
once());
mockClient.verify(request().withMethod("GET")
.withPath("/geo/search.json")
.withQueryStringParameter("lat", "52.378")
.withQueryStringParameter("long", "4.9")
.withQueryStringParameter("query", "Amsterdam"), once());
String outPayload = new String((byte[]) received.getPayload());
@@ -180,13 +162,11 @@ public abstract class TwitterGeoFunctionTest {
List places = new ObjectMapper().readValue(outPayload, List.class);
assertThat(places).hasSize(12);
}
}
@TestPropertySource(properties = {
"twitter.geo.type=reverse",
"twitter.geo.location.lat='52.378'",
"twitter.geo.location.lon='4.9'"
})
@TestPropertySource(properties = { "twitter.geo.type=reverse", "twitter.geo.location.lat='52.378'",
"twitter.geo.location.lon='4.9'" })
public static class TwitterGeoSearchByLocation2Tests extends TwitterGeoFunctionTest {
@Test
@@ -202,12 +182,10 @@ public abstract class TwitterGeoFunctionTest {
Message<?> received = twitterUsersFunction.apply(MessageBuilder.withPayload(inPayload).build());
mockClient.verify(request()
.withMethod("GET")
.withPath("/geo/search.json")
.withQueryStringParameter("lat", "52.378")
.withQueryStringParameter("long", "4.9"),
once());
mockClient.verify(request().withMethod("GET")
.withPath("/geo/search.json")
.withQueryStringParameter("lat", "52.378")
.withQueryStringParameter("long", "4.9"), once());
String outPayload = new String((byte[]) received.getPayload());
@@ -216,13 +194,12 @@ public abstract class TwitterGeoFunctionTest {
List places = new ObjectMapper().readValue(outPayload, List.class);
assertThat(places).hasSize(12);
}
}
@TestPropertySource(properties = {
"twitter.geo.location.lat=#jsonPath(new String(payload),'$.location.lat')",
@TestPropertySource(properties = { "twitter.geo.location.lat=#jsonPath(new String(payload),'$.location.lat')",
"twitter.geo.location.lon=#jsonPath(new String(payload),'$.location.lon')",
"twitter.geo.search.query=#jsonPath(new String(payload),'$.country')"
})
"twitter.geo.search.query=#jsonPath(new String(payload),'$.country')" })
public static class TwitterGeoSearchJsonPathTests extends TwitterGeoFunctionTest {
@Test
@@ -237,18 +214,15 @@ public abstract class TwitterGeoFunctionTest {
String inPayload = "{ \"country\" : \"Netherlands\", \"location\" : { \"lat\" : 52.00 , \"lon\" : 5.0 } }";
Message<?> received = twitterUsersFunction.apply(MessageBuilder
.withPayload(inPayload)
.setHeader("contentType", MimeTypeUtils.APPLICATION_JSON_VALUE)
.build());
Message<?> received = twitterUsersFunction.apply(MessageBuilder.withPayload(inPayload)
.setHeader("contentType", MimeTypeUtils.APPLICATION_JSON_VALUE)
.build());
mockClient.verify(request()
.withMethod("GET")
.withPath("/geo/search.json")
.withQueryStringParameter("lat", "52.0")
.withQueryStringParameter("long", "5.0")
.withQueryStringParameter("query", "Netherlands"),
once());
mockClient.verify(request().withMethod("GET")
.withPath("/geo/search.json")
.withQueryStringParameter("lat", "52.0")
.withQueryStringParameter("long", "5.0")
.withQueryStringParameter("query", "Netherlands"), once());
String outPayload = new String((byte[]) received.getPayload());
@@ -257,23 +231,26 @@ public abstract class TwitterGeoFunctionTest {
List places = new ObjectMapper().readValue(outPayload, List.class);
assertThat(places).hasSize(12);
}
}
@SpringBootConfiguration
@EnableAutoConfiguration
@Import(TwitterGeoFunctionConfiguration.class)
public static class TwitterGeoFunctionTestApplication {
@Bean
@Primary
public twitter4j.conf.Configuration twitterConfiguration2(TwitterConnectionProperties properties,
Function<TwitterConnectionProperties, ConfigurationBuilder> toConfigurationBuilder) {
Function<TwitterConnectionProperties, ConfigurationBuilder> mockedConfiguration =
toConfigurationBuilder.andThen(
new TwitterTestUtils().mockTwitterUrls(
String.format("http://%s:%s", MOCK_SERVER_IP, MOCK_SERVER_PORT)));
Function<TwitterConnectionProperties, ConfigurationBuilder> mockedConfiguration = toConfigurationBuilder
.andThen(new TwitterTestUtils()
.mockTwitterUrls(String.format("http://%s:%s", MOCK_SERVER_IP, MOCK_SERVER_PORT)));
return mockedConfiguration.apply(properties).build();
}
}
}

View File

@@ -52,14 +52,10 @@ import static org.mockserver.verify.VerificationTimes.once;
/**
* @author Christian Tzolov
*/
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.NONE,
properties = {
"twitter.connection.consumerKey=consumerKey666",
"twitter.connection.consumerSecret=consumerSecret666",
"twitter.connection.accessToken=accessToken666",
"twitter.connection.accessTokenSecret=accessTokenSecret666"
})
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE,
properties = { "twitter.connection.consumerKey=consumerKey666",
"twitter.connection.consumerSecret=consumerSecret666", "twitter.connection.accessToken=accessToken666",
"twitter.connection.accessTokenSecret=accessTokenSecret666" })
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public abstract class TwitterTrendFunctionTests {
@@ -70,6 +66,7 @@ public abstract class TwitterTrendFunctionTests {
private static ClientAndServer mockServer;
private static MockServerClient mockClient;
private static HttpRequest trendsRequest;
@Autowired
@@ -80,10 +77,8 @@ public abstract class TwitterTrendFunctionTests {
mockServer = ClientAndServer.startClientAndServer(MOCK_SERVER_PORT);
mockClient = new MockServerClient(MOCK_SERVER_IP, MOCK_SERVER_PORT);
trendsRequest = setExpectation(request()
.withMethod("GET")
.withPath("/trends/place.json")
.withQueryStringParameter("id", "2972"));
trendsRequest = setExpectation(
request().withMethod("GET").withPath("/trends/place.json").withQueryStringParameter("id", "2972"));
}
@AfterAll
@@ -92,23 +87,16 @@ public abstract class TwitterTrendFunctionTests {
}
public static HttpRequest setExpectation(HttpRequest request) {
mockClient
.when(request, exactly(1))
.respond(response()
.withStatusCode(200)
.withHeaders(
new Header("Content-Type", "application/json; charset=utf-8"),
new Header("Cache-Control", "public, max-age=86400"))
.withBody(TwitterTestUtils.asString("classpath:/response/trends.json"))
.withDelay(TimeUnit.SECONDS, 1)
);
mockClient.when(request, exactly(1))
.respond(response().withStatusCode(200)
.withHeaders(new Header("Content-Type", "application/json; charset=utf-8"),
new Header("Cache-Control", "public, max-age=86400"))
.withBody(TwitterTestUtils.asString("classpath:/response/trends.json"))
.withDelay(TimeUnit.SECONDS, 1));
return request;
}
@TestPropertySource(properties = {
"twitter.trend.locationId='2972'",
"twitter.connection.rawJson=true"
})
@TestPropertySource(properties = { "twitter.trend.locationId='2972'", "twitter.connection.rawJson=true" })
public static class TwitterTrendPayloadTests extends TwitterTrendFunctionTests {
@Test
@@ -117,24 +105,26 @@ public abstract class TwitterTrendFunctionTests {
mockClient.verify(trendsRequest, once());
assertThat(received).isNotNull();
}
}
@SpringBootConfiguration
@EnableAutoConfiguration
@Import(TwitterTrendFunctionConfiguration.class)
public static class TwitterTrendFunctionTestApplication {
@Bean
@Primary
public twitter4j.conf.Configuration twitterConfiguration2(TwitterConnectionProperties properties,
Function<TwitterConnectionProperties, ConfigurationBuilder> toConfigurationBuilder) {
Function<TwitterConnectionProperties, ConfigurationBuilder> mockedConfiguration =
toConfigurationBuilder.andThen(
new TwitterTestUtils().mockTwitterUrls(
String.format("http://%s:%s", MOCK_SERVER_IP, MOCK_SERVER_PORT)));
Function<TwitterConnectionProperties, ConfigurationBuilder> mockedConfiguration = toConfigurationBuilder
.andThen(new TwitterTestUtils()
.mockTwitterUrls(String.format("http://%s:%s", MOCK_SERVER_IP, MOCK_SERVER_PORT)));
return mockedConfiguration.apply(properties).build();
}
}
}

View File

@@ -55,14 +55,10 @@ import static org.mockserver.verify.VerificationTimes.once;
/**
* @author Christian Tzolov
*/
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.NONE,
properties = {
"twitter.connection.consumerKey=consumerKey666",
"twitter.connection.consumerSecret=consumerSecret666",
"twitter.connection.accessToken=accessToken666",
"twitter.connection.accessTokenSecret=accessTokenSecret666"
})
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE,
properties = { "twitter.connection.consumerKey=consumerKey666",
"twitter.connection.consumerSecret=consumerSecret666", "twitter.connection.accessToken=accessToken666",
"twitter.connection.accessTokenSecret=accessTokenSecret666" })
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public abstract class TwitterUsersFunctionTests {
@@ -73,8 +69,11 @@ public abstract class TwitterUsersFunctionTests {
private static ClientAndServer mockServer;
private static MockServerClient mockClient;
private static HttpRequest searchUsersRequest;
private static HttpRequest lookupUsersRequest;
private static HttpRequest lookupUsersRequest2;
@Autowired
@@ -84,16 +83,12 @@ public abstract class TwitterUsersFunctionTests {
Function<Message<?>, Message<byte[]>> twitterUsersFunction;
public static HttpRequest setExpectation(HttpRequest request, String responseUri) {
mockClient
.when(request, exactly(1))
.respond(response()
.withStatusCode(200)
.withHeaders(
new Header("Content-Type", "application/json; charset=utf-8"),
new Header("Cache-Control", "public, max-age=86400"))
.withBody(TwitterTestUtils.asString(responseUri))
.withDelay(TimeUnit.SECONDS, 1)
);
mockClient.when(request, exactly(1))
.respond(response().withStatusCode(200)
.withHeaders(new Header("Content-Type", "application/json; charset=utf-8"),
new Header("Cache-Control", "public, max-age=86400"))
.withBody(TwitterTestUtils.asString(responseUri))
.withDelay(TimeUnit.SECONDS, 1));
return request;
}
@@ -102,25 +97,20 @@ public abstract class TwitterUsersFunctionTests {
mockServer = ClientAndServer.startClientAndServer(MOCK_SERVER_PORT);
mockClient = new MockServerClient(MOCK_SERVER_IP, MOCK_SERVER_PORT);
searchUsersRequest = setExpectation(request()
.withMethod("GET")
.withPath("/users/search.json")
.withQueryStringParameter("q", "tzolov")
.withQueryStringParameter("page", "3"),
"classpath:/response/search_users.json");
searchUsersRequest = setExpectation(request().withMethod("GET")
.withPath("/users/search.json")
.withQueryStringParameter("q", "tzolov")
.withQueryStringParameter("page", "3"), "classpath:/response/search_users.json");
lookupUsersRequest = setExpectation(request()
.withMethod("GET")
.withPath("/users/lookup.json")
.withQueryStringParameter("user_id",
"710705860343963648,326896547,267603736,781497571629989888,838754923"),
lookupUsersRequest = setExpectation(request().withMethod("GET")
.withPath("/users/lookup.json")
.withQueryStringParameter("user_id", "710705860343963648,326896547,267603736,781497571629989888,838754923"),
"classpath:/response/lookup_users_id.json");
lookupUsersRequest2 = setExpectation(request()
.withMethod("GET")
.withPath("/users/lookup.json")
.withQueryStringParameter("screen_name",
"TzolovMarto,Rabotnik57,antzolov,peyo_tzolov,ivantzolov"),
lookupUsersRequest2 = setExpectation(
request().withMethod("GET")
.withPath("/users/lookup.json")
.withQueryStringParameter("screen_name", "TzolovMarto,Rabotnik57,antzolov,peyo_tzolov,ivantzolov"),
"classpath:/response/lookup_users_id.json");
}
@@ -129,10 +119,7 @@ public abstract class TwitterUsersFunctionTests {
mockServer.stop();
}
@TestPropertySource(properties = {
"twitter.users.type=search",
"twitter.users.search.query=payload"
})
@TestPropertySource(properties = { "twitter.users.type=search", "twitter.users.search.query=payload" })
public static class TwitterSearchUsersTests extends TwitterUsersFunctionTests {
@Test
@@ -143,12 +130,11 @@ public abstract class TwitterUsersFunctionTests {
List list = mapper.readValue(new String((byte[]) received.getPayload()), List.class);
assertThat(list).hasSize(20);
}
}
@TestPropertySource(properties = {
"twitter.users.type=lookup",
"twitter.users.lookup.userId='710705860343963648,326896547,267603736,781497571629989888,838754923'"
})
@TestPropertySource(properties = { "twitter.users.type=lookup",
"twitter.users.lookup.userId='710705860343963648,326896547,267603736,781497571629989888,838754923'" })
public static class TwitterLookupUserIdLiteralTests extends TwitterUsersFunctionTests {
@Test
@@ -161,12 +147,11 @@ public abstract class TwitterUsersFunctionTests {
List list = mapper.readValue(new String((byte[]) received.getPayload()), List.class);
assertThat(list).hasSize(5);
}
}
@TestPropertySource(properties = {
"twitter.users.type=lookup",
"twitter.users.lookup.screenName=#jsonPath(payload,'$[*].code')"
})
@TestPropertySource(properties = { "twitter.users.type=lookup",
"twitter.users.lookup.screenName=#jsonPath(payload,'$[*].code')" })
public static class TwitterLookupScreenNamePayloadTests extends TwitterUsersFunctionTests {
@Test
@@ -182,23 +167,26 @@ public abstract class TwitterUsersFunctionTests {
List list = mapper.readValue(new String((byte[]) received.getPayload()), List.class);
assertThat(list).hasSize(5);
}
}
@SpringBootConfiguration
@EnableAutoConfiguration
@Import(TwitterUsersFunctionConfiguration.class)
static class TwitterUsersFunctionTestApplication {
@Bean
@Primary
public twitter4j.conf.Configuration twitterConfiguration2(TwitterConnectionProperties properties,
Function<TwitterConnectionProperties, ConfigurationBuilder> toConfigurationBuilder) {
Function<TwitterConnectionProperties, ConfigurationBuilder> mockedConfiguration =
toConfigurationBuilder.andThen(
new TwitterTestUtils().mockTwitterUrls(
String.format("http://%s:%s", MOCK_SERVER_IP, MOCK_SERVER_PORT)));
Function<TwitterConnectionProperties, ConfigurationBuilder> mockedConfiguration = toConfigurationBuilder
.andThen(new TwitterTestUtils()
.mockTwitterUrls(String.format("http://%s:%s", MOCK_SERVER_IP, MOCK_SERVER_PORT)));
return mockedConfiguration.apply(properties).build();
}
}
}