17
17
import org .mockito .Mock ;
18
18
import org .mockito .junit .jupiter .MockitoExtension ;
19
19
20
+ import java .net .URI ;
21
+ import java .util .Arrays ;
22
+ import java .util .HashSet ;
23
+ import java .util .Set ;
24
+
20
25
import static org .mockito .Mockito .mock ;
21
26
import static org .mockito .Mockito .verify ;
22
27
@@ -42,6 +47,23 @@ void serializeRegistersTermIriMappingInJsonLdContext() throws Exception {
42
47
43
48
@ Test
44
49
void serializeRegistersExtendedTermDefinitionWithIdAndTypeInJsonLdContextWhenConfiguredToUseExtendedDefinition () throws Exception {
50
+ final Configuration config = new Configuration ();
51
+ config .set (ConfigParam .SERIALIZE_INDIVIDUALS_USING_EXPANDED_DEFINITION , Boolean .TRUE .toString ());
52
+ sut .configure (config );
53
+ final JsonLdContext ctx = mock (JsonLdContext .class );
54
+ final URI value = Generator .generateUri ();
55
+ final SerializationContext <URI > serializationCtx =
56
+ new SerializationContext <>(Vocabulary .ORIGIN , Organization .class .getDeclaredField ("country" ), value ,
57
+ ctx );
58
+
59
+ sut .serialize (value , serializationCtx );
60
+ verify (ctx ).registerTermMapping ("country" ,
61
+ SerializerUtils .createTypedTermDefinition ("country" , Vocabulary .ORIGIN ,
62
+ JsonLd .ID ));
63
+ }
64
+
65
+ @ Test
66
+ void serializeRegistersTermIriMappingInJsonLdContextWhenConfiguredToUseExtendedDefinitionWhenValueIsComplex () throws Exception {
45
67
final Configuration config = new Configuration ();
46
68
config .set (ConfigParam .SERIALIZE_INDIVIDUALS_USING_EXPANDED_DEFINITION , Boolean .TRUE .toString ());
47
69
sut .configure (config );
@@ -51,9 +73,23 @@ void serializeRegistersExtendedTermDefinitionWithIdAndTypeInJsonLdContextWhenCon
51
73
new SerializationContext <>(Vocabulary .IS_MEMBER_OF , Employee .getEmployerField (), value , ctx );
52
74
53
75
sut .serialize (value , serializationCtx );
54
- verify (ctx ).registerTermMapping (Employee .getEmployerField ().getName (),
55
- SerializerUtils .createTypedTermDefinition (Employee .getEmployerField ().getName (),
56
- Vocabulary .IS_MEMBER_OF ,
57
- JsonLd .ID ));
76
+ verify (ctx ).registerTermMapping (Employee .getEmployerField ().getName (), Vocabulary .IS_MEMBER_OF );
77
+ }
78
+
79
+ @ Test
80
+ void serializeRegistersTermIriMappingInJsonLdContextWhenConfiguredToUseExtendedDefinitionWhenValueIsCollectionOfComplexObjects () throws Exception {
81
+ final Configuration config = new Configuration ();
82
+ config .set (ConfigParam .SERIALIZE_INDIVIDUALS_USING_EXPANDED_DEFINITION , Boolean .TRUE .toString ());
83
+ sut .configure (config );
84
+ final JsonLdContext ctx = mock (JsonLdContext .class );
85
+ final Set <URI > value = new HashSet <>(Arrays .asList (Generator .generateUri (), Generator .generateUri ()));
86
+ final SerializationContext <Set <URI >> serializationCtx =
87
+ new SerializationContext <>(Vocabulary .HAS_MEMBER , Organization .getEmployeesField (), value , ctx );
88
+
89
+ sut .serialize (value , serializationCtx );
90
+ verify (ctx ).registerTermMapping (Organization .getEmployeesField ().getName (),
91
+ SerializerUtils .createTypedTermDefinition (
92
+ Organization .getEmployeesField ().getName (), Vocabulary .HAS_MEMBER ,
93
+ JsonLd .ID ));
58
94
}
59
95
}
0 commit comments