Hope someone might be able to help me, been beating my head against the wall for a while and can't seem to break through. I have tried following multiple examples and doing endless searching, just can't seem to find out what I am missing. There are a lot of examples to follow but most are spring applications and I know nothing about spring so I don't know if I am trying to mix spring with non-spring code...
This is NOT a spring application nor do I want it to be. I am trying to get this going as just a simple java producer verification. Pretty much as simple as it can be...
I have a good contract and I am able to get a successful verification of the contract using JS but want to use JAVA.
I have way too many imports in my code but don't know at this point which ones are not important and or are duplications.
I have a few compile errors but can't seem to find out how to resolve. I noted the compile errors in the code. I think I am close but just don't know at this point.
Is the pactTestTemplate method the one that actually does the contract verification? So that is the method I would call from my unit test? Really confused at this point as to all the magic that is going on in the background...
If you made it this far, thanks...
package testWorkContract;
import au.com.dius.pact.provider.junit.PactRunner;
import au.com.dius.pact.provider.junit.Provider;
import au.com.dius.pact.provider.junit5.*;
import au.com.dius.pact.provider.junit5.PactVerificationContext;
import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider;
import org.junit.jupiter.api.extension.*;
import org.junit.runner.RunWith;
import au.com.dius.pact.provider.junit.loader.PactFolder;
import au.com.dius.pact.provider.junit.loader.PactUrl;
import au.com.dius.pact.provider.junit.target.HttpTarget;
import au.com.dius.pact.provider.junit.target.Target;
import au.com.dius.pact.provider.junit.target.TestTarget;
import org.apache.http.HttpRequest;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.runner.RunWith;
import au.com.dius.pact.provider.junit.*;
@PactFolder("/temp/pacts")
@RunWith(PactRunner.class) // Say JUnit to run tests with custom Runner
@Provider("work") // Set up name of tested provider
public class PactProvider {
@TestTarget // Annotation denotes Target that will be used for tests
public final HttpsTestTarget target = new HttpsTestTarget("127.0.0.1", 443);
@BeforeClass // Method will be run once: before whole contract test suite
public static void setUpService() {
}
@Before // Method will be run before each test of interaction
public void before() {
}
// JUST A QUICK TEST METHOD TO MAKE SURE MY UNIT TEST CAN WORK...
public int testService() {
return 0;
}
@TestTemplate // THIS IS AN ERROR, CAN'T FIND @TestTemplate
@ExtendWith(PactVerificationInvocationContextProvider.class)
void pactTestTemplate(PactVerificationContext context, HttpRequest request) {
context.verifyInteraction();
}
}
Here are my dependencies, first time setting up maven also so there might be problems there:
<properties>
<json-schema-validator.version>3.3.0</json-schema-validator.version>
<junit.jupiter.version>5.5.2</junit.jupiter.version>
<pact.version>4.0.10</pact.version>
<maven.surefire.version>3.0.0-M5</maven.surefire.version>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.3.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-consumer-junit5</artifactId>
<version>${pact.version}</version>
</dependency>
<dependency>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-junit</artifactId>
<version>${pact.version}</version>
</dependency>
<dependency>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-junit5</artifactId>
<version>${pact.version}</version>
</dependency>
</dependencies>