Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<properties>
<kotlin.version>2.3.0</kotlin.version>
<maven.compiler>17</maven.compiler>
<specmatic.version>2.37.2</specmatic.version>
<specmatic.version>2.37.4-SNAPSHOT</specmatic.version>
<spring.boot.version>3.5.9</spring.boot.version>
<cxf.version>4.1.4</cxf.version>
</properties>
Expand Down
11 changes: 9 additions & 2 deletions specmatic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ contracts:
- git:
url: https://github.com/specmatic/specmatic-order-contracts.git
provides:
- io/specmatic/examples/store/openapi/api_order_v5.yaml
- specs:
- io/specmatic/examples/store/openapi/api_order_v5.yaml
baseUrl: http://localhost:8090
- consumes:
- wsdls/inventory.wsdl
- wsdls/inventory.wsdl

report:
types:
APICoverage:
Expand All @@ -14,3 +17,7 @@ report:
minThresholdPercentage: 65
maxMissedEndpointsInSpec: 4
enforce: true
test:
resiliencyTests:
enable: all
filter: "PATH!='/internal/metrics'"
25 changes: 5 additions & 20 deletions src/test/java/com/store/ContractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,27 @@
import io.specmatic.test.SpecmaticContractTest;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.junit.jupiter.api.TestInstance;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.IOException;
import java.util.Optional;

import static io.specmatic.stub.API.createStub;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class ContractTest implements SpecmaticContractTest {
private static ConfigurableApplicationContext context;
private static final String EXCLUDED_ENDPOINTS = "'/internal/metrics'";
private static ContractStub stub = null;

@BeforeAll
public static void setUp() {
System.setProperty("host", "localhost");
System.setProperty("port", "8090");
System.setProperty("SPECMATIC_GENERATIVE_TESTS", "true");
System.setProperty("SPECMATIC_TEST_PARALLELISM", "auto");
System.setProperty("filter", String.format("PATH!=%s", EXCLUDED_ENDPOINTS));
System.setProperty("INVENTORY_API_URL", "http://localhost:9000/ws");
System.out.println("Running contract tests using Specmatic against application at localhost:8080");

public static void setup() throws Exception {
DB.INSTANCE.resetDB();

stub = createStub("localhost", 9000);

context = SpringApplication.run(Application.class);
}

@AfterAll
public static void tearDown() throws IOException {
if(stub != null) {
stub.close();
}

context.close();
}
}
11 changes: 5 additions & 6 deletions src/test/java/com/store/ContractTestUsingCLITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Map;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyMap;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@EnabledIf(value = "isNonCIOrLinux", disabledReason = "Run only on Linux in CI; all platforms allowed locally")
Expand Down Expand Up @@ -48,14 +49,12 @@ public static void teardown() throws Exception {
}

private static SpecmaticExecutor createStub() {
List<String> args = asList("virtualize", "--port=" + HTTP_STUB_PORT);
Map<String, String> env = Map.of("SOME_ENV", "value");
return new SpecmaticExecutor(args, env);
List<String> args = asList("virtualize");
return new SpecmaticExecutor(args, emptyMap());
}

private static SpecmaticExecutor createTest() {
List<String> args = asList("test", "--host=" + APPLICATION_HOST, "--port=" + APPLICATION_PORT, "--filter=PATH!=" + EXCLUDED_ENDPOINTS);
Map<String, String> env = Map.of("SPECMATIC_GENERATIVE_TESTS", "true", "SPECMATIC_TEST_PARALLELISM", "auto");
return new SpecmaticExecutor(args, env);
List<String> args = asList("test");
return new SpecmaticExecutor(args, emptyMap());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ public static boolean isNonCIOrLinux() {

System.out.println("Using docker host address: " + dockerHostAddress);
testContainer = new GenericContainer<>("specmatic/specmatic:latest")
.withCommand("test", "--host=" + APPLICATION_HOST, "--port=" + APPLICATION_PORT, "--filter=PATH!=" + EXCLUDED_ENDPOINTS)
.withCommand("test")
// .withImagePullPolicy(PullPolicy.alwaysPull())
.withEnv("SPECMATIC_GENERATIVE_TESTS", "true")
.withEnv("SPECMATIC_TEST_PARALLELISM", "auto")
.withFileSystemBind("./specmatic.yaml", "/usr/src/app/specmatic.yaml", BindMode.READ_ONLY)
.withFileSystemBind("./build/reports/specmatic", "/usr/src/app/build/reports/specmatic", BindMode.READ_WRITE)
// For Docker Desktop on Windows and Mac, "host.docker.internal" is used to refer to the host machine.
Expand All @@ -53,8 +51,7 @@ public static boolean isNonCIOrLinux() {
stubContainer = new GenericContainer<>("specmatic/specmatic")
// .withImagePullPolicy(PullPolicy.alwaysPull())
.withCommand(
"virtualize",
"--port=" + HTTP_STUB_PORT
"virtualize"
)
.withCreateContainerCmdModifier(cmd -> {
if (cmd.getHostConfig() != null) {
Expand Down