Skip to content

Commit

Permalink
#19 - Integration test for SendReviews cron
Browse files Browse the repository at this point in the history
  • Loading branch information
iakunin committed Apr 16, 2020
1 parent 02f52c2 commit f80fe0d
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 1 deletion.
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());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
codexia_review: []

codexia_review_notification: []
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: ""
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: ""
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
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,.*"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
codexia_review: []
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
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
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
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
5 changes: 4 additions & 1 deletion src/test/resources/dbunit.yml
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

0 comments on commit f80fe0d

Please sign in to comment.