Fix path for api call to schema registry to fetch schema by id

This commit is contained in:
Aliaksandr Parfianiuk
2020-03-25 18:24:23 +03:00
committed by Christian Tzolov
parent 01a932734f
commit 0cdff772bf
2 changed files with 31 additions and 1 deletions

View File

@@ -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");

View File

@@ -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);
}
}