Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seralization cleanup #461

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
public class RuneJsonSerializerErrorHandlingTest {
public static final String TEST_TYPE = "rune-serializer-error-handling-test";
private ObjectMapper objectMapper;
public static final String NAMESPACE_PREFIX = TEST_MODEL_NAME + ".test.failing.";

private static CodeGeneratorTestHelper helper;

Expand Down Expand Up @@ -142,7 +143,7 @@ private static Path getGroupPath(String groupName) {
private Class<RosettaModelObject> getRootRosettaModelObjectClass(Path groupPath, String fileName) {
Path rosetta = getFile(groupPath, fileName);
String groupName = groupPath.getFileName().toString();
return generateCompileAndGetRootDataType(groupName, Collections.singletonList(rosetta), helper, new DynamicCompiledClassLoader());
return generateCompileAndGetRootDataType(NAMESPACE_PREFIX, groupName, Collections.singletonList(rosetta), helper, new DynamicCompiledClassLoader());
}

private <T extends RosettaModelObject> T fromJson(String runeJson, Class<T> type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
public class RuneJsonSerializerRoundTripTest {
public static final String TEST_TYPE = "rune-serializer-round-trip-test";
private static DynamicCompiledClassLoader dynamicCompiledClassLoader;
public static final String NAMESPACE_PREFIX = TEST_MODEL_NAME + ".test.passing.";

private static CodeGeneratorTestHelper helper;
private ObjectMapper objectMapper;
Expand Down Expand Up @@ -72,7 +73,7 @@ public static Stream<Arguments> testCases() {
.flatMap(groupPath -> {
List<Path> rosettas = listFiles(groupPath, ".rosetta");
String groupName = groupPath.getFileName().toString();
Class<RosettaModelObject> rootDataType = generateCompileAndGetRootDataType(groupName, rosettas, helper, dynamicCompiledClassLoader);
Class<RosettaModelObject> rootDataType = generateCompileAndGetRootDataType(NAMESPACE_PREFIX, groupName, rosettas, helper, dynamicCompiledClassLoader);

return listFiles(groupPath, ".json").stream()
.map(jsonPath -> Arguments.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@
import java.util.stream.Stream;

public class RuneSerializerTestHelper {

public static final String TEST_MODEL_NAME = "serialization";

@SuppressWarnings("unchecked")
public static <T extends RosettaModelObject> Class<T> generateCompileAndGetRootDataType(String groupName,
public static <T extends RosettaModelObject> Class<T> generateCompileAndGetRootDataType(String namespacePrefix, String groupName,
List<Path> rosettaPaths,
CodeGeneratorTestHelper helper, DynamicCompiledClassLoader dynamicCompiledClassLoader) {
CodeGeneratorTestHelper helper,
DynamicCompiledClassLoader dynamicCompiledClassLoader) {
String[] rosettaFileContents = rosettaPaths.stream().map(RuneSerializerTestHelper::readAsString).toArray(String[]::new);
HashMap<String, String> generatedCode = helper.generateCode(rosettaFileContents);
Map<String, Class<?>> compiledCode = helper.compileToClasses(generatedCode);
dynamicCompiledClassLoader.setCompiledCode(compiledCode);
Class<?> aClass = compiledCode.get(TEST_MODEL_NAME + ".test." + groupName + ".Root");
Class<?> aClass = compiledCode.get(namespacePrefix + groupName + ".Root");
return (Class<T>) aClass;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace cardinality
namespace serialization.test.failing.cardinality

annotation rootType: <"Mark a type as a root of the rosetta model">

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model": "test.cardinality",
"@type": "test.cardinality.Root",
"@model": "serialization",
"@type": "serialization.test.failing.cardinality.Root",
"@version": "0.0.0",
"stringList": ["foo", "bar", "baz"]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.metakey.Root",
"@type" : "serialization.test.failing.metakey.Root",
"@version" : "0.0.0",
"attributeRef" : {
"dateReference" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.metakey.Root",
"@type" : "serialization.test.failing.metakey.Root",
"@version" : "0.0.0",
"nodeRef" : {
"aReference" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace serialization.test.failing.metakey

annotation rootType: <"Mark a type as a root of the rosetta model">

type A:
[metadata key]
fieldA string (1..1)

type NodeRef:
typeA A (0..1)
aReference A (0..1)
[metadata reference]

type AttributeRef:
dateField date (0..1)
[metadata id]
dateReference date (0..1)
[metadata reference]

type Root:
[rootType]
nodeRef NodeRef (0..1)
attributeRef AttributeRef (0..1)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.metalocation.Root",
"@type" : "serialization.test.failing.metalocation.Root",
"@version" : "0.0.0",
"bAddress" : {
"@ref:scoped" : "someLocation"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace serialization.failing.metalocation

annotation rootType: <"Mark a type as a root of the rosetta model">

type A:
b B (1..1)
[metadata location]

type B:
fieldB string (1..1)

type Root:
[rootType]
typeA A (0..1)
bAddress B (0..1)
[metadata address "pointsTo"=A->b]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model": "test.parameterised",
"@type": "test.parameterised.Root",
"@model": "serialization",
"@type": "serialization.test.failing.parameterised.Root",
"@version": "0.0.0",
"parameterisedNumber": 1.23456789
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model": "test.parameterised",
"@type": "test.parameterised.Root",
"@model": "serialization",
"@type": "serialization.test.failing.parameterised.Root",
"@version": "0.0.0",
"parameterisedNumber": 123456789
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace parameterised
namespace serialization.test.failing.parameterised

annotation rootType: <"Mark a type as a root of the rosetta model">

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model": "test.parameterised",
"@type": "test.parameterised.Root",
"@model": "serialization",
"@type": "serialization.test.failing.parameterised.Root",
"@version": "0.0.0",
"parameterisedString": "$$"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model": "test.parameterised",
"@type": "test.parameterised.Root",
"@model": "serialization",
"@type": "serialization.test.failing.parameterised.Root",
"@version": "0.0.0",
"parameterisedString": "abcdefg"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.basic.Root",
"@type" : "serialization.test.passing.basic.Root",
"@version" : "0.0.0",
"basicList" : {
"booleanTypes" : [ true, false, true ],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.basic.Root",
"@type" : "serialization.test.passing.basic.Root",
"@version" : "0.0.0",
"basicSingle" : {
"booleanType" : true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace serialization.test.basic
namespace serialization.test.passing.basic

annotation rootType: <"Mark a type as a root of the rosetta model">

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.choicetype.Root",
"@type" : "serialization.test.passing.choicetype.Root",
"@version" : "0.0.0",
"choiceBasic" : {
"string" : "foo"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.choicetype.Root",
"@type" : "serialization.test.passing.choicetype.Root",
"@version" : "0.0.0",
"choiceData" : {
"A" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.choicetype.Root",
"@type" : "serialization.test.passing.choicetype.Root",
"@version" : "0.0.0",
"choiceMixed" : {
"B" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.choicetype.Root",
"@type" : "serialization.test.passing.choicetype.Root",
"@version" : "0.0.0",
"choiceMixed" : {
"string" : "foo"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace serialization.test.choicetype
namespace serialization.test.passing.choicetype

annotation rootType: <"Mark a type as a root of the rosetta model">

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.data.Root",
"@type" : "serialization.test.passing.data.Root",
"@version" : "0.0.0",
"a" : {
"b" : [ { }, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
namespace serialization.test.data

namespace serialization.test.passing.data
annotation rootType: <"Mark a type as a root of the rosetta model">

type A:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.enumtypes.Root",
"@type" : "serialization.test.passing.enumtypes.Root",
"@version" : "0.0.0",
"enumList" : {
"enumType" : [ "A", "B", "C", "B" ]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.enumtypes.Root",
"@type" : "serialization.test.passing.enumtypes.Root",
"@version" : "0.0.0",
"enumSingle" : {
"enumType" : "A"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace serialization.test.enumtypes
namespace serialization.test.passing.enumtypes

annotation rootType: <"Mark a type as a root of the rosetta model">

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.extension.Root",
"@type" : "serialization.test.passing.extension.Root",
"@version" : "0.0.0",
"typeA" : {
"fieldA" : "foo"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"@model" : "serialization",
"@type" : "serialization.test.extension.Root",
"@type" : "serialization.test.passing.extension.Root",
"@version" : "0.0.0",
"typeB" : {
"fieldA" : "bar",
"fieldB" : "foo",
"@type" : "serialization.test.extension.B"
"@type" : "serialization.test.passing.extension.B"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"@model" : "serialization",
"@type" : "serialization.test.extension.Root",
"@type" : "serialization.test.passing.extension.Root",
"@version" : "0.0.0",
"typeA" : {
"fieldA" : "bar",
"fieldB" : "foo",
"@type" : "serialization.test.extension.B"
"@type" : "serialization.test.passing.extension.B"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace serialization.test.extension
namespace serialization.test.passing.extension

annotation rootType: <"Mark a type as a root of the rosetta model">

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.metakey.Root",
"@type" : "serialization.test.passing.metakey.Root",
"@version" : "0.0.0",
"attributeRef" : {
"dateField" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace serialization.test.metakey
namespace serialization.test.passing.metakey

annotation rootType: <"Mark a type as a root of the rosetta model">

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.metakey.Root",
"@type" : "serialization.test.passing.metakey.Root",
"@version" : "0.0.0",
"nodeRef" : {
"typeA" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.metalocation.Root",
"@type" : "serialization.test.passing.metalocation.Root",
"@version" : "0.0.0",
"typeA" : {
"b" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace serialization.test.metalocation
namespace serialization.test.passing.metalocation

annotation rootType: <"Mark a type as a root of the rosetta model">

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.metascheme.Root",
"@type" : "serialization.test.passing.metascheme.Root",
"@version" : "0.0.0",
"enumTypeList" : [ {
"@data" : "A",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.metascheme.Root",
"@type" : "serialization.test.passing.metascheme.Root",
"@version" : "0.0.0",
"enumType" : {
"@data" : "A",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace serialization.test.metascheme
namespace serialization.test.passing.metascheme

annotation rootType: <"Mark a type as a root of the rosetta model">

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.metascheme.Root",
"@type" : "serialization.test.passing.metascheme.Root",
"@version" : "0.0.0",
"typeAList" : [ {
"fieldA" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@model" : "serialization",
"@type" : "serialization.test.metascheme.Root",
"@type" : "serialization.test.passing.metascheme.Root",
"@version" : "0.0.0",
"typeA" : {
"fieldA" : {
Expand Down
Loading