From 0cdff772bf62c33c8b578b143f5184666842ded0 Mon Sep 17 00:00:00 2001 From: Aliaksandr Parfianiuk Date: Wed, 25 Mar 2020 18:24:23 +0300 Subject: [PATCH] Fix path for api call to schema registry to fetch schema by id --- .../client/ConfluentSchemaRegistryClient.java | 2 +- .../ConfluentSchemaRegistryClientTests.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/client/ConfluentSchemaRegistryClient.java b/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/client/ConfluentSchemaRegistryClient.java index c52131e..a0a3d9d 100644 --- a/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/client/ConfluentSchemaRegistryClient.java +++ b/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/client/ConfluentSchemaRegistryClient.java @@ -150,7 +150,7 @@ public class ConfluentSchemaRegistryClient implements SchemaRegistryClient { @Override public String fetch(int id) { - String path = String.format("/schemas/%d", id); + String path = String.format("/schemas/ids/%d", id); HttpHeaders headers = new HttpHeaders(); headers.put("Accept", ACCEPT_HEADERS); headers.add("Content-Type", "application/vnd.schemaregistry.v1+json"); diff --git a/spring-cloud-schema-registry-client/src/test/java/org/springframework/cloud/schema/avro/client/ConfluentSchemaRegistryClientTests.java b/spring-cloud-schema-registry-client/src/test/java/org/springframework/cloud/schema/avro/client/ConfluentSchemaRegistryClientTests.java index 5dbb771..a20be13 100644 --- a/spring-cloud-schema-registry-client/src/test/java/org/springframework/cloud/schema/avro/client/ConfluentSchemaRegistryClientTests.java +++ b/spring-cloud-schema-registry-client/src/test/java/org/springframework/cloud/schema/avro/client/ConfluentSchemaRegistryClientTests.java @@ -166,4 +166,34 @@ public class ConfluentSchemaRegistryClientTests { assertThat(expected.getCause() instanceof HttpStatusCodeException).isTrue(); this.mockRestServiceServer.verify(); } + + @Test + public void fetchById() { + this.mockRestServiceServer + .expect(requestTo("http://localhost:8081/schemas/ids/1")) + .andExpect(method(HttpMethod.GET)) + .andExpect( + header("Content-Type", "application/vnd.schemaregistry.v1+json")) + .andExpect(header("Accept", "application/vnd.schemaregistry.v1+json")) + .andRespond(withSuccess("{\"schema\":\"\"}", MediaType.APPLICATION_JSON)); + ConfluentSchemaRegistryClient client = new ConfluentSchemaRegistryClient( + this.restTemplate); + String schema = client.fetch(1); + assertThat(schema).isEqualTo(""); + this.mockRestServiceServer.verify(); + } + + @Test(expected = SchemaNotFoundException.class) + public void fetchByIdSchemaNotFound() { + this.mockRestServiceServer + .expect(requestTo("http://localhost:8081/schemas/ids/1")) + .andExpect(method(HttpMethod.GET)) + .andExpect( + header("Content-Type", "application/vnd.schemaregistry.v1+json")) + .andExpect(header("Accept", "application/vnd.schemaregistry.v1+json")) + .andRespond(withStatus(HttpStatus.NOT_FOUND)); + ConfluentSchemaRegistryClient client = new ConfluentSchemaRegistryClient( + this.restTemplate); + String schema = client.fetch(1); + } }