-
-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support consumer version selector methods on Kotlin test classes #…
- Loading branch information
Showing
7 changed files
with
232 additions
and
26 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...unit5/src/test/java/au/com/dius/pact/provider/junit5/ConsumerVersionSelectorJavaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package au.com.dius.pact.provider.junit5; | ||
|
||
import au.com.dius.pact.provider.junitsupport.IgnoreNoPactsToVerify; | ||
import au.com.dius.pact.provider.junitsupport.Provider; | ||
import au.com.dius.pact.provider.junitsupport.loader.PactBroker; | ||
import au.com.dius.pact.provider.junitsupport.loader.PactBrokerConsumerVersionSelectors; | ||
import au.com.dius.pact.provider.junitsupport.loader.SelectorBuilder; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@Provider("Animal Profile Service") | ||
@PactBroker(url = "http://broker.host") | ||
@IgnoreNoPactsToVerify(ignoreIoErrors = "true") | ||
class ConsumerVersionSelectorJavaTest { | ||
static boolean called = false; | ||
|
||
@PactBrokerConsumerVersionSelectors | ||
public static SelectorBuilder consumerVersionSelectors() { | ||
called = true; | ||
return new SelectorBuilder().branch("current"); | ||
} | ||
|
||
@TestTemplate | ||
@ExtendWith(PactVerificationInvocationContextProvider.class) | ||
void pactVerificationTestTemplate(PactVerificationContext context) { | ||
if (context != null) { | ||
context.verifyInteraction(); | ||
} | ||
} | ||
|
||
@AfterAll | ||
static void after() { | ||
assertThat("consumerVersionSelectors() was not called", called, is(true)); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...it5/src/test/kotlin/au/com/dius/pact/provider/junit5/ConsumerVersionSelectorKotlinTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package au.com.dius.pact.provider.junit5 | ||
|
||
import au.com.dius.pact.provider.junitsupport.IgnoreNoPactsToVerify | ||
import au.com.dius.pact.provider.junitsupport.Provider | ||
import au.com.dius.pact.provider.junitsupport.loader.PactBroker | ||
import au.com.dius.pact.provider.junitsupport.loader.PactBrokerConsumerVersionSelectors | ||
import au.com.dius.pact.provider.junitsupport.loader.SelectorBuilder | ||
import org.hamcrest.MatcherAssert | ||
import org.hamcrest.Matchers | ||
import org.junit.jupiter.api.AfterAll | ||
import org.junit.jupiter.api.TestTemplate | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
@Provider("Animal Profile Service") | ||
@PactBroker(url = "http://broker.host") | ||
@IgnoreNoPactsToVerify(ignoreIoErrors = "true") | ||
class ConsumerVersionSelectorKotlinTest { | ||
@PactBrokerConsumerVersionSelectors | ||
fun consumerVersionSelectors(): SelectorBuilder { | ||
called = true | ||
return SelectorBuilder().branch("current") | ||
} | ||
|
||
@TestTemplate | ||
@ExtendWith(PactVerificationInvocationContextProvider::class) | ||
fun pactVerificationTestTemplate(context: PactVerificationContext?) { | ||
context?.verifyInteraction() | ||
} | ||
|
||
companion object { | ||
private var called: Boolean = false | ||
|
||
@AfterAll | ||
fun after() { | ||
MatcherAssert.assertThat("consumerVersionSelectors() was not called", called, Matchers.`is`(true)) | ||
} | ||
} | ||
} | ||
|
||
@PactBroker(url = "http://broker.host") | ||
@IgnoreNoPactsToVerify(ignoreIoErrors = "true") | ||
abstract class Base { | ||
@PactBrokerConsumerVersionSelectors | ||
fun consumerVersionSelectors(): SelectorBuilder { | ||
called = true | ||
return SelectorBuilder().branch("current") | ||
} | ||
|
||
companion object { | ||
var called: Boolean = false | ||
} | ||
} | ||
|
||
@Provider("Animal Profile Service") | ||
class ConsumerVersionSelectorKotlinTestWithAbstractBase: Base() { | ||
@TestTemplate | ||
@ExtendWith(PactVerificationInvocationContextProvider::class) | ||
fun pactVerificationTestTemplate(context: PactVerificationContext?) { | ||
context?.verifyInteraction() | ||
} | ||
|
||
companion object { | ||
@AfterAll | ||
fun after() { | ||
MatcherAssert.assertThat("consumerVersionSelectors() was not called", called, Matchers.`is`(true)) | ||
} | ||
} | ||
} | ||
|
||
@Provider("Animal Profile Service") | ||
@PactBroker(url = "http://broker.host") | ||
@IgnoreNoPactsToVerify(ignoreIoErrors = "true") | ||
class ConsumerVersionSelectorKotlinTestWithCompanionMethod { | ||
@TestTemplate | ||
@ExtendWith(PactVerificationInvocationContextProvider::class) | ||
fun pactVerificationTestTemplate(context: PactVerificationContext?) { | ||
context?.verifyInteraction() | ||
} | ||
|
||
companion object { | ||
private var called: Boolean = false | ||
|
||
@PactBrokerConsumerVersionSelectors | ||
fun consumerVersionSelectors(): SelectorBuilder { | ||
called = true | ||
return SelectorBuilder().branch("current") | ||
} | ||
|
||
@AfterAll | ||
fun after() { | ||
MatcherAssert.assertThat("consumerVersionSelectors() was not called", called, Matchers.`is`(true)) | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...rc/test/java/au/com/dius/pact/provider/spring/junit5/ConsumerVersionSelectorJavaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package au.com.dius.pact.provider.spring.junit5; | ||
|
||
import au.com.dius.pact.provider.junit5.PactVerificationContext; | ||
import au.com.dius.pact.provider.junitsupport.IgnoreNoPactsToVerify; | ||
import au.com.dius.pact.provider.junitsupport.Provider; | ||
import au.com.dius.pact.provider.junitsupport.loader.PactBroker; | ||
import au.com.dius.pact.provider.junitsupport.loader.PactBrokerConsumerVersionSelectors; | ||
import au.com.dius.pact.provider.junitsupport.loader.SelectorBuilder; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@Provider("Animal Profile Service") | ||
@PactBroker | ||
@IgnoreNoPactsToVerify(ignoreIoErrors = "true") | ||
class ConsumerVersionSelectorJavaTest { | ||
static boolean called = false; | ||
|
||
@PactBrokerConsumerVersionSelectors | ||
public static SelectorBuilder consumerVersionSelectors() { | ||
called = true; | ||
return new SelectorBuilder().branch("current"); | ||
} | ||
|
||
@TestTemplate | ||
@ExtendWith(PactVerificationSpringProvider.class) | ||
void pactVerificationTestTemplate(PactVerificationContext context) { | ||
if (context != null) { | ||
context.verifyInteraction(); | ||
} | ||
} | ||
|
||
@AfterAll | ||
static void after() { | ||
assertThat("consumerVersionSelectors() was not called", called, is(true)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters