Skip to content

Commit 6c44e36

Browse files
Kiota sync client (#4184)
* [WIP] switch to the Kiota sync client * it compiles * more * test in ci * more fixes * more * fix * auth debugging * Adapt mock and tests to vertx auth * remove-trailing-slash * fixes * more * minor * minor revert * Make mock match endpoint and add stub for basic user * Restore CI * Fix exception unwrap * Fix usernames in realm * Fix wrong credentials exception handling in integration tests * Fix assertion * bupm versions and rename to java-sdk * bump kiota --------- Co-authored-by: Carles Arnal <carlesarnal92@gmail.com>
1 parent 266c718 commit 6c44e36

File tree

76 files changed

+1345
-1861
lines changed

Some content is hidden

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

76 files changed

+1345
-1861
lines changed

.github/test-mvn-deploy/pom.xml

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
</dependency>
2323
<dependency>
2424
<groupId>io.apicurio</groupId>
25-
<artifactId>apicurio-registry-client</artifactId>
25+
<artifactId>apicurio-registry-java-sdk</artifactId>
2626
<version>${version.apicurio}</version>
2727
</dependency>
2828
</dependencies>
2929
</project>
30-
31-

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

-22
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
package io.apicurio.registry;
22

3-
import com.microsoft.kiota.ApiException;
43
import io.apicurio.registry.content.ContentHandle;
54
import io.apicurio.registry.utils.tests.ParallelizableTest;
65
import io.apicurio.registry.utils.tests.TestUtils;
76

8-
import io.apicurio.rest.client.auth.exception.NotAuthorizedException;
97
import org.eclipse.microprofile.config.inject.ConfigProperty;
108
import org.junit.jupiter.api.Assertions;
119
import java.io.BufferedReader;
1210
import java.io.IOException;
1311
import java.io.InputStream;
1412
import java.io.InputStreamReader;
1513
import java.nio.charset.StandardCharsets;
16-
import java.util.concurrent.ExecutionException;
1714
import java.util.stream.Collectors;
1815

1916
/**
@@ -63,23 +60,4 @@ protected final ContentHandle resourceToContentHandle(String resourceName) {
6360
public static void assertMultilineTextEquals(String expected, String actual) throws Exception {
6461
Assertions.assertEquals(TestUtils.normalizeMultiLineString(expected), TestUtils.normalizeMultiLineString(actual));
6562
}
66-
67-
protected void assertForbidden(ExecutionException executionException) {
68-
Assertions.assertNotNull(executionException.getCause());
69-
Assertions.assertEquals(ApiException.class, executionException.getCause().getClass());
70-
Assertions.assertEquals(403, ((ApiException)executionException.getCause()).getResponseStatusCode());
71-
}
72-
73-
protected void assertNotAuthorized(ExecutionException executionException) {
74-
Assertions.assertNotNull(executionException.getCause());
75-
76-
if (executionException.getCause() instanceof NotAuthorizedException) {
77-
// thrown by the token provider adapter
78-
} else {
79-
// mapped by Kiota
80-
Assertions.assertEquals(ApiException.class, executionException.getCause().getClass());
81-
Assertions.assertEquals(401, ((ApiException) executionException.getCause()).getResponseStatusCode());
82-
}
83-
}
84-
8563
}

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

+23-30
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@
99
import java.util.Collections;
1010
import java.util.List;
1111
import java.util.UUID;
12-
import java.util.concurrent.ExecutionException;
13-
import java.util.concurrent.TimeUnit;
14-
import java.util.concurrent.TimeoutException;
1512
import java.util.stream.Collectors;
1613

1714
import com.microsoft.kiota.ApiException;
1815
import com.microsoft.kiota.RequestAdapter;
19-
import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider;
20-
import com.microsoft.kiota.http.OkHttpRequestAdapter;
16+
2117
import io.apicurio.registry.rest.client.models.ArtifactMetaData;
2218
import io.apicurio.registry.rest.v3.beans.ArtifactReference;
2319
import io.apicurio.rest.client.auth.exception.NotAuthorizedException;
20+
import io.kiota.http.vertx.VertXRequestAdapter;
21+
import io.apicurio.registry.client.auth.VertXAuthFactory;
2422
import org.junit.jupiter.api.AfterAll;
2523
import org.junit.jupiter.api.Assertions;
2624
import org.junit.jupiter.api.BeforeAll;
@@ -78,7 +76,7 @@ protected RestService buildConfluentClient() {
7876
return new RestService("http://localhost:" + testPort + "/apis/ccompat/v7");
7977
}
8078

81-
protected final RequestAdapter anonymousAdapter = new OkHttpRequestAdapter(new AnonymousAuthenticationProvider());
79+
protected final RequestAdapter anonymousAdapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx);
8280

8381
protected RegistryClient createRestClientV3() {
8482
anonymousAdapter.setBaseUrl(registryV3ApiUrl);
@@ -101,11 +99,11 @@ protected void deleteGlobalRules(int expectedDefaultRulesCount) throws Exception
10199
// Delete all global rules
102100
TestUtils.retry(() -> {
103101
try {
104-
clientV3.admin().rules().delete().get(3, TimeUnit.SECONDS);
102+
clientV3.admin().rules().delete();
105103
} catch (Exception err) {
106104
// ignore
107105
}
108-
Assertions.assertEquals(expectedDefaultRulesCount, clientV3.admin().rules().get().get(3, TimeUnit.SECONDS).size());
106+
Assertions.assertEquals(expectedDefaultRulesCount, clientV3.admin().rules().get().size());
109107
});
110108
}
111109

@@ -125,7 +123,7 @@ protected Long createArtifact(String groupId, String artifactId, String artifact
125123
config.headers.add("X-Registry-ArtifactId", artifactId);
126124
config.headers.add("X-Registry-ArtifactType", artifactType);
127125
})
128-
.get(3, TimeUnit.SECONDS);
126+
;
129127

130128
assert( result.getId().equals(artifactId) );
131129
assert( result.getType().equals(artifactType) );
@@ -181,7 +179,7 @@ protected ArtifactMetaData createArtifactExtendedRaw(String groupId, String arti
181179
config.headers.add("X-Registry-ArtifactType", artifactType);
182180
}
183181
})
184-
.get(3, TimeUnit.SECONDS);
182+
;
185183
}
186184

187185
protected ArtifactMetaData updateArtifactExtendedRaw(String groupId, String artifactId, String artifactType, String artifactContent, List<ArtifactReference> artifactReferences) throws Exception {
@@ -207,7 +205,7 @@ protected ArtifactMetaData updateArtifactExtendedRaw(String groupId, String arti
207205
config.headers.add("X-Registry-ArtifactId", artifactId);
208206
config.headers.add("X-Registry-ArtifactType", artifactType);
209207
})
210-
.get(3, TimeUnit.SECONDS);
208+
;
211209
}
212210

213211
protected Long createArtifactVersion(String artifactId, String artifactType, String artifactContent) throws Exception {
@@ -225,15 +223,15 @@ protected Long createArtifactVersion(String groupId, String artifactId, String a
225223
.byArtifactId(artifactId)
226224
.versions()
227225
.post(content, config -> {config.headers.add("X-Registry-ArtifactType", artifactType); })
228-
.get(3, TimeUnit.SECONDS);
226+
;
229227

230228
assert( version.getId().equals(artifactId) );
231229
assert( version.getType().equals(artifactType) );
232230

233231
return version.getGlobalId();
234232
}
235233

236-
protected void createArtifactRule(String groupId, String artifactId, RuleType ruleType, String ruleConfig) throws ExecutionException, InterruptedException, TimeoutException {
234+
protected void createArtifactRule(String groupId, String artifactId, RuleType ruleType, String ruleConfig) {
237235
var rule = new io.apicurio.registry.rest.client.models.Rule();
238236
rule.setConfig(ruleConfig);
239237
rule.setType(io.apicurio.registry.rest.client.models.RuleType.forValue(ruleType.value()));
@@ -244,28 +242,25 @@ protected void createArtifactRule(String groupId, String artifactId, RuleType ru
244242
.artifacts()
245243
.byArtifactId(artifactId)
246244
.rules()
247-
.post(rule)
248-
.get(3, TimeUnit.SECONDS);
245+
.post(rule);
249246
}
250247

251248
@SuppressWarnings("deprecation")
252-
protected io.apicurio.registry.rest.client.models.Rule createGlobalRule(RuleType ruleType, String ruleConfig) throws ExecutionException, InterruptedException, TimeoutException {
249+
protected io.apicurio.registry.rest.client.models.Rule createGlobalRule(RuleType ruleType, String ruleConfig) {
253250
var rule = new io.apicurio.registry.rest.client.models.Rule();
254251
rule.setConfig(ruleConfig);
255252
rule.setType(io.apicurio.registry.rest.client.models.RuleType.forValue(ruleType.value()));
256253

257254
clientV3
258255
.admin()
259256
.rules()
260-
.post(rule)
261-
.get(3, TimeUnit.SECONDS);
257+
.post(rule);
262258
// TODO: verify this get
263259
return clientV3
264260
.admin()
265261
.rules()
266262
.byRule(ruleType.value())
267-
.get()
268-
.get(3, TimeUnit.SECONDS);
263+
.get();
269264
}
270265

271266
/**
@@ -312,21 +307,19 @@ protected List<ArtifactReferenceDto> toReferenceDtos(List<ArtifactReference> ref
312307
.collect(Collectors.toList());
313308
}
314309

315-
protected void assertForbidden(ExecutionException executionException) {
316-
Assertions.assertNotNull(executionException.getCause());
317-
Assertions.assertEquals(ApiException.class, executionException.getCause().getClass());
318-
Assertions.assertEquals(403, ((ApiException)executionException.getCause()).getResponseStatusCode());
310+
protected void assertForbidden(Exception exception) {
311+
Assertions.assertEquals(ApiException.class, exception.getClass());
312+
Assertions.assertEquals(403, ((ApiException)exception).getResponseStatusCode());
319313
}
320314

321-
protected void assertNotAuthorized(ExecutionException executionException) {
322-
Assertions.assertNotNull(executionException.getCause());
323-
324-
if (executionException.getCause() instanceof NotAuthorizedException) {
315+
protected void assertNotAuthorized(Exception exception) {
316+
if (exception instanceof NotAuthorizedException) {
325317
// thrown by the token provider adapter
326318
} else {
327319
// mapped by Kiota
328-
Assertions.assertEquals(ApiException.class, executionException.getCause().getClass());
329-
Assertions.assertEquals(401, ((ApiException) executionException.getCause()).getResponseStatusCode());
320+
Assertions.assertEquals(ApiException.class, exception.getClass());
321+
Assertions.assertEquals(401, ((ApiException) exception).getResponseStatusCode());
330322
}
331323
}
324+
332325
}

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

-32
This file was deleted.

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import org.junit.jupiter.api.Test;
55

66
import java.io.InputStream;
7-
import java.util.concurrent.TimeUnit;
87

98
@QuarkusTest
109
public class MigrationTest extends AbstractResourceTestBase {
@@ -19,12 +18,12 @@ public void migrateData() throws Exception {
1918
clientV3.admin().importEscaped().post(originalData, config -> {
2019
// TODO: this header should be injected by Kiota
2120
config.headers.add("Content-Type", "application/zip");
22-
}).get(10, TimeUnit.SECONDS);
21+
});
2322
clientV3.admin().importEscaped().post(migratedData, config -> {
2423
// TODO: this header should be injected by Kiota
2524
config.headers.add("Content-Type", "application/zip");
2625
config.headers.add("X-Registry-Preserve-GlobalId", "false");
2726
config.headers.add("X-Registry-Preserve-ContentId", "false");
28-
}).get(40, TimeUnit.SECONDS);
27+
});
2928
}
3029
}
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
package io.apicurio.registry.auth;
22

33
import com.microsoft.kiota.ApiException;
4-
import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider;
5-
import com.microsoft.kiota.authentication.BaseBearerTokenAuthenticationProvider;
6-
import com.microsoft.kiota.http.OkHttpRequestAdapter;
74
import io.apicurio.common.apps.config.Info;
85
import io.apicurio.registry.AbstractResourceTestBase;
96
import io.apicurio.registry.rest.client.RegistryClient;
107
import io.apicurio.registry.types.ArtifactType;
118
import io.apicurio.registry.utils.tests.ApicurioTestTags;
129
import io.apicurio.registry.utils.tests.AuthTestProfileAnonymousCredentials;
1310
import io.apicurio.registry.utils.tests.JWKSMockServer;
11+
import io.kiota.http.vertx.VertXRequestAdapter;
1412
import io.quarkus.test.junit.QuarkusTest;
1513
import io.quarkus.test.junit.TestProfile;
14+
import io.apicurio.registry.client.auth.VertXAuthFactory;
1615
import org.eclipse.microprofile.config.inject.ConfigProperty;
1716
import org.junit.jupiter.api.Assertions;
1817
import org.junit.jupiter.api.Tag;
1918
import org.junit.jupiter.api.Test;
2019

21-
import java.util.concurrent.ExecutionException;
22-
import java.util.concurrent.TimeUnit;
20+
import static io.apicurio.registry.client.auth.VertXAuthFactory.buildOIDCWebClient;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2322

2423
@QuarkusTest
2524
@TestProfile(AuthTestProfileAnonymousCredentials.class)
@@ -34,24 +33,24 @@ public class AuthTestAnonymousCredentials extends AbstractResourceTestBase {
3433

3534
@Test
3635
public void testWrongCreds() throws Exception {
37-
var adapter = new OkHttpRequestAdapter(
38-
new BaseBearerTokenAuthenticationProvider(
39-
new OidcAccessTokenProvider(authServerUrl, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "secret")));
36+
var adapter = new VertXRequestAdapter(buildOIDCWebClient(authServerUrl, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55"));
4037
adapter.setBaseUrl(registryV3ApiUrl);
4138
RegistryClient client = new RegistryClient(adapter);
42-
var executionException = Assertions.assertThrows(ExecutionException.class, () -> {
43-
client.groups().byGroupId(groupId).artifacts().get().get(3, TimeUnit.SECONDS);
39+
40+
var exception = Assertions.assertThrows(Exception.class, () -> {
41+
client.groups().byGroupId(groupId).artifacts().get();
4442
});
45-
assertNotAuthorized(executionException);
43+
44+
assertTrue(exception.getMessage().contains("Unauthorized"));
4645
}
4746

4847
@Test
4948
public void testNoCredentials() throws Exception {
50-
var adapter = new OkHttpRequestAdapter(new AnonymousAuthenticationProvider());
49+
var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx);
5150
adapter.setBaseUrl(registryV3ApiUrl);
5251
RegistryClient client = new RegistryClient(adapter);
5352
// Read-only operation should work without any credentials.
54-
var results = client.search().artifacts().get(config -> config.queryParameters.group = groupId).get(3, TimeUnit.SECONDS);
53+
var results = client.search().artifacts().get(config -> config.queryParameters.group = groupId);
5554
Assertions.assertTrue(results.getCount() >= 0);
5655

5756
// Write operation should fail without any credentials
@@ -61,7 +60,7 @@ public void testNoCredentials() throws Exception {
6160
" \"namespace\" : \"my.example\",\r\n" +
6261
" \"fields\" : [{\"name\" : \"age\", \"type\" : \"int\"}]\r\n" +
6362
"}";
64-
var executionException = Assertions.assertThrows(ExecutionException.class, () -> {
63+
var exception = Assertions.assertThrows(ApiException.class, () -> {
6564
var content = new io.apicurio.registry.rest.client.models.ArtifactContent();
6665
content.setContent(data);
6766
client
@@ -71,10 +70,8 @@ public void testNoCredentials() throws Exception {
7170
.post(content, config -> {
7271
config.headers.add("X-Registry-ArtifactType", ArtifactType.AVRO);
7372
config.headers.add("X-Registry-ArtifactId", "testNoCredentials");
74-
}).get(3, TimeUnit.SECONDS);
73+
});
7574
});
76-
Assertions.assertNotNull(executionException.getCause());
77-
Assertions.assertEquals(ApiException.class, executionException.getCause().getClass());
78-
Assertions.assertEquals(401, ((ApiException)executionException.getCause()).getResponseStatusCode());
75+
Assertions.assertEquals(401, exception.getResponseStatusCode());
7976
}
8077
}

0 commit comments

Comments
 (0)