1
1
package io .apicurio .registry ;
2
2
3
+ import io .apicurio .registry .model .GroupId ;
4
+ import io .apicurio .registry .rest .client .models .ArtifactReference ;
5
+ import io .apicurio .registry .utils .IoUtil ;
3
6
import io .apicurio .registry .utils .tests .ApicurioTestTags ;
4
7
import io .quarkus .test .junit .QuarkusTest ;
5
8
import io .quarkus .test .junit .TestProfile ;
9
+ import org .junit .jupiter .api .Assertions ;
6
10
import org .junit .jupiter .api .BeforeEach ;
7
11
import org .junit .jupiter .api .Tag ;
8
12
import org .junit .jupiter .api .Test ;
9
13
10
- import static io .restassured .RestAssured .given ;
11
- import static org .hamcrest .Matchers .is ;
14
+ import java .util .List ;
12
15
13
16
@ QuarkusTest
14
17
@ TestProfile (DataUpgradeTestProfile .class )
@@ -22,8 +25,77 @@ protected void beforeEach() throws Exception {
22
25
}
23
26
24
27
@ Test
25
- public void testCheckImportedData () throws Exception {
26
- given ().when ().accept (CT_JSON ).get ("/registry/v3/search/artifacts" ).then ().statusCode (200 )
27
- .body ("count" , is (26 ));
28
+ public void testArtifactsCount () {
29
+ Assertions .assertEquals (26 , clientV3 .search ().artifacts ().get ().getCount ());
30
+ }
31
+
32
+ @ Test
33
+ public void testCheckGlobalRules () throws Exception {
34
+ // Global rules are enabled in the export file, they must be activated.
35
+ Assertions .assertEquals (3 , clientV3 .admin ().rules ().get ().size ());
36
+ Assertions .assertEquals ("FULL" , clientV3 .admin ().rules ().byRuleType ("VALIDITY" ).get ().getConfig ());
37
+ Assertions .assertEquals ("BACKWARD" ,
38
+ clientV3 .admin ().rules ().byRuleType ("COMPATIBILITY" ).get ().getConfig ());
39
+ Assertions .assertEquals ("FULL" , clientV3 .admin ().rules ().byRuleType ("INTEGRITY" ).get ().getConfig ());
40
+ }
41
+
42
+ @ Test
43
+ public void testCheckAvroWithReferences () throws Exception {
44
+ String dereferencedContent = IoUtil .toString (clientV3 .groups ().byGroupId ("default" ).artifacts ()
45
+ .byArtifactId ("AvroSerdeReferencesExample-value" ).versions ().byVersionExpression ("1" )
46
+ .content ().get ());
47
+
48
+ Assertions .assertEquals (
49
+ "{\" 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\" }}]}" ,
50
+ dereferencedContent );
51
+ }
52
+
53
+ @ Test
54
+ public void testCheckProtobufWithReferences () throws Exception {
55
+ List <String > artifactReferences = clientV3 .groups ()
56
+ .byGroupId (GroupId .DEFAULT .getRawGroupIdWithDefaultString ()).artifacts ()
57
+ .byArtifactId ("ProtobufSerdeReferencesExample-value" ).versions ().byVersionExpression ("1" )
58
+ .references ().get ().stream ().map (ArtifactReference ::getArtifactId ).toList ();
59
+
60
+ Assertions .assertTrue (artifactReferences .containsAll (List .of ("google/protobuf/timestamp.proto" ,
61
+ "sample/table_info.proto" , "sample/table_notification_type.proto" )));
62
+ Assertions .assertEquals (3 , artifactReferences .size ());
63
+ }
64
+
65
+ @ Test
66
+ public void testCheckJsonWithReferences () throws Exception {
67
+ List <String > artifactReferences = clientV3 .groups ()
68
+ .byGroupId (GroupId .DEFAULT .getRawGroupIdWithDefaultString ()).artifacts ()
69
+ .byArtifactId ("JsonSerdeReferencesExample" ).versions ().byVersionExpression ("1" ).references ()
70
+ .get ().stream ().map (ArtifactReference ::getArtifactId ).toList ();
71
+
72
+ Assertions .assertEquals (4 , artifactReferences .size ());
73
+ Assertions .assertTrue (artifactReferences
74
+ .containsAll (List .of ("city" , "qualification" , "citizenIdentifier" , "address" )));
75
+
76
+ List <ArtifactReference > cityReferences = clientV3 .groups ()
77
+ .byGroupId (GroupId .DEFAULT .getRawGroupIdWithDefaultString ()).artifacts ().byArtifactId ("city" )
78
+ .versions ().byVersionExpression ("1" ).references ().get ();
79
+
80
+ Assertions .assertEquals (1 , cityReferences .size ());
81
+ Assertions .assertTrue (cityReferences .stream ().anyMatch (
82
+ artifactReference -> artifactReference .getArtifactId ().equals ("cityQualification" )));
83
+
84
+ List <ArtifactReference > identifierReferences = clientV3 .groups ()
85
+ .byGroupId (GroupId .DEFAULT .getRawGroupIdWithDefaultString ()).artifacts ()
86
+ .byArtifactId ("citizenIdentifier" ).versions ().byVersionExpression ("1" ).references ().get ();
87
+
88
+ Assertions .assertEquals (1 , identifierReferences .size ());
89
+ Assertions .assertTrue (identifierReferences .stream ().anyMatch (
90
+ artifactReference -> artifactReference .getArtifactId ().equals ("identifierQualification" )));
91
+
92
+ /*
93
+ * FIXME:carnalca this cannot be asserted until json schema dereferencing is implemented in v3. The
94
+ * intention here is to make sure that the content can be dereferenced as in Registry v2. String
95
+ * dereferencedContent = IoUtil.toString(clientV3.groups().byGroupId("default")
96
+ * .artifacts().byArtifactId("JsonSerdeReferencesExample") .versions().byVersionExpression("1")
97
+ * .content() .get(configuration -> { configuration.queryParameters.references =
98
+ * HandleReferencesType.DEREFERENCE; }));
99
+ */
28
100
}
29
101
}
0 commit comments