Discover Model paths and compatible binding targets in both hosts
Add non-constructing target metadata and a shared read-only browser for the Person fixtures. Negotiate binding discovery independently, preserve FXML, and explain direction/type mismatches. Record remaining manual navigation checks as explicitly skipped.
This commit is contained in:
+141
@@ -0,0 +1,141 @@
|
||||
package de.neitzel.fxdesigner.target;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class BindingDiscoveryTest {
|
||||
public static class Address {
|
||||
public String getStreet() {
|
||||
throw new AssertionError("Getter executed");
|
||||
}
|
||||
|
||||
public void setStreet(String s) {
|
||||
throw new AssertionError("Setter executed");
|
||||
}
|
||||
}
|
||||
|
||||
public static class Model {
|
||||
static {
|
||||
System.setProperty("discovery.model.initialized", "yes");
|
||||
}
|
||||
|
||||
public Model() {
|
||||
throw new AssertionError("Model constructed");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
throw new AssertionError("Getter executed");
|
||||
}
|
||||
|
||||
public void setName(String s) {}
|
||||
|
||||
public int getRank() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setRank(int n) {}
|
||||
|
||||
public Address getHome() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setHome(Address a) {}
|
||||
|
||||
public List<Address> getVisits() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setVisits(List<Address> a) {}
|
||||
|
||||
public String getReadOnly() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private String fxml() {
|
||||
return "<?neitzel-model "
|
||||
+ Model.class.getName()
|
||||
+ "?><?import javafx.scene.control.TextField?><TextField"
|
||||
+ " xmlns:fx=\"http://javafx.com/fxml/1\" fx:id=\"input\"/>";
|
||||
}
|
||||
|
||||
@Test
|
||||
void discoversNestedAndCollectionSignaturesWithoutApplicationOrToolkitInitialization()
|
||||
throws Exception {
|
||||
var metadata = BindingDiscovery.inspect(fxml(), "name", "both", getClass().getClassLoader());
|
||||
assertEquals(
|
||||
Set.of("home", "home.street", "name", "rank", "visits"),
|
||||
metadata.attributes().stream()
|
||||
.map(a -> a.path())
|
||||
.collect(java.util.stream.Collectors.toSet()));
|
||||
assertEquals(
|
||||
Address.class.getName(),
|
||||
metadata.attributes().stream()
|
||||
.filter(a -> a.path().equals("visits"))
|
||||
.findFirst()
|
||||
.orElseThrow()
|
||||
.elementType());
|
||||
assertTrue(
|
||||
metadata.targets().stream()
|
||||
.anyMatch(t -> t.property().equals("text") && t.status().equals("COMPATIBLE")));
|
||||
assertTrue(
|
||||
metadata.targets().stream()
|
||||
.anyMatch(t -> t.property().equals("width") && t.status().equals("INCOMPATIBLE")));
|
||||
assertNull(System.getProperty("discovery.model.initialized"));
|
||||
assertThrows(IllegalStateException.class, () -> javafx.application.Platform.runLater(() -> {}));
|
||||
}
|
||||
|
||||
@Test
|
||||
void explainsMismatchesAndRequiresExplicitModel() throws Exception {
|
||||
var result = BindingDiscovery.inspect(fxml(), "rank", "view", getClass().getClassLoader());
|
||||
assertTrue(
|
||||
result.targets().stream()
|
||||
.anyMatch(t -> t.property().equals("text") && t.status().equals("CONVERTER_REQUIRED")));
|
||||
assertTrue(
|
||||
BindingDiscovery.inspect("<VBox/>", "", "both", getClass().getClassLoader())
|
||||
.diagnostics()
|
||||
.getFirst()
|
||||
.contains("neitzel-model"));
|
||||
assertThrows(
|
||||
Exception.class,
|
||||
() ->
|
||||
BindingDiscovery.inspect(
|
||||
"<!DOCTYPE x SYSTEM 'file:///etc/passwd'><x/>",
|
||||
"",
|
||||
"both",
|
||||
getClass().getClassLoader()));
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> BindingDiscovery.inspect(fxml(), "", "wrong", getClass().getClassLoader()));
|
||||
}
|
||||
|
||||
public static class NumberModel {
|
||||
public Number getAmount() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setAmount(Number n) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
void compatibilityDependsOnDirection() throws Exception {
|
||||
String xml =
|
||||
"<?neitzel-model "
|
||||
+ NumberModel.class.getName()
|
||||
+ "?><?import javafx.scene.control.ProgressBar?><ProgressBar"
|
||||
+ " xmlns:fx=\"http://javafx.com/fxml/1\" fx:id=\"progress\"/>";
|
||||
for (String direction : List.of("view", "model", "both")) {
|
||||
var metadata =
|
||||
BindingDiscovery.inspect(xml, "amount", direction, getClass().getClassLoader());
|
||||
var target =
|
||||
metadata.targets().stream()
|
||||
.filter(t -> t.property().equals("progress"))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
assertEquals(
|
||||
direction.equals("model") ? "COMPATIBLE" : "CONVERTER_REQUIRED", target.status());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user