Skip to content

Commit

Permalink
#55 - ResendErroneousReviewsIntegrationTest
Browse files Browse the repository at this point in the history
  • Loading branch information
iakunin committed May 14, 2020
1 parent 8f4a753 commit e4119cb
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
codexia_review_notification: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
codexia_review_notification:
-
codexia_review_id: 2
status: "SUCCESS"
response_code: 200
response: "Successfully sent"
Original file line number Diff line number Diff line change
@@ -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.*"
Original file line number Diff line number Diff line change
@@ -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.*"
Original file line number Diff line number Diff line change
@@ -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: ""
Original file line number Diff line number Diff line change
@@ -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.*"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
codexia_project: []

codexia_review: []

codexia_review_notification: []
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: 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"
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: 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: ""
Original file line number Diff line number Diff line change
@@ -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: ""
Original file line number Diff line number Diff line change
@@ -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: ""

0 comments on commit e4119cb

Please sign in to comment.