Skip to content

Commit 30727f5

Browse files
committed
Fixed several broken tests
1 parent fe2d8e1 commit 30727f5

File tree

5 files changed

+53
-16
lines changed

5 files changed

+53
-16
lines changed

app/src/main/java/io/apicurio/registry/ccompat/rest/v7/impl/AbstractResource.java

-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import io.apicurio.registry.types.VersionState;
3232
import io.apicurio.registry.types.provider.ArtifactTypeUtilProvider;
3333
import io.apicurio.registry.types.provider.ArtifactTypeUtilProviderFactory;
34-
import io.apicurio.registry.content.util.ContentTypeUtil;
3534
import jakarta.inject.Inject;
3635
import org.apache.avro.AvroTypeException;
3736
import org.apache.avro.SchemaParseException;
@@ -76,8 +75,6 @@ protected ArtifactVersionMetaDataDto createOrUpdateArtifact(String subject, Stri
7675
String contentType = ContentTypes.APPLICATION_JSON;
7776
if (artifactType.equals(ArtifactType.PROTOBUF)) {
7877
contentType = ContentTypes.APPLICATION_PROTOBUF;
79-
} else if (ContentTypeUtil.isParsableYaml(schemaContent)) {
80-
contentType = ContentTypes.APPLICATION_YAML;
8178
}
8279

8380
if (!doesArtifactExist(subject, groupId)) {

app/src/main/java/io/apicurio/registry/storage/impl/gitops/GitManager.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,13 @@ private Content processContent(ProcessingState state, GitFile base, String conte
377377
try {
378378
// FIXME need to better determine the content type?
379379
String contentType = ContentTypes.APPLICATION_JSON;
380-
if (contentFile.getPath().toLowerCase().endsWith(".yaml") || contentFile.getPath().toLowerCase().endsWith(".yml")) {
380+
if (dataFile.getPath().toLowerCase().endsWith(".yaml") || dataFile.getPath().toLowerCase().endsWith(".yml")) {
381381
contentType = ContentTypes.APPLICATION_YAML;
382-
} else if (contentFile.getPath().toLowerCase().endsWith(".xml") || contentFile.getPath().toLowerCase().endsWith(".wsdl") || contentFile.getPath().toLowerCase().endsWith(".xsd")) {
382+
} else if (dataFile.getPath().toLowerCase().endsWith(".xml") || dataFile.getPath().toLowerCase().endsWith(".wsdl") || dataFile.getPath().toLowerCase().endsWith(".xsd")) {
383383
contentType = ContentTypes.APPLICATION_XML;
384-
} else if (contentFile.getPath().toLowerCase().endsWith(".proto")) {
384+
} else if (dataFile.getPath().toLowerCase().endsWith(".proto")) {
385385
contentType = ContentTypes.APPLICATION_PROTOBUF;
386-
} else if (contentFile.getPath().toLowerCase().endsWith(".graphql")) {
386+
} else if (dataFile.getPath().toLowerCase().endsWith(".graphql")) {
387387
contentType = ContentTypes.APPLICATION_GRAPHQL;
388388
}
389389
var typedContent = TypedContent.create(data, contentType);

app/src/test/java/io/apicurio/registry/noprofile/ccompat/rest/v7/ConfluentClientTest.java

+47-7
Original file line numberDiff line numberDiff line change
@@ -822,13 +822,53 @@ public void testSchemaReferences() throws Exception {
822822

823823
@Test
824824
public void testSchemaReferencesMultipleLevels() throws Exception {
825-
String root = "[\"myavro.BudgetDecreased\",\"myavro.BudgetUpdated\"]";
826-
827-
String ref1 = "{\n" + " \"type\" : \"record\",\n" + " \"name\" : \"BudgetDecreased\",\n" + " \"namespace\" : \"myavro\",\n" + " \"fields\" : [ {\n" + " \"name\" : \"buyerId\",\n" + " \"type\" : \"long\"\n" + " }, {\n" + " \"name\" : \"currency\",\n" + " \"type\" : {\n" + " \"type\" : \"myavro.currencies.Currency\"" + " }\n" + " }, {\n" + " \"name\" : \"amount\",\n" + " \"type\" : \"double\"\n" + " } ]\n" + "}";
828-
829-
String ref2 = "{\n" + " \"type\" : \"record\",\n" + " \"name\" : \"BudgetUpdated\",\n" + " \"namespace\" : \"myavro\",\n" + " \"fields\" : [ {\n" + " \"name\" : \"buyerId\",\n" + " \"type\" : \"long\"\n" + " }, {\n" + " \"name\" : \"currency\",\n" + " \"type\" : {\n" + " \"type\" : \"myavro.currencies.Currency\"" + " }\n" + " }, {\n" + " \"name\" : \"updatedValue\",\n" + " \"type\" : \"double\"\n" + " } ]\n" + "}";
830-
831-
String sharedRef = "{\n" + " \"type\" : \"enum\",\n" + " \"name\" : \"Currency\",\n" + " \"namespace\" : \"myavro.currencies\",\n" + " \"symbols\" : [ \"EUR\", \"USD\" ]\n" + " }\n";
825+
String root = """
826+
["myavro.BudgetDecreased","myavro.BudgetUpdated"]""";
827+
828+
String ref1 = """
829+
{
830+
"type" : "record",
831+
"name" : "BudgetDecreased",
832+
"namespace" : "myavro",
833+
"fields" : [ {
834+
"name" : "buyerId",
835+
"type" : "long"
836+
}, {
837+
"name" : "currency",
838+
"type" : {
839+
"type" : "myavro.currencies.Currency" }
840+
}, {
841+
"name" : "amount",
842+
"type" : "double"
843+
} ]
844+
}""";
845+
846+
String ref2 = """
847+
{
848+
"type" : "record",
849+
"name" : "BudgetUpdated",
850+
"namespace" : "myavro",
851+
"fields" : [ {
852+
"name" : "buyerId",
853+
"type" : "long"
854+
}, {
855+
"name" : "currency",
856+
"type" : {
857+
"type" : "myavro.currencies.Currency" }
858+
}, {
859+
"name" : "updatedValue",
860+
"type" : "double"
861+
} ]
862+
}""";
863+
864+
String sharedRef = """
865+
{
866+
"type" : "enum",
867+
"name" : "Currency",
868+
"namespace" : "myavro.currencies",
869+
"symbols" : [ "EUR", "USD" ]
870+
}
871+
""";
832872

833873
ConfluentTestUtils.registerAndVerifySchema(confluentClient, new AvroSchema(sharedRef).canonicalString(), "shared");
834874

schema-util/common/src/main/java/io/apicurio/registry/content/util/ContentTypeUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static boolean isParsableYaml(ContentHandle yaml) {
9696
public static boolean isParsableJson(ContentHandle content) {
9797
try {
9898
JsonNode root = jsonMapper.readTree(content.stream());
99-
return root != null && (root.isObject() || root.isArray());
99+
return root != null && !root.isNull() && !root.isMissingNode();
100100
} catch (Throwable t) {
101101
return false;
102102
}

schema-util/util-provider/src/main/java/io/apicurio/registry/types/provider/JsonArtifactTypeUtilProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class JsonArtifactTypeUtilProvider extends AbstractArtifactTypeUtilProvid
2525
public boolean acceptsContent(TypedContent content, Map<String, TypedContent> resolvedReferences) {
2626
try {
2727
String contentType = content.getContentType();
28-
if (contentType.toLowerCase().contains("json") && ContentTypeUtil.isParsableXml(content.getContent())) {
28+
if (contentType.toLowerCase().contains("json") && ContentTypeUtil.isParsableJson(content.getContent())) {
2929
JsonNode tree = ContentTypeUtil.parseJson(content.getContent());
3030
if (tree.has("$schema") && tree.get("$schema").asText().contains("json-schema.org") || tree.has("properties")) {
3131
return true;

0 commit comments

Comments
 (0)