Skip to content

Commit

Permalink
(#74) Merge pull request #166 from iakunin/74
Browse files Browse the repository at this point in the history
#6 74 - AllItemsIntegrationTest
  • Loading branch information
iakunin committed May 7, 2020
2 parents 717a95f + 5e0a842 commit 497e15b
Show file tree
Hide file tree
Showing 16 changed files with 253 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 GapsFiller: 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 @@ -20,6 +20,8 @@ public class AllItems implements Runnable {

private final HackernewsModule hackernews;

// @todo #74 AllItems: 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() {
try (Stream<GithubRepoSource> sources = this.github.findAllRepoSources(Source.HACKERNEWS)) {
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,99 @@
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.Response;
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.http.HttpStatus;
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() {
WireMockServer.stub(
new Stub(
"/item/2222.json",
new ResourceOf("wiremock/hackernews/cron/health-check/all-items/oneDeletedItem.json")
)
);

allItems.run();
}

@Test
@DataSet(
value = "db-rider/hackernews/cron/health-check/all-items/initial/hackernewsException.yml",
cleanBefore = true, cleanAfter = true
)
@ExpectedDataSet("db-rider/hackernews/cron/health-check/all-items/expected/hackernewsException.yml")
public void hackernewsException() {
WireMockServer.stub(
new Stub(
"/item/2222.json",
new Response(HttpStatus.INTERNAL_SERVER_ERROR.value())
)
);

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,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,16 @@
github_repo_source:
-
github_repo_id: 1
source: "HACKERNEWS"
external_id: "2222"
deleted_at: regex:^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{1,6}$

hackernews_item:
-
external_id: 2222
type: story
by: smartmic
title: Title for casbin
url: https://github.com/casbin/casbin
time: 2009-01-15 05:56:02
deleted: true
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,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,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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"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,
"deleted": true
}

3 comments on commit 497e15b

@0pdd
Copy link

@0pdd 0pdd commented on 497e15b May 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 66-1eb62372 disappeared from src/test/java/dev/iakunin/codexiabot/hackernews/cron/healthcheck/AllItemsIntegrationTest.java, that's why I closed #74. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link

@0pdd 0pdd commented on 497e15b May 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 74-721dfe5c discovered in src/main/java/dev/iakunin/codexiabot/hackernews/cron/healthcheck/AllItems.java and submitted as #167. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 497e15b May 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 74-fdc38b44 discovered in src/main/java/dev/iakunin/codexiabot/hackernews/cron/GapsFiller.java and submitted as #168. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.