-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add example JUnit4 Spring test using new consumer version selec…
…tor method
- Loading branch information
1 parent
a601f18
commit 041e69b
Showing
3 changed files
with
68 additions
and
22 deletions.
There are no files selected for viewing
22 changes: 0 additions & 22 deletions
22
...src/test/groovy/au/com/dius/pact/provider/spring/testspringbootapp/TestApplication.groovy
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
...er/spring/src/test/java/au/com/dius/pact/provider/spring/ConsumerVersionSelectorTest.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,40 @@ | ||
package au.com.dius.pact.provider.spring; | ||
|
||
import au.com.dius.pact.provider.junit.target.HttpTarget; | ||
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 au.com.dius.pact.provider.junitsupport.target.Target; | ||
import au.com.dius.pact.provider.junitsupport.target.TestTarget; | ||
import au.com.dius.pact.provider.spring.testspringbootapp.TestApplication; | ||
import org.junit.AfterClass; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@RunWith(SpringRestPactRunner.class) | ||
@Provider("myAwesomeService") | ||
@PactBroker(url = "http://broker.host") | ||
@IgnoreNoPactsToVerify(ignoreIoErrors = "true") | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, | ||
classes = { TestApplication.class }) | ||
public class ConsumerVersionSelectorTest { | ||
@TestTarget | ||
public final Target target = new HttpTarget(8332); | ||
|
||
static boolean called = false; | ||
@PactBrokerConsumerVersionSelectors | ||
public static SelectorBuilder consumerVersionSelectors() { | ||
called = true; | ||
return new SelectorBuilder().branch("current"); | ||
} | ||
|
||
@AfterClass | ||
public static void after() { | ||
assertThat("consumerVersionSelectors() was not called", called, is(true)); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ing/src/test/java/au/com/dius/pact/provider/spring/testspringbootapp/TestApplication.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,28 @@ | ||
package au.com.dius.pact.provider.spring.testspringbootapp; | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@SpringBootApplication | ||
public class TestApplication { | ||
|
||
public static class ObjectThatMustBeClosed { | ||
private ObjectThatMustBeClosed() {} | ||
|
||
private static final ObjectThatMustBeClosed instance = new ObjectThatMustBeClosed(); | ||
public static ObjectThatMustBeClosed getInstance() { | ||
return instance; | ||
} | ||
|
||
public boolean destroyed = false; | ||
|
||
public void shutdown() { | ||
destroyed = true; | ||
} | ||
} | ||
|
||
@Bean(destroyMethod="shutdown") | ||
ObjectThatMustBeClosed mustBeClosed() { | ||
return ObjectThatMustBeClosed.getInstance(); | ||
} | ||
} |