diff --git a/src/test/java/dev/iakunin/codexiabot/AbstractIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/AbstractIntegrationTest.java index 28aa2bb7..687e3946 100644 --- a/src/test/java/dev/iakunin/codexiabot/AbstractIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/AbstractIntegrationTest.java @@ -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; @@ -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 { @@ -58,8 +61,17 @@ 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 + // @todo: check all child classes + void after() { + WireMockServer.getInstance().resetAll(); + } } diff --git a/src/test/java/dev/iakunin/codexiabot/codexia/cron/CodexiaParserIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/codexia/cron/CodexiaParserIntegrationTest.java index f8b9d283..a44e232d 100644 --- a/src/test/java/dev/iakunin/codexiabot/codexia/cron/CodexiaParserIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/codexia/cron/CodexiaParserIntegrationTest.java @@ -20,7 +20,6 @@ AbstractIntegrationTest.TestConfig.class, GithubConfig.class, }) -@ContextConfiguration(initializers = CodexiaParserIntegrationTest.Initializer.class) public class CodexiaParserIntegrationTest extends AbstractIntegrationTest { @Autowired @@ -103,18 +102,4 @@ public void deletedProject() { codexiaParser.run(); } - - @AfterEach - void after() { - WireMockServer.getInstance().resetAll(); - } - - static class Initializer implements ApplicationContextInitializer { - @Override - public void initialize(ConfigurableApplicationContext applicationContext) { - TestPropertyValues.of( - "app.codexia.base-url=" + WireMockServer.getInstance().baseUrl() + "/codexia" - ).applyTo(applicationContext.getEnvironment()); - } - } } diff --git a/src/test/java/dev/iakunin/codexiabot/codexia/cron/ProjectsHealthCheckIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/codexia/cron/ProjectsHealthCheckIntegrationTest.java index 04188112..096d6ecb 100644 --- a/src/test/java/dev/iakunin/codexiabot/codexia/cron/ProjectsHealthCheckIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/codexia/cron/ProjectsHealthCheckIntegrationTest.java @@ -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 @@ -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" @@ -53,18 +52,4 @@ public void twoActiveProjectsInRepoButDeletedInCodexia() { projectsHealthCheck.run(); } - - @AfterEach - void after() { - WireMockServer.getInstance().resetAll(); - } - - static class Initializer implements ApplicationContextInitializer { - @Override - public void initialize(ConfigurableApplicationContext applicationContext) { - TestPropertyValues.of( - "app.codexia.base-url=" + WireMockServer.getInstance().baseUrl() - ).applyTo(applicationContext.getEnvironment()); - } - } } diff --git a/src/test/java/dev/iakunin/codexiabot/codexia/cron/ResendErroneousReviewsIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/codexia/cron/ResendErroneousReviewsIntegrationTest.java index 45494392..49ff7d70 100644 --- a/src/test/java/dev/iakunin/codexiabot/codexia/cron/ResendErroneousReviewsIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/codexia/cron/ResendErroneousReviewsIntegrationTest.java @@ -9,16 +9,10 @@ import dev.iakunin.codexiabot.util.wiremock.Request; import dev.iakunin.codexiabot.util.wiremock.Response; import dev.iakunin.codexiabot.util.wiremock.Stub; -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 = ResendErroneousReviewsIntegrationTest.Initializer.class) public class ResendErroneousReviewsIntegrationTest extends AbstractIntegrationTest { @Autowired @@ -53,7 +47,7 @@ public void noErroneous() { public void oneErroneous() { WireMockServer.stub( new Stub( - new Request(RequestMethod.POST, WireMock.urlPathMatching("/p/\\d+/post")), + new Request(RequestMethod.POST, WireMock.urlPathMatching("/codexia/p/\\d+/post")), new Response("Review successfully sent") ) ); @@ -70,7 +64,7 @@ public void oneErroneous() { public void oneSuccessfulOneErroneous() { WireMockServer.stub( new Stub( - new Request(RequestMethod.POST, WireMock.urlPathMatching("/p/\\d+/post")), + new Request(RequestMethod.POST, WireMock.urlPathMatching("/codexia/p/\\d+/post")), new Response("Review successfully sent") ) ); @@ -87,7 +81,7 @@ public void oneSuccessfulOneErroneous() { public void twoErroneous() { WireMockServer.stub( new Stub( - new Request(RequestMethod.POST, WireMock.urlPathMatching("/p/\\d+/post")), + new Request(RequestMethod.POST, WireMock.urlPathMatching("/codexia/p/\\d+/post")), new Response("Review successfully sent") ) ); @@ -104,25 +98,11 @@ public void twoErroneous() { public void reviewSentWith500() { WireMockServer.stub( new Stub( - new Request(RequestMethod.POST, WireMock.urlPathMatching("/p/\\d+/post")), + new Request(RequestMethod.POST, WireMock.urlPathMatching("/codexia/p/\\d+/post")), new Response(HttpStatus.INTERNAL_SERVER_ERROR.value()) ) ); resendErroneousReviews.run(); } - - @AfterEach - void after() { - WireMockServer.getInstance().resetAll(); - } - - static class Initializer implements ApplicationContextInitializer { - @Override - public void initialize(ConfigurableApplicationContext applicationContext) { - TestPropertyValues.of( - "app.codexia.base-url=" + WireMockServer.getInstance().baseUrl() - ).applyTo(applicationContext.getEnvironment()); - } - } } diff --git a/src/test/java/dev/iakunin/codexiabot/codexia/cron/ResendReviewsUntilDuplicatedIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/codexia/cron/ResendReviewsUntilDuplicatedIntegrationTest.java index 288ed3f3..1ef37c78 100644 --- a/src/test/java/dev/iakunin/codexiabot/codexia/cron/ResendReviewsUntilDuplicatedIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/codexia/cron/ResendReviewsUntilDuplicatedIntegrationTest.java @@ -9,16 +9,10 @@ import dev.iakunin.codexiabot.util.wiremock.Request; import dev.iakunin.codexiabot.util.wiremock.Response; import dev.iakunin.codexiabot.util.wiremock.Stub; -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 = ResendReviewsUntilDuplicatedIntegrationTest.Initializer.class) public class ResendReviewsUntilDuplicatedIntegrationTest extends AbstractIntegrationTest { @Autowired @@ -63,25 +57,11 @@ public void oneSuccessfulNotificationWithDuplicatedCode() { public void happyPath() { WireMockServer.stub( new Stub( - new Request(RequestMethod.POST, WireMock.urlPathMatching("/p/\\d+/post")), + new Request(RequestMethod.POST, WireMock.urlPathMatching("/codexia/p/\\d+/post")), new Response(HttpStatus.NOT_FOUND.value(), "Review already exists.") ) ); cron.run(); } - - @AfterEach - void after() { - WireMockServer.getInstance().resetAll(); - } - - static class Initializer implements ApplicationContextInitializer { - @Override - public void initialize(ConfigurableApplicationContext applicationContext) { - TestPropertyValues.of( - "app.codexia.base-url=" + WireMockServer.getInstance().baseUrl() - ).applyTo(applicationContext.getEnvironment()); - } - } } diff --git a/src/test/java/dev/iakunin/codexiabot/codexia/cron/SendReviewsIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/codexia/cron/SendReviewsIntegrationTest.java index 5d5de4be..97dd1cf5 100644 --- a/src/test/java/dev/iakunin/codexiabot/codexia/cron/SendReviewsIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/codexia/cron/SendReviewsIntegrationTest.java @@ -9,16 +9,10 @@ import dev.iakunin.codexiabot.util.wiremock.Request; import dev.iakunin.codexiabot.util.wiremock.Response; import dev.iakunin.codexiabot.util.wiremock.Stub; -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 = SendReviewsIntegrationTest.Initializer.class) public class SendReviewsIntegrationTest extends AbstractIntegrationTest { @Autowired @@ -43,7 +37,7 @@ public void noReviewsToSend() { public void reviewSuccessfullySent() { WireMockServer.stub( new Stub( - new Request(RequestMethod.POST, WireMock.urlPathMatching("/p/\\d+/post")), + new Request(RequestMethod.POST, WireMock.urlPathMatching("/codexia/p/\\d+/post")), new Response() ) ); @@ -60,7 +54,7 @@ public void reviewSuccessfullySent() { public void reviewSentWithDuplicate_responseBodyExists() { WireMockServer.stub( new Stub( - new Request(RequestMethod.POST, WireMock.urlPathMatching("/p/\\d+/post")), + new Request(RequestMethod.POST, WireMock.urlPathMatching("/codexia/p/\\d+/post")), new Response(HttpStatus.NOT_FOUND.value(), "Review already exists") ) ); @@ -77,7 +71,7 @@ public void reviewSentWithDuplicate_responseBodyExists() { public void reviewSentWithDuplicate_responseBodyEmpty() { WireMockServer.stub( new Stub( - new Request(RequestMethod.POST, WireMock.urlPathMatching("/p/\\d+/post")), + new Request(RequestMethod.POST, WireMock.urlPathMatching("/codexia/p/\\d+/post")), new Response(HttpStatus.NOT_FOUND.value()) ) ); @@ -94,25 +88,11 @@ public void reviewSentWithDuplicate_responseBodyEmpty() { public void reviewSentWith500() { WireMockServer.stub( new Stub( - new Request(RequestMethod.POST, WireMock.urlPathMatching("/p/\\d+/post")), + new Request(RequestMethod.POST, WireMock.urlPathMatching("/codexia/p/\\d+/post")), new Response(HttpStatus.INTERNAL_SERVER_ERROR.value()) ) ); sendReviews.run(); } - - @AfterEach - void after() { - WireMockServer.getInstance().resetAll(); - } - - static class Initializer implements ApplicationContextInitializer { - @Override - public void initialize(ConfigurableApplicationContext applicationContext) { - TestPropertyValues.of( - "app.codexia.base-url=" + WireMockServer.getInstance().baseUrl() - ).applyTo(applicationContext.getEnvironment()); - } - } } diff --git a/src/test/java/dev/iakunin/codexiabot/github/GithubModuleCreateRepoIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/github/GithubModuleCreateRepoIntegrationTest.java index 0aba2756..85266d11 100644 --- a/src/test/java/dev/iakunin/codexiabot/github/GithubModuleCreateRepoIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/github/GithubModuleCreateRepoIntegrationTest.java @@ -27,7 +27,6 @@ AbstractIntegrationTest.TestConfig.class, GithubConfig.class, }) -@ContextConfiguration(initializers = GithubModuleCreateRepoIntegrationTest.Initializer.class) public class GithubModuleCreateRepoIntegrationTest extends AbstractIntegrationTest { @Autowired @@ -160,13 +159,4 @@ public void notFoundInGithub() throws IOException { void after() { WireMockServer.getInstance().resetAll(); } - - static class Initializer implements ApplicationContextInitializer { - @Override - public void initialize(ConfigurableApplicationContext applicationContext) { - TestPropertyValues.of( - "app.codexia.base-url=" + WireMockServer.getInstance().baseUrl() + "/codexia" - ).applyTo(applicationContext.getEnvironment()); - } - } } diff --git a/src/test/java/dev/iakunin/codexiabot/github/cron/stat/loc/CodexiaIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/github/cron/stat/loc/CodexiaIntegrationTest.java index 89ba8fcc..a7be6b4d 100644 --- a/src/test/java/dev/iakunin/codexiabot/github/cron/stat/loc/CodexiaIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/github/cron/stat/loc/CodexiaIntegrationTest.java @@ -9,16 +9,10 @@ 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 = CodexiaIntegrationTest.Initializer.class) public class CodexiaIntegrationTest extends AbstractIntegrationTest { @Autowired @@ -43,7 +37,7 @@ public void emptyDatabase() { public void processedRepo() { WireMockServer.stub( new Stub( - new Request(WireMock.urlPathEqualTo("/loc")), + new Request(WireMock.urlPathEqualTo("/codetabs/loc")), new Response( new ResourceOf("wiremock/github/cron/stat/loc/happyPath.json") ) @@ -62,7 +56,7 @@ public void processedRepo() { public void happyPath() { WireMockServer.stub( new Stub( - new Request(WireMock.urlPathEqualTo("/loc")), + new Request(WireMock.urlPathEqualTo("/codetabs/loc")), new Response( new ResourceOf("wiremock/github/cron/stat/loc/happyPath.json") ) @@ -81,7 +75,7 @@ public void happyPath() { public void tooManyRequests() { WireMockServer.stub( new Stub( - new Request(WireMock.urlPathEqualTo("/loc")), + new Request(WireMock.urlPathEqualTo("/codetabs/loc")), new Response(HttpStatus.TOO_MANY_REQUESTS.value()) ) ); @@ -98,26 +92,11 @@ public void tooManyRequests() { public void codetabsException() { WireMockServer.stub( new Stub( - new Request(WireMock.urlPathEqualTo("/loc")), + new Request(WireMock.urlPathEqualTo("/codetabs/loc")), new Response(HttpStatus.INTERNAL_SERVER_ERROR.value()) ) ); linesOfCode.run(); } - - @AfterEach - void after() { - WireMockServer.getInstance().resetAll(); - } - - static class Initializer implements ApplicationContextInitializer { - @Override - public void initialize(ConfigurableApplicationContext applicationContext) { - TestPropertyValues.of( - "app.codetabs.base-url=" + WireMockServer.getInstance().baseUrl(), - "app.github.service.lines-of-code.delay=0" - ).applyTo(applicationContext.getEnvironment()); - } - } } diff --git a/src/test/java/dev/iakunin/codexiabot/github/cron/stat/loc/WithoutLocIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/github/cron/stat/loc/WithoutLocIntegrationTest.java index 518e5952..8a841304 100644 --- a/src/test/java/dev/iakunin/codexiabot/github/cron/stat/loc/WithoutLocIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/github/cron/stat/loc/WithoutLocIntegrationTest.java @@ -9,16 +9,10 @@ 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 = WithoutLocIntegrationTest.Initializer.class) public class WithoutLocIntegrationTest extends AbstractIntegrationTest { @Autowired @@ -53,7 +47,7 @@ public void processedRepo() { public void happyPath() { WireMockServer.stub( new Stub( - new Request(WireMock.urlPathEqualTo("/loc")), + new Request(WireMock.urlPathEqualTo("/codetabs/loc")), new Response( new ResourceOf("wiremock/github/cron/stat/loc/happyPath.json") ) @@ -72,7 +66,7 @@ public void happyPath() { public void tooManyRequests() { WireMockServer.stub( new Stub( - new Request(WireMock.urlPathEqualTo("/loc")), + new Request(WireMock.urlPathEqualTo("/codetabs/loc")), new Response(HttpStatus.TOO_MANY_REQUESTS.value()) ) ); @@ -89,26 +83,11 @@ public void tooManyRequests() { public void codetabsException() { WireMockServer.stub( new Stub( - new Request(WireMock.urlPathEqualTo("/loc")), + new Request(WireMock.urlPathEqualTo("/codetabs/loc")), new Response(HttpStatus.INTERNAL_SERVER_ERROR.value()) ) ); linesOfCode.run(); } - - @AfterEach - void after() { - WireMockServer.getInstance().resetAll(); - } - - static class Initializer implements ApplicationContextInitializer { - @Override - public void initialize(ConfigurableApplicationContext applicationContext) { - TestPropertyValues.of( - "app.codetabs.base-url=" + WireMockServer.getInstance().baseUrl(), - "app.github.service.lines-of-code.delay=0" - ).applyTo(applicationContext.getEnvironment()); - } - } } diff --git a/src/test/java/dev/iakunin/codexiabot/hackernews/cron/GapsFillerIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/hackernews/cron/GapsFillerIntegrationTest.java index c9c35c13..074066b4 100644 --- a/src/test/java/dev/iakunin/codexiabot/hackernews/cron/GapsFillerIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/hackernews/cron/GapsFillerIntegrationTest.java @@ -8,15 +8,9 @@ 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 @@ -41,7 +35,7 @@ public void emptyDatabase() { public void oneMissing() { WireMockServer.stub( new Stub( - new Request("/item/2.json"), + new Request("/hackernews/item/2.json"), new Response( new ResourceOf("wiremock/hackernews/cron/gaps-filler/2.json") ) @@ -60,7 +54,7 @@ public void oneMissing() { public void twoMissing() { WireMockServer.stub( new Stub( - new Request("/item/2.json"), + new Request("/hackernews/item/2.json"), new Response( new ResourceOf("wiremock/hackernews/cron/gaps-filler/2.json") ) @@ -68,7 +62,7 @@ public void twoMissing() { ); WireMockServer.stub( new Stub( - new Request("/item/4.json"), + new Request("/hackernews/item/4.json"), new Response( new ResourceOf("wiremock/hackernews/cron/gaps-filler/4.json") ) @@ -77,18 +71,4 @@ public void twoMissing() { gapsFiller.run(); } - - @AfterEach - void after() { - WireMockServer.getInstance().resetAll(); - } - - static class Initializer implements ApplicationContextInitializer { - @Override - public void initialize(ConfigurableApplicationContext applicationContext) { - TestPropertyValues.of( - "app.hackernews.base-url=" + WireMockServer.getInstance().baseUrl() - ).applyTo(applicationContext.getEnvironment()); - } - } } diff --git a/src/test/java/dev/iakunin/codexiabot/hackernews/cron/IncrementedParserIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/hackernews/cron/IncrementedParserIntegrationTest.java index 82050949..efa1d6f6 100644 --- a/src/test/java/dev/iakunin/codexiabot/hackernews/cron/IncrementedParserIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/hackernews/cron/IncrementedParserIntegrationTest.java @@ -14,9 +14,7 @@ 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 = IncrementedParserIntegrationTest.Initializer.class) public class IncrementedParserIntegrationTest extends AbstractIntegrationTest { @Autowired @@ -41,7 +39,7 @@ public void emptyDatabaseWithoutHackernews() { public void emptyDatabaseItemWithoutUrl() { WireMockServer.stub( new Stub( - new Request("/item/1.json"), + new Request("/hackernews/item/1.json"), new Response( new ResourceOf("wiremock/hackernews/cron/incremented-parser/itemWithoutUrl.json") ) @@ -60,7 +58,7 @@ public void emptyDatabaseItemWithoutUrl() { public void emptyDatabaseItemWithGithubUrl() { WireMockServer.stub( new Stub( - new Request("/item/1.json"), + new Request("/hackernews/item/1.json"), new Response( new ResourceOf("wiremock/hackernews/cron/incremented-parser/itemWithGithubUrl.json") ) @@ -79,7 +77,7 @@ public void emptyDatabaseItemWithGithubUrl() { public void emptyDatabaseItemWithGistUrl() { WireMockServer.stub( new Stub( - new Request("/item/1.json"), + new Request("/hackernews/item/1.json"), new Response( new ResourceOf("wiremock/hackernews/cron/incremented-parser/itemWithGistUrl.json") ) @@ -98,7 +96,7 @@ public void emptyDatabaseItemWithGistUrl() { public void emptyDatabaseEmptyResponse() { WireMockServer.stub( new Stub( - new Request("/item/1.json"), + new Request("/hackernews/item/1.json"), new Response("") ) ); @@ -115,7 +113,7 @@ public void emptyDatabaseEmptyResponse() { public void emptyDatabaseAndTwoItemsAtHackernews() { WireMockServer.stub( new Stub( - new Request("/item/1.json"), + new Request("/hackernews/item/1.json"), new Response( new ResourceOf("wiremock/hackernews/cron/incremented-parser/itemWithoutUrl.json") ) @@ -123,7 +121,7 @@ public void emptyDatabaseAndTwoItemsAtHackernews() { ); WireMockServer.stub( new Stub( - new Request("/item/2.json"), + new Request("/hackernews/item/2.json"), new Response( new ResourceOf("wiremock/hackernews/cron/incremented-parser/itemWithUrl.json") ) @@ -152,7 +150,7 @@ public void notEmptyDatabaseWithoutHackernews() { public void notEmptyDatabaseExistsInRepo() { WireMockServer.stub( new Stub( - new Request("/item/2.json"), + new Request("/hackernews/item/2.json"), new Response( new ResourceOf("wiremock/hackernews/cron/incremented-parser/itemWithoutUrl.json") ) @@ -161,18 +159,4 @@ public void notEmptyDatabaseExistsInRepo() { incrementedParser.run(); } - - @AfterEach - void after() { - WireMockServer.getInstance().resetAll(); - } - - static class Initializer implements ApplicationContextInitializer { - @Override - public void initialize(ConfigurableApplicationContext applicationContext) { - TestPropertyValues.of( - "app.hackernews.base-url=" + WireMockServer.getInstance().baseUrl() - ).applyTo(applicationContext.getEnvironment()); - } - } } diff --git a/src/test/java/dev/iakunin/codexiabot/hackernews/cron/RetryErroneousIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/hackernews/cron/RetryErroneousIntegrationTest.java index 745f3a99..d37ee35a 100644 --- a/src/test/java/dev/iakunin/codexiabot/hackernews/cron/RetryErroneousIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/hackernews/cron/RetryErroneousIntegrationTest.java @@ -8,15 +8,10 @@ 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; +import org.springframework.http.HttpStatus; -@ContextConfiguration(initializers = RetryErroneousIntegrationTest.Initializer.class) public class RetryErroneousIntegrationTest extends AbstractIntegrationTest { @Autowired @@ -51,8 +46,8 @@ public void oneUnprocessedItem() { public void hackernewsException() { WireMockServer.stub( new Stub( - new Request("/item/1.json"), - new Response(500) + new Request("/hackernews/item/1.json"), + new Response(HttpStatus.INTERNAL_SERVER_ERROR.value()) ) ); @@ -68,7 +63,7 @@ public void hackernewsException() { public void oneItem() { WireMockServer.stub( new Stub( - new Request("/item/1.json"), + new Request("/hackernews/item/1.json"), new Response( new ResourceOf("wiremock/hackernews/cron/retry-erroneous/1.json") ) @@ -87,7 +82,7 @@ public void oneItem() { public void twoItems() { WireMockServer.stub( new Stub( - new Request("/item/1.json"), + new Request("/hackernews/item/1.json"), new Response( new ResourceOf("wiremock/hackernews/cron/retry-erroneous/1.json") ) @@ -95,7 +90,7 @@ public void twoItems() { ); WireMockServer.stub( new Stub( - new Request("/item/2.json"), + new Request("/hackernews/item/2.json"), new Response( new ResourceOf("wiremock/hackernews/cron/retry-erroneous/2.json") ) @@ -104,18 +99,4 @@ public void twoItems() { retryErroneous.run(); } - - @AfterEach - void after() { - WireMockServer.getInstance().resetAll(); - } - - static class Initializer implements ApplicationContextInitializer { - @Override - public void initialize(ConfigurableApplicationContext applicationContext) { - TestPropertyValues.of( - "app.hackernews.base-url=" + WireMockServer.getInstance().baseUrl() - ).applyTo(applicationContext.getEnvironment()); - } - } } diff --git a/src/test/java/dev/iakunin/codexiabot/hackernews/cron/healthcheck/AllItemsIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/hackernews/cron/healthcheck/AllItemsIntegrationTest.java index 5ffc826d..e02cdc03 100644 --- a/src/test/java/dev/iakunin/codexiabot/hackernews/cron/healthcheck/AllItemsIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/hackernews/cron/healthcheck/AllItemsIntegrationTest.java @@ -9,16 +9,10 @@ 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 @@ -43,7 +37,7 @@ public void emptyDatabase() { public void oneActiveItem() { WireMockServer.stub( new Stub( - "/item/2222.json", + "/hackernews/item/2222.json", new ResourceOf("wiremock/hackernews/cron/health-check/activeItem.json") ) ); @@ -60,7 +54,7 @@ public void oneActiveItem() { public void twoActiveItems() { WireMockServer.stub( new Stub( - new Request(WireMock.urlPathMatching("/item/\\d+\\.json")), + new Request(WireMock.urlPathMatching("/hackernews/item/\\d+\\.json")), new Response( new ResourceOf("wiremock/hackernews/cron/health-check/activeItem.json") ) @@ -79,7 +73,7 @@ public void twoActiveItems() { public void oneDeletedItem() { WireMockServer.stub( new Stub( - "/item/2222.json", + "/hackernews/item/2222.json", new ResourceOf("wiremock/hackernews/cron/health-check/deletedItem.json") ) ); @@ -96,7 +90,7 @@ public void oneDeletedItem() { public void twoDeletedItems() { WireMockServer.stub( new Stub( - new Request(WireMock.urlPathMatching("/item/\\d+\\.json")), + new Request(WireMock.urlPathMatching("/hackernews/item/\\d+\\.json")), new Response( new ResourceOf("wiremock/hackernews/cron/health-check/deletedItem.json") ) @@ -115,25 +109,11 @@ public void twoDeletedItems() { public void hackernewsException() { WireMockServer.stub( new Stub( - "/item/2222.json", + "/hackernews/item/2222.json", new Response(HttpStatus.INTERNAL_SERVER_ERROR.value()) ) ); allItems.run(); } - - @AfterEach - void after() { - WireMockServer.getInstance().resetAll(); - } - - static class Initializer implements ApplicationContextInitializer { - @Override - public void initialize(ConfigurableApplicationContext applicationContext) { - TestPropertyValues.of( - "app.hackernews.base-url=" + WireMockServer.getInstance().baseUrl() - ).applyTo(applicationContext.getEnvironment()); - } - } } diff --git a/src/test/java/dev/iakunin/codexiabot/hackernews/cron/healthcheck/CodexiaItemsIntegrationTest.java b/src/test/java/dev/iakunin/codexiabot/hackernews/cron/healthcheck/CodexiaItemsIntegrationTest.java index ab4c3119..23207575 100644 --- a/src/test/java/dev/iakunin/codexiabot/hackernews/cron/healthcheck/CodexiaItemsIntegrationTest.java +++ b/src/test/java/dev/iakunin/codexiabot/hackernews/cron/healthcheck/CodexiaItemsIntegrationTest.java @@ -9,16 +9,10 @@ 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 = CodexiaItemsIntegrationTest.Initializer.class) public class CodexiaItemsIntegrationTest extends AbstractIntegrationTest { @Autowired @@ -53,7 +47,7 @@ public void withoutCodexiaSource() { public void oneActiveItem() { WireMockServer.stub( new Stub( - "/item/2222.json", + "/hackernews/item/2222.json", new ResourceOf("wiremock/hackernews/cron/health-check/activeItem.json") ) ); @@ -70,7 +64,7 @@ public void oneActiveItem() { public void twoActiveItems() { WireMockServer.stub( new Stub( - new Request(WireMock.urlPathMatching("/item/\\d+\\.json")), + new Request(WireMock.urlPathMatching("/hackernews/item/\\d+\\.json")), new Response( new ResourceOf("wiremock/hackernews/cron/health-check/activeItem.json") ) @@ -89,7 +83,7 @@ public void twoActiveItems() { public void oneDeletedItem() { WireMockServer.stub( new Stub( - "/item/2222.json", + "/hackernews/item/2222.json", new ResourceOf("wiremock/hackernews/cron/health-check/deletedItem.json") ) ); @@ -106,7 +100,7 @@ public void oneDeletedItem() { public void twoDeletedItems() { WireMockServer.stub( new Stub( - new Request(WireMock.urlPathMatching("/item/\\d+\\.json")), + new Request(WireMock.urlPathMatching("/hackernews/item/\\d+\\.json")), new Response( new ResourceOf("wiremock/hackernews/cron/health-check/deletedItem.json") ) @@ -125,25 +119,11 @@ public void twoDeletedItems() { public void hackernewsException() { WireMockServer.stub( new Stub( - "/item/2222.json", + "/hackernews/item/2222.json", new Response(HttpStatus.INTERNAL_SERVER_ERROR.value()) ) ); codexiaItems.run(); } - - @AfterEach - void after() { - WireMockServer.getInstance().resetAll(); - } - - static class Initializer implements ApplicationContextInitializer { - @Override - public void initialize(ConfigurableApplicationContext applicationContext) { - TestPropertyValues.of( - "app.hackernews.base-url=" + WireMockServer.getInstance().baseUrl() - ).applyTo(applicationContext.getEnvironment()); - } - } } diff --git a/src/test/resources/wiremock/codexia/cron/projects-health-check/twoActiveProjectsInRepoButDeletedInCodexia.json b/src/test/resources/wiremock/codexia/cron/projects-health-check/twoActiveProjectsInRepoButDeletedInCodexia.json index f677791d..c177f567 100644 --- a/src/test/resources/wiremock/codexia/cron/projects-health-check/twoActiveProjectsInRepoButDeletedInCodexia.json +++ b/src/test/resources/wiremock/codexia/cron/projects-health-check/twoActiveProjectsInRepoButDeletedInCodexia.json @@ -1,5 +1,5 @@ { - "id": {{ replace request.requestLine.pathSegments.[1] '.json' '' }}, + "id": {{ replace request.requestLine.pathSegments.[2] '.json' '' }}, "coordinates": "test-project/test-repo", "platform": "github", "submitter": {