-
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.
#19 - Integration test for SendReviews cron
- Loading branch information
Showing
12 changed files
with
251 additions
and
1 deletion.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
src/test/java/dev/iakunin/codexiabot/codexia/cron/SendReviewsIntegrationTest.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,115 @@ | ||
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.ok; | ||
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 = SendReviewsIntegrationTest.Initializer.class) | ||
public class SendReviewsIntegrationTest extends AbstractIntegrationTest { | ||
|
||
@Autowired | ||
private SendReviews sendReviews; | ||
|
||
@Test | ||
@DataSet( | ||
value = "db-rider/codexia/cron/send-reviews/initial/noReviewsToSend.yml", | ||
cleanBefore = true, cleanAfter = true | ||
) | ||
@ExpectedDataSet("db-rider/codexia/cron/send-reviews/expected/noReviewsToSend.yml") | ||
public void noReviewsToSend() { | ||
sendReviews.run(); | ||
} | ||
|
||
@Test | ||
@DataSet( | ||
value = "db-rider/codexia/cron/send-reviews/initial/reviewSuccessfullySent.yml", | ||
cleanBefore = true, cleanAfter = true | ||
) | ||
@ExpectedDataSet("db-rider/codexia/cron/send-reviews/expected/reviewSuccessfullySent.yml") | ||
public void reviewSuccessfullySent() { | ||
WireMockServer.getInstance().stubFor( | ||
post(urlPathMatching("/p/\\d+/post")) | ||
.willReturn(ok()) | ||
); | ||
|
||
sendReviews.run(); | ||
} | ||
|
||
@Test | ||
@DataSet( | ||
value = "db-rider/codexia/cron/send-reviews/initial/reviewSentWithDuplicate_responseBodyExists.yml", | ||
cleanAfter = true, cleanBefore = true | ||
) | ||
@ExpectedDataSet("db-rider/codexia/cron/send-reviews/expected/reviewSentWithDuplicate_responseBodyExists.yml") | ||
public void reviewSentWithDuplicate_responseBodyExists() { | ||
WireMockServer.getInstance().stubFor( | ||
post(urlPathMatching("/p/\\d+/post")) | ||
.willReturn(aResponse() | ||
.withStatus(404) | ||
.withBody("Review already exists") | ||
) | ||
); | ||
|
||
sendReviews.run(); | ||
} | ||
|
||
@Test | ||
@DataSet( | ||
value = "db-rider/codexia/cron/send-reviews/initial/reviewSentWithDuplicate_responseBodyEmpty.yml", | ||
cleanAfter = true, cleanBefore = true | ||
) | ||
@ExpectedDataSet("db-rider/codexia/cron/send-reviews/expected/reviewSentWithDuplicate_responseBodyEmpty.yml") | ||
public void reviewSentWithDuplicate_responseBodyEmpty() { | ||
WireMockServer.getInstance().stubFor( | ||
post(urlPathMatching("/p/\\d+/post")) | ||
.willReturn(aResponse() | ||
.withStatus(404) | ||
) | ||
); | ||
|
||
sendReviews.run(); | ||
} | ||
|
||
@Test | ||
@DataSet( | ||
value = "db-rider/codexia/cron/send-reviews/initial/reviewSentWith500.yml", | ||
cleanAfter = true, cleanBefore = true | ||
) | ||
@ExpectedDataSet("db-rider/codexia/cron/send-reviews/expected/reviewSentWith500.yml") | ||
public void reviewSentWith500() { | ||
WireMockServer.getInstance().stubFor( | ||
post(urlPathMatching("/p/\\d+/post")) | ||
.willReturn(aResponse() | ||
.withStatus(500) | ||
) | ||
); | ||
|
||
sendReviews.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()); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/test/resources/db-rider/codexia/cron/send-reviews/expected/noReviewsToSend.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,3 @@ | ||
codexia_review: [] | ||
|
||
codexia_review_notification: [] |
14 changes: 14 additions & 0 deletions
14
src/test/resources/db-rider/codexia/cron/send-reviews/expected/reviewSentWith500.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,14 @@ | ||
codexia_review: | ||
- | ||
id: 1 | ||
codexia_project_id: 5 | ||
author: Review author | ||
reason: Review reason | ||
text: Review text | ||
|
||
codexia_review_notification: | ||
- | ||
codexia_review_id: 1 | ||
status: "ERROR" | ||
response_code: 500 | ||
response: "" |
14 changes: 14 additions & 0 deletions
14
...db-rider/codexia/cron/send-reviews/expected/reviewSentWithDuplicate_responseBodyEmpty.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,14 @@ | ||
codexia_review: | ||
- | ||
id: 1 | ||
codexia_project_id: 5 | ||
author: Review author | ||
reason: Review reason | ||
text: Review text | ||
|
||
codexia_review_notification: | ||
- | ||
codexia_review_id: 1 | ||
status: "SUCCESS" | ||
response_code: 404 | ||
response: "" |
14 changes: 14 additions & 0 deletions
14
...b-rider/codexia/cron/send-reviews/expected/reviewSentWithDuplicate_responseBodyExists.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,14 @@ | ||
codexia_review: | ||
- | ||
id: 1 | ||
codexia_project_id: 5 | ||
author: Review author | ||
reason: Review reason | ||
text: Review text | ||
|
||
codexia_review_notification: | ||
- | ||
codexia_review_id: 1 | ||
status: "SUCCESS" | ||
response_code: 404 | ||
response: Review already exists |
14 changes: 14 additions & 0 deletions
14
src/test/resources/db-rider/codexia/cron/send-reviews/expected/reviewSuccessfullySent.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,14 @@ | ||
codexia_review: | ||
- | ||
id: 1 | ||
codexia_project_id: 5 | ||
author: Review author | ||
reason: Review reason | ||
text: Review text | ||
|
||
codexia_review_notification: | ||
- | ||
codexia_review_id: 1 | ||
status: "SUCCESS" | ||
response_code: 200 | ||
response: "regex:^<200 OK OK,.*" |
1 change: 1 addition & 0 deletions
1
src/test/resources/db-rider/codexia/cron/send-reviews/initial/noReviewsToSend.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 @@ | ||
codexia_review: [] |
18 changes: 18 additions & 0 deletions
18
src/test/resources/db-rider/codexia/cron/send-reviews/initial/reviewSentWith500.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,18 @@ | ||
codexia_project: | ||
- | ||
id: 5 | ||
uuid: "groovy: UUID.randomUUID().toString()" | ||
external_id: 12 | ||
coordinates: "test-project1/test-repo1" | ||
author: "some-first-author" | ||
author_id: 44 | ||
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 |
18 changes: 18 additions & 0 deletions
18
.../db-rider/codexia/cron/send-reviews/initial/reviewSentWithDuplicate_responseBodyEmpty.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,18 @@ | ||
codexia_project: | ||
- | ||
id: 5 | ||
uuid: "groovy: UUID.randomUUID().toString()" | ||
external_id: 12 | ||
coordinates: "test-project1/test-repo1" | ||
author: "some-first-author" | ||
author_id: 44 | ||
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 |
18 changes: 18 additions & 0 deletions
18
...db-rider/codexia/cron/send-reviews/initial/reviewSentWithDuplicate_responseBodyExists.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,18 @@ | ||
codexia_project: | ||
- | ||
id: 5 | ||
uuid: "groovy: UUID.randomUUID().toString()" | ||
external_id: 12 | ||
coordinates: "test-project1/test-repo1" | ||
author: "some-first-author" | ||
author_id: 44 | ||
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 |
18 changes: 18 additions & 0 deletions
18
src/test/resources/db-rider/codexia/cron/send-reviews/initial/reviewSuccessfullySent.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,18 @@ | ||
codexia_project: | ||
- | ||
id: 5 | ||
uuid: "groovy: UUID.randomUUID().toString()" | ||
external_id: 12 | ||
coordinates: "test-project1/test-repo1" | ||
author: "some-first-author" | ||
author_id: 44 | ||
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 |
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
cacheConnection: true | ||
cacheTableNames: true | ||
caseInsensitiveStrategy: !!com.github.database.rider.core.api.configuration.Orthography 'LOWERCASE' | ||
cacheConnection: false | ||
properties: | ||
datatypeFactory: !!dev.iakunin.codexiabot.dbunit.CustomPostgresqlDataTypeFactory {} | ||
batchedStatements: true | ||
caseSensitiveTableNames: false |