|
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;
|
9 | 11 | import org.junit.jupiter.api.Test;
|
@@ -37,13 +39,46 @@ public void testArtifactsCount() {
|
37 | 39 |
|
38 | 40 | @Test
|
39 | 41 | 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()); |
| 42 | + String tradeRawDereferenced = IoUtil.toString(clientV3.groups().byGroupId("avro-maven-with-references-auto") |
| 43 | + .artifacts() |
| 44 | + .byArtifactId("TradeRaw") |
| 45 | + .versions().byVersionExpression("2.0").content().get(configuration -> { |
| 46 | + configuration.queryParameters.references = HandleReferencesType.DEREFERENCE; |
| 47 | + })); |
43 | 48 |
|
44 | 49 | 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); |
| 50 | + "{\"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\"}]}", |
| 51 | + tradeRawDereferenced); |
| 52 | + |
| 53 | + //We try to parse the dereferenced schema to ensure it can be used. |
| 54 | + new Schema.Parser().parse(tradeRawDereferenced); |
| 55 | + |
| 56 | + List<String> tradeRawReferences = clientV3.groups() |
| 57 | + .byGroupId("avro-maven-with-references-auto").artifacts() |
| 58 | + .byArtifactId("TradeRaw").versions().byVersionExpression("2.0").references() |
| 59 | + .get().stream().map(ArtifactReference::getArtifactId).toList(); |
| 60 | + |
| 61 | + Assertions.assertEquals(2, tradeRawReferences.size()); |
| 62 | + Assertions.assertTrue(tradeRawReferences |
| 63 | + .containsAll(List.of("com.kubetrade.schema.trade.TradeKey", "com.kubetrade.schema.trade.TradeValue"))); |
| 64 | + |
| 65 | + List<String> tradeKeyReferences = clientV3.groups() |
| 66 | + .byGroupId("avro-maven-with-references-auto").artifacts() |
| 67 | + .byArtifactId("com.kubetrade.schema.trade.TradeKey").versions().byVersionExpression("1").references() |
| 68 | + .get().stream().map(ArtifactReference::getArtifactId).toList(); |
| 69 | + |
| 70 | + Assertions.assertEquals(1, tradeKeyReferences.size()); |
| 71 | + Assertions.assertTrue(tradeKeyReferences |
| 72 | + .containsAll(List.of("com.kubetrade.schema.common.Exchange"))); |
| 73 | + |
| 74 | + List<String> tradeValueReferences = clientV3.groups() |
| 75 | + .byGroupId("avro-maven-with-references-auto").artifacts() |
| 76 | + .byArtifactId("com.kubetrade.schema.trade.TradeValue").versions().byVersionExpression("1").references() |
| 77 | + .get().stream().map(ArtifactReference::getArtifactId).toList(); |
| 78 | + |
| 79 | + Assertions.assertEquals(1, tradeValueReferences.size()); |
| 80 | + Assertions.assertTrue(tradeValueReferences |
| 81 | + .containsAll(List.of("com.kubetrade.schema.common.Exchange"))); |
47 | 82 | }
|
48 | 83 |
|
49 | 84 | @Test
|
|
0 commit comments