use of io.confluent.rest.exceptions.RestConstraintViolationException in project kafka-rest by confluentinc.
the class SchemaManagerImplTest method getSchema_avro_schemaId_nonExistingSchemaId.
@Test
public void getSchema_avro_schemaId_nonExistingSchemaId() {
RestConstraintViolationException rcve = assertThrows(RestConstraintViolationException.class, () -> schemaManager.getSchema(TOPIC_NAME, /* format= */
Optional.empty(), /* subject= */
Optional.empty(), /* subjectNameStrategy= */
Optional.empty(), /* schemaId= */
Optional.of(1000), /* schemaVersion= */
Optional.empty(), /* rawSchema= */
Optional.empty(), /* isKey= */
true));
assertEquals("Error serializing message. Error when fetching schema by id. schemaId = 1000", rcve.getMessage());
assertEquals(42207, rcve.getErrorCode());
}
use of io.confluent.rest.exceptions.RestConstraintViolationException in project kafka-rest by confluentinc.
the class SchemaManagerImplTest method schemaRegistryDisabledReturnsError.
@Test
public void schemaRegistryDisabledReturnsError() {
SchemaManager mySchemaManager = new SchemaManagerThrowing();
RestConstraintViolationException e = assertThrows(RestConstraintViolationException.class, () -> mySchemaManager.getSchema(TOPIC_NAME, /* format= */
Optional.empty(), /* subject= */
Optional.empty(), /* subjectNameStrategy= */
Optional.empty(), /* schemaId= */
Optional.empty(), /* schemaVersion= */
Optional.empty(), /* rawSchema= */
Optional.empty(), /* isKey= */
true));
assertEquals("Payload error. Schema Registry must be configured when using schemas.", e.getMessage());
assertEquals(42206, e.getErrorCode());
}
use of io.confluent.rest.exceptions.RestConstraintViolationException in project kafka-rest by confluentinc.
the class SchemaManagerImplTest method errorFetchingLatestSchemaBySchemaVersionInvalidSchema.
@Test
public void errorFetchingLatestSchemaBySchemaVersionInvalidSchema() throws RestClientException, IOException {
SchemaRegistryClient schemaRegistryClientMock = mock(SchemaRegistryClient.class);
SchemaMetadata schemaMetadataMock = mock(SchemaMetadata.class);
expect(schemaRegistryClientMock.getLatestSchemaMetadata("subject1")).andReturn(schemaMetadataMock);
expect(schemaMetadataMock.getSchemaType()).andReturn(EmbeddedFormat.AVRO.name());
expect(schemaMetadataMock.getSchema()).andReturn(TextNode.valueOf("schema").toString());
expect(schemaMetadataMock.getReferences()).andReturn(emptyList());
replay(schemaRegistryClientMock, schemaMetadataMock);
SchemaManager mySchemaManager = new SchemaManagerImpl(schemaRegistryClientMock, new TopicNameStrategy());
RestConstraintViolationException rcve = assertThrows(RestConstraintViolationException.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("Invalid schema: Error when fetching latest schema version. subject = subject1", rcve.getMessage());
assertEquals(42205, rcve.getErrorCode());
}
use of io.confluent.rest.exceptions.RestConstraintViolationException in project kafka-rest by confluentinc.
the class ProduceActionTest method testHasNextOnNullData.
@Test
public void testHasNextOnNullData() throws Exception {
Properties properties = new Properties();
properties.put(PRODUCE_MAX_REQUESTS_PER_SECOND, "100");
properties.put(PRODUCE_MAX_BYTES_PER_SECOND, // first record is 25 bytes long
Integer.toString(30));
properties.put(PRODUCE_RATE_LIMIT_CACHE_EXPIRY_MS, "3600000");
properties.put(PRODUCE_RATE_LIMIT_ENABLED, "true");
// setup
ChunkedOutputFactory chunkedOutputFactory = mock(ChunkedOutputFactory.class);
Provider<RequestRateLimiter> countLimitProvider = mock(Provider.class);
Provider<RequestRateLimiter> bytesLimitProvider = mock(Provider.class);
RequestRateLimiter rateLimiterForCount = mock(RequestRateLimiter.class);
RequestRateLimiter rateLimiterForBytes = mock(RequestRateLimiter.class);
expect(countLimitProvider.get()).andReturn(rateLimiterForCount);
expect(bytesLimitProvider.get()).andReturn(rateLimiterForBytes);
rateLimiterForCount.rateLimit(anyInt());
rateLimiterForBytes.rateLimit(anyInt());
ProduceAction produceAction = getProduceAction(properties, chunkedOutputFactory, 1, countLimitProvider, bytesLimitProvider);
MappingIterator<ProduceRequest> requests = null;
FakeAsyncResponse fakeAsyncResponse = new FakeAsyncResponse();
RestConstraintViolationException e = assertThrows(RestConstraintViolationException.class, () -> produceAction.produce(fakeAsyncResponse, "clusterId", "topicName", requests));
assertEquals("Payload error. Null input provided. Data is required.", e.getMessage());
assertEquals(42206, e.getErrorCode());
}
Aggregations