Search in sources :

Example 11 with BadRequestException

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());
}
Also used : BadRequestException(io.confluent.kafkarest.exceptions.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 12 with BadRequestException

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());
}
Also used : SchemaMetadata(io.confluent.kafka.schemaregistry.client.SchemaMetadata) TopicNameStrategy(io.confluent.kafka.serializers.subject.TopicNameStrategy) BadRequestException(io.confluent.kafkarest.exceptions.BadRequestException) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) MockSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient) Test(org.junit.jupiter.api.Test)

Example 13 with BadRequestException

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());
}
Also used : Schema(io.confluent.kafka.schemaregistry.client.rest.entities.Schema) AvroSchema(io.confluent.kafka.schemaregistry.avro.AvroSchema) RegisteredSchema(io.confluent.kafkarest.entities.RegisteredSchema) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) TopicNameStrategy(io.confluent.kafka.serializers.subject.TopicNameStrategy) BadRequestException(io.confluent.kafkarest.exceptions.BadRequestException) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) MockSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient) Test(org.junit.jupiter.api.Test)

Aggregations

BadRequestException (io.confluent.kafkarest.exceptions.BadRequestException)13 Test (org.junit.jupiter.api.Test)7 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)5 SchemaProvider (io.confluent.kafka.schemaregistry.SchemaProvider)5 IOException (java.io.IOException)5 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)3 MockSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient)3 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)3 TopicNameStrategy (io.confluent.kafka.serializers.subject.TopicNameStrategy)3 SchemaParseException (org.apache.avro.SchemaParseException)3 AvroSchemaProvider (io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider)2 SchemaMetadata (io.confluent.kafka.schemaregistry.client.SchemaMetadata)2 Schema (io.confluent.kafka.schemaregistry.client.rest.entities.Schema)2 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)2 JsonSchemaProvider (io.confluent.kafka.schemaregistry.json.JsonSchemaProvider)2 ProtobufSchemaProvider (io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider)2 EmbeddedFormat (io.confluent.kafkarest.entities.EmbeddedFormat)2 RegisteredSchema (io.confluent.kafkarest.entities.RegisteredSchema)2 Message (com.google.protobuf.Message)1 JsonSchema (io.confluent.kafka.schemaregistry.json.JsonSchema)1