Skip to content

Commit aae7b85

Browse files
committed
Improve test assertions
1 parent 9fdf469 commit aae7b85

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

app/src/test/java/io/apicurio/registry/DataUpgradeTest.java

+55-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
import io.apicurio.registry.model.GroupId;
44
import io.apicurio.registry.rest.client.models.ArtifactReference;
5+
import io.apicurio.registry.rest.client.models.HandleReferencesType;
56
import io.apicurio.registry.utils.IoUtil;
67
import io.quarkus.test.junit.QuarkusTest;
8+
import org.apache.avro.Schema;
79
import org.junit.jupiter.api.Assertions;
810
import org.junit.jupiter.api.BeforeAll;
11+
import org.junit.jupiter.api.BeforeEach;
912
import org.junit.jupiter.api.Test;
1013

1114
import java.io.InputStream;
@@ -30,20 +33,67 @@ protected void beforeAll() throws Exception {
3033
}
3134
}
3235

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+
3352
@Test
3453
public void testArtifactsCount() {
3554
Assertions.assertEquals(32, clientV3.search().artifacts().get().getCount());
3655
}
3756

3857
@Test
3958
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+
}));
4364

4465
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")));
4797
}
4898

4999
@Test
Binary file not shown.

0 commit comments

Comments
 (0)