2
2
3
3
import io .apicurio .registry .model .GroupId ;
4
4
import io .apicurio .registry .rest .client .models .ArtifactReference ;
5
+ import io .apicurio .registry .rest .client .models .HandleReferencesType ;
5
6
import io .apicurio .registry .utils .IoUtil ;
6
7
import io .quarkus .test .junit .QuarkusTest ;
8
+ import org .apache .avro .Schema ;
7
9
import org .junit .jupiter .api .Assertions ;
8
10
import org .junit .jupiter .api .BeforeAll ;
11
+ import org .junit .jupiter .api .BeforeEach ;
9
12
import org .junit .jupiter .api .Test ;
10
13
11
14
import java .io .InputStream ;
@@ -30,20 +33,67 @@ protected void beforeAll() throws Exception {
30
33
}
31
34
}
32
35
36
+ @ BeforeEach
37
+ public void beforeEach () {
38
+ setupRestAssured ();
39
+ }
40
+
41
+ @ Test
42
+ public void testCheckGlobalRules () throws Exception {
43
+ // Global rules are enabled in the export file, they must be activated.
44
+ Assertions .assertEquals (3 , clientV3 .admin ().rules ().get ().size ());
45
+ Assertions .assertEquals ("SYNTAX_ONLY" ,
46
+ clientV3 .admin ().rules ().byRuleType ("VALIDITY" ).get ().getConfig ());
47
+ Assertions .assertEquals ("FULL" ,
48
+ clientV3 .admin ().rules ().byRuleType ("COMPATIBILITY" ).get ().getConfig ());
49
+ Assertions .assertEquals ("NONE" , clientV3 .admin ().rules ().byRuleType ("INTEGRITY" ).get ().getConfig ());
50
+ }
51
+
33
52
@ Test
34
53
public void testArtifactsCount () {
35
54
Assertions .assertEquals (32 , clientV3 .search ().artifacts ().get ().getCount ());
36
55
}
37
56
38
57
@ Test
39
58
public void testCheckAvroWithReferences () throws Exception {
40
- String dereferencedContent = IoUtil .toString (clientV3 .groups ().byGroupId ("default" ).artifacts ()
41
- .byArtifactId ("AvroSerdeReferencesExample-value" ).versions ().byVersionExpression ("1" )
42
- .content ().get ());
59
+ String tradeRawDereferenced = IoUtil .toString (clientV3 .groups ()
60
+ .byGroupId ("avro-maven-with-references-auto" ).artifacts ().byArtifactId ("TradeRaw" ).versions ()
61
+ .byVersionExpression ("2.0" ).content ().get (configuration -> {
62
+ configuration .queryParameters .references = HandleReferencesType .DEREFERENCE ;
63
+ }));
43
64
44
65
Assertions .assertEquals (
45
- "{\" type\" :\" record\" ,\" name\" :\" TradeRaw\" ,\" namespace\" :\" com.kubetrade.schema.trade\" ,\" fields\" :[{\" name\" :\" tradeKey\" ,\" type\" :{\" type\" :\" record\" ,\" name\" :\" TradeKey\" ,\" fields\" :[{\" name\" :\" exchange\" ,\" type\" :{\" type\" :\" enum\" ,\" name\" :\" Exchange\" ,\" namespace\" :\" com.kubetrade.schema.common\" ,\" symbols\" :[\" GEMINI\" ]}},{\" name\" :\" key\" ,\" type\" :{\" type\" :\" string\" ,\" avro.java.string\" :\" String\" }}]}},{\" name\" :\" symbol\" ,\" type\" :{\" type\" :\" string\" ,\" avro.java.string\" :\" String\" }},{\" name\" :\" payload\" ,\" type\" :{\" type\" :\" string\" ,\" avro.java.string\" :\" String\" }}]}" ,
46
- dereferencedContent );
66
+ "{\" type\" :\" record\" ,\" name\" :\" TradeRaw\" ,\" namespace\" :\" com.kubetrade.schema.trade\" ,\" fields\" :[{\" name\" :\" tradeKey\" ,\" type\" :{\" type\" :\" record\" ,\" name\" :\" TradeKey\" ,\" fields\" :[{\" name\" :\" exchange\" ,\" type\" :{\" type\" :\" enum\" ,\" name\" :\" Exchange\" ,\" namespace\" :\" com.kubetrade.schema.common\" ,\" symbols\" :[\" GEMINI\" ]}},{\" name\" :\" key\" ,\" type\" :\" string\" }]}},{\" name\" :\" value\" ,\" type\" :{\" type\" :\" record\" ,\" name\" :\" TradeValue\" ,\" fields\" :[{\" name\" :\" exchange\" ,\" type\" :\" com.kubetrade.schema.common.Exchange\" },{\" name\" :\" value\" ,\" type\" :\" string\" }]}},{\" name\" :\" symbol\" ,\" type\" :\" string\" },{\" name\" :\" payload\" ,\" type\" :\" string\" }]}" ,
67
+ tradeRawDereferenced );
68
+
69
+ // We try to parse the dereferenced schema to ensure it can be used.
70
+ new Schema .Parser ().parse (tradeRawDereferenced );
71
+
72
+ List <String > tradeRawReferences = clientV3 .groups ().byGroupId ("avro-maven-with-references-auto" )
73
+ .artifacts ().byArtifactId ("TradeRaw" ).versions ().byVersionExpression ("2.0" ).references ().get ()
74
+ .stream ().map (ArtifactReference ::getArtifactId ).toList ();
75
+
76
+ Assertions .assertEquals (2 , tradeRawReferences .size ());
77
+ Assertions .assertTrue (tradeRawReferences .containsAll (
78
+ List .of ("com.kubetrade.schema.trade.TradeKey" , "com.kubetrade.schema.trade.TradeValue" )));
79
+
80
+ List <String > tradeKeyReferences = clientV3 .groups ().byGroupId ("avro-maven-with-references-auto" )
81
+ .artifacts ().byArtifactId ("com.kubetrade.schema.trade.TradeKey" ).versions ()
82
+ .byVersionExpression ("1" ).references ().get ().stream ().map (ArtifactReference ::getArtifactId )
83
+ .toList ();
84
+
85
+ Assertions .assertEquals (1 , tradeKeyReferences .size ());
86
+ Assertions
87
+ .assertTrue (tradeKeyReferences .containsAll (List .of ("com.kubetrade.schema.common.Exchange" )));
88
+
89
+ List <String > tradeValueReferences = clientV3 .groups ().byGroupId ("avro-maven-with-references-auto" )
90
+ .artifacts ().byArtifactId ("com.kubetrade.schema.trade.TradeValue" ).versions ()
91
+ .byVersionExpression ("1" ).references ().get ().stream ().map (ArtifactReference ::getArtifactId )
92
+ .toList ();
93
+
94
+ Assertions .assertEquals (1 , tradeValueReferences .size ());
95
+ Assertions .assertTrue (
96
+ tradeValueReferences .containsAll (List .of ("com.kubetrade.schema.common.Exchange" )));
47
97
}
48
98
49
99
@ Test
0 commit comments