Search in sources :

Example 1 with ConfluentSchemaRegistryClient

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();
}
Also used : SchemaRegistrationResponse(org.springframework.cloud.stream.schema.SchemaRegistrationResponse) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException) ConfluentSchemaRegistryClient(org.springframework.cloud.stream.schema.client.ConfluentSchemaRegistryClient) SchemaNotFoundException(org.springframework.cloud.stream.schema.SchemaNotFoundException) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException) Test(org.junit.Test)

Example 2 with ConfluentSchemaRegistryClient

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();
}
Also used : SchemaReference(org.springframework.cloud.stream.schema.SchemaReference) ConfluentSchemaRegistryClient(org.springframework.cloud.stream.schema.client.ConfluentSchemaRegistryClient) Test(org.junit.Test)

Example 3 with ConfluentSchemaRegistryClient

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();
}
Also used : SchemaRegistrationResponse(org.springframework.cloud.stream.schema.SchemaRegistrationResponse) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException) ConfluentSchemaRegistryClient(org.springframework.cloud.stream.schema.client.ConfluentSchemaRegistryClient) SchemaNotFoundException(org.springframework.cloud.stream.schema.SchemaNotFoundException) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException) Test(org.junit.Test)

Example 4 with ConfluentSchemaRegistryClient

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", "<>");
}
Also used : SchemaRegistrationResponse(org.springframework.cloud.stream.schema.SchemaRegistrationResponse) ConfluentSchemaRegistryClient(org.springframework.cloud.stream.schema.client.ConfluentSchemaRegistryClient) Test(org.junit.Test)

Example 5 with ConfluentSchemaRegistryClient

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();
}
Also used : SchemaRegistrationResponse(org.springframework.cloud.stream.schema.SchemaRegistrationResponse) ConfluentSchemaRegistryClient(org.springframework.cloud.stream.schema.client.ConfluentSchemaRegistryClient) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 ConfluentSchemaRegistryClient (org.springframework.cloud.stream.schema.client.ConfluentSchemaRegistryClient)6 SchemaRegistrationResponse (org.springframework.cloud.stream.schema.SchemaRegistrationResponse)4 SchemaNotFoundException (org.springframework.cloud.stream.schema.SchemaNotFoundException)2 SchemaReference (org.springframework.cloud.stream.schema.SchemaReference)2 HttpStatusCodeException (org.springframework.web.client.HttpStatusCodeException)2