Discover Table compatibility and declared Row alignment
This commit is contained in:
+51
-4
@@ -17,7 +17,45 @@ public record BindingMetadata(
|
||||
List<Computed> computed,
|
||||
List<RepeatOption> collections,
|
||||
List<RepeatOption> components,
|
||||
List<RepeatOption> panes) {
|
||||
List<RepeatOption> panes,
|
||||
List<RepeatOption> tableCollections,
|
||||
List<RepeatOption> tableRows,
|
||||
List<RepeatOption> tableColumns) {
|
||||
public BindingMetadata(
|
||||
String model,
|
||||
String path,
|
||||
String direction,
|
||||
List<Attribute> attributes,
|
||||
List<Target> targets,
|
||||
List<String> diagnostics,
|
||||
List<Converter> converters,
|
||||
List<Problem> problems,
|
||||
String controller,
|
||||
String viewModel,
|
||||
List<Computed> computed,
|
||||
List<RepeatOption> collections,
|
||||
List<RepeatOption> components,
|
||||
List<RepeatOption> panes) {
|
||||
this(
|
||||
model,
|
||||
path,
|
||||
direction,
|
||||
attributes,
|
||||
targets,
|
||||
diagnostics,
|
||||
converters,
|
||||
problems,
|
||||
controller,
|
||||
viewModel,
|
||||
computed,
|
||||
collections,
|
||||
components,
|
||||
panes,
|
||||
List.of(),
|
||||
List.of(),
|
||||
List.of());
|
||||
}
|
||||
|
||||
public record RepeatOption(String name, String type, String status, String reason) {
|
||||
public String toString() {
|
||||
return name + " : " + type + " — " + status + " (" + reason + ")";
|
||||
@@ -119,16 +157,22 @@ public record BindingMetadata(
|
||||
collections = List.copyOf(collections);
|
||||
components = List.copyOf(components);
|
||||
panes = List.copyOf(panes);
|
||||
tableCollections = List.copyOf(tableCollections);
|
||||
tableRows = List.copyOf(tableRows);
|
||||
tableColumns = List.copyOf(tableColumns);
|
||||
if (!Set.of("view", "model", "both").contains(direction))
|
||||
throw new IllegalArgumentException("Invalid direction");
|
||||
}
|
||||
|
||||
public Map<String, String> encode() {
|
||||
var m = new TreeMap<String, String>();
|
||||
m.put("format", "4");
|
||||
m.put("format", "5");
|
||||
encodeOptions(m, "rc", collections);
|
||||
encodeOptions(m, "rt", components);
|
||||
encodeOptions(m, "rp", panes);
|
||||
encodeOptions(m, "tc", tableCollections);
|
||||
encodeOptions(m, "tr", tableRows);
|
||||
encodeOptions(m, "ta", tableColumns);
|
||||
m.put("controller", controller);
|
||||
m.put("viewModel", viewModel);
|
||||
m.put("computed", "" + computed.size());
|
||||
@@ -222,7 +266,7 @@ public record BindingMetadata(
|
||||
}
|
||||
|
||||
public static BindingMetadata decode(Map<String, String> m) {
|
||||
if (!"4".equals(field(m, "format")))
|
||||
if (!"5".equals(field(m, "format")))
|
||||
throw new IllegalArgumentException("Unsupported binding metadata");
|
||||
var a = new ArrayList<Attribute>();
|
||||
var t = new ArrayList<Target>();
|
||||
@@ -286,6 +330,9 @@ public record BindingMetadata(
|
||||
methods,
|
||||
decodeOptions(m, "rc"),
|
||||
decodeOptions(m, "rt"),
|
||||
decodeOptions(m, "rp"));
|
||||
decodeOptions(m, "rp"),
|
||||
decodeOptions(m, "tc"),
|
||||
decodeOptions(m, "tr"),
|
||||
decodeOptions(m, "ta"));
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -82,8 +82,8 @@ public final class ProtocolSession implements AutoCloseable {
|
||||
&& supported.contains("interactive-v1")
|
||||
&& hello.capabilities().contains("interactive-v1")) usable.add(Operation.INTERACTIVE);
|
||||
if (hello.metadata().major() == 1
|
||||
&& supported.contains("bindings-v4")
|
||||
&& hello.capabilities().contains("bindings-v4")) usable.add(Operation.BINDINGS);
|
||||
&& supported.contains("bindings-v5")
|
||||
&& hello.capabilities().contains("bindings-v5")) usable.add(Operation.BINDINGS);
|
||||
var requiredByEither = new HashSet<>(required);
|
||||
requiredByEither.addAll(hello.required());
|
||||
if ((requiredByEither.contains("discover-v1") && !usable.contains(Operation.DISCOVER))
|
||||
@@ -92,7 +92,7 @@ public final class ProtocolSession implements AutoCloseable {
|
||||
if ((requiredByEither.contains("layout-v1") && !usable.contains(Operation.MEASURE))
|
||||
|| (requiredByEither.contains("interactive-v1") && !usable.contains(Operation.INTERACTIVE)))
|
||||
throw new IllegalArgumentException("Required capability version incompatible");
|
||||
if (requiredByEither.contains("bindings-v4") && !usable.contains(Operation.BINDINGS))
|
||||
if (requiredByEither.contains("bindings-v5") && !usable.contains(Operation.BINDINGS))
|
||||
throw new IllegalArgumentException("Required capability version incompatible");
|
||||
operations = Set.copyOf(usable);
|
||||
state = State.READY;
|
||||
|
||||
+11
-8
@@ -29,7 +29,10 @@ class BindingMetadataTest {
|
||||
"#caption", "java.lang.String", "COMPATIBLE", "Declared type")),
|
||||
List.of(new BindingMetadata.RepeatOption("visits", "Address", "COMPATIBLE", "Element")),
|
||||
List.of(new BindingMetadata.RepeatOption("app.Card", "Address", "COMPATIBLE", "Model")),
|
||||
List.of(new BindingMetadata.RepeatOption("rows", "VBox", "COMPATIBLE", "Pane")));
|
||||
List.of(new BindingMetadata.RepeatOption("rows", "VBox", "COMPATIBLE", "Pane")),
|
||||
List.of(new BindingMetadata.RepeatOption("visits", "Address", "COMPATIBLE", "Bean")),
|
||||
List.of(new BindingMetadata.RepeatOption("Row", "Address", "COMPATIBLE", "Row")),
|
||||
List.of(new BindingMetadata.RepeatOption("street", "String", "COMPATIBLE", "Column")));
|
||||
assertEquals(
|
||||
m, BindingMetadata.decode(PreviewMessages.decode(PreviewMessages.encode(m.encode()))));
|
||||
var id = new Identity("s", "r", "c", "b", Map.of("file", 1L), 0, 0);
|
||||
@@ -44,14 +47,14 @@ class BindingMetadataTest {
|
||||
new Identity("s", "r", "c", "b", Map.of(), 0, 0),
|
||||
new byte[0]));
|
||||
var invalid = new HashMap<>(m.encode());
|
||||
invalid.put("rc", "99999");
|
||||
invalid.put("ta", "99999");
|
||||
assertThrows(IllegalArgumentException.class, () -> BindingMetadata.decode(invalid));
|
||||
}
|
||||
|
||||
@Test
|
||||
void negotiationRequiresMetadataVersion() throws Exception {
|
||||
String token = ProtocolSession.newToken();
|
||||
var session = new ProtocolSession("s", 1, token, Set.of("bindings-v4"), Set.of("bindings-v4"));
|
||||
var session = new ProtocolSession("s", 1, token, Set.of("bindings-v5"), Set.of("bindings-v5"));
|
||||
assertTrue(
|
||||
session
|
||||
.authenticate(
|
||||
@@ -63,11 +66,11 @@ class BindingMetadataTest {
|
||||
new Version(1, 0),
|
||||
new Version(1, 0),
|
||||
new Version(1, 0),
|
||||
Set.of("bindings-v4"),
|
||||
Set.of("bindings-v5"),
|
||||
Set.of()))
|
||||
.contains(Operation.BINDINGS));
|
||||
var oldWorker =
|
||||
new ProtocolSession("s", 1, token, Set.of("bindings-v4"), Set.of("bindings-v4"));
|
||||
new ProtocolSession("s", 1, token, Set.of("bindings-v5"), Set.of("bindings-v5"));
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
@@ -80,10 +83,10 @@ class BindingMetadataTest {
|
||||
new Version(1, 0),
|
||||
new Version(1, 0),
|
||||
new Version(1, 0),
|
||||
Set.of("bindings-v3"),
|
||||
Set.of("bindings-v4"),
|
||||
Set.of())));
|
||||
var incompatible =
|
||||
new ProtocolSession("s", 1, token, Set.of("bindings-v4"), Set.of("bindings-v4"));
|
||||
new ProtocolSession("s", 1, token, Set.of("bindings-v5"), Set.of("bindings-v5"));
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
@@ -96,7 +99,7 @@ class BindingMetadataTest {
|
||||
new Version(1, 0),
|
||||
new Version(2, 0),
|
||||
new Version(1, 0),
|
||||
Set.of("bindings-v4"),
|
||||
Set.of("bindings-v5"),
|
||||
Set.of())));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user