Search in sources :

Example 56 with FakeAsyncResponse

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

the class ClusterConfigResourceTest method getClusterConfig_existingConfig_returnsConfig.

@Test
public void getClusterConfig_existingConfig_returnsConfig() {
    expect(clusterConfigManager.getClusterConfig(CLUSTER_ID, ClusterConfig.Type.BROKER, CONFIG_1.getName())).andReturn(completedFuture(Optional.of(CONFIG_1)));
    replay(clusterConfigManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    clusterConfigsResource.getClusterConfig(response, CLUSTER_ID, ClusterConfig.Type.BROKER, CONFIG_1.getName());
    GetClusterConfigResponse expected = GetClusterConfigResponse.create(ClusterConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/broker-configs/config-1").setResourceName("crn:///kafka=cluster-1/broker-config=config-1").build()).setClusterId(CLUSTER_ID).setConfigType(ClusterConfig.Type.BROKER).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) GetClusterConfigResponse(io.confluent.kafkarest.entities.v3.GetClusterConfigResponse) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 57 with FakeAsyncResponse

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

the class ClusterConfigResourceTest method resetClusterConfig_existingConfig_resetsConfig.

@Test
public void resetClusterConfig_existingConfig_resetsConfig() {
    expect(clusterConfigManager.deleteClusterConfig(CLUSTER_ID, ClusterConfig.Type.BROKER, CONFIG_1.getName())).andReturn(completedFuture(null));
    replay(clusterConfigManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    clusterConfigsResource.deleteClusterConfig(response, CLUSTER_ID, ClusterConfig.Type.BROKER, CONFIG_1.getName());
    assertNull(response.getValue());
    assertNull(response.getException());
    assertTrue(response.isDone());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 58 with FakeAsyncResponse

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

the class AclsResourceTest method deleteAcl_deletesAndReturnsMatchedAcls.

@Test
public void deleteAcl_deletesAndReturnsMatchedAcls() {
    expect(aclManager.deleteAcls(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.deleteAcls(response, CLUSTER_ID, Acl.ResourceType.TOPIC, /* resourceName= */
    "topic-1", Acl.PatternType.MATCH, /* principal= */
    "", /* host= */
    "", Acl.Operation.ANY, Acl.Permission.ALLOW);
    DeleteAclsResponse expected = DeleteAclsResponse.create(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()));
    assertEquals(expected, response.getValue());
}
Also used : DeleteAclsResponse(io.confluent.kafkarest.entities.v3.DeleteAclsResponse) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 59 with FakeAsyncResponse

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

the class AclsResourceTest method createAcl_createsAcl.

@Test
public void createAcl_createsAcl() {
    expect(aclManager.createAcl(CLUSTER_ID, Acl.ResourceType.TOPIC, /* resourceName= */
    "*", Acl.PatternType.LITERAL, /* principal= */
    "User:alice", /* host= */
    "*", Acl.Operation.READ, Acl.Permission.ALLOW)).andReturn(completedFuture(/* value= */
    null));
    replay(aclManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    aclsResource.createAcl(response, CLUSTER_ID, CreateAclRequest.builder().setResourceType(Acl.ResourceType.TOPIC).setResourceName("*").setPatternType(Acl.PatternType.LITERAL).setPrincipal("User:alice").setHost("*").setOperation(Acl.Operation.READ).setPermission(Acl.Permission.ALLOW).build());
    assertNull(response.getValue());
    assertNull(response.getException());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 60 with FakeAsyncResponse

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

the class AlterClusterConfigBatchActionTest method alterClusterConfigs_existingConfig_alterConfigs.

@Test
public void alterClusterConfigs_existingConfig_alterConfigs() {
    expect(clusterConfigManager.alterClusterConfigs(CLUSTER_ID, ClusterConfig.Type.BROKER, Arrays.asList(AlterConfigCommand.set(CONFIG_1.getName(), "newValue"), AlterConfigCommand.delete(CONFIG_2.getName())))).andReturn(completedFuture(null));
    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()))));
    assertNull(response.getValue());
    assertNull(response.getException());
    assertTrue(response.isDone());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) 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