-
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.
#74 - hackernews.cron.healthcheck.AllItems tests
- Loading branch information
Showing
10 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
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
65 changes: 64 additions & 1 deletion
65
...test/java/dev/iakunin/codexiabot/hackernews/cron/healthcheck/AllItemsIntegrationTest.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 |
---|---|---|
@@ -1,13 +1,76 @@ | ||
package dev.iakunin.codexiabot.hackernews.cron.healthcheck; | ||
|
||
import com.github.database.rider.core.api.dataset.DataSet; | ||
import com.github.database.rider.core.api.dataset.ExpectedDataSet; | ||
import dev.iakunin.codexiabot.AbstractIntegrationTest; | ||
import dev.iakunin.codexiabot.util.WireMockServer; | ||
import dev.iakunin.codexiabot.util.wiremock.Stub; | ||
import org.cactoos.io.ResourceOf; | ||
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 = AllItemsIntegrationTest.Initializer.class) | ||
public class AllItemsIntegrationTest extends AbstractIntegrationTest { | ||
|
||
@Autowired | ||
private AllItems allItems; | ||
|
||
// @todo #66 Implement AllItemsIntegrationTest | ||
@Test | ||
@DataSet( | ||
value = "db-rider/hackernews/cron/health-check/all-items/initial/emptyDatabase.yml", | ||
cleanBefore = true, cleanAfter = true | ||
) | ||
@ExpectedDataSet("db-rider/hackernews/cron/health-check/all-items/expected/emptyDatabase.yml") | ||
public void emptyDatabase() { | ||
allItems.run(); | ||
} | ||
|
||
@Test | ||
@DataSet( | ||
value = "db-rider/hackernews/cron/health-check/all-items/initial/oneActiveItem.yml", | ||
cleanBefore = true, cleanAfter = true | ||
) | ||
@ExpectedDataSet("db-rider/hackernews/cron/health-check/all-items/expected/oneActiveItem.yml") | ||
public void oneActiveItem() { | ||
WireMockServer.stub( | ||
new Stub( | ||
"/item/2222.json", | ||
new ResourceOf("wiremock/hackernews/cron/health-check/all-items/oneActiveItem.json") | ||
) | ||
); | ||
|
||
allItems.run(); | ||
} | ||
|
||
// @Test | ||
// @DataSet( | ||
// value = "db-rider/hackernews/cron/health-check/all-items/initial/oneDeletedItem.yml", | ||
// cleanBefore = true, cleanAfter = true | ||
// ) | ||
// @ExpectedDataSet("db-rider/hackernews/cron/health-check/all-items/expected/oneDeletedItem.yml") | ||
// public void oneDeletedItem() { | ||
// | ||
// // @todo wiremock | ||
// | ||
// allItems.run(); | ||
// } | ||
|
||
@AfterEach | ||
void after() { | ||
WireMockServer.getInstance().resetAll(); | ||
} | ||
|
||
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { | ||
@Override | ||
public void initialize(ConfigurableApplicationContext applicationContext) { | ||
TestPropertyValues.of( | ||
"app.hackernews.base-url=" + WireMockServer.getInstance().baseUrl() | ||
).applyTo(applicationContext.getEnvironment()); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...test/resources/db-rider/hackernews/cron/health-check/all-items/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,3 @@ | ||
github_repo_source: [] | ||
|
||
hackernews_item: [] |
15 changes: 15 additions & 0 deletions
15
...test/resources/db-rider/hackernews/cron/health-check/all-items/expected/oneActiveItem.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,15 @@ | ||
github_repo_source: | ||
- | ||
github_repo_id: 1 | ||
source: "HACKERNEWS" | ||
external_id: "2222" | ||
|
||
hackernews_item: | ||
- | ||
external_id: 2222 | ||
type: story | ||
by: smartmic | ||
title: Title for casbin | ||
url: https://github.com/casbin/casbin | ||
time: 2020-02-14 18:43:33 | ||
deleted: false |
5 changes: 5 additions & 0 deletions
5
src/test/resources/db-rider/hackernews/cron/health-check/all-items/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 @@ | ||
github_repo: [] | ||
|
||
github_repo_source: [] | ||
|
||
hackernews_item: [] |
26 changes: 26 additions & 0 deletions
26
src/test/resources/db-rider/hackernews/cron/health-check/all-items/initial/oneActiveItem.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,26 @@ | ||
github_repo: | ||
- | ||
id: 1 | ||
uuid: "groovy: UUID.randomUUID().toString()" | ||
external_id: 202275988 | ||
full_name: casbin/casbin | ||
html_url: https://github.com/casbin/casbin | ||
repo_created_at: 2019-08-14 04:42:36 | ||
|
||
github_repo_source: | ||
- | ||
uuid: "groovy: UUID.randomUUID().toString()" | ||
github_repo_id: 1 | ||
source: "HACKERNEWS" | ||
external_id: "2222" | ||
|
||
hackernews_item: | ||
- | ||
uuid: "groovy: UUID.randomUUID().toString()" | ||
external_id: 2222 | ||
type: story | ||
by: smartmic | ||
title: Title for casbin | ||
url: https://github.com/casbin/casbin | ||
time: 2020-02-14 18:43:33 | ||
deleted: false |
11 changes: 11 additions & 0 deletions
11
src/test/resources/wiremock/hackernews/cron/health-check/all-items/oneActiveItem.json
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 @@ | ||
{ | ||
"by": "smartmic", | ||
"id": 2222, | ||
"text": "Some awesome text.", | ||
"title": "Title for casbin", | ||
"url": "https://github.com/casbin/casbin", | ||
"time": 1231998962, | ||
"type": "story", | ||
"descendants": 0, | ||
"score": 2 | ||
} |