Search in sources :

Example 1 with FakeAsyncResponse

use of io.confluent.kafkarest.response.FakeAsyncResponse in project kafka-rest by confluentinc.

the class AclsResourceTest method searchAcls_returnsMatchedAcls.

@Test
public void searchAcls_returnsMatchedAcls() {
    expect(aclManager.searchAcls(CLUSTER_ID, Acl.ResourceType.TOPIC, /* resourceName= */
    "topic-1", Acl.PatternType.MATCH, /* principal= */
    null, /* host= */
    null, Acl.Operation.ANY, Acl.Permission.ALLOW)).andReturn(completedFuture(Arrays.asList(ACL_1, ACL_2)));
    replay(aclManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    aclsResource.searchAcls(response, CLUSTER_ID, Acl.ResourceType.TOPIC, /* resourceName= */
    "topic-1", Acl.PatternType.MATCH, /* principal= */
    "", /* host= */
    "", Acl.Operation.ANY, Acl.Permission.ALLOW);
    SearchAclsResponse expected = SearchAclsResponse.create(AclDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters/cluster-1/acls" + "?resource_type=TOPIC" + "&resource_name=topic-1" + "&pattern_type=MATCH" + "&principal=" + "&host=" + "&operation=ANY" + "&permission=ALLOW").build()).setData(Arrays.asList(AclData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/acls" + "?resource_type=TOPIC" + "&resource_name=*" + "&pattern_type=LITERAL" + "&principal=User%3Aalice" + "&host=*" + "&operation=READ" + "&permission=ALLOW").build()).setClusterId(CLUSTER_ID).setResourceType(Acl.ResourceType.TOPIC).setResourceName("*").setPatternType(Acl.PatternType.LITERAL).setPrincipal("User:alice").setHost("*").setOperation(Acl.Operation.READ).setPermission(Acl.Permission.ALLOW).build(), AclData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/acls" + "?resource_type=TOPIC" + "&resource_name=topic-" + "&pattern_type=PREFIXED" + "&principal=User%3Abob" + "&host=1.2.3.4" + "&operation=WRITE" + "&permission=ALLOW").build()).setClusterId(CLUSTER_ID).setResourceType(Acl.ResourceType.TOPIC).setResourceName("topic-").setPatternType(Acl.PatternType.PREFIXED).setPrincipal("User:bob").setHost("1.2.3.4").setOperation(Acl.Operation.WRITE).setPermission(Acl.Permission.ALLOW).build())).build());
    assertEquals(expected, response.getValue());
}
Also used : SearchAclsResponse(io.confluent.kafkarest.entities.v3.SearchAclsResponse) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 2 with FakeAsyncResponse

use of io.confluent.kafkarest.response.FakeAsyncResponse in project kafka-rest by confluentinc.

the class AlterClusterConfigBatchActionTest method alterClusterConfigs_nonExistingCluster_throwsNotFound.

@Test
public void alterClusterConfigs_nonExistingCluster_throwsNotFound() {
    expect(clusterConfigManager.alterClusterConfigs(CLUSTER_ID, ClusterConfig.Type.BROKER, Arrays.asList(AlterConfigCommand.set(CONFIG_1.getName(), "newValue"), AlterConfigCommand.delete(CONFIG_2.getName())))).andReturn(failedFuture(new NotFoundException()));
    replay(clusterConfigManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    alterClusterConfigBatchAction.alterClusterConfigBatch(response, CLUSTER_ID, ClusterConfig.Type.BROKER, AlterClusterConfigBatchRequest.create(AlterConfigBatchRequestData.create(Arrays.asList(AlterEntry.builder().setName(CONFIG_1.getName()).setValue("newValue").build(), AlterEntry.builder().setName(CONFIG_2.getName()).setOperation(AlterOperation.DELETE).build()))));
    assertEquals(NotFoundException.class, response.getException().getClass());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 3 with FakeAsyncResponse

use of io.confluent.kafkarest.response.FakeAsyncResponse in project kafka-rest by confluentinc.

the class BrokerConfigResourceTest method resetBrokerConfig_nonExistingConfigOrBrokerOrCluster_throwsNotFound.

@Test
public void resetBrokerConfig_nonExistingConfigOrBrokerOrCluster_throwsNotFound() {
    expect(brokerConfigManager.resetBrokerConfig(CLUSTER_ID, BROKER_ID, CONFIG_1.getName())).andReturn(failedFuture(new NotFoundException()));
    replay(brokerConfigManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    brokerConfigsResource.resetBrokerConfig(response, CLUSTER_ID, BROKER_ID, CONFIG_1.getName());
    assertEquals(NotFoundException.class, response.getException().getClass());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 4 with FakeAsyncResponse

use of io.confluent.kafkarest.response.FakeAsyncResponse in project kafka-rest by confluentinc.

the class BrokerConfigResourceTest method getBrokerConfig_nonExistingBrokerorCluster_throwsNotFound.

@Test
public void getBrokerConfig_nonExistingBrokerorCluster_throwsNotFound() {
    expect(brokerConfigManager.getBrokerConfig(CLUSTER_ID, BROKER_ID, CONFIG_1.getName())).andReturn(failedFuture(new NotFoundException()));
    replay(brokerConfigManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    brokerConfigsResource.getBrokerConfig(response, CLUSTER_ID, BROKER_ID, CONFIG_1.getName());
    assertEquals(NotFoundException.class, response.getException().getClass());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 5 with FakeAsyncResponse

use of io.confluent.kafkarest.response.FakeAsyncResponse in project kafka-rest by confluentinc.

the class BrokerConfigResourceTest method getBrokerConfig_existingConfig_returnsConfig.

@Test
public void getBrokerConfig_existingConfig_returnsConfig() {
    expect(brokerConfigManager.getBrokerConfig(CLUSTER_ID, BROKER_ID, CONFIG_1.getName())).andReturn(completedFuture(Optional.of(CONFIG_1)));
    replay(brokerConfigManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    brokerConfigsResource.getBrokerConfig(response, CLUSTER_ID, BROKER_ID, CONFIG_1.getName());
    GetBrokerConfigResponse expected = GetBrokerConfigResponse.create(BrokerConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/brokers/1/configs/config-1").setResourceName("crn:///kafka=cluster-1/broker=1/config=config-1").build()).setClusterId(CLUSTER_ID).setBrokerId(BROKER_ID).setName(CONFIG_1.getName()).setValue(CONFIG_1.getValue()).setDefault(CONFIG_1.isDefault()).setReadOnly(CONFIG_1.isReadOnly()).setSensitive(CONFIG_1.isSensitive()).setSource(CONFIG_1.getSource()).setSynonyms(CONFIG_1.getSynonyms().stream().map(ConfigSynonymData::fromConfigSynonym).collect(Collectors.toList())).build());
    assertEquals(expected, response.getValue());
}
Also used : ConfigSynonymData(io.confluent.kafkarest.entities.v3.ConfigSynonymData) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) GetBrokerConfigResponse(io.confluent.kafkarest.entities.v3.GetBrokerConfigResponse) Test(org.junit.jupiter.api.Test)

Aggregations

FakeAsyncResponse (io.confluent.kafkarest.response.FakeAsyncResponse)107 Test (org.junit.jupiter.api.Test)107 NotFoundException (javax.ws.rs.NotFoundException)35 ProduceRequest (io.confluent.kafkarest.entities.v3.ProduceRequest)6 RequestRateLimiter (io.confluent.kafkarest.ratelimit.RequestRateLimiter)6 ChunkedOutputFactory (io.confluent.kafkarest.response.ChunkedOutputFactory)6 Properties (java.util.Properties)6 ResultOrError (io.confluent.kafkarest.response.StreamingResponse.ResultOrError)5 CreateTopicResponse (io.confluent.kafkarest.entities.v3.CreateTopicResponse)4 ProduceResponse (io.confluent.kafkarest.entities.v3.ProduceResponse)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ConfigSynonymData (io.confluent.kafkarest.entities.v3.ConfigSynonymData)3 ListBrokerConfigsResponse (io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse)3 ListTopicConfigsResponse (io.confluent.kafkarest.entities.v3.ListTopicConfigsResponse)3 ErrorResponse (io.confluent.kafkarest.exceptions.v3.ErrorResponse)3 BrokerConfig (io.confluent.kafkarest.entities.BrokerConfig)2 TopicConfig (io.confluent.kafkarest.entities.TopicConfig)2 RateLimitExceededException (io.confluent.kafkarest.ratelimit.RateLimitExceededException)2 TimeoutException (org.apache.kafka.common.errors.TimeoutException)2