From cdd991616d4dba7af062ab3a2c99c89a7443a6a9 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 28 Mar 2016 11:36:40 +0200 Subject: [PATCH] Added JUnit rule test --- stub-runner/stub-runner-junit/build.gradle | 2 + .../junit/AccurestRuleJUnitTest.java | 51 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleJUnitTest.java diff --git a/stub-runner/stub-runner-junit/build.gradle b/stub-runner/stub-runner-junit/build.gradle index d7156d14b9..fa14799646 100644 --- a/stub-runner/stub-runner-junit/build.gradle +++ b/stub-runner/stub-runner-junit/build.gradle @@ -12,4 +12,6 @@ dependencies { testCompile 'cglib:cglib-nodep:2.2' testCompile 'org.objenesis:objenesis:2.1' testCompile 'ch.qos.logback:logback-classic:1.1.3' + testCompile 'org.assertj:assertj-core:2.3.0' + testCompile 'org.apache.commons:commons-io:1.3.2' } diff --git a/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleJUnitTest.java b/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleJUnitTest.java new file mode 100644 index 0000000000..b22f1f60fe --- /dev/null +++ b/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleJUnitTest.java @@ -0,0 +1,51 @@ +package io.codearte.accurest.stubrunner.junit; + +import java.io.InputStream; +import java.net.URI; + +import org.apache.commons.io.IOUtils; +import org.junit.ClassRule; +import org.junit.Test; + +import static org.assertj.core.api.BDDAssertions.then; + +/** + * @author Marcin Grzejszczak + */ +public class AccurestRuleJUnitTest { + + @ClassRule public static AccurestRule rule = new AccurestRule() + .repoRoot(repoRoot()) + .downloadStub("io.codearte.accurest.stubs", "loanIssuance") + .downloadStub("io.codearte.accurest.stubs:fraudDetectionServer"); + + @Test + public void should_start_wiremock_servers() throws Exception { + // expect: 'WireMocks are running' + then(rule.findStubUrl("io.codearte.accurest.stubs", "loanIssuance")).isNotNull(); + then(rule.findStubUrl("loanIssuance")).isNotNull(); + then(rule.findStubUrl("loanIssuance")).isEqualTo(rule.findStubUrl("io.codearte.accurest.stubs", "loanIssuance")); + then(rule.findStubUrl("io.codearte.accurest.stubs:fraudDetectionServer")).isNotNull(); + // and: + then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue(); + then(rule.findAllRunningStubs().isPresent("io.codearte.accurest.stubs", "fraudDetectionServer")).isTrue(); + then(rule.findAllRunningStubs().isPresent("io.codearte.accurest.stubs:fraudDetectionServer")).isTrue(); + // and: 'Stubs were registered' + then(httpGet(rule.findStubUrl("loanIssuance").toString() + "/name")).isEqualTo("loanIssuance"); + then(httpGet(rule.findStubUrl("fraudDetectionServer").toString() + "/name")).isEqualTo("fraudDetectionServer"); + } + + private static String repoRoot() { + try { + return AccurestRuleJUnitTest.class.getResource("/m2repo").toURI().toString(); + } catch (Exception e) { + return ""; + } + } + + private String httpGet(String url) throws Exception { + try(InputStream stream = URI.create(url).toURL().openStream()) { + return IOUtils.toString(stream); + } + } +}