Skip to content

Commit

Permalink
feat: completed the import of the Scala modules to the new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Holshausen committed Apr 29, 2019
1 parent 29bba8c commit 6b4639f
Show file tree
Hide file tree
Showing 69 changed files with 514 additions and 833 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,12 @@ class PactBuilder extends BaseBuilder {
* @param options Optional map of options for the run
* @param closure
*/
@SuppressWarnings('InvertedIfElse')
void runTestAndVerify(Map options = [:], Closure closure) {
PactVerificationResult result = runTest(options, closure)
if (result != PactVerificationResult.Ok.INSTANCE) {
if (!(result instanceof PactVerificationResult.Ok)) {
if (result instanceof PactVerificationResult.Error) {
if (result.mockServerState != PactVerificationResult.Ok.INSTANCE) {
if (!(result.mockServerState instanceof PactVerificationResult.Ok)) {
throw new AssertionError('Pact Test function failed with an exception, possibly due to ' +
result.mockServerState, result.error)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ExampleFileUploadSpec extends Specification {
}

then:
result == PactVerificationResult.Ok.INSTANCE
result instanceof PactVerificationResult.Ok
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class ExampleFormPostTest {
willRespondWith(status: 201, body: 'form posted ok', headers: ['Content-Type': 'text/plain'])
}

assert PactVerificationResult.Ok.INSTANCE == service.runTest {
assert service.runTest {
def http = new HTTPBuilder( 'http://localhost:8000' )
http.post(path: '/path', body: [number: '12345678'], requestContentType: ContentType.URLENC) { resp ->
assert resp.statusLine.statusCode == 201
}
}
} instanceof PactVerificationResult.Ok
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ExampleGroovyConsumerPactTest {
def data = aliceResponse.data.text()
assert data == '"That is some good Mallory."'
}
assert result == PactVerificationResult.Ok.INSTANCE
assert result instanceof PactVerificationResult.Ok

result = bobService.runTest { mockServer, context ->
def client = new RESTClient(mockServer.url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ExampleGroovyConsumerV3PactTest {
def data = aliceResponse.data.text()
assert data == '"That is some good Mallory."'
}
assert result == PactVerificationResult.Ok.INSTANCE
assert result instanceof PactVerificationResult.Ok

def pactFile = new File("${PactConsumerConfig.INSTANCE.pactDirectory}/V3Consumer-V3Service.json")
def json = new JsonSlurper().parse(pactFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class GroovyConsumerMatchersPactSpec extends Specification {
}

then:
result == PactVerificationResult.Ok.INSTANCE
result instanceof PactVerificationResult.Ok
}

def 'matching on query parameters'() {
Expand All @@ -136,7 +136,7 @@ class GroovyConsumerMatchersPactSpec extends Specification {
}

then:
result == PactVerificationResult.Ok.INSTANCE
result instanceof PactVerificationResult.Ok
}

def 'matching with and and or'() {
Expand Down Expand Up @@ -169,6 +169,6 @@ class GroovyConsumerMatchersPactSpec extends Specification {
}

then:
result == PactVerificationResult.Ok.INSTANCE
result instanceof PactVerificationResult.Ok
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ProviderStateInjectedPactTest {
assert response.status == 200
assert response.data == [userName: 'Test', userId: 100]
}
assert result == PactVerificationResult.Ok.INSTANCE
assert result instanceof PactVerificationResult.Ok

def pactFile = new File("${PactConsumerConfig.pactDirectory}/V3Consumer-ProviderStateService.json")
def json = new JsonSlurper().parse(pactFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class WildcardPactSpec extends Specification {
}

then:
result == PactVerificationResult.Ok.INSTANCE
result instanceof PactVerificationResult.Ok
articleService.interactions.size() == 1
articleService.interactions[0].response.matchingRules.rulesForCategory('body').matchingRules.keySet() == [
'$.articles',
Expand Down Expand Up @@ -115,7 +115,7 @@ class WildcardPactSpec extends Specification {
}

then:
result == PactVerificationResult.Ok.INSTANCE
result instanceof PactVerificationResult.Ok
articleService.interactions.size() == 1
articleService.interactions[0].response.matchingRules.rulesForCategory('body').matchingRules.keySet() == [
'$.events',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ private PactVerificationResult runPactTest(final Statement base, RequestResponse
if (pactFolder != null) {
context.setPactFolder(pactFolder.value());
}

return null;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ public void testPact() throws Throwable {
RequestResponsePact pact = createPact(ConsumerPactBuilder.consumer(consumerName()).hasPactWith(providerName()));
final MockProviderConfig config = MockProviderConfig.createDefault(getSpecificationVersion());

PactVerificationResult result = runConsumerTest(pact, config, this::runTest);
PactVerificationResult result = runConsumerTest(pact, config, (mockServer, context) -> {
runTest(mockServer, context);
return null;
});

if (!result.equals(PactVerificationResult.Ok.INSTANCE)) {
if (!(result instanceof PactVerificationResult.Ok)) {
if (result instanceof PactVerificationResult.Error) {
PactVerificationResult.Error error = (PactVerificationResult.Error) result;
if (error.getMockServerState() != PactVerificationResult.Ok.INSTANCE) {
if (!(error.getMockServerState() instanceof PactVerificationResult.Ok)) {
throw new AssertionError("Pact Test function failed with an exception, possibly due to " +
error.getMockServerState(), ((PactVerificationResult.Error) result).getError());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
(.status 200)
.toPact)
config (-> (MockProviderConfig/createDefault))]
(is (= (PactVerificationResult$Ok/INSTANCE)
(is (instance? PactVerificationResult$Ok
(ConsumerPactRunnerKt/runConsumerTest consumer-pact config
(proxy [PactTestRun] []
(run [mock-server _] (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import java.util.Map;

import static au.com.dius.pact.consumer.ConsumerPactRunnerKt.runConsumerTest;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;

/**
Expand Down Expand Up @@ -44,13 +47,14 @@ public void testPact() {
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
});

if (result instanceof PactVerificationResult.Error) {
throw new RuntimeException(((PactVerificationResult.Error)result).getError());
}

assertEquals(PactVerificationResult.Ok.INSTANCE, result);
assertThat(result, is(instanceOf(PactVerificationResult.Ok.class)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public RequestResponsePact createFragment2(PactDslWithProvider builder) {
public void allPass() throws IOException {
mockTestProvider.validateResultWith((result, t) -> {
assertThat(t, is(nullValue()));
assertThat(result, is(PactVerificationResult.Ok.INSTANCE));
assertThat(result, is(instanceOf(PactVerificationResult.Ok.class)));
});
doTest("/", NAME_LARRY_JSON);
}
Expand All @@ -92,7 +92,7 @@ public void consumerTestFails() throws IOException, InterruptedException {
PactVerificationResult.Error error = (PactVerificationResult.Error) result;
assertThat(error.getError(), is(instanceOf(RuntimeException.class)));
assertThat(error.getError().getMessage(), is("Oops"));
assertThat(error.getMockServerState(), is(PactVerificationResult.Ok.INSTANCE));
assertThat(error.getMockServerState(), is(instanceOf(PactVerificationResult.Ok.class)));
});
doTest("/", NAME_LARRY_JSON);
throw new RuntimeException("Oops");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void runTestWithUserCodeFailure() throws IOException {
"<{responsetest=true, name=harry}> but was:<{responsetest=true, name=fred}>"));
assertThat(result, is(instanceOf(PactVerificationResult.Error.class)));
PactVerificationResult.Error error = (PactVerificationResult.Error) result;
assertThat(error.getMockServerState(), is(instanceOf(PactVerificationResult.Ok.INSTANCE.getClass())));
assertThat(error.getMockServerState(), is(instanceOf(PactVerificationResult.Ok.class)));
assertThat(error.getError(), is(instanceOf(AssertionError.class)));
});
Assert.assertEquals(new ConsumerClient(mockTestProvider.getUrl()).options("/second"), 200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ class PactConsumerTestExt : Extension, BeforeEachCallback, BeforeAllCallback, Pa
val config = store["mockServerConfig"] as MockProviderConfig
Thread.sleep(100) // give the mock server some time to have consistent state
mockServer.close()
val result = mockServer.validateMockServerState()
if (result === PactVerificationResult.Ok) {
val result = mockServer.validateMockServerState(null)
if (result is PactVerificationResult.Ok) {
logger.debug {
"Writing pact ${pact.consumer.name} -> ${pact.provider.name} to file " +
"${pact.fileForPact(pactDirectory)}"
Expand Down
3 changes: 0 additions & 3 deletions consumer/pact-jvm-consumer-scalasupport/README.md

This file was deleted.

4 changes: 0 additions & 4 deletions consumer/pact-jvm-consumer-scalasupport/build.gradle

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6b4639f

Please sign in to comment.