diff --git a/src/test/java/dev/iakunin/codexiabot/codexia/cron/ResendErroneousReviewsIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/codexia/cron/ResendErroneousReviewsIntegrationTest.java index aca7d472..45494392 100644 --- a/src/test/java/dev/iakunin/codexiabot/codexia/cron/ResendErroneousReviewsIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/codexia/cron/ResendErroneousReviewsIntegrationTest.java @@ -1,12 +1,21 @@ 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 com.github.tomakehurst.wiremock.client.WireMock; +import com.github.tomakehurst.wiremock.http.RequestMethod; import dev.iakunin.codexiabot.AbstractIntegrationTest; import dev.iakunin.codexiabot.util.WireMockServer; +import dev.iakunin.codexiabot.util.wiremock.Request; +import dev.iakunin.codexiabot.util.wiremock.Response; +import dev.iakunin.codexiabot.util.wiremock.Stub; 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.http.HttpStatus; import org.springframework.test.context.ContextConfiguration; @ContextConfiguration(initializers = ResendErroneousReviewsIntegrationTest.Initializer.class) @@ -15,7 +24,93 @@ public class ResendErroneousReviewsIntegrationTest extends AbstractIntegrationTe @Autowired private ResendErroneousReviews resendErroneousReviews; - // @todo #10 Implement ResendErroneousReviewsIntegrationTest + @Test + @DataSet( + value = "db-rider/codexia/cron/resend-erroneous/initial/emptyDatabase.yml", + cleanBefore = true, cleanAfter = true + ) + @ExpectedDataSet("db-rider/codexia/cron/resend-erroneous/expected/emptyDatabase.yml") + public void emptyDatabase() { + resendErroneousReviews.run(); + } + + @Test + @DataSet( + value = "db-rider/codexia/cron/resend-erroneous/initial/noErroneous.yml", + cleanBefore = true, cleanAfter = true + ) + @ExpectedDataSet("db-rider/codexia/cron/resend-erroneous/expected/noErroneous.yml") + public void noErroneous() { + resendErroneousReviews.run(); + } + + @Test + @DataSet( + value = "db-rider/codexia/cron/resend-erroneous/initial/oneErroneous.yml", + cleanBefore = true, cleanAfter = true + ) + @ExpectedDataSet("db-rider/codexia/cron/resend-erroneous/expected/oneErroneous.yml") + public void oneErroneous() { + WireMockServer.stub( + new Stub( + new Request(RequestMethod.POST, WireMock.urlPathMatching("/p/\\d+/post")), + new Response("Review successfully sent") + ) + ); + + resendErroneousReviews.run(); + } + + @Test + @DataSet( + value = "db-rider/codexia/cron/resend-erroneous/initial/oneSuccessfulOneErroneous.yml", + cleanBefore = true, cleanAfter = true + ) + @ExpectedDataSet("db-rider/codexia/cron/resend-erroneous/expected/oneSuccessfulOneErroneous.yml") + public void oneSuccessfulOneErroneous() { + WireMockServer.stub( + new Stub( + new Request(RequestMethod.POST, WireMock.urlPathMatching("/p/\\d+/post")), + new Response("Review successfully sent") + ) + ); + + resendErroneousReviews.run(); + } + + @Test + @DataSet( + value = "db-rider/codexia/cron/resend-erroneous/initial/twoErroneous.yml", + cleanBefore = true, cleanAfter = true + ) + @ExpectedDataSet("db-rider/codexia/cron/resend-erroneous/expected/twoErroneous.yml") + public void twoErroneous() { + WireMockServer.stub( + new Stub( + new Request(RequestMethod.POST, WireMock.urlPathMatching("/p/\\d+/post")), + new Response("Review successfully sent") + ) + ); + + resendErroneousReviews.run(); + } + + @Test + @DataSet( + value = "db-rider/codexia/cron/resend-erroneous/initial/oneErroneous.yml", + cleanBefore = true, cleanAfter = true + ) + @ExpectedDataSet("db-rider/codexia/cron/resend-erroneous/expected/reviewSentWith500.yml") + public void reviewSentWith500() { + WireMockServer.stub( + new Stub( + new Request(RequestMethod.POST, WireMock.urlPathMatching("/p/\\d+/post")), + new Response(HttpStatus.INTERNAL_SERVER_ERROR.value()) + ) + ); + + resendErroneousReviews.run(); + } @AfterEach void after() { diff --git a/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/emptyDatabase.yml b/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/emptyDatabase.yml new file mode 100644 index 00000000..94cd76f2 --- /dev/null +++ b/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/emptyDatabase.yml @@ -0,0 +1 @@ +codexia_review_notification: [] diff --git a/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/noErroneous.yml b/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/noErroneous.yml new file mode 100644 index 00000000..0ba06c27 --- /dev/null +++ b/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/noErroneous.yml @@ -0,0 +1,6 @@ +codexia_review_notification: + - + codexia_review_id: 2 + status: "SUCCESS" + response_code: 200 + response: "Successfully sent" diff --git a/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/oneErroneous.yml b/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/oneErroneous.yml new file mode 100644 index 00000000..9a68bb58 --- /dev/null +++ b/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/oneErroneous.yml @@ -0,0 +1,11 @@ +codexia_review_notification: + - + codexia_review_id: 2 + status: "ERROR" + response_code: 500 + response: "" + - + codexia_review_id: 2 + status: "SUCCESS" + response_code: 200 + response: "regex:^<200 OK OK,Review successfully sent.*" diff --git a/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/oneSuccessfulOneErroneous.yml b/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/oneSuccessfulOneErroneous.yml new file mode 100644 index 00000000..cc313c42 --- /dev/null +++ b/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/oneSuccessfulOneErroneous.yml @@ -0,0 +1,16 @@ +codexia_review_notification: + - + codexia_review_id: 2 + status: "SUCCESS" + response_code: 500 + response: "" + - + codexia_review_id: 3 + status: "ERROR" + response_code: 500 + response: "" + - + codexia_review_id: 3 + status: "SUCCESS" + response_code: 200 + response: "regex:^<200 OK OK,Review successfully sent.*" diff --git a/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/reviewSentWith500.yml b/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/reviewSentWith500.yml new file mode 100644 index 00000000..a0527898 --- /dev/null +++ b/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/reviewSentWith500.yml @@ -0,0 +1,11 @@ +codexia_review_notification: + - + codexia_review_id: 2 + status: "ERROR" + response_code: 500 + response: "" + - + codexia_review_id: 2 + status: "ERROR" + response_code: 500 + response: "" diff --git a/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/twoErroneous.yml b/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/twoErroneous.yml new file mode 100644 index 00000000..140d5936 --- /dev/null +++ b/src/test/resources/db-rider/codexia/cron/resend-erroneous/expected/twoErroneous.yml @@ -0,0 +1,21 @@ +codexia_review_notification: + - + codexia_review_id: 2 + status: "ERROR" + response_code: 500 + response: "" + - + codexia_review_id: 3 + status: "ERROR" + response_code: 500 + response: "" + - + codexia_review_id: 2 + status: "SUCCESS" + response_code: 200 + response: "regex:^<200 OK OK,Review successfully sent.*" + - + codexia_review_id: 3 + status: "SUCCESS" + response_code: 200 + response: "regex:^<200 OK OK,Review successfully sent.*" diff --git a/src/test/resources/db-rider/codexia/cron/resend-erroneous/initial/emptyDatabase.yml b/src/test/resources/db-rider/codexia/cron/resend-erroneous/initial/emptyDatabase.yml new file mode 100644 index 00000000..3c3b95b0 --- /dev/null +++ b/src/test/resources/db-rider/codexia/cron/resend-erroneous/initial/emptyDatabase.yml @@ -0,0 +1,5 @@ +codexia_project: [] + +codexia_review: [] + +codexia_review_notification: [] diff --git a/src/test/resources/db-rider/codexia/cron/resend-erroneous/initial/noErroneous.yml b/src/test/resources/db-rider/codexia/cron/resend-erroneous/initial/noErroneous.yml new file mode 100644 index 00000000..3f06ee88 --- /dev/null +++ b/src/test/resources/db-rider/codexia/cron/resend-erroneous/initial/noErroneous.yml @@ -0,0 +1,25 @@ +codexia_project: + - + id: 5 + uuid: "groovy: UUID.randomUUID().toString()" + external_id: 1222 + coordinates: "test-project1/test-repo1" + author: "some-first-author" + project_created_at: "2019-12-20 12:01:02" + +codexia_review: + - + id: 2 + 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: 2 + status: "SUCCESS" + response_code: 200 + response: "Successfully sent" diff --git a/src/test/resources/db-rider/codexia/cron/resend-erroneous/initial/oneErroneous.yml b/src/test/resources/db-rider/codexia/cron/resend-erroneous/initial/oneErroneous.yml new file mode 100644 index 00000000..67168f15 --- /dev/null +++ b/src/test/resources/db-rider/codexia/cron/resend-erroneous/initial/oneErroneous.yml @@ -0,0 +1,25 @@ +codexia_project: + - + id: 5 + uuid: "groovy: UUID.randomUUID().toString()" + external_id: 1222 + coordinates: "test-project1/test-repo1" + author: "some-first-author" + project_created_at: "2019-12-20 12:01:02" + +codexia_review: + - + id: 2 + 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: 2 + status: "ERROR" + response_code: 500 + response: "" diff --git a/src/test/resources/db-rider/codexia/cron/resend-erroneous/initial/oneSuccessfulOneErroneous.yml b/src/test/resources/db-rider/codexia/cron/resend-erroneous/initial/oneSuccessfulOneErroneous.yml new file mode 100644 index 00000000..35dfed84 --- /dev/null +++ b/src/test/resources/db-rider/codexia/cron/resend-erroneous/initial/oneSuccessfulOneErroneous.yml @@ -0,0 +1,38 @@ +codexia_project: + - + id: 5 + uuid: "groovy: UUID.randomUUID().toString()" + external_id: 1222 + coordinates: "test-project1/test-repo1" + author: "some-first-author" + project_created_at: "2019-12-20 12:01:02" + +codexia_review: + - + id: 2 + uuid: "groovy: UUID.randomUUID().toString()" + codexia_project_id: 5 + author: Review author + reason: Review reason + text: Review text + - + id: 3 + uuid: "groovy: UUID.randomUUID().toString()" + codexia_project_id: 5 + author: Another review author + reason: Another review reason + text: Another review text + +codexia_review_notification: + - + uuid: "groovy: UUID.randomUUID().toString()" + codexia_review_id: 2 + status: "SUCCESS" + response_code: 500 + response: "" + - + uuid: "groovy: UUID.randomUUID().toString()" + codexia_review_id: 3 + status: "ERROR" + response_code: 500 + response: "" diff --git a/src/test/resources/db-rider/codexia/cron/resend-erroneous/initial/twoErroneous.yml b/src/test/resources/db-rider/codexia/cron/resend-erroneous/initial/twoErroneous.yml new file mode 100644 index 00000000..1bc6b313 --- /dev/null +++ b/src/test/resources/db-rider/codexia/cron/resend-erroneous/initial/twoErroneous.yml @@ -0,0 +1,38 @@ +codexia_project: + - + id: 5 + uuid: "groovy: UUID.randomUUID().toString()" + external_id: 1222 + coordinates: "test-project1/test-repo1" + author: "some-first-author" + project_created_at: "2019-12-20 12:01:02" + +codexia_review: + - + id: 2 + uuid: "groovy: UUID.randomUUID().toString()" + codexia_project_id: 5 + author: Review author + reason: Review reason + text: Review text + - + id: 3 + uuid: "groovy: UUID.randomUUID().toString()" + codexia_project_id: 5 + author: Another review author + reason: Another review reason + text: Another review text + +codexia_review_notification: + - + uuid: "groovy: UUID.randomUUID().toString()" + codexia_review_id: 2 + status: "ERROR" + response_code: 500 + response: "" + - + uuid: "groovy: UUID.randomUUID().toString()" + codexia_review_id: 3 + status: "ERROR" + response_code: 500 + response: ""