Files
NeitzelFXDesigner/designer-contracts/src/test/java/de/neitzel/fxdesigner/protocol/ModelMetadataTest.java
T

36 lines
1.2 KiB
Java

package de.neitzel.fxdesigner.protocol;
import static org.junit.jupiter.api.Assertions.*;
import java.io.*;
import java.util.*;
import org.junit.jupiter.api.Test;
class ModelMetadataTest {
@Test
void deterministicRoundTripAndSchemaValidation() throws Exception {
var m =
new ModelMetadata(
"app.Person",
List.of(
new ModelMetadata.Property("name", "java.lang.String", "", "getName", "setName")));
assertEquals(m, ModelMetadata.read(new ByteArrayInputStream(m.encode())));
assertThrows(
IOException.class,
() ->
ModelMetadata.read(
new ByteArrayInputStream(
new String(m.encode(), java.nio.charset.StandardCharsets.UTF_8)
.replace("schemaVersion=1.0", "schemaVersion=9.0")
.getBytes(java.nio.charset.StandardCharsets.UTF_8))));
assertThrows(
IOException.class,
() -> ModelMetadata.read(new ByteArrayInputStream(new byte[ModelMetadata.LIMIT + 1])));
assertThrows(
IllegalArgumentException.class,
() ->
new ModelMetadata(
"app.Person", List.of(m.properties().getFirst(), m.properties().getFirst())));
}
}