use of io.confluent.kafkarest.exceptions.BadRequestException in project kafka-rest by confluentinc.
the class SchemaManagerImplTest method rawSchemaWithUnsupportedSchemaVersionThrowsException.
@Test
public void rawSchemaWithUnsupportedSchemaVersionThrowsException() {
BadRequestException iae = assertThrows(BadRequestException.class, () -> schemaManager.getSchema(TOPIC_NAME, /* format= */
Optional.empty(), /* subject= */
Optional.empty(), /* subjectNameStrategy= */
Optional.empty(), /* schemaId= */
Optional.empty(), /* schemaVersion= */
Optional.of(0), /* rawSchema= */
Optional.empty(), /* isKey= */
true));
assertEquals("Schema does not exist for subject: topic-1-key, version: 0", iae.getMessage());
assertEquals(400, iae.getCode());
}
use of io.confluent.kafkarest.exceptions.BadRequestException in project kafka-rest by confluentinc.
the class SchemaManagerImplTest method errorFetchingLatestSchemaBySchemaVersionBadRequest.
@Test
public void errorFetchingLatestSchemaBySchemaVersionBadRequest() throws RestClientException, IOException {
SchemaRegistryClient schemaRegistryClientMock = mock(SchemaRegistryClient.class);
SchemaMetadata schemaMetadataMock = mock(SchemaMetadata.class);
expect(schemaRegistryClientMock.getLatestSchemaMetadata("subject1")).andReturn(schemaMetadataMock);
expect(schemaMetadataMock.getSchemaType()).andThrow(new UnsupportedOperationException(// this is faking the UnsupportedOperationException but I
"testing exception"));
// can't see another way to do this.
expect(schemaMetadataMock.getSchemaType()).andReturn("schemaType");
replay(schemaRegistryClientMock, schemaMetadataMock);
SchemaManager mySchemaManager = new SchemaManagerImpl(schemaRegistryClientMock, new TopicNameStrategy());
BadRequestException bre = assertThrows(BadRequestException.class, () -> mySchemaManager.getSchema(TOPIC_NAME, /* format= */
Optional.empty(), /* subject= */
Optional.of("subject1"), /* subjectNameStrategy= */
Optional.empty(), /* schemaId= */
Optional.empty(), /* schemaVersion= */
Optional.empty(), /* rawSchema= */
Optional.empty(), /* isKey= */
true));
assertEquals("Schema subject not supported for schema type = schemaType", bre.getMessage());
assertEquals(400, bre.getCode());
}
use of io.confluent.kafkarest.exceptions.BadRequestException in project kafka-rest by confluentinc.
the class SchemaManagerImplTest method getSchemaFromSchemaVersionThrowsInvalidBadRequestException.
@Test
public void getSchemaFromSchemaVersionThrowsInvalidBadRequestException() {
SchemaRegistryClient schemaRegistryClientMock = mock(SchemaRegistryClient.class);
Schema schemaMock = mock(Schema.class);
expect(schemaRegistryClientMock.getByVersion("subject1", 0, false)).andReturn(schemaMock);
expect(schemaMock.getSchemaType()).andThrow(new UnsupportedOperationException("exception message"));
expect(schemaMock.getSchemaType()).andReturn("JSON");
replay(schemaRegistryClientMock, schemaMock);
SchemaManager mySchemaManager = new SchemaManagerImpl(schemaRegistryClientMock, new TopicNameStrategy());
BadRequestException iae = assertThrows(BadRequestException.class, () -> mySchemaManager.getSchema(TOPIC_NAME, /* format= */
Optional.empty(), /* subject= */
Optional.of("subject1"), /* subjectNameStrategy= */
Optional.empty(), /* schemaId= */
Optional.empty(), /* schemaVersion= */
Optional.of(0), /* rawSchema= */
Optional.empty(), /* isKey= */
true));
assertEquals("Schema version not supported for JSON", iae.getMessage());
assertEquals(400, iae.getCode());
}
Aggregations