-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
16 changed files
with
299 additions
and
3 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...in/java/dev/iakunin/codexiabot/codexia/config/ResendReviewsUntilDuplicatedCronConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package dev.iakunin.codexiabot.codexia.config; | ||
|
||
import dev.iakunin.codexiabot.codexia.cron.ResendReviewsUntilDuplicated; | ||
import dev.iakunin.codexiabot.common.runnable.Logging; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.SchedulingConfigurer; | ||
import org.springframework.scheduling.config.ScheduledTaskRegistrar; | ||
|
||
@Configuration | ||
public class ResendReviewsUntilDuplicatedCronConfig implements SchedulingConfigurer { | ||
|
||
private final ResendReviewsUntilDuplicated resendReviewsUntilDuplicated; | ||
|
||
private final String cronExpression; | ||
|
||
public ResendReviewsUntilDuplicatedCronConfig( | ||
ResendReviewsUntilDuplicated resendReviewsUntilDuplicated, | ||
@Value("${app.cron.codexia.resend-reviews-until-duplicated:-}") String cronExpression | ||
) { | ||
this.resendReviewsUntilDuplicated = resendReviewsUntilDuplicated; | ||
this.cronExpression = cronExpression; | ||
} | ||
|
||
@Bean | ||
public Runnable resendReviewsUntilDuplicatedRunnable() { | ||
return new Logging(this.resendReviewsUntilDuplicated); | ||
} | ||
|
||
@Override | ||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { | ||
taskRegistrar.addCronTask( | ||
this.resendReviewsUntilDuplicatedRunnable(), | ||
this.cronExpression | ||
); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/dev/iakunin/codexiabot/codexia/cron/ResendReviewsUntilDuplicated.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package dev.iakunin.codexiabot.codexia.cron; | ||
|
||
import dev.iakunin.codexiabot.codexia.entity.CodexiaReviewNotification; | ||
import dev.iakunin.codexiabot.codexia.repository.CodexiaReviewNotificationRepository; | ||
import dev.iakunin.codexiabot.codexia.sdk.CodexiaClient; | ||
import dev.iakunin.codexiabot.codexia.service.ReviewSender; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
@AllArgsConstructor(onConstructor_={@Autowired}) | ||
// @todo #85 Remove this cron after https://github.com/yegor256/codexia/issues/98 is done | ||
public final class ResendReviewsUntilDuplicated implements Runnable { | ||
|
||
private final CodexiaReviewNotificationRepository codexiaReviewNotificationRepository; | ||
|
||
private final ReviewSender reviewSender; | ||
|
||
public void run() { | ||
this.codexiaReviewNotificationRepository | ||
.findAllByLastStatusExcludingResponseCode( | ||
CodexiaReviewNotification.Status.SUCCESS, | ||
CodexiaClient.ReviewStatus.ALREADY_EXISTS.httpStatus() | ||
) | ||
.stream() | ||
.map(CodexiaReviewNotification::getCodexiaReview) | ||
.forEach(this.reviewSender::send); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...java/dev/iakunin/codexiabot/codexia/cron/ResendReviewsUntilDuplicatedIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package dev.iakunin.codexiabot.codexia.cron; | ||
|
||
import com.github.database.rider.core.api.dataset.DataSet; | ||
import com.github.database.rider.core.api.dataset.ExpectedDataSet; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.post; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching; | ||
import dev.iakunin.codexiabot.AbstractIntegrationTest; | ||
import dev.iakunin.codexiabot.util.WireMockServer; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.util.TestPropertyValues; | ||
import org.springframework.context.ApplicationContextInitializer; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
@ContextConfiguration(initializers = ResendReviewsUntilDuplicatedIntegrationTest.Initializer.class) | ||
public class ResendReviewsUntilDuplicatedIntegrationTest extends AbstractIntegrationTest { | ||
|
||
@Autowired | ||
private ResendReviewsUntilDuplicated cron; | ||
|
||
@Test | ||
@DataSet( | ||
value = "db-rider/codexia/cron/resend-reviews-until-duplicated/initial/emptyDatabase.yml", | ||
cleanBefore = true, cleanAfter = true | ||
) | ||
@ExpectedDataSet("db-rider/codexia/cron/resend-reviews-until-duplicated/expected/emptyDatabase.yml") | ||
public void emptyDatabase() { | ||
cron.run(); | ||
} | ||
|
||
@Test | ||
@DataSet( | ||
value = "db-rider/codexia/cron/resend-reviews-until-duplicated/initial/oneUnsuccessfulNotification.yml", | ||
cleanBefore = true, cleanAfter = true | ||
) | ||
@ExpectedDataSet("db-rider/codexia/cron/resend-reviews-until-duplicated/expected/oneUnsuccessfulNotification.yml") | ||
public void oneUnsuccessfulNotification() { | ||
cron.run(); | ||
} | ||
|
||
@Test | ||
@DataSet( | ||
value = "db-rider/codexia/cron/resend-reviews-until-duplicated/initial/oneSuccessfulNotificationWithDuplicatedCode.yml", | ||
cleanBefore = true, cleanAfter = true | ||
) | ||
@ExpectedDataSet("db-rider/codexia/cron/resend-reviews-until-duplicated/expected/oneSuccessfulNotificationWithDuplicatedCode.yml") | ||
public void oneSuccessfulNotificationWithDuplicatedCode() { | ||
cron.run(); | ||
} | ||
|
||
@Test | ||
@DataSet( | ||
value = "db-rider/codexia/cron/resend-reviews-until-duplicated/initial/happyPath.yml", | ||
cleanBefore = true, cleanAfter = true | ||
) | ||
@ExpectedDataSet("db-rider/codexia/cron/resend-reviews-until-duplicated/expected/happyPath.yml") | ||
public void happyPath() { | ||
WireMockServer.getInstance().stubFor( | ||
post(urlPathMatching("/p/\\d+/post")) | ||
.willReturn(aResponse() | ||
.withStatus(404) | ||
.withHeader("Content-Type", "application/text") | ||
.withBody("Review already exists.") | ||
) | ||
); | ||
|
||
cron.run(); | ||
} | ||
|
||
@AfterEach | ||
void after() { | ||
WireMockServer.getInstance().resetAll(); | ||
} | ||
|
||
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { | ||
@Override | ||
public void initialize(ConfigurableApplicationContext applicationContext) { | ||
TestPropertyValues.of( | ||
"app.codexia.base-url=" + WireMockServer.getInstance().baseUrl() | ||
).applyTo(applicationContext.getEnvironment()); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...esources/db-rider/codexia/cron/resend-reviews-until-duplicated/expected/emptyDatabase.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
codexia_project: [] | ||
|
||
codexia_review: [] | ||
|
||
codexia_review_notification: [] |
11 changes: 11 additions & 0 deletions
11
...st/resources/db-rider/codexia/cron/resend-reviews-until-duplicated/expected/happyPath.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
codexia_review_notification: | ||
- | ||
codexia_review_id: 1 | ||
status: SUCCESS | ||
response_code: 200 | ||
response: Some response | ||
- | ||
codexia_review_id: 1 | ||
status: SUCCESS | ||
response_code: 404 | ||
response: "Review already exists." |
6 changes: 6 additions & 0 deletions
6
.../resend-reviews-until-duplicated/expected/oneSuccessfulNotificationWithDuplicatedCode.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
codexia_review_notification: | ||
- | ||
codexia_review_id: 1 | ||
status: SUCCESS | ||
response_code: 404 | ||
response: Some response |
6 changes: 6 additions & 0 deletions
6
...der/codexia/cron/resend-reviews-until-duplicated/expected/oneUnsuccessfulNotification.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
codexia_review_notification: | ||
- | ||
codexia_review_id: 1 | ||
status: ERROR | ||
response_code: 500 | ||
response: Some response |
5 changes: 5 additions & 0 deletions
5
...resources/db-rider/codexia/cron/resend-reviews-until-duplicated/initial/emptyDatabase.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
codexia_project: [] | ||
|
||
codexia_review: [] | ||
|
||
codexia_review_notification: [] |
25 changes: 25 additions & 0 deletions
25
...est/resources/db-rider/codexia/cron/resend-reviews-until-duplicated/initial/happyPath.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
codexia_project: | ||
- | ||
id: 5 | ||
uuid: "groovy: UUID.randomUUID().toString()" | ||
external_id: 12 | ||
coordinates: "test-project1/test-repo1" | ||
author: "some-first-author" | ||
project_created_at: "2019-12-20 12:01:02" | ||
|
||
codexia_review: | ||
- | ||
id: 1 | ||
uuid: "groovy: UUID.randomUUID().toString()" | ||
codexia_project_id: 5 | ||
author: Review author | ||
reason: Review reason | ||
text: Review text | ||
|
||
codexia_review_notification: | ||
- | ||
uuid: "groovy: UUID.randomUUID().toString()" | ||
codexia_review_id: 1 | ||
status: SUCCESS | ||
response_code: 200 | ||
response: Some response |
25 changes: 25 additions & 0 deletions
25
...n/resend-reviews-until-duplicated/initial/oneSuccessfulNotificationWithDuplicatedCode.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
codexia_project: | ||
- | ||
id: 5 | ||
uuid: "groovy: UUID.randomUUID().toString()" | ||
external_id: 12 | ||
coordinates: "test-project1/test-repo1" | ||
author: "some-first-author" | ||
project_created_at: "2019-12-20 12:01:02" | ||
|
||
codexia_review: | ||
- | ||
id: 1 | ||
uuid: "groovy: UUID.randomUUID().toString()" | ||
codexia_project_id: 5 | ||
author: Review author | ||
reason: Review reason | ||
text: Review text | ||
|
||
codexia_review_notification: | ||
- | ||
uuid: "groovy: UUID.randomUUID().toString()" | ||
codexia_review_id: 1 | ||
status: SUCCESS | ||
response_code: 404 | ||
response: Some response |
25 changes: 25 additions & 0 deletions
25
...ider/codexia/cron/resend-reviews-until-duplicated/initial/oneUnsuccessfulNotification.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
codexia_project: | ||
- | ||
id: 5 | ||
uuid: "groovy: UUID.randomUUID().toString()" | ||
external_id: 12 | ||
coordinates: "test-project1/test-repo1" | ||
author: "some-first-author" | ||
project_created_at: "2019-12-20 12:01:02" | ||
|
||
codexia_review: | ||
- | ||
id: 1 | ||
uuid: "groovy: UUID.randomUUID().toString()" | ||
codexia_project_id: 5 | ||
author: Review author | ||
reason: Review reason | ||
text: Review text | ||
|
||
codexia_review_notification: | ||
- | ||
uuid: "groovy: UUID.randomUUID().toString()" | ||
codexia_review_id: 1 | ||
status: ERROR | ||
response_code: 500 | ||
response: Some response |
4e68e54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
85-a7ac8fa2
discovered insrc/main/java/dev/iakunin/codexiabot/codexia/cron/ResendReviewsUntilDuplicated.java
and submitted as #89. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.