From 2ae095d8bf07fd1bc5947daff07c39f6c22a2fce Mon Sep 17 00:00:00 2001 From: iakunin Date: Thu, 14 May 2020 13:31:33 +0300 Subject: [PATCH] #55 - GithubIntegrationTest --- .../cron/stat/GithubIntegrationTest.java | 92 ++++++++++++- .../stat/github/expected/emptyDatabase.yml | 1 + .../github/expected/githubIoException.yml | 1 + .../cron/stat/github/expected/happyPath.yml | 5 + .../stat/github/expected/notCodexiaSource.yml | 1 + .../stat/github/initial/emptyDatabase.yml | 6 + .../stat/github/initial/githubIoException.yml | 17 +++ .../cron/stat/github/initial/happyPath.yml | 17 +++ .../stat/github/initial/notCodexiaSource.yml | 17 +++ .../github/cron/stat/github/instaloader.json | 123 ++++++++++++++++++ 10 files changed, 279 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/db-rider/github/cron/stat/github/expected/emptyDatabase.yml create mode 100644 src/test/resources/db-rider/github/cron/stat/github/expected/githubIoException.yml create mode 100644 src/test/resources/db-rider/github/cron/stat/github/expected/happyPath.yml create mode 100644 src/test/resources/db-rider/github/cron/stat/github/expected/notCodexiaSource.yml create mode 100644 src/test/resources/db-rider/github/cron/stat/github/initial/emptyDatabase.yml create mode 100644 src/test/resources/db-rider/github/cron/stat/github/initial/githubIoException.yml create mode 100644 src/test/resources/db-rider/github/cron/stat/github/initial/happyPath.yml create mode 100644 src/test/resources/db-rider/github/cron/stat/github/initial/notCodexiaSource.yml create mode 100644 src/test/resources/wiremock/github/cron/stat/github/instaloader.json diff --git a/src/test/java/dev/iakunin/codexiabot/github/cron/stat/GithubIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/github/cron/stat/GithubIntegrationTest.java index 12b8152a..f0b82fbe 100644 --- a/src/test/java/dev/iakunin/codexiabot/github/cron/stat/GithubIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/github/cron/stat/GithubIntegrationTest.java @@ -1,13 +1,103 @@ package dev.iakunin.codexiabot.github.cron.stat; +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.CodexiaBotApplication; +import dev.iakunin.codexiabot.util.WireMockServer; +import dev.iakunin.codexiabot.util.wiremock.Response; +import dev.iakunin.codexiabot.util.wiremock.Stub; +import lombok.SneakyThrows; +import org.cactoos.io.ResourceOf; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.kohsuke.github.GitHub; +import org.kohsuke.github.GitHubBuilder; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.http.HttpStatus; +@SpringBootTest(classes = { + AbstractIntegrationTest.TestConfig.class, + GithubIntegrationTest.TestConfig.class, +}) public class GithubIntegrationTest extends AbstractIntegrationTest { @Autowired private Github github; - // @todo #10 Implement GithubIntegrationTest + @Test + @DataSet( + value = "db-rider/github/cron/stat/github/initial/emptyDatabase.yml", + cleanBefore = true, cleanAfter = true + ) + @ExpectedDataSet("db-rider/github/cron/stat/github/expected/emptyDatabase.yml") + public void emptyDatabase() { + github.run(); + } + @Test + @DataSet( + value = "db-rider/github/cron/stat/github/initial/notCodexiaSource.yml", + cleanBefore = true, cleanAfter = true + ) + @ExpectedDataSet("db-rider/github/cron/stat/github/expected/notCodexiaSource.yml") + public void notCodexiaSource() { + github.run(); + } + + @Test + @DataSet( + value = "db-rider/github/cron/stat/github/initial/happyPath.yml", + cleanBefore = true, cleanAfter = true + ) + @ExpectedDataSet("db-rider/github/cron/stat/github/expected/happyPath.yml") + public void oneWithoutGithubRepo() { + WireMockServer.stub( + new Stub( + "/repos/instaloader/instaloader", + new ResourceOf("wiremock/github/cron/stat/github/instaloader.json") + ) + ); + + github.run(); + } + + @Test + @DataSet( + value = "db-rider/github/cron/stat/github/initial/githubIoException.yml", + cleanBefore = true, cleanAfter = true + ) + @ExpectedDataSet("db-rider/github/cron/stat/github/expected/githubIoException.yml") + public void githubIoException() { + WireMockServer.stub( + new Stub( + "/repos/instaloader/instaloader", + new Response(HttpStatus.INTERNAL_SERVER_ERROR.value()) + ) + ); + + github.run(); + } + + @AfterEach + void after() { + WireMockServer.getInstance().resetAll(); + } + + @Configuration + @Import(CodexiaBotApplication.class) + static class TestConfig { + @SneakyThrows + @Bean + public GitHub gitHub() { + return new GitHubBuilder() + .withEndpoint( + WireMockServer.getInstance().baseUrl() + ).build(); + } + } } diff --git a/src/test/resources/db-rider/github/cron/stat/github/expected/emptyDatabase.yml b/src/test/resources/db-rider/github/cron/stat/github/expected/emptyDatabase.yml new file mode 100644 index 00000000..3e661246 --- /dev/null +++ b/src/test/resources/db-rider/github/cron/stat/github/expected/emptyDatabase.yml @@ -0,0 +1 @@ +github_repo_stat: [] diff --git a/src/test/resources/db-rider/github/cron/stat/github/expected/githubIoException.yml b/src/test/resources/db-rider/github/cron/stat/github/expected/githubIoException.yml new file mode 100644 index 00000000..3e661246 --- /dev/null +++ b/src/test/resources/db-rider/github/cron/stat/github/expected/githubIoException.yml @@ -0,0 +1 @@ +github_repo_stat: [] diff --git a/src/test/resources/db-rider/github/cron/stat/github/expected/happyPath.yml b/src/test/resources/db-rider/github/cron/stat/github/expected/happyPath.yml new file mode 100644 index 00000000..21a2a71b --- /dev/null +++ b/src/test/resources/db-rider/github/cron/stat/github/expected/happyPath.yml @@ -0,0 +1,5 @@ +github_repo_stat: + - + github_repo_id: 1 + type: "GITHUB_API" + stat: '{"description":"Download pictures (or videos) along with their captions and other metadata from Instagram.","pushedAt":[2020,5,11,18,27,23],"language":"Python","homepage":"https://instaloader.github.io/","forks":281,"watchers":1561,"stars":1561,"type":"GITHUB_API"}' diff --git a/src/test/resources/db-rider/github/cron/stat/github/expected/notCodexiaSource.yml b/src/test/resources/db-rider/github/cron/stat/github/expected/notCodexiaSource.yml new file mode 100644 index 00000000..3e661246 --- /dev/null +++ b/src/test/resources/db-rider/github/cron/stat/github/expected/notCodexiaSource.yml @@ -0,0 +1 @@ +github_repo_stat: [] diff --git a/src/test/resources/db-rider/github/cron/stat/github/initial/emptyDatabase.yml b/src/test/resources/db-rider/github/cron/stat/github/initial/emptyDatabase.yml new file mode 100644 index 00000000..244c2fa6 --- /dev/null +++ b/src/test/resources/db-rider/github/cron/stat/github/initial/emptyDatabase.yml @@ -0,0 +1,6 @@ +github_repo: [] + +github_repo_source: [] + +github_repo_stat: [] + diff --git a/src/test/resources/db-rider/github/cron/stat/github/initial/githubIoException.yml b/src/test/resources/db-rider/github/cron/stat/github/initial/githubIoException.yml new file mode 100644 index 00000000..44edeebe --- /dev/null +++ b/src/test/resources/db-rider/github/cron/stat/github/initial/githubIoException.yml @@ -0,0 +1,17 @@ +github_repo: + - + id: 1 + uuid: "groovy: UUID.randomUUID().toString()" + external_id: 61200117 + full_name: instaloader/instaloader + html_url: https://github.com/instaloader/instaloader + repo_created_at: 2019-08-14 04:42:36 + +github_repo_source: + - + uuid: "groovy: UUID.randomUUID().toString()" + github_repo_id: 1 + source: "CODEXIA" + external_id: "2222" + +github_repo_stat: [] diff --git a/src/test/resources/db-rider/github/cron/stat/github/initial/happyPath.yml b/src/test/resources/db-rider/github/cron/stat/github/initial/happyPath.yml new file mode 100644 index 00000000..44edeebe --- /dev/null +++ b/src/test/resources/db-rider/github/cron/stat/github/initial/happyPath.yml @@ -0,0 +1,17 @@ +github_repo: + - + id: 1 + uuid: "groovy: UUID.randomUUID().toString()" + external_id: 61200117 + full_name: instaloader/instaloader + html_url: https://github.com/instaloader/instaloader + repo_created_at: 2019-08-14 04:42:36 + +github_repo_source: + - + uuid: "groovy: UUID.randomUUID().toString()" + github_repo_id: 1 + source: "CODEXIA" + external_id: "2222" + +github_repo_stat: [] diff --git a/src/test/resources/db-rider/github/cron/stat/github/initial/notCodexiaSource.yml b/src/test/resources/db-rider/github/cron/stat/github/initial/notCodexiaSource.yml new file mode 100644 index 00000000..97e3c740 --- /dev/null +++ b/src/test/resources/db-rider/github/cron/stat/github/initial/notCodexiaSource.yml @@ -0,0 +1,17 @@ +github_repo: + - + id: 1 + uuid: "groovy: UUID.randomUUID().toString()" + external_id: 202275988 + full_name: test1/test1 + html_url: https://github.com/test1/test1 + 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" + +github_repo_stat: [] diff --git a/src/test/resources/wiremock/github/cron/stat/github/instaloader.json b/src/test/resources/wiremock/github/cron/stat/github/instaloader.json new file mode 100644 index 00000000..de5621cd --- /dev/null +++ b/src/test/resources/wiremock/github/cron/stat/github/instaloader.json @@ -0,0 +1,123 @@ +{ + "id": 61200117, + "node_id": "MDEwOlJlcG9zaXRvcnk2MTIwMDExNw==", + "name": "instaloader", + "full_name": "instaloader/instaloader", + "private": false, + "owner": { + "login": "instaloader", + "id": 37333353, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjM3MzMzMzUz", + "avatar_url": "https://avatars0.githubusercontent.com/u/37333353?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/instaloader", + "html_url": "https://github.com/instaloader", + "followers_url": "https://api.github.com/users/instaloader/followers", + "following_url": "https://api.github.com/users/instaloader/following{/other_user}", + "gists_url": "https://api.github.com/users/instaloader/gists{/gist_id}", + "starred_url": "https://api.github.com/users/instaloader/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/instaloader/subscriptions", + "organizations_url": "https://api.github.com/users/instaloader/orgs", + "repos_url": "https://api.github.com/users/instaloader/repos", + "events_url": "https://api.github.com/users/instaloader/events{/privacy}", + "received_events_url": "https://api.github.com/users/instaloader/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/instaloader/instaloader", + "description": "Download pictures (or videos) along with their captions and other metadata from Instagram.", + "fork": false, + "url": "https://api.github.com/repos/instaloader/instaloader", + "forks_url": "https://api.github.com/repos/instaloader/instaloader/forks", + "keys_url": "https://api.github.com/repos/instaloader/instaloader/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/instaloader/instaloader/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/instaloader/instaloader/teams", + "hooks_url": "https://api.github.com/repos/instaloader/instaloader/hooks", + "issue_events_url": "https://api.github.com/repos/instaloader/instaloader/issues/events{/number}", + "events_url": "https://api.github.com/repos/instaloader/instaloader/events", + "assignees_url": "https://api.github.com/repos/instaloader/instaloader/assignees{/user}", + "branches_url": "https://api.github.com/repos/instaloader/instaloader/branches{/branch}", + "tags_url": "https://api.github.com/repos/instaloader/instaloader/tags", + "blobs_url": "https://api.github.com/repos/instaloader/instaloader/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/instaloader/instaloader/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/instaloader/instaloader/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/instaloader/instaloader/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/instaloader/instaloader/statuses/{sha}", + "languages_url": "https://api.github.com/repos/instaloader/instaloader/languages", + "stargazers_url": "https://api.github.com/repos/instaloader/instaloader/stargazers", + "contributors_url": "https://api.github.com/repos/instaloader/instaloader/contributors", + "subscribers_url": "https://api.github.com/repos/instaloader/instaloader/subscribers", + "subscription_url": "https://api.github.com/repos/instaloader/instaloader/subscription", + "commits_url": "https://api.github.com/repos/instaloader/instaloader/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/instaloader/instaloader/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/instaloader/instaloader/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/instaloader/instaloader/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/instaloader/instaloader/contents/{+path}", + "compare_url": "https://api.github.com/repos/instaloader/instaloader/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/instaloader/instaloader/merges", + "archive_url": "https://api.github.com/repos/instaloader/instaloader/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/instaloader/instaloader/downloads", + "issues_url": "https://api.github.com/repos/instaloader/instaloader/issues{/number}", + "pulls_url": "https://api.github.com/repos/instaloader/instaloader/pulls{/number}", + "milestones_url": "https://api.github.com/repos/instaloader/instaloader/milestones{/number}", + "notifications_url": "https://api.github.com/repos/instaloader/instaloader/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/instaloader/instaloader/labels{/name}", + "releases_url": "https://api.github.com/repos/instaloader/instaloader/releases{/id}", + "deployments_url": "https://api.github.com/repos/instaloader/instaloader/deployments", + "created_at": "2016-06-15T10:40:37Z", + "updated_at": "2020-05-13T13:33:20Z", + "pushed_at": "2020-05-11T18:27:23Z", + "git_url": "git://github.com/instaloader/instaloader.git", + "ssh_url": "git@github.com:instaloader/instaloader.git", + "clone_url": "https://github.com/instaloader/instaloader.git", + "svn_url": "https://github.com/instaloader/instaloader", + "homepage": "https://instaloader.github.io/", + "size": 1477, + "stargazers_count": 1561, + "watchers_count": 1561, + "language": "Python", + "has_issues": true, + "has_projects": false, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "forks_count": 281, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 54, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 281, + "open_issues": 54, + "watchers": 1561, + "default_branch": "master", + "temp_clone_token": null, + "organization": { + "login": "instaloader", + "id": 37333353, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjM3MzMzMzUz", + "avatar_url": "https://avatars0.githubusercontent.com/u/37333353?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/instaloader", + "html_url": "https://github.com/instaloader", + "followers_url": "https://api.github.com/users/instaloader/followers", + "following_url": "https://api.github.com/users/instaloader/following{/other_user}", + "gists_url": "https://api.github.com/users/instaloader/gists{/gist_id}", + "starred_url": "https://api.github.com/users/instaloader/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/instaloader/subscriptions", + "organizations_url": "https://api.github.com/users/instaloader/orgs", + "repos_url": "https://api.github.com/users/instaloader/repos", + "events_url": "https://api.github.com/users/instaloader/events{/privacy}", + "received_events_url": "https://api.github.com/users/instaloader/received_events", + "type": "Organization", + "site_admin": false + }, + "network_count": 281, + "subscribers_count": 79 +}