Skip to content

Commit ce59d31

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

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

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

+56-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,68 @@ 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", 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+
3351
@Test
3452
public void testArtifactsCount() {
3553
Assertions.assertEquals(32, clientV3.search().artifacts().get().getCount());
3654
}
3755

3856
@Test
3957
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+
}));
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()
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")));
4798
}
4899

49100
@Test
Binary file not shown.

0 commit comments

Comments
 (0)