Connect minimal hosts to snapshots, target workers and shared Kit editing
This commit is contained in:
+175
@@ -0,0 +1,175 @@
|
||||
package de.neitzel.fxdesigner.workflow;
|
||||
|
||||
import de.neitzel.fxdesigner.build.*;
|
||||
import de.neitzel.fxdesigner.contracts.*;
|
||||
import de.neitzel.fxdesigner.host.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public final class ConnectedWorkflowContract {
|
||||
private int checks;
|
||||
|
||||
private void check(boolean value, String message) {
|
||||
if (!value) throw new AssertionError(message);
|
||||
checks++;
|
||||
}
|
||||
|
||||
private static <T> T await(CompletionStage<T> stage) throws Exception {
|
||||
return stage.toCompletableFuture().get(120, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public int run(HostServices host, Path root, Path fixture) throws Exception {
|
||||
var tools =
|
||||
List.of(
|
||||
root.resolve("designer-target-tools/target/designer-target-tools-0.1.0-SNAPSHOT.jar"),
|
||||
root.resolve("designer-contracts/target/designer-contracts-0.1.0-SNAPSHOT.jar"),
|
||||
root.resolve("designer-preview-api/target/designer-preview-api-0.1.0-SNAPSHOT.jar"));
|
||||
var workflow =
|
||||
new DesignerWorkflow(
|
||||
host,
|
||||
fixture.resolve("neitzel-fx-designer.json"),
|
||||
"fixture",
|
||||
root.resolve("mvnw"),
|
||||
tools,
|
||||
System.out::println);
|
||||
var built = await(workflow.build(Map.of()).completion());
|
||||
check(built.status() == BuildRefresh.Status.READY, "Build failed: " + built.message());
|
||||
var examples = await(workflow.discover(false));
|
||||
check(examples.size() == 9, "Discovery from snapshot");
|
||||
Path file = fixture.resolve("app/src/main/resources/fixture/components/Person.fxml"),
|
||||
child = fixture.resolve("app/src/main/resources/fixture/components/Card.fxml");
|
||||
try (var doc = await(host.documents().open(file.toUri()));
|
||||
var component = await(host.documents().open(child.toUri()))) {
|
||||
var initial = await(doc.snapshot());
|
||||
var first = await(workflow.render(false, "standard", "card", 310, 220, List.of(initial)));
|
||||
check(first.rgba().length == 310 * 220 * 4, "Image frame");
|
||||
var batch =
|
||||
await(
|
||||
workflow.renderImages(
|
||||
false,
|
||||
"standard",
|
||||
Map.of(
|
||||
"card",
|
||||
new DesignerWorkflow.Size(310, 220),
|
||||
"second",
|
||||
new DesignerWorkflow.Size(310, 220)),
|
||||
List.of(initial)));
|
||||
check(
|
||||
batch.size() == 2
|
||||
&& batch.stream().allMatch(image -> image.snapshot().equals(first.snapshot())),
|
||||
"Shared parent render batch");
|
||||
check(
|
||||
Path.of(await(workflow.componentSource("fixture.components.Card")))
|
||||
.equals(child.toRealPath()),
|
||||
"Component navigation source");
|
||||
|
||||
var changed =
|
||||
await(
|
||||
doc.apply(
|
||||
new EditBatch(
|
||||
initial.revision(),
|
||||
"Caption",
|
||||
List.of(
|
||||
new EditBatch.Replacement(
|
||||
0,
|
||||
initial.text().length(),
|
||||
initial.text().replace("FXML caption", "Draft caption"))))));
|
||||
var second = await(workflow.render(false, "standard", "card", 310, 220, List.of(changed)));
|
||||
check(!Arrays.equals(first.rgba(), second.rgba()), "Parent draft not rendered");
|
||||
check(first.snapshot().equals(second.snapshot()), "FXML edit rebuilt Java");
|
||||
var childInitial = await(component.snapshot());
|
||||
var childDraft =
|
||||
await(
|
||||
component.apply(
|
||||
new EditBatch(
|
||||
childInitial.revision(),
|
||||
"Component",
|
||||
List.of(
|
||||
new EditBatch.Replacement(
|
||||
0,
|
||||
childInitial.text().length(),
|
||||
childInitial
|
||||
.text()
|
||||
.replace(
|
||||
"<TextField",
|
||||
"<TextField style=\"-fx-background-color: red;\""))))));
|
||||
var third =
|
||||
await(workflow.render(false, "standard", "card", 310, 220, List.of(changed, childDraft)));
|
||||
check(!Arrays.equals(second.rgba(), third.rgba()), "Component draft not rendered");
|
||||
var undo = await(doc.undo());
|
||||
check(undo.text().equals(initial.text()), "Native host undo");
|
||||
var redo = await(doc.redo());
|
||||
check(redo.text().equals(changed.text()), "Native host redo");
|
||||
var obsolete = workflow.render(false, "standard", "card", 310, 220, List.of(redo));
|
||||
var newer =
|
||||
await(
|
||||
doc.apply(
|
||||
new EditBatch(
|
||||
redo.revision(),
|
||||
"Concurrent edit",
|
||||
List.of(
|
||||
new EditBatch.Replacement(
|
||||
0,
|
||||
redo.text().length(),
|
||||
redo.text().replace("Draft caption", "Concurrent caption"))))));
|
||||
try {
|
||||
await(obsolete);
|
||||
throw new AssertionError("Obsolete render accepted");
|
||||
} catch (Exception expected) {
|
||||
checks++;
|
||||
}
|
||||
redo = await(doc.undo());
|
||||
var bad =
|
||||
await(
|
||||
doc.apply(
|
||||
new EditBatch(
|
||||
redo.revision(),
|
||||
"Broken source",
|
||||
List.of(
|
||||
new EditBatch.Replacement(
|
||||
0,
|
||||
redo.text().length(),
|
||||
redo.text()
|
||||
.replace("prefWidth=\"310\"", "prefWidth=\"invalid\""))))));
|
||||
try {
|
||||
await(workflow.render(false, "standard", "card", 310, 220, List.of(bad)));
|
||||
throw new AssertionError("Invalid draft accepted");
|
||||
} catch (ExecutionException expected) {
|
||||
check(
|
||||
expected.getCause().getMessage().contains("LOAD_FAILED"), "Missing target diagnostic");
|
||||
}
|
||||
check(await(doc.snapshot()).writable(), "Failure disabled source");
|
||||
await(doc.undo());
|
||||
var saved = await(doc.save(await(doc.snapshot()).revision()));
|
||||
var savedChild = await(component.save(childDraft.revision()));
|
||||
var savedRender =
|
||||
await(workflow.render(false, "standard", "card", 310, 220, List.of(saved, savedChild)));
|
||||
check(
|
||||
savedRender.snapshot().equals(first.snapshot()),
|
||||
"Saving overlaid FXML required Java rebuild");
|
||||
var store = new SnapshotStore(fixture.resolve(".neitzel-fx-designer/snapshots"));
|
||||
try (var lease = store.lease(built.snapshot())) {
|
||||
check(lease.snapshot().id().equals(built.snapshot()), "Overlay mutated snapshot");
|
||||
}
|
||||
var pending =
|
||||
workflow.render(
|
||||
false,
|
||||
"timeout",
|
||||
"card",
|
||||
310,
|
||||
220,
|
||||
List.of(await(doc.snapshot()), await(component.snapshot())));
|
||||
Thread.sleep(500);
|
||||
workflow.cancel();
|
||||
try {
|
||||
await(pending);
|
||||
throw new AssertionError("Cancellation accepted result");
|
||||
} catch (Exception expected) {
|
||||
checks++;
|
||||
}
|
||||
}
|
||||
workflow.close();
|
||||
return checks;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user