SimpleAclRuleResource { public static SimpleAclRuleResource fromKafkaResourcePattern(ResourcePattern kafkaResourcePattern) { String resourceName; SimpleAclRuleResourceType resourceType; AclResourcePatternType resourcePattern = null; switch (kafkaResourcePattern.resourceType()) { case TOPIC: resourceName = kafkaResourcePattern.name(); resourceType = SimpleAclRuleResourceType.TOPIC; switch (kafkaResourcePattern.patternType()) { case LITERAL: resourcePattern = AclResourcePatternType.LITERAL; break; case PREFIXED: resourcePattern = AclResourcePatternType.PREFIX; break; default: throw new IllegalArgumentException("Invalid Resource type: " + kafkaResourcePattern.resourceType()); } break; case GROUP: resourceType = SimpleAclRuleResourceType.GROUP; resourceName = kafkaResourcePattern.name(); switch (kafkaResourcePattern.patternType()) { case LITERAL: resourcePattern = AclResourcePatternType.LITERAL; break; case PREFIXED: resourcePattern = AclResourcePatternType.PREFIX; break; default: throw new IllegalArgumentException("Invalid Resource type: " + kafkaResourcePattern.resourceType()); } break; case CLUSTER: resourceType = SimpleAclRuleResourceType.CLUSTER; resourceName = "kafka-cluster"; resourcePattern = AclResourcePatternType.LITERAL; break; case TRANSACTIONAL_ID: resourceType = SimpleAclRuleResourceType.TRANSACTIONAL_ID; resourceName = kafkaResourcePattern.name(); switch (kafkaResourcePattern.patternType()) { case LITERAL: resourcePattern = AclResourcePatternType.LITERAL; break; case PREFIXED: resourcePattern = AclResourcePatternType.PREFIX; break; default: throw new IllegalArgumentException("Invalid Resource type: " + kafkaResourcePattern.resourceType()); } break; default: throw new IllegalArgumentException("Invalid Resource type: " + kafkaResourcePattern.resourceType()); } return new SimpleAclRuleResource(resourceName, resourceType, resourcePattern); } 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 testFromKafkaResourcePatternWithTopicResource() { ResourcePattern kafkaTopicResourcePattern = new ResourcePattern(ResourceType.TOPIC, "my-topic", PatternType.LITERAL); SimpleAclRuleResource expectedTopicResourceRules = new SimpleAclRuleResource("my-topic", SimpleAclRuleResourceType.TOPIC, AclResourcePatternType.LITERAL); assertThat(SimpleAclRuleResource.fromKafkaResourcePattern(kafkaTopicResourcePattern), is(expectedTopicResourceRules)); kafkaTopicResourcePattern = new ResourcePattern(ResourceType.TOPIC, "my-", PatternType.PREFIXED); expectedTopicResourceRules = new SimpleAclRuleResource("my-", SimpleAclRuleResourceType.TOPIC, AclResourcePatternType.PREFIX); assertThat(SimpleAclRuleResource.fromKafkaResourcePattern(kafkaTopicResourcePattern), is(expectedTopicResourceRules)); }
@Test public void testFromKafkaResourcePatternWithGroupResource() { ResourcePattern kafkaGroupResourcePattern = new ResourcePattern(ResourceType.GROUP, "my-group", PatternType.LITERAL); SimpleAclRuleResource expectedGroupResourceRules = new SimpleAclRuleResource("my-group", SimpleAclRuleResourceType.GROUP, AclResourcePatternType.LITERAL); assertThat(SimpleAclRuleResource.fromKafkaResourcePattern(kafkaGroupResourcePattern), is(expectedGroupResourceRules)); kafkaGroupResourcePattern = new ResourcePattern(ResourceType.GROUP, "my-", PatternType.PREFIXED); expectedGroupResourceRules = new SimpleAclRuleResource("my-", SimpleAclRuleResourceType.GROUP, AclResourcePatternType.PREFIX); assertThat(SimpleAclRuleResource.fromKafkaResourcePattern(kafkaGroupResourcePattern), is(expectedGroupResourceRules)); }
@Test public void testFromKafkaResourcePatternWithClusterResource() { ResourcePattern kafkaClusterResourcePattern = new ResourcePattern(ResourceType.CLUSTER, "kafka-cluster", PatternType.LITERAL); SimpleAclRuleResource expectedClusterResourceRules = new SimpleAclRuleResource("kafka-cluster", SimpleAclRuleResourceType.CLUSTER, AclResourcePatternType.LITERAL); assertThat(SimpleAclRuleResource.fromKafkaResourcePattern(kafkaClusterResourcePattern), is(expectedClusterResourceRules)); }
@Test public void testFromKafkaResourcePatternWithTransactionalIdResource() { ResourcePattern kafkaTransactionalIdResourcePattern = new ResourcePattern(ResourceType.TRANSACTIONAL_ID, "my-transactionalId", PatternType.LITERAL); SimpleAclRuleResource expectedTransactionalIdResourceRules = new SimpleAclRuleResource("my-transactionalId", SimpleAclRuleResourceType.TRANSACTIONAL_ID, AclResourcePatternType.LITERAL); assertThat(SimpleAclRuleResource.fromKafkaResourcePattern(kafkaTransactionalIdResourcePattern), is(expectedTransactionalIdResourceRules)); kafkaTransactionalIdResourcePattern = new ResourcePattern(ResourceType.TRANSACTIONAL_ID, "my-", PatternType.PREFIXED); expectedTransactionalIdResourceRules = new SimpleAclRuleResource("my-", SimpleAclRuleResourceType.TRANSACTIONAL_ID, AclResourcePatternType.PREFIX); assertThat(SimpleAclRuleResource.fromKafkaResourcePattern(kafkaTransactionalIdResourcePattern), is(expectedTransactionalIdResourceRules)); }