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());
}
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);
}
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);
}
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);
}
Aggregations