Connect minimal hosts to snapshots, target workers and shared Kit editing
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package de.neitzel.fxdesigner.kit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class FxmlProjectionTest {
|
||||
private static final String XML =
|
||||
"""
|
||||
<?neitzel-model app.Person?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import app.Card?>
|
||||
<VBox xmlns:fx="http://javafx.com/fxml/1" fx:controller="app.Controller">
|
||||
<!-- retained -->
|
||||
<fx:define><app.Binding control="card" path="home"/></fx:define>
|
||||
<Card fx:id="card" caption="before" prefWidth="310" custom="preserve"/>
|
||||
</VBox>
|
||||
""";
|
||||
|
||||
@Test
|
||||
void patchesOnlySupportedAttributesAndPreservesOriginalMetadata() throws Exception {
|
||||
var projection = new FxmlProjection(XML);
|
||||
String projected = projection.project();
|
||||
assertFalse(projected.contains("app.Controller"));
|
||||
assertFalse(projected.contains("app.Card"));
|
||||
assertFalse(projected.contains("app.Binding"));
|
||||
String restored =
|
||||
projection.restore(projected.replace("caption=\"before\"", "caption=\"after\""));
|
||||
assertTrue(restored.contains("caption=\"after\""));
|
||||
assertTrue(restored.contains("custom=\"preserve\""));
|
||||
assertTrue(restored.contains("app.Binding"));
|
||||
assertTrue(restored.contains("app.Controller"));
|
||||
assertTrue(restored.contains("retained"));
|
||||
assertTrue(restored.contains("neitzel-model"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsExternalEntitiesAndExecutableFXML() throws Exception {
|
||||
assertThrows(
|
||||
Exception.class,
|
||||
() -> new FxmlProjection("<!DOCTYPE x SYSTEM 'file:///tmp/private'><VBox/>"));
|
||||
assertThrows(
|
||||
Exception.class,
|
||||
() ->
|
||||
new FxmlProjection(
|
||||
"<VBox"
|
||||
+ " xmlns:fx=\"http://javafx.com/fxml/1\"><fx:script>evil</fx:script></VBox>")
|
||||
.project());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsStructuralEditsAndUnnamedComponents() throws Exception {
|
||||
var projection = new FxmlProjection(XML);
|
||||
String projected = projection.project();
|
||||
assertThrows(
|
||||
Exception.class,
|
||||
() -> projection.restore(projected.replace("fx:id=\"card\"", "fx:id=\"different\"")));
|
||||
assertThrows(
|
||||
Exception.class, () -> new FxmlProjection(XML.replace("fx:id=\"card\"", "")).project());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user