Search in sources :

Example 6 with RestConstraintViolationException

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

the class SchemaManagerImplTest method getSchema_avro_schemaId_schemaIdNotInSubject.

@Test
public void getSchema_avro_schemaId_schemaIdNotInSubject() throws Exception {
    ParsedSchema schema = new AvroSchema("{\"type\": \"int\"}");
    int schemaId = schemaRegistryClient.register("foobar", schema);
    RestConstraintViolationException rcve = assertThrows(RestConstraintViolationException.class, () -> schemaManager.getSchema(TOPIC_NAME, /* format= */
    Optional.empty(), /* subject= */
    Optional.empty(), /* subjectNameStrategy= */
    Optional.empty(), /* schemaId= */
    Optional.of(schemaId), /* schemaVersion= */
    Optional.empty(), /* rawSchema= */
    Optional.empty(), /* isKey= */
    true));
    assertEquals("Error serializing message. Error when fetching schema version. subject = topic-1-key, schema = \"int\"\n" + "Subject Not Found; error code: 40401", rcve.getMessage());
    assertEquals(42207, rcve.getErrorCode());
}
Also used : AvroSchema(io.confluent.kafka.schemaregistry.avro.AvroSchema) RestConstraintViolationException(io.confluent.rest.exceptions.RestConstraintViolationException) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) Test(org.junit.jupiter.api.Test)

Example 7 with RestConstraintViolationException

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

the class SchemaManagerImplTest method getSchema_avro_latestSchema_noSchema.

@Test
public void getSchema_avro_latestSchema_noSchema() {
    RestConstraintViolationException rcve = assertThrows(RestConstraintViolationException.class, () -> schemaManager.getSchema(TOPIC_NAME, /* format= */
    Optional.empty(), /* subject= */
    Optional.empty(), /* subjectNameStrategy= */
    Optional.empty(), /* schemaId= */
    Optional.empty(), /* schemaVersion= */
    Optional.empty(), /* rawSchema= */
    Optional.empty(), /* isKey= */
    true));
    assertEquals("Error serializing message. Error when fetching latest schema version. subject = topic-1-key\n" + "Subject Not Found; error code: 40401", rcve.getMessage());
    assertEquals(42207, rcve.getErrorCode());
}
Also used : RestConstraintViolationException(io.confluent.rest.exceptions.RestConstraintViolationException) Test(org.junit.jupiter.api.Test)

Example 8 with RestConstraintViolationException

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

the class SchemaManagerImplTest method getSchema_jsonschema_rawSchema_invalidSchema.

@Test
public void getSchema_jsonschema_rawSchema_invalidSchema() {
    RestConstraintViolationException rcve = assertThrows(RestConstraintViolationException.class, () -> schemaManager.getSchema(TOPIC_NAME, /* format= */
    Optional.of(EmbeddedFormat.JSONSCHEMA), /* 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 = JSONSCHEMA, schema = foobar", rcve.getMessage());
    assertEquals(42205, rcve.getErrorCode());
}
Also used : RestConstraintViolationException(io.confluent.rest.exceptions.RestConstraintViolationException) Test(org.junit.jupiter.api.Test)

Example 9 with RestConstraintViolationException

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

the class SchemaRecordSerializerTest method errorWhenNoSchemaRegistryDefined.

@Test
public void errorWhenNoSchemaRegistryDefined() {
    SchemaRecordSerializer schemaRecordSerializer = new SchemaRecordSerializerThrowing();
    RestConstraintViolationException rcve = assertThrows(RestConstraintViolationException.class, () -> schemaRecordSerializer.serialize(EmbeddedFormat.AVRO, "topic", Optional.empty(), null, true));
    assertEquals(42207, rcve.getErrorCode());
    assertEquals("Error serializing message. Schema Registry not defined, no Schema Registry client available to serialize message.", rcve.getMessage());
}
Also used : RestConstraintViolationException(io.confluent.rest.exceptions.RestConstraintViolationException) Test(org.junit.jupiter.api.Test)

Example 10 with RestConstraintViolationException

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

the class RecordSerializerFacadeTest method noSchemaRegistryClientConfigured.

@Test
public void noSchemaRegistryClientConfigured() {
    RecordSerializerFacade myRecordSerializer = new RecordSerializerFacade(new NoSchemaRecordSerializer(SCHEMA_SERIALIZER_CONFIGS), () -> new SchemaRecordSerializerThrowing());
    RestConstraintViolationException rcve = assertThrows(RestConstraintViolationException.class, () -> myRecordSerializer.serialize(EmbeddedFormat.AVRO, TOPIC_NAME, /* schema= */
    Optional.empty(), TextNode.valueOf(BaseEncoding.base64().encode("foobar".getBytes(StandardCharsets.UTF_8))), /* isKey= */
    true));
    assertEquals("Error serializing message. Schema Registry not defined, no Schema Registry client available to serialize message.", rcve.getMessage());
    assertEquals(42207, rcve.getErrorCode());
}
Also used : RestConstraintViolationException(io.confluent.rest.exceptions.RestConstraintViolationException) 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