Skip to content

Commit dabd569

Browse files
committed
Switch from Error to ProblemDetails in Core v3 API + update all tests
1 parent c515756 commit dabd569

File tree

67 files changed

+630
-544
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+630
-544
lines changed

app/src/main/java/io/apicurio/registry/services/http/CCompatExceptionMapperService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import io.apicurio.registry.ccompat.rest.error.UnprocessableEntityException;
1212
import io.apicurio.registry.metrics.health.liveness.LivenessUtil;
1313
import io.apicurio.registry.metrics.health.liveness.ResponseErrorLivenessCheck;
14-
import io.apicurio.registry.rest.v3.beans.Error;
15-
import io.apicurio.registry.rest.v3.beans.RuleViolationCause;
16-
import io.apicurio.registry.rest.v3.beans.RuleViolationError;
14+
import io.apicurio.registry.rest.v2.beans.Error;
15+
import io.apicurio.registry.rest.v2.beans.RuleViolationCause;
16+
import io.apicurio.registry.rest.v2.beans.RuleViolationError;
1717
import io.apicurio.registry.rules.RuleViolation;
1818
import io.apicurio.registry.rules.RuleViolationException;
1919
import io.apicurio.registry.storage.error.AlreadyExistsException;

app/src/main/java/io/apicurio/registry/services/http/CoreRegistryExceptionMapperService.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import io.apicurio.common.apps.config.Info;
44
import io.apicurio.registry.metrics.health.liveness.LivenessUtil;
55
import io.apicurio.registry.metrics.health.liveness.ResponseErrorLivenessCheck;
6-
import io.apicurio.registry.rest.v3.beans.Error;
6+
import io.apicurio.registry.rest.v3.beans.ProblemDetails;
77
import io.apicurio.registry.rest.v3.beans.RuleViolationCause;
8-
import io.apicurio.registry.rest.v3.beans.RuleViolationError;
8+
import io.apicurio.registry.rest.v3.beans.RuleViolationProblemDetails;
99
import io.apicurio.registry.rules.RuleViolation;
1010
import io.apicurio.registry.rules.RuleViolationException;
1111
import jakarta.enterprise.context.ApplicationScoped;
@@ -71,30 +71,30 @@ public Response mapException(Throwable t) {
7171
builder = Response.status(code);
7272
}
7373

74-
Error error = toError(t, code);
74+
ProblemDetails error = toProblemDetails(t, code);
7575
return builder.entity(error).type(MediaType.APPLICATION_JSON).build();
7676
}
7777

78-
private Error toError(Throwable t, int code) {
79-
Error error;
78+
private ProblemDetails toProblemDetails(Throwable t, int code) {
79+
ProblemDetails details;
8080

8181
if (t instanceof RuleViolationException) {
8282
RuleViolationException rve = (RuleViolationException) t;
83-
error = new RuleViolationError();
84-
((RuleViolationError) error).setCauses(toRestCauses(rve.getCauses()));
83+
details = new RuleViolationProblemDetails();
84+
((RuleViolationProblemDetails) details).setCauses(toRestCauses(rve.getCauses()));
8585
} else {
86-
error = new Error();
86+
details = new ProblemDetails();
8787
}
8888

89-
error.setErrorCode(code);
90-
error.setMessage(t.getLocalizedMessage());
89+
details.setStatus(code);
90+
details.setTitle(t.getLocalizedMessage());
91+
details.setName(t.getClass().getSimpleName());
9192
if (includeStackTrace) {
92-
error.setDetail(getStackTrace(t));
93+
details.setDetail(getStackTrace(t));
9394
} else {
94-
error.setDetail(getRootMessage(t));
95+
details.setDetail(getRootMessage(t));
9596
}
96-
error.setName(t.getClass().getSimpleName());
97-
return error;
97+
return details;
9898
}
9999

100100
/**

app/src/main/java/io/apicurio/registry/services/http/CoreV2RegistryExceptionMapperService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import io.apicurio.common.apps.config.Info;
44
import io.apicurio.registry.metrics.health.liveness.LivenessUtil;
55
import io.apicurio.registry.metrics.health.liveness.ResponseErrorLivenessCheck;
6-
import io.apicurio.registry.rest.v3.beans.Error;
7-
import io.apicurio.registry.rest.v3.beans.RuleViolationCause;
8-
import io.apicurio.registry.rest.v3.beans.RuleViolationError;
6+
import io.apicurio.registry.rest.v2.beans.Error;
7+
import io.apicurio.registry.rest.v2.beans.RuleViolationCause;
8+
import io.apicurio.registry.rest.v2.beans.RuleViolationError;
99
import io.apicurio.registry.rules.RuleViolation;
1010
import io.apicurio.registry.rules.RuleViolationException;
1111
import jakarta.enterprise.context.ApplicationScoped;

app/src/test/java/io/apicurio/registry/auth/BasicAuthWithPropertiesTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ protected RegistryClient createRestClientV3() {
6464
}
6565

6666
protected void assertArtifactNotFound(Exception exception) {
67-
Assertions.assertEquals(io.apicurio.registry.rest.client.models.Error.class, exception.getClass());
67+
Assertions.assertEquals(io.apicurio.registry.rest.client.models.ProblemDetails.class,
68+
exception.getClass());
6869
Assertions.assertEquals("ArtifactNotFoundException",
69-
((io.apicurio.registry.rest.client.models.Error) exception).getName());
70+
((io.apicurio.registry.rest.client.models.ProblemDetails) exception).getName());
7071
Assertions.assertEquals(404,
71-
((io.apicurio.registry.rest.client.models.Error) exception).getErrorCode());
72+
((io.apicurio.registry.rest.client.models.ProblemDetails) exception).getStatus());
7273
}
7374

7475
@Test

app/src/test/java/io/apicurio/registry/auth/SimpleAuthTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ protected RegistryClient createRestClientV3() {
7070
}
7171

7272
protected void assertArtifactNotFound(Exception exception) {
73-
Assertions.assertEquals(io.apicurio.registry.rest.client.models.Error.class, exception.getClass());
73+
Assertions.assertEquals(io.apicurio.registry.rest.client.models.ProblemDetails.class,
74+
exception.getClass());
7475
Assertions.assertEquals("ArtifactNotFoundException",
75-
((io.apicurio.registry.rest.client.models.Error) exception).getName());
76+
((io.apicurio.registry.rest.client.models.ProblemDetails) exception).getName());
7677
Assertions.assertEquals(404,
77-
((io.apicurio.registry.rest.client.models.Error) exception).getErrorCode());
78+
((io.apicurio.registry.rest.client.models.ProblemDetails) exception).getStatus());
7879
}
7980

8081
@Test

app/src/test/java/io/apicurio/registry/limits/LimitsTest.java

+15-14
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,22 @@ public void testLimits() throws Exception {
8787
Assertions.assertEquals(409, exception1.getResponseStatusCode());
8888

8989
// schema number 3 , exceeds the max number of schemas
90-
var exception2 = Assertions.assertThrows(io.apicurio.registry.rest.client.models.Error.class, () -> {
91-
CreateArtifact createArtifact = new CreateArtifact();
92-
createArtifact.setArtifactId(artifactId);
93-
createArtifact.setArtifactType(ArtifactType.JSON);
94-
CreateVersion createVersion = new CreateVersion();
95-
createArtifact.setFirstVersion(createVersion);
96-
VersionContent versionContent = new VersionContent();
97-
createVersion.setContent(versionContent);
98-
versionContent.setContent("{}");
99-
versionContent.setContentType(ContentTypes.APPLICATION_JSON);
90+
var exception2 = Assertions.assertThrows(io.apicurio.registry.rest.client.models.ProblemDetails.class,
91+
() -> {
92+
CreateArtifact createArtifact = new CreateArtifact();
93+
createArtifact.setArtifactId(artifactId);
94+
createArtifact.setArtifactType(ArtifactType.JSON);
95+
CreateVersion createVersion = new CreateVersion();
96+
createArtifact.setFirstVersion(createVersion);
97+
VersionContent versionContent = new VersionContent();
98+
createVersion.setContent(versionContent);
99+
versionContent.setContent("{}");
100+
versionContent.setContentType(ContentTypes.APPLICATION_JSON);
100101

101-
clientV3.groups().byGroupId(GroupId.DEFAULT.getRawGroupIdWithDefaultString()).artifacts()
102-
.post(createArtifact);
103-
});
104-
Assertions.assertEquals(409, exception2.getErrorCode());
102+
clientV3.groups().byGroupId(GroupId.DEFAULT.getRawGroupIdWithDefaultString()).artifacts()
103+
.post(createArtifact);
104+
});
105+
Assertions.assertEquals(409, exception2.getStatus());
105106
}
106107

107108
}

app/src/test/java/io/apicurio/registry/noprofile/VersionStateTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public void testSmoke() throws Exception {
5656

5757
// cannot get a disabled artifact version *content*
5858

59-
var exception = assertThrows(io.apicurio.registry.rest.client.models.Error.class, () -> {
59+
var exception = assertThrows(io.apicurio.registry.rest.client.models.ProblemDetails.class, () -> {
6060
clientV3.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).versions()
6161
.byVersionExpression("3").content().get();
6262
});
63-
Assertions.assertEquals(404, exception.getErrorCode());
63+
Assertions.assertEquals(404, exception.getStatus());
6464
Assertions.assertEquals("VersionNotFoundException", exception.getName());
6565

6666
// can update and get metadata for a disabled artifact, but must specify version

app/src/test/java/io/apicurio/registry/noprofile/resolver/SchemaResolverTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ public String artifactType() {
9797
() -> resolver.resolveSchema(new CustomResolverRecord(avroRecord,
9898
ArtifactReference.builder().groupId(GroupId.DEFAULT.getRawGroupIdWithDefaultString())
9999
.artifactId("foo").build())));
100-
io.apicurio.registry.rest.client.models.Error error = (io.apicurio.registry.rest.client.models.Error) runtimeException
100+
io.apicurio.registry.rest.client.models.ProblemDetails error = (io.apicurio.registry.rest.client.models.ProblemDetails) runtimeException
101101
.getCause();
102102
assertEquals("VersionNotFoundException", error.getName());
103-
assertEquals(404, error.getErrorCode());
103+
assertEquals(404, error.getStatus());
104104

105105
resolver.close();
106106
}

app/src/test/java/io/apicurio/registry/noprofile/rest/v3/AllYamlTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import io.apicurio.registry.rest.client.models.CreateArtifactResponse;
66
import io.apicurio.registry.rest.client.models.CreateRule;
77
import io.apicurio.registry.rest.client.models.CreateVersion;
8-
import io.apicurio.registry.rest.client.models.Error;
8+
import io.apicurio.registry.rest.client.models.ProblemDetails;
99
import io.apicurio.registry.rest.client.models.RuleType;
1010
import io.apicurio.registry.rest.client.models.VersionSearchResults;
1111
import io.apicurio.registry.rules.compatibility.CompatibilityLevel;
@@ -124,7 +124,7 @@ public void testCreateYamlArtifactWithValidity() throws Exception {
124124
CreateArtifact createArtifact = TestUtils.clientCreateArtifact(artifactId, ArtifactType.OPENAPI,
125125
YAML_CONTENT, ContentTypes.APPLICATION_YAML);
126126
clientV3.groups().byGroupId(groupId).artifacts().post(createArtifact);
127-
} catch (Error e) {
127+
} catch (ProblemDetails e) {
128128
System.out.println("ERROR: " + e.getDetail());
129129
e.getCause().printStackTrace();
130130
throw e;

app/src/test/java/io/apicurio/registry/noprofile/rest/v3/BranchesTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import io.apicurio.registry.rest.client.models.CreateBranch;
88
import io.apicurio.registry.rest.client.models.CreateVersion;
99
import io.apicurio.registry.rest.client.models.EditableBranchMetaData;
10-
import io.apicurio.registry.rest.client.models.Error;
10+
import io.apicurio.registry.rest.client.models.ProblemDetails;
1111
import io.apicurio.registry.rest.client.models.ReplaceBranchVersions;
1212
import io.apicurio.registry.rest.client.models.VersionMetaData;
1313
import io.apicurio.registry.rest.client.models.VersionSearchResults;
@@ -42,11 +42,11 @@ public void testLatestBranch() throws Exception {
4242
Assertions.assertEquals(2, versions.getCount());
4343

4444
// Not allowed to delete the latest branch.
45-
var error = Assertions.assertThrows(Error.class, () -> {
45+
var error = Assertions.assertThrows(ProblemDetails.class, () -> {
4646
clientV3.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).branches()
4747
.byBranchId("latest").delete();
4848
});
49-
Assertions.assertEquals("System generated branches cannot be deleted.", error.getMessageEscaped());
49+
Assertions.assertEquals("System generated branches cannot be deleted.", error.getTitle());
5050
}
5151

5252
@Test

app/src/test/java/io/apicurio/registry/noprofile/rest/v3/DryRunTest.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import io.apicurio.registry.rest.client.models.CreateGroup;
88
import io.apicurio.registry.rest.client.models.CreateRule;
99
import io.apicurio.registry.rest.client.models.CreateVersion;
10-
import io.apicurio.registry.rest.client.models.Error;
1110
import io.apicurio.registry.rest.client.models.IfArtifactExists;
11+
import io.apicurio.registry.rest.client.models.ProblemDetails;
1212
import io.apicurio.registry.rest.client.models.RuleType;
1313
import io.apicurio.registry.rest.client.models.VersionMetaData;
1414
import io.apicurio.registry.rest.client.models.VersionSearchResults;
@@ -71,22 +71,22 @@ public void testCreateArtifactDryRun() throws Exception {
7171
ArtifactSearchResults results = clientV3.groups().byGroupId(groupId).artifacts().get();
7272
Assertions.assertEquals(0, results.getCount());
7373
Assertions.assertEquals(0, results.getArtifacts().size());
74-
Error error = Assertions.assertThrows(Error.class, () -> {
74+
ProblemDetails error = Assertions.assertThrows(ProblemDetails.class, () -> {
7575
clientV3.groups().byGroupId(groupId).artifacts().byArtifactId("valid-artifact").get();
7676
});
7777
Assertions.assertEquals(
7878
"No artifact with ID 'valid-artifact' in group 'testCreateArtifactDryRun' was found.",
79-
error.getMessageEscaped());
79+
error.getTitle());
8080

8181
// Dry run: invalid artifact that should NOT be created.
82-
error = Assertions.assertThrows(Error.class, () -> {
82+
error = Assertions.assertThrows(ProblemDetails.class, () -> {
8383
CreateArtifact ca = TestUtils.clientCreateArtifact("invalid-artifact", ArtifactType.AVRO,
8484
INVALID_SCHEMA, ContentTypes.APPLICATION_JSON);
8585
clientV3.groups().byGroupId(groupId).artifacts().post(ca, config -> {
8686
config.queryParameters.dryRun = true;
8787
});
8888
});
89-
Assertions.assertEquals("Syntax violation for Avro artifact.", error.getMessageEscaped());
89+
Assertions.assertEquals("Syntax violation for Avro artifact.", error.getTitle());
9090
Assertions.assertNotNull(car);
9191
Assertions.assertEquals(groupId, car.getArtifact().getGroupId());
9292
Assertions.assertEquals("valid-artifact", car.getArtifact().getArtifactId());
@@ -96,12 +96,12 @@ public void testCreateArtifactDryRun() throws Exception {
9696
results = clientV3.groups().byGroupId(groupId).artifacts().get();
9797
Assertions.assertEquals(0, results.getCount());
9898
Assertions.assertEquals(0, results.getArtifacts().size());
99-
error = Assertions.assertThrows(Error.class, () -> {
99+
error = Assertions.assertThrows(ProblemDetails.class, () -> {
100100
clientV3.groups().byGroupId(groupId).artifacts().byArtifactId("invalid-artifact").get();
101101
});
102102
Assertions.assertEquals(
103103
"No artifact with ID 'invalid-artifact' in group 'testCreateArtifactDryRun' was found.",
104-
error.getMessageEscaped());
104+
error.getTitle());
105105

106106
// Actually create an artifact in the group.
107107
createArtifact(groupId, "actual-artifact", ArtifactType.AVRO, SCHEMA_SIMPLE,
@@ -111,7 +111,7 @@ public void testCreateArtifactDryRun() throws Exception {
111111
Assertions.assertEquals(1, results.getArtifacts().size());
112112

113113
// DryRun: Try to create the *same* artifact (conflict)
114-
error = Assertions.assertThrows(Error.class, () -> {
114+
error = Assertions.assertThrows(ProblemDetails.class, () -> {
115115
CreateArtifact ca = TestUtils.clientCreateArtifact("actual-artifact", ArtifactType.AVRO,
116116
SCHEMA_SIMPLE, ContentTypes.APPLICATION_JSON);
117117
clientV3.groups().byGroupId(groupId).artifacts().post(ca, config -> {
@@ -120,7 +120,7 @@ public void testCreateArtifactDryRun() throws Exception {
120120
});
121121
Assertions.assertEquals(
122122
"An artifact with ID 'actual-artifact' in group 'testCreateArtifactDryRun' already exists.",
123-
error.getMessageEscaped());
123+
error.getTitle());
124124

125125
// DryRun: Try to create the *same* artifact but with ifExists set (success)
126126
createArtifact = TestUtils.clientCreateArtifact("actual-artifact", ArtifactType.AVRO, SCHEMA_SIMPLE,
@@ -165,15 +165,15 @@ public void testCreateVersionDryRun() throws Exception {
165165
createArtifact(groupId, artifactId, ArtifactType.AVRO, SCHEMA_SIMPLE, ContentTypes.APPLICATION_JSON);
166166

167167
// DryRun: try to create an invalid version
168-
Error error = Assertions.assertThrows(Error.class, () -> {
168+
ProblemDetails error = Assertions.assertThrows(ProblemDetails.class, () -> {
169169
CreateVersion createVersion = TestUtils.clientCreateVersion(INVALID_SCHEMA,
170170
ContentTypes.APPLICATION_JSON);
171171
clientV3.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).versions()
172172
.post(createVersion, config -> {
173173
config.queryParameters.dryRun = true;
174174
});
175175
});
176-
Assertions.assertEquals("Syntax violation for Avro artifact.", error.getMessageEscaped());
176+
Assertions.assertEquals("Syntax violation for Avro artifact.", error.getTitle());
177177

178178
// DryRun: try to create a valid version (appears to work)
179179
{

app/src/test/java/io/apicurio/registry/noprofile/rest/v3/GroupRulesTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import io.apicurio.registry.AbstractResourceTestBase;
44
import io.apicurio.registry.rest.client.models.CreateGroup;
55
import io.apicurio.registry.rest.client.models.CreateRule;
6-
import io.apicurio.registry.rest.client.models.Error;
6+
import io.apicurio.registry.rest.client.models.ProblemDetails;
77
import io.apicurio.registry.rest.client.models.Rule;
88
import io.apicurio.registry.rest.client.models.RuleType;
99
import io.apicurio.registry.rules.compatibility.CompatibilityLevel;
@@ -41,13 +41,13 @@ public void testGroupRules() throws Exception {
4141
Assertions.assertEquals(ValidityLevel.FULL.name(), rule.getConfig());
4242

4343
// Try to add the rule again - should get a 409
44-
Error error = Assertions.assertThrows(Error.class, () -> {
44+
ProblemDetails error = Assertions.assertThrows(ProblemDetails.class, () -> {
4545
CreateRule cr = new CreateRule();
4646
cr.setRuleType(RuleType.VALIDITY);
4747
cr.setConfig(ValidityLevel.FULL.name());
4848
clientV3.groups().byGroupId(groupId).rules().post(cr);
4949
});
50-
Assertions.assertEquals("A rule named 'VALIDITY' already exists.", error.getMessageEscaped());
50+
Assertions.assertEquals("A rule named 'VALIDITY' already exists.", error.getTitle());
5151

5252
// Add another rule
5353
createRule = new CreateRule();
@@ -81,10 +81,10 @@ public void testGroupRules() throws Exception {
8181
clientV3.groups().byGroupId(groupId).rules().byRuleType(RuleType.COMPATIBILITY.name()).delete();
8282

8383
// Get a single (deleted) rule by name (should fail with a 404)
84-
error = Assertions.assertThrows(Error.class, () -> {
84+
error = Assertions.assertThrows(ProblemDetails.class, () -> {
8585
clientV3.groups().byGroupId(groupId).rules().byRuleType(RuleType.COMPATIBILITY.name()).get();
8686
});
87-
Assertions.assertEquals("No rule named 'COMPATIBILITY' was found.", error.getMessageEscaped());
87+
Assertions.assertEquals("No rule named 'COMPATIBILITY' was found.", error.getTitle());
8888

8989
// Get the list of rules (should be 1 of them)
9090
rules = clientV3.groups().byGroupId(groupId).rules().get();
@@ -102,13 +102,13 @@ public void testGroupRules() throws Exception {
102102
createRule = new CreateRule();
103103
createRule.setRuleType(RuleType.VALIDITY);
104104
createRule.setConfig("FULL");
105-
error = Assertions.assertThrows(Error.class, () -> {
105+
error = Assertions.assertThrows(ProblemDetails.class, () -> {
106106
CreateRule cr = new CreateRule();
107107
cr.setRuleType(RuleType.VALIDITY);
108108
cr.setConfig(ValidityLevel.FULL.name());
109109
clientV3.groups().byGroupId("group-that-does-not-exist").rules().post(cr);
110110
});
111-
Assertions.assertEquals("No group 'group-that-does-not-exist' was found.", error.getMessageEscaped());
111+
Assertions.assertEquals("No group 'group-that-does-not-exist' was found.", error.getTitle());
112112
}
113113

114114
}

0 commit comments

Comments
 (0)