Search in sources :

Example 1 with ErrorMessage

use of com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.ErrorMessage in project registry by hortonworks.

the class ConfluentRegistryCompatibleResourceTest method doTestAPIsMixWithIncompatibleInvalidSchemas.

private void doTestAPIsMixWithIncompatibleInvalidSchemas(String subjectName) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    // register initial version of schema
    long initialSchemaId = objectMapper.readValue(postSubjectSchema(subjectName, fetchSchema("/device.avsc")).readEntity(String.class), Id.class).getId();
    // try to register incompatible schema and check for expected errors
    Response response = postSubjectSchema(subjectName, fetchSchema("/device-incompat.avsc"));
    Assert.assertEquals(incompatibleSchemaError().getStatus(), response.getStatus());
    ErrorMessage errorMessage = objectMapper.readValue(response.readEntity(String.class), ErrorMessage.class);
    Assert.assertEquals(((ErrorMessage) incompatibleSchemaError().getEntity()).getErrorCode(), errorMessage.getErrorCode());
    // register valid schema
    String secondVersionSchema = fetchSchema("/device-compat.avsc");
    long secondSchemaId = objectMapper.readValue(postSubjectSchema(subjectName, secondVersionSchema).readEntity(String.class), Id.class).getId();
    Assert.assertTrue(initialSchemaId < secondSchemaId);
    // retrieve the schema for that version and check whether it has same schema.
    String receivedSchema = getVersion(subjectName, "latest").getSchema();
    Assert.assertEquals(new org.apache.avro.Schema.Parser().parse(secondVersionSchema), new org.apache.avro.Schema.Parser().parse(receivedSchema));
    // check latest version of schema
    String latestSchema = getVersion(subjectName, "latest").getSchema();
    Assert.assertEquals(new org.apache.avro.Schema.Parser().parse(secondVersionSchema), new org.apache.avro.Schema.Parser().parse(latestSchema));
    // check for invalid schemas
    Response invalidSchemaResponse = postSubjectSchema(subjectName, fetchSchema("/device-unsupported-type.avsc"));
    Assert.assertEquals(invalidSchemaError().getStatus(), invalidSchemaResponse.getStatus());
    ErrorMessage invalidSchemaErrorMessage = objectMapper.readValue(invalidSchemaResponse.readEntity(String.class), ErrorMessage.class);
    Assert.assertEquals(((ErrorMessage) invalidSchemaError().getEntity()).getErrorCode(), invalidSchemaErrorMessage.getErrorCode());
}
Also used : Response(javax.ws.rs.core.Response) Id(com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.Id) SchemaString(com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.SchemaString) ErrorMessage(com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.ErrorMessage) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with ErrorMessage

use of com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.ErrorMessage in project registry by hortonworks.

the class ConfluentRegistryCompatibleResourceTest method testNonExistingSubject.

@Test
public void testNonExistingSubject() throws Exception {
    // check non existing subject
    Response nonExistingSubjectResponse = rootTarget.path("/subjects/" + testName() + "/versions").request(MediaType.APPLICATION_JSON_TYPE).get();
    ErrorMessage errorMessage = new ObjectMapper().readValue(nonExistingSubjectResponse.readEntity(String.class), ErrorMessage.class);
    Assert.assertEquals(subjectNotFoundError().getStatus(), nonExistingSubjectResponse.getStatus());
    Assert.assertEquals(subjectNotFoundError().getEntity(), errorMessage);
}
Also used : Response(javax.ws.rs.core.Response) SchemaString(com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.SchemaString) ErrorMessage(com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.ErrorMessage) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with ErrorMessage

use of com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.ErrorMessage in project registry by hortonworks.

the class ConfluentRegistryCompatibleResourceTest method testIncompatibleSchemas.

@Test
public void testIncompatibleSchemas() throws Exception {
    String subject = testName();
    String response = postSubjectSchema(subject, fetchSchema("/device.avsc")).readEntity(String.class);
    ObjectMapper objectMapper = new ObjectMapper();
    long id = objectMapper.readValue(response, Id.class).getId();
    Assert.assertTrue(id > 0);
    // add incompatible schema
    Response incompatSchemaResponse = postSubjectSchema(subject, fetchSchema("/device-incompat.avsc"));
    Assert.assertEquals(incompatibleSchemaError().getStatus(), incompatSchemaResponse.getStatus());
    ErrorMessage errorMessage = objectMapper.readValue(incompatSchemaResponse.readEntity(String.class), ErrorMessage.class);
    Assert.assertEquals(incompatibleSchemaError().getEntity(), errorMessage);
}
Also used : Response(javax.ws.rs.core.Response) SchemaString(com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.SchemaString) Id(com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.Id) ErrorMessage(com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.ErrorMessage) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 4 with ErrorMessage

use of com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.ErrorMessage in project registry by hortonworks.

the class ConfluentRegistryCompatibleResourceTest method testInValidSchemas.

@Test
public void testInValidSchemas() throws Exception {
    // add invalid schema
    Response invalidSchemaResponse = postSubjectSchema(testName(), fetchSchema("/device-unsupported-type.avsc"));
    Assert.assertEquals(invalidSchemaError().getStatus(), invalidSchemaResponse.getStatus());
    ErrorMessage errorMessage = new ObjectMapper().readValue(invalidSchemaResponse.readEntity(String.class), ErrorMessage.class);
    Assert.assertEquals(invalidSchemaError().getEntity(), errorMessage);
}
Also used : Response(javax.ws.rs.core.Response) SchemaString(com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.SchemaString) ErrorMessage(com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.ErrorMessage) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ErrorMessage (com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.ErrorMessage)4 SchemaString (com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.SchemaString)4 Response (javax.ws.rs.core.Response)4 Test (org.junit.Test)3 Id (com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.Id)2