Skip to content

Commit

Permalink
#62 - GapsFillerIntegrationTest
Browse files Browse the repository at this point in the history
  • Loading branch information
iakunin committed May 13, 2020
1 parent b2df59c commit 4941057
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,13 +1,94 @@
package dev.iakunin.codexiabot.hackernews.cron;

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.Request;
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.test.context.ContextConfiguration;

@ContextConfiguration(initializers = GapsFillerIntegrationTest.Initializer.class)
public class GapsFillerIntegrationTest extends AbstractIntegrationTest {

@Autowired
private GapsFiller gapsFiller;

// @todo #10 Implement GapsFillerIntegrationTest
@Test
@DataSet(
value = "db-rider/hackernews/cron/gaps-filler/initial/emptyDatabase.yml",
cleanBefore = true, cleanAfter = true
)
@ExpectedDataSet("db-rider/hackernews/cron/gaps-filler/expected/emptyDatabase.yml")
public void emptyDatabase() {
gapsFiller.run();
}

@Test
@DataSet(
value = "db-rider/hackernews/cron/gaps-filler/initial/oneMissing.yml",
cleanBefore = true, cleanAfter = true
)
@ExpectedDataSet("db-rider/hackernews/cron/gaps-filler/expected/oneMissing.yml")
public void oneMissing() {
WireMockServer.stub(
new Stub(
new Request("/item/2.json"),
new Response(
new ResourceOf("wiremock/hackernews/cron/gaps-filler/2.json")
)
)
);

gapsFiller.run();
}

@Test
@DataSet(
value = "db-rider/hackernews/cron/gaps-filler/initial/twoMissing.yml",
cleanBefore = true, cleanAfter = true
)
@ExpectedDataSet("db-rider/hackernews/cron/gaps-filler/expected/twoMissing.yml")
public void twoMissing() {
WireMockServer.stub(
new Stub(
new Request("/item/2.json"),
new Response(
new ResourceOf("wiremock/hackernews/cron/gaps-filler/2.json")
)
)
);
WireMockServer.stub(
new Stub(
new Request("/item/4.json"),
new Response(
new ResourceOf("wiremock/hackernews/cron/gaps-filler/4.json")
)
)
);

gapsFiller.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 @@
hackernews_item: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
hackernews_item:
-
external_id: 1
type: story
by: test1author
title: Title for test1
url: test 1 url
time: 2009-01-15 05:56:17
deleted: false
-
external_id: 3
type: story
by: test3author
title: Title for test3
url: test 3 url
time: 2009-01-15 05:58:12
deleted: false
-
external_id: 2
type: story
by: test2author
title: Title for test2
url: test 2 url
time: 2009-01-15 06:12:49
deleted: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
hackernews_item:
-
external_id: 1
type: story
by: test1author
title: Title for test1
url: test 1 url
time: 2009-01-15 05:56:17
deleted: false
-
external_id: 3
type: story
by: test3author
title: Title for test3
url: test 3 url
time: 2009-01-15 05:58:12
deleted: false
-
external_id: 5
type: story
by: test5author
title: Title for test5
url: test 5 url
time: 2009-01-15 06:32:52
deleted: false
-
external_id: 2
type: story
by: test2author
title: Title for test2
url: test 2 url
time: 2009-01-15 06:12:49
deleted: false
-
external_id: 4
type: story
by: test4author
title: Title for test4
url: test 4 url
time: 2009-01-15 06:12:53
deleted: false
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hackernews_item: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
hackernews_item:
-
external_id: 1
type: story
by: test1author
title: Title for test1
url: test 1 url
time: 2009-01-15 05:56:17
deleted: false
-
external_id: 3
type: story
by: test3author
title: Title for test3
url: test 3 url
time: 2009-01-15 05:58:12
deleted: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
hackernews_item:
-
external_id: 1
type: story
by: test1author
title: Title for test1
url: test 1 url
time: 2009-01-15 05:56:17
deleted: false
-
external_id: 3
type: story
by: test3author
title: Title for test3
url: test 3 url
time: 2009-01-15 05:58:12
deleted: false
-
external_id: 5
type: story
by: test5author
title: Title for test5
url: test 5 url
time: 2009-01-15 06:32:52
deleted: false
11 changes: 11 additions & 0 deletions src/test/resources/wiremock/hackernews/cron/gaps-filler/2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"by": "test2author",
"id": 2,
"text": "Some awesome text for test 2.",
"title": "Title for test2",
"url": "test 2 url",
"time": 1231999969,
"type": "story",
"descendants": 0,
"score": 2
}
11 changes: 11 additions & 0 deletions src/test/resources/wiremock/hackernews/cron/gaps-filler/4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"by": "test4author",
"id": 4,
"text": "Some awesome text for test 4.",
"title": "Title for test4",
"url": "test 4 url",
"time": 1231999973,
"type": "story",
"descendants": 30,
"score": 55
}

0 comments on commit 4941057

Please sign in to comment.