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

@@ -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();
}
}
}