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,68 @@ 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" , clientV3 .admin ().rules ().byRuleType ("VALIDITY" ).get ().getConfig ());
46
+ Assertions .assertEquals ("FULL" ,
47
+ clientV3 .admin ().rules ().byRuleType ("COMPATIBILITY" ).get ().getConfig ());
48
+ Assertions .assertEquals ("NONE" , clientV3 .admin ().rules ().byRuleType ("INTEGRITY" ).get ().getConfig ());
49
+ }
50
+
33
51
@ Test
34
52
public void testArtifactsCount () {
35
53
Assertions .assertEquals (32 , clientV3 .search ().artifacts ().get ().getCount ());
36
54
}
37
55
38
56
@ Test
39
57
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 ());
58
+ String tradeRawDereferenced = IoUtil .toString (clientV3 .groups ().byGroupId ("avro-maven-with-references-auto" )
59
+ .artifacts ()
60
+ .byArtifactId ("TradeRaw" )
61
+ .versions ().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 ()
73
+ .byGroupId ("avro-maven-with-references-auto" ).artifacts ()
74
+ .byArtifactId ("TradeRaw" ).versions ().byVersionExpression ("2.0" ).references ()
75
+ .get ().stream ().map (ArtifactReference ::getArtifactId ).toList ();
76
+
77
+ Assertions .assertEquals (2 , tradeRawReferences .size ());
78
+ Assertions .assertTrue (tradeRawReferences
79
+ .containsAll (List .of ("com.kubetrade.schema.trade.TradeKey" , "com.kubetrade.schema.trade.TradeValue" )));
80
+
81
+ List <String > tradeKeyReferences = clientV3 .groups ()
82
+ .byGroupId ("avro-maven-with-references-auto" ).artifacts ()
83
+ .byArtifactId ("com.kubetrade.schema.trade.TradeKey" ).versions ().byVersionExpression ("1" ).references ()
84
+ .get ().stream ().map (ArtifactReference ::getArtifactId ).toList ();
85
+
86
+ Assertions .assertEquals (1 , tradeKeyReferences .size ());
87
+ Assertions .assertTrue (tradeKeyReferences
88
+ .containsAll (List .of ("com.kubetrade.schema.common.Exchange" )));
89
+
90
+ List <String > tradeValueReferences = clientV3 .groups ()
91
+ .byGroupId ("avro-maven-with-references-auto" ).artifacts ()
92
+ .byArtifactId ("com.kubetrade.schema.trade.TradeValue" ).versions ().byVersionExpression ("1" ).references ()
93
+ .get ().stream ().map (ArtifactReference ::getArtifactId ).toList ();
94
+
95
+ Assertions .assertEquals (1 , tradeValueReferences .size ());
96
+ Assertions .assertTrue (tradeValueReferences
97
+ .containsAll (List .of ("com.kubetrade.schema.common.Exchange" )));
47
98
}
48
99
49
100
@ Test
0 commit comments