Added JUnit rule test

This commit is contained in:
Marcin Grzejszczak
2016-03-28 11:36:40 +02:00
parent 987613f8a7
commit cdd991616d
2 changed files with 53 additions and 0 deletions

View File

@@ -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'
}

View File

@@ -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);
}
}
}