Search in sources :

Example 1 with RestConstraintViolationException

use of io.confluent.rest.exceptions.RestConstraintViolationException in project kafka-rest by confluentinc.

the class SchemaManagerImplTest method getSchemaFromSchemaVersionThrowsInvalidSchemaException.

@Test
public void getSchemaFromSchemaVersionThrowsInvalidSchemaException() {
    SchemaRegistryClient schemaRegistryClientMock = mock(SchemaRegistryClient.class);
    Schema schemaMock = mock(Schema.class);
    expect(schemaRegistryClientMock.getByVersion("subject1", 0, false)).andReturn(schemaMock);
    expect(schemaMock.getSchemaType()).andReturn(EmbeddedFormat.AVRO.toString());
    expect(schemaMock.getSchema()).andReturn(null);
    expect(schemaMock.getReferences()).andReturn(Collections.emptyList());
    replay(schemaRegistryClientMock, schemaMock);
    SchemaManager mySchemaManager = new SchemaManagerImpl(schemaRegistryClientMock, new TopicNameStrategy());
    RestConstraintViolationException iae = assertThrows(RestConstraintViolationException.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("Invalid schema: Error when fetching schema by version. subject = subject1, version = 0", iae.getMessage());
    assertEquals(42205, iae.getErrorCode());
}
Also used : RestConstraintViolationException(io.confluent.rest.exceptions.RestConstraintViolationException) 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) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) MockSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient) Test(org.junit.jupiter.api.Test)

Example 2 with RestConstraintViolationException

use of io.confluent.rest.exceptions.RestConstraintViolationException in project kafka-rest by confluentinc.

the class SchemaManagerImplTest method getSchema_avro_rawSchema_invalidSchema.

@Test
public void getSchema_avro_rawSchema_invalidSchema() {
    RestConstraintViolationException rcve = assertThrows(RestConstraintViolationException.class, () -> schemaManager.getSchema(TOPIC_NAME, /* format= */
    Optional.of(EmbeddedFormat.AVRO), /* subject= */
    Optional.empty(), /* subjectNameStrategy= */
    Optional.empty(), /* schemaId= */
    Optional.empty(), /* schemaVersion= */
    Optional.empty(), /* rawSchema= */
    Optional.of("foobar"), /* isKey= */
    true));
    assertEquals("Invalid schema: Error when parsing raw schema. format = AVRO, schema = foobar", rcve.getMessage());
    assertEquals(42205, rcve.getErrorCode());
}
Also used : RestConstraintViolationException(io.confluent.rest.exceptions.RestConstraintViolationException) Test(org.junit.jupiter.api.Test)

Example 3 with RestConstraintViolationException

use of io.confluent.rest.exceptions.RestConstraintViolationException in project kafka-rest by confluentinc.

the class SchemaManagerImplTest method errorRegisteringSchema.

@Test
public void errorRegisteringSchema() throws RestClientException, IOException {
    SchemaRegistryClient schemaRegistryClientMock = mock(SchemaRegistryClient.class);
    ParsedSchema parsedSchemaMock = mock(ParsedSchema.class);
    EmbeddedFormat embeddedFormatMock = mock(EmbeddedFormat.class);
    SchemaProvider schemaProviderMock = mock(SchemaProvider.class);
    expect(embeddedFormatMock.requiresSchema()).andReturn(true);
    expect(embeddedFormatMock.getSchemaProvider()).andReturn(schemaProviderMock);
    expect(schemaProviderMock.parseSchema(TextNode.valueOf("rawString").toString(), emptyList(), true)).andReturn(Optional.of(parsedSchemaMock));
    expect(schemaRegistryClientMock.getId("subject1", parsedSchemaMock)).andThrow(new IOException("Can't get Schema"));
    expect(schemaRegistryClientMock.register("subject1", parsedSchemaMock)).andThrow(new IOException("Can't register Schema"));
    replay(schemaRegistryClientMock, embeddedFormatMock, schemaProviderMock);
    SchemaManager mySchemaManager = new SchemaManagerImpl(schemaRegistryClientMock, new TopicNameStrategy());
    RestConstraintViolationException rcve = assertThrows(RestConstraintViolationException.class, () -> mySchemaManager.getSchema(TOPIC_NAME, /* format= */
    Optional.of(embeddedFormatMock), /* subject= */
    Optional.of("subject1"), /* subjectNameStrategy= */
    Optional.empty(), /* schemaId= */
    Optional.empty(), /* schemaVersion= */
    Optional.empty(), /* rawSchema= */
    Optional.of(TextNode.valueOf("rawString").toString()), /* isKey= */
    true));
    assertEquals("Error serializing message. Error when registering schema. format = EasyMock for class io.confluent.kafkarest.entities.EmbeddedFormat, subject = subject1, schema = null\n" + "Can't register Schema", rcve.getMessage());
    assertEquals(42207, rcve.getErrorCode());
}
Also used : EmbeddedFormat(io.confluent.kafkarest.entities.EmbeddedFormat) RestConstraintViolationException(io.confluent.rest.exceptions.RestConstraintViolationException) ProtobufSchemaProvider(io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider) SchemaProvider(io.confluent.kafka.schemaregistry.SchemaProvider) JsonSchemaProvider(io.confluent.kafka.schemaregistry.json.JsonSchemaProvider) AvroSchemaProvider(io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider) TopicNameStrategy(io.confluent.kafka.serializers.subject.TopicNameStrategy) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) IOException(java.io.IOException) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) MockSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient) Test(org.junit.jupiter.api.Test)

Example 4 with RestConstraintViolationException

use of io.confluent.rest.exceptions.RestConstraintViolationException in project kafka-rest by confluentinc.

the class SchemaManagerImplTest method getSchema_protobuf_rawSchema_invalidSchema.

@Test
public void getSchema_protobuf_rawSchema_invalidSchema() {
    RestConstraintViolationException rcve = assertThrows(RestConstraintViolationException.class, () -> schemaManager.getSchema(TOPIC_NAME, /* format= */
    Optional.of(EmbeddedFormat.PROTOBUF), /* subject= */
    Optional.empty(), /* subjectNameStrategy= */
    Optional.empty(), /* schemaId= */
    Optional.empty(), /* schemaVersion= */
    Optional.empty(), /* rawSchema= */
    Optional.of("foobar"), /* isKey= */
    true));
    assertEquals("Invalid schema: Error when parsing raw schema. format = PROTOBUF, schema = foobar", rcve.getMessage());
    assertEquals(42205, rcve.getErrorCode());
}
Also used : RestConstraintViolationException(io.confluent.rest.exceptions.RestConstraintViolationException) Test(org.junit.jupiter.api.Test)

Example 5 with RestConstraintViolationException

use of io.confluent.rest.exceptions.RestConstraintViolationException in project kafka-rest by confluentinc.

the class SchemaManagerImplTest method errorFetchingSchemaBySchemaVersion.

@Test
public void errorFetchingSchemaBySchemaVersion() {
    SchemaRegistryClient schemaRegistryClientMock = mock(SchemaRegistryClient.class);
    Schema schemaMock = mock(Schema.class);
    expect(schemaRegistryClientMock.getByVersion("subject1", 123, false)).andReturn(schemaMock);
    expect(schemaMock.getSchemaType()).andReturn(EmbeddedFormat.JSON.toString());
    expect(schemaMock.getSchema()).andReturn(null);
    expect(schemaMock.getReferences()).andReturn(Collections.emptyList());
    replay(schemaRegistryClientMock, schemaMock);
    SchemaManager mySchemaManager = new SchemaManagerImpl(schemaRegistryClientMock, new TopicNameStrategy());
    RestConstraintViolationException iae = assertThrows(RestConstraintViolationException.class, () -> mySchemaManager.getSchema(TOPIC_NAME, /* format= */
    Optional.empty(), /* subject= */
    Optional.of("subject1"), /* subjectNameStrategy= */
    Optional.empty(), /* schemaId= */
    Optional.empty(), /* schemaVersion= */
    Optional.of(123), /* rawSchema= */
    Optional.empty(), /* isKey= */
    true));
    assertEquals("Invalid schema: Error when fetching schema by version. subject = subject1, version = 123", iae.getMessage());
    assertEquals(42205, iae.getErrorCode());
}
Also used : RestConstraintViolationException(io.confluent.rest.exceptions.RestConstraintViolationException) 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) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) MockSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient) Test(org.junit.jupiter.api.Test)

Aggregations

RestConstraintViolationException (io.confluent.rest.exceptions.RestConstraintViolationException)14 Test (org.junit.jupiter.api.Test)14 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)4 MockSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient)4 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)4 TopicNameStrategy (io.confluent.kafka.serializers.subject.TopicNameStrategy)4 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)3 Schema (io.confluent.kafka.schemaregistry.client.rest.entities.Schema)2 RegisteredSchema (io.confluent.kafkarest.entities.RegisteredSchema)2 SchemaProvider (io.confluent.kafka.schemaregistry.SchemaProvider)1 AvroSchemaProvider (io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider)1 SchemaMetadata (io.confluent.kafka.schemaregistry.client.SchemaMetadata)1 JsonSchemaProvider (io.confluent.kafka.schemaregistry.json.JsonSchemaProvider)1 ProtobufSchemaProvider (io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider)1 EmbeddedFormat (io.confluent.kafkarest.entities.EmbeddedFormat)1 ProduceRequest (io.confluent.kafkarest.entities.v3.ProduceRequest)1 RequestRateLimiter (io.confluent.kafkarest.ratelimit.RequestRateLimiter)1 ChunkedOutputFactory (io.confluent.kafkarest.response.ChunkedOutputFactory)1 FakeAsyncResponse (io.confluent.kafkarest.response.FakeAsyncResponse)1 IOException (java.io.IOException)1