use of org.springframework.cloud.stream.schema.client.ConfluentSchemaRegistryClient in project spring-cloud-stream by spring-cloud.
the class ConfluentSchemaRegistryClientTests method responseErrorFetch.
@Test
public void responseErrorFetch() {
this.mockRestServiceServer.expect(requestTo("http://localhost:8081/subjects/user/versions")).andExpect(method(HttpMethod.POST)).andExpect(header("Content-Type", "application/json")).andExpect(header("Accept", "application/vnd.schemaregistry.v1+json")).andRespond(withSuccess("{\"id\":101}", MediaType.APPLICATION_JSON));
this.mockRestServiceServer.expect(requestTo("http://localhost:8081/subjects/user")).andExpect(method(HttpMethod.POST)).andExpect(header("Content-Type", "application/json")).andExpect(header("Accept", "application/vnd.schemaregistry.v1+json")).andRespond(withBadRequest());
ConfluentSchemaRegistryClient client = new ConfluentSchemaRegistryClient(this.restTemplate);
Exception expected = null;
try {
SchemaRegistrationResponse response = client.register("user", "avro", "{}");
} catch (Exception e) {
expected = e;
}
Assert.assertTrue(expected instanceof RuntimeException);
Assert.assertTrue(expected.getCause() instanceof HttpStatusCodeException);
this.mockRestServiceServer.verify();
}
use of org.springframework.cloud.stream.schema.client.ConfluentSchemaRegistryClient in project spring-cloud-stream by spring-cloud.
the class ConfluentSchemaRegistryClientTests method findByReference.
@Test
public void findByReference() {
this.mockRestServiceServer.expect(requestTo("http://localhost:8081/subjects/user/versions/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);
SchemaReference reference = new SchemaReference("user", 1, "avro");
String schema = client.fetch(reference);
Assert.assertEquals("", schema);
this.mockRestServiceServer.verify();
}
use of org.springframework.cloud.stream.schema.client.ConfluentSchemaRegistryClient in project spring-cloud-stream by spring-cloud.
the class ConfluentSchemaRegistryClientTests method registerIncompatibleSchema.
@Test
public void registerIncompatibleSchema() {
this.mockRestServiceServer.expect(requestTo("http://localhost:8081/subjects/user/versions")).andExpect(method(HttpMethod.POST)).andExpect(header("Content-Type", "application/json")).andExpect(header("Accept", "application/vnd.schemaregistry.v1+json")).andRespond(withStatus(HttpStatus.CONFLICT));
ConfluentSchemaRegistryClient client = new ConfluentSchemaRegistryClient(this.restTemplate);
Exception expected = null;
try {
SchemaRegistrationResponse response = client.register("user", "avro", "{}");
} catch (Exception e) {
expected = e;
}
Assert.assertTrue(expected instanceof RuntimeException);
Assert.assertTrue(expected.getCause() instanceof HttpStatusCodeException);
this.mockRestServiceServer.verify();
}
use of org.springframework.cloud.stream.schema.client.ConfluentSchemaRegistryClient in project spring-cloud-stream by spring-cloud.
the class ConfluentSchemaRegistryClientTests method registerWithInvalidJson.
@Test(expected = RuntimeException.class)
public void registerWithInvalidJson() {
this.mockRestServiceServer.expect(requestTo("http://localhost:8081/subjects/user/versions")).andExpect(method(HttpMethod.POST)).andExpect(header("Content-Type", "application/json")).andExpect(header("Accept", "application/vnd.schemaregistry.v1+json")).andRespond(withBadRequest());
ConfluentSchemaRegistryClient client = new ConfluentSchemaRegistryClient(this.restTemplate);
SchemaRegistrationResponse response = client.register("user", "avro", "<>");
}
use of org.springframework.cloud.stream.schema.client.ConfluentSchemaRegistryClient in project spring-cloud-stream by spring-cloud.
the class ConfluentSchemaRegistryClientTests method registerSchema.
@Test
public void registerSchema() throws Exception {
this.mockRestServiceServer.expect(requestTo("http://localhost:8081/subjects/user/versions")).andExpect(method(HttpMethod.POST)).andExpect(header("Content-Type", "application/json")).andExpect(header("Accept", "application/vnd.schemaregistry.v1+json")).andRespond(withSuccess("{\"id\":101}", MediaType.APPLICATION_JSON));
this.mockRestServiceServer.expect(requestTo("http://localhost:8081/subjects/user")).andExpect(method(HttpMethod.POST)).andExpect(header("Content-Type", "application/json")).andExpect(header("Accept", "application/vnd.schemaregistry.v1+json")).andRespond(withSuccess("{\"version\":1}", MediaType.APPLICATION_JSON));
ConfluentSchemaRegistryClient client = new ConfluentSchemaRegistryClient(this.restTemplate);
SchemaRegistrationResponse response = client.register("user", "avro", "{}");
Assert.assertEquals(1, response.getSchemaReference().getVersion());
Assert.assertEquals(101, response.getId());
this.mockRestServiceServer.verify();
}
Aggregations