Skip to content

Commit

Permalink
#74 - hackernews.cron.healthcheck.AllItems tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iakunin committed May 7, 2020
1 parent 717a95f commit 9a6ef3b
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class GapsFiller implements Runnable {

private final Writer writer;

// @todo #74 get rid of this @Transactional spike
// to do so it's necessary to get rid of Stream<> in repository
@Transactional // https://stackoverflow.com/a/40593697/3456163
public void run() {
this.repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@FeignClient(
name = "hackernewsClient",
url = "https://hacker-news.firebaseio.com/v0/",
url = "${app.hackernews.base-url}",
configuration = GeneralClientConfiguration.class
)
public interface HackernewsClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@
"type": "java.lang.String",
"description": "Base url of Codetabs."
},
{
"name": "app.hackernews.base-url",
"type": "java.lang.String",
"description": "Base url of Hackernews."
},
{
"name": "app.github.service.lines-of-code.delay",
"type": "java.lang.Integer",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ app.reddit.client-id=<insert-your-reddit-client-id-here>
app.reddit.client-secret=<insert-your-reddit-client-secret-here>

app.codetabs.base-url=https://api.codetabs.com/v1/
app.hackernews.base-url=https://hacker-news.firebaseio.com/v0/

app.github.service.lines-of-code.delay=5000
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());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
github_repo_source: []

hackernews_item: []
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
github_repo: []

github_repo_source: []

hackernews_item: []
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
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
}

0 comments on commit 9a6ef3b

Please sign in to comment.