Skip to content

Commit

Permalink
(#55) Merge pull request #180 from iakunin/55
Browse files Browse the repository at this point in the history
  • Loading branch information
iakunin authored May 14, 2020
2 parents 8b8a6e0 + 5ab14a1 commit 4187d38
Show file tree
Hide file tree
Showing 63 changed files with 1,936 additions and 370 deletions.
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ services:
- "/var/wiremock/lib/*:/var/wiremock/extensions/*"
- "com.github.tomakehurst.wiremock.standalone.WireMockServerRunner"
- "--local-response-templating"
- "--port"
- "80"
- "--port=80"
- "--verbose"
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
@AllArgsConstructor(onConstructor_={@Autowired})
public final class ResendErroneousReviews implements Runnable {

private final CodexiaReviewNotificationRepository codexiaReviewNotificationRepository;
private final CodexiaReviewNotificationRepository repository;

private final ReviewSender reviewSender;
private final ReviewSender sender;

public void run() {
this.codexiaReviewNotificationRepository
this.repository
.findAllByLastStatus(CodexiaReviewNotification.Status.ERROR)
.stream()
.map(CodexiaReviewNotification::getCodexiaReview)
.forEach(this.reviewSender::send);
.forEach(this.sender::send);
}
}
32 changes: 15 additions & 17 deletions src/main/java/dev/iakunin/codexiabot/reddit/config/Client.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.iakunin.codexiabot.reddit.config;

import net.dean.jraw.RedditClient;
import net.dean.jraw.http.NetworkAdapter;
import net.dean.jraw.http.OkHttpNetworkAdapter;
import net.dean.jraw.http.UserAgent;
import net.dean.jraw.oauth.Credentials;
Expand All @@ -21,23 +20,22 @@ public RedditClient redditClient(
@Value("${app.reddit.client-id}") String clientId,
@Value("${app.reddit.client-secret}") String clientSecret
) {
UserAgent userAgent = new UserAgent(
"bot",
"dev.iakunin.codexiabot",
"v0.1",
username
final RedditClient client = OAuthHelper.automatic(
new OkHttpNetworkAdapter(
new UserAgent(
"bot",
"dev.iakunin.codexiabot",
"v0.1",
username
)
),
Credentials.script(
username,
password,
clientId,
clientSecret
)
);

Credentials credentials = Credentials.script(
username,
password,
clientId,
clientSecret
);

NetworkAdapter adapter = new OkHttpNetworkAdapter(userAgent);

final RedditClient client = OAuthHelper.automatic(adapter, credentials);
client.setLogHttp(false);

return client;
Expand Down
15 changes: 13 additions & 2 deletions src/test/java/dev/iakunin/codexiabot/AbstractIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.github.database.rider.spring.api.DBRider;
import com.github.javafaker.Faker;
import dev.iakunin.codexiabot.util.PostgreSQLContainer;
import dev.iakunin.codexiabot.util.WireMockServer;
import lombok.extern.slf4j.Slf4j;
import net.dean.jraw.RedditClient;
import org.junit.jupiter.api.AfterEach;
import org.kohsuke.github.GitHub;
import org.mockito.Mockito;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -26,7 +28,8 @@
@TestPropertySource(properties = {
"app.scheduling.enable=false",
"spring.liquibase.enabled=false",
"spring.main.allow-bean-definition-overriding=true"
"spring.main.allow-bean-definition-overriding=true",
"app.github.service.lines-of-code.delay=0",
})
abstract public class AbstractIntegrationTest {

Expand Down Expand Up @@ -58,8 +61,16 @@ public void initialize(ConfigurableApplicationContext configurableApplicationCon
),
"app.database.name=" + PostgreSQLContainer.getInstance().getDatabaseName(),
"spring.datasource.username=" + PostgreSQLContainer.getInstance().getUsername(),
"spring.datasource.password=" + PostgreSQLContainer.getInstance().getPassword()
"spring.datasource.password=" + PostgreSQLContainer.getInstance().getPassword(),
"app.codexia.base-url=" + WireMockServer.getInstance().baseUrl() + "/codexia",
"app.codetabs.base-url=" + WireMockServer.getInstance().baseUrl() + "/codetabs",
"app.hackernews.base-url=" + WireMockServer.getInstance().baseUrl() + "/hackernews"
).applyTo(configurableApplicationContext.getEnvironment());
}
}

@AfterEach
void after() {
WireMockServer.getInstance().resetAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,23 @@
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.config.GithubConfig;
import dev.iakunin.codexiabot.util.WireMockServer;
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.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ContextConfiguration;

@SpringBootTest(classes = {
AbstractIntegrationTest.TestConfig.class,
CodexiaParserIntegrationTest.TestConfig.class,
GithubConfig.class,
})
@ContextConfiguration(initializers = CodexiaParserIntegrationTest.Initializer.class)
public class CodexiaParserIntegrationTest extends AbstractIntegrationTest {

@Autowired
Expand Down Expand Up @@ -109,31 +102,4 @@ public void deletedProject() {

codexiaParser.run();
}

@AfterEach
void after() {
WireMockServer.getInstance().resetAll();
}

static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
TestPropertyValues.of(
"app.codexia.base-url=" + WireMockServer.getInstance().baseUrl() + "/codexia"
).applyTo(applicationContext.getEnvironment());
}
}

@Configuration
@Import(CodexiaBotApplication.class)
static class TestConfig {
@SneakyThrows
@Bean
public GitHub gitHub() {
return new GitHubBuilder()
.withEndpoint(
WireMockServer.getInstance().baseUrl() + "/github"
).build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,82 @@
package dev.iakunin.codexiabot.codexia.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.config.GithubConfig;
import dev.iakunin.codexiabot.util.WireMockServer;
import org.junit.jupiter.api.AfterEach;
import dev.iakunin.codexiabot.util.wiremock.Stub;
import org.cactoos.io.ResourceOf;
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;
import org.springframework.boot.test.context.SpringBootTest;

@ContextConfiguration(initializers = MissingFillerIntegrationTest.Initializer.class)
@SpringBootTest(classes = {
AbstractIntegrationTest.TestConfig.class,
GithubConfig.class,
})
public class MissingFillerIntegrationTest extends AbstractIntegrationTest {

@Autowired
private MissingFiller missingFiller;

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

@AfterEach
void after() {
WireMockServer.getInstance().resetAll();
@Test
@DataSet(
value = "db-rider/codexia/cron/missing-filler/initial/oneWithGithubRepo.yml",
cleanBefore = true, cleanAfter = true
)
@ExpectedDataSet("db-rider/codexia/cron/missing-filler/expected/oneWithGithubRepo.yml")
public void oneWithGithubRepo() {
missingFiller.run();
}

static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
TestPropertyValues.of(
"app.codexia.base-url=" + WireMockServer.getInstance().baseUrl()
).applyTo(applicationContext.getEnvironment());
}
@Test
@DataSet(
value = "db-rider/codexia/cron/missing-filler/initial/oneWithoutGithubRepo.yml",
cleanBefore = true, cleanAfter = true
)
@ExpectedDataSet("db-rider/codexia/cron/missing-filler/expected/oneWithoutGithubRepo.yml")
public void oneWithoutGithubRepo() {
WireMockServer.stub(
new Stub(
"/github/repos/instaloader/instaloader",
new ResourceOf("wiremock/codexia/cron/missing-filler/instaloader.json")
)
);

missingFiller.run();
}

@Test
@DataSet(
value = "db-rider/codexia/cron/missing-filler/initial/twoWithoutGithubRepo.yml",
cleanBefore = true, cleanAfter = true
)
@ExpectedDataSet("db-rider/codexia/cron/missing-filler/expected/twoWithoutGithubRepo.yml")
public void twoWithoutGithubRepo() {
WireMockServer.stub(
new Stub(
"/github/repos/instaloader/instaloader",
new ResourceOf("wiremock/codexia/cron/missing-filler/instaloader.json")
)
);
WireMockServer.stub(
new Stub(
"/github/repos/arpit9667/algorithms-js",
new ResourceOf("wiremock/codexia/cron/missing-filler/algorithms-js.json")
)
);

missingFiller.run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.ContextConfiguration;

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

@Autowired
Expand All @@ -42,7 +41,7 @@ public void noActiveProjectsInRepo() {
public void twoActiveProjectsInRepoButDeletedInCodexia() {
WireMockServer.stub(
new Stub(
new Request(WireMock.urlPathMatching("/p/\\d+\\.json")),
new Request(WireMock.urlPathMatching("/codexia/p/\\d+\\.json")),
new Response(
new ResourceOf(
"wiremock/codexia/cron/projects-health-check/twoActiveProjectsInRepoButDeletedInCodexia.json"
Expand All @@ -53,18 +52,4 @@ public void twoActiveProjectsInRepoButDeletedInCodexia() {

projectsHealthCheck.run();
}

@AfterEach
void after() {
WireMockServer.getInstance().resetAll();
}

static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
TestPropertyValues.of(
"app.codexia.base-url=" + WireMockServer.getInstance().baseUrl()
).applyTo(applicationContext.getEnvironment());
}
}
}
Loading

4 comments on commit 4187d38

@0pdd
Copy link

@0pdd 0pdd commented on 4187d38 May 14, 2020

Choose a reason for hiding this comment

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

Puzzle 10-5ffba3e0 disappeared from src/test/java/dev/iakunin/codexiabot/codexia/cron/MissingFillerIntegrationTest.java, that's why I closed #55. 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 4187d38 May 14, 2020

Choose a reason for hiding this comment

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

Puzzle 10-c5423926 disappeared from src/test/java/dev/iakunin/codexiabot/codexia/cron/ResendErroneousReviewsIntegrationTest.java, that's why I closed #56. 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 4187d38 May 14, 2020

Choose a reason for hiding this comment

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

Puzzle 10-e69f73e3 disappeared from src/test/java/dev/iakunin/codexiabot/github/cron/stat/GithubIntegrationTest.java, that's why I closed #59. 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 4187d38 May 14, 2020

Choose a reason for hiding this comment

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

Puzzle 10-d5175438 disappeared from src/test/java/dev/iakunin/codexiabot/reddit/cron/ParserIntegrationTest.java, that's why I closed #60. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.