SimpleAclRuleResource { public ResourcePattern toKafkaResourcePattern() { org.apache.kafka.common.resource.ResourceType kafkaType; String kafkaName; PatternType kafkaPattern = PatternType.LITERAL; switch (type) { case TOPIC: kafkaType = org.apache.kafka.common.resource.ResourceType.TOPIC; kafkaName = name; if (AclResourcePatternType.PREFIX.equals(pattern)) { kafkaPattern = PatternType.PREFIXED; } break; case GROUP: kafkaType = org.apache.kafka.common.resource.ResourceType.GROUP; kafkaName = name; if (AclResourcePatternType.PREFIX.equals(pattern)) { kafkaPattern = PatternType.PREFIXED; } break; case CLUSTER: kafkaType = org.apache.kafka.common.resource.ResourceType.CLUSTER; kafkaName = "kafka-cluster"; break; case TRANSACTIONAL_ID: kafkaType = org.apache.kafka.common.resource.ResourceType.TRANSACTIONAL_ID; kafkaName = name; if (AclResourcePatternType.PREFIX.equals(pattern)) { kafkaPattern = PatternType.PREFIXED; } break; default: throw new IllegalArgumentException("Invalid Acl resource type: " + type); } return new ResourcePattern(kafkaType, kafkaName, kafkaPattern); } SimpleAclRuleResource(String name, SimpleAclRuleResourceType type, AclResourcePatternType pattern); String getName(); SimpleAclRuleResourceType getType(); AclResourcePatternType getPattern(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); ResourcePattern toKafkaResourcePattern(); static SimpleAclRuleResource fromKafkaResourcePattern(ResourcePattern kafkaResourcePattern); static SimpleAclRuleResource fromCrd(AclRuleResource resource);  }
@Test public void testToKafkaResourcePatternForTopicResource() { SimpleAclRuleResource topicResourceRules = new SimpleAclRuleResource("my-topic", SimpleAclRuleResourceType.TOPIC, AclResourcePatternType.LITERAL); ResourcePattern expectedKafkaResourcePattern = new ResourcePattern(ResourceType.TOPIC, "my-topic", PatternType.LITERAL); assertThat(topicResourceRules.toKafkaResourcePattern(), is(expectedKafkaResourcePattern)); topicResourceRules = new SimpleAclRuleResource("my-", SimpleAclRuleResourceType.TOPIC, AclResourcePatternType.PREFIX); expectedKafkaResourcePattern = new ResourcePattern(ResourceType.TOPIC, "my-", PatternType.PREFIXED); assertThat(topicResourceRules.toKafkaResourcePattern(), is(expectedKafkaResourcePattern)); }
@Test public void testToKafkaResourcePatternForGroupResource() { SimpleAclRuleResource groupResourceRules = new SimpleAclRuleResource("my-group", SimpleAclRuleResourceType.GROUP, AclResourcePatternType.LITERAL); ResourcePattern expectedKafkaResourcePattern = new ResourcePattern(ResourceType.GROUP, "my-group", PatternType.LITERAL); assertThat(groupResourceRules.toKafkaResourcePattern(), is(expectedKafkaResourcePattern)); groupResourceRules = new SimpleAclRuleResource("my-", SimpleAclRuleResourceType.GROUP, AclResourcePatternType.PREFIX); expectedKafkaResourcePattern = new ResourcePattern(ResourceType.GROUP, "my-", PatternType.PREFIXED); assertThat(groupResourceRules.toKafkaResourcePattern(), is(expectedKafkaResourcePattern)); }
@Test public void testToKafkaResourcePatternForClusterResource() { SimpleAclRuleResource clusterResourceRules = new SimpleAclRuleResource(null, SimpleAclRuleResourceType.CLUSTER, null); ResourcePattern expectedKafkaResourcePattern = new ResourcePattern(ResourceType.CLUSTER, "kafka-cluster", PatternType.LITERAL); assertThat(clusterResourceRules.toKafkaResourcePattern(), is(expectedKafkaResourcePattern)); }
@Test public void testToKafkaResourcePatternForTransactionalIdResource() { SimpleAclRuleResource transactionalIdResourceRules = new SimpleAclRuleResource("my-transactionalId", SimpleAclRuleResourceType.TRANSACTIONAL_ID, null); ResourcePattern expectedKafkaResourcePattern = new ResourcePattern(ResourceType.TRANSACTIONAL_ID, "my-transactionalId", PatternType.LITERAL); assertThat(transactionalIdResourceRules.toKafkaResourcePattern(), is(expectedKafkaResourcePattern)); transactionalIdResourceRules = new SimpleAclRuleResource("my-", SimpleAclRuleResourceType.TRANSACTIONAL_ID, AclResourcePatternType.PREFIX); expectedKafkaResourcePattern = new ResourcePattern(ResourceType.TRANSACTIONAL_ID, "my-", PatternType.PREFIXED); assertThat(transactionalIdResourceRules.toKafkaResourcePattern(), is(expectedKafkaResourcePattern)); }