Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem;
import io.quarkus.runtime.util.ClassPathUtils;

public class MoquProjectProcessor {
Expand Down Expand Up @@ -68,6 +69,16 @@ MoquProjectBuildItem generate(MoquConfig config) {
}
}

@BuildStep(onlyIf = { IsDevelopment.class })
void watchOpenApiFiles(MoquConfig config, BuildProducer<HotDeploymentWatchedFileBuildItem> watchedPaths)
throws IOException {
ClassPathUtils.consumeAsPaths(config.resourceDir(), path -> {
if (Files.exists(path)) {
watchedPaths.produce(new HotDeploymentWatchedFileBuildItem(path.toString(), Files.isDirectory(path)));
}
});
}

@BuildStep(onlyIf = { IsDevelopment.class })
void consume(Optional<MoquProjectBuildItem> moquProject,
BuildProducer<MoquBuildItem> moquMocks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

public class MoquProjectProcessorTest {

private static final String WIREMOCK_MAPPINGS_JSON_PATH = "/q/moqu/json/api/wiremock-mappings.json";

@RegisterExtension
static final QuarkusDevModeTest unitTest = new QuarkusDevModeTest()
.withApplicationRoot(javaArchive -> javaArchive
Expand Down Expand Up @@ -38,10 +40,27 @@ void testModeAsDownload() {
@Test
void testModeAsDownloadUsingJson() {
RestAssured.given()
.when().get("/q/moqu/json/api/wiremock-mappings.json")
.when().get(WIREMOCK_MAPPINGS_JSON_PATH)
.then()
.statusCode(200)
.body(Matchers.containsString("Alice"))
.log().ifError();
}

@Test
void testDevModeWatchOpenApiFiles() {
RestAssured.given()
.when().get(WIREMOCK_MAPPINGS_JSON_PATH)
.then()
.statusCode(200)
.body(Matchers.containsString("80"));

unitTest.modifyResourceFile("openapi/api.json", (content) -> content.replace("80", "77"));

RestAssured.given()
.when().get(WIREMOCK_MAPPINGS_JSON_PATH)
.then()
.statusCode(200)
.body(Matchers.containsString("77"));
}
}