Skip to content

Commit

Permalink
add 1 TU for TopicService
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasCAI-mlv committed Jul 16, 2024
1 parent ce49426 commit 4bc35b3
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/test/java/com/michelin/ns4kafka/service/TopicServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,63 @@ void findAllForNamespaceNoAcls() {
assertTrue(actual.isEmpty());
}

@Test
void findAllForNamespaceNoAclsOfTopic() {
Namespace ns = Namespace.builder()
.metadata(Metadata.builder()
.name("namespace")
.cluster("local")
.build())
.spec(NamespaceSpec.builder()
.connectClusters(List.of("local-name"))
.build())
.build();

// init ns4kfk topics
Topic t1 = Topic.builder()
.metadata(Metadata.builder().name("ns-topic1").build())
.build();
Topic t2 = Topic.builder()
.metadata(Metadata.builder().name("ns-topic2").build())
.build();
Topic t3 = Topic.builder()
.metadata(Metadata.builder().name("ns1-topic1").build())
.build();
Topic t4 = Topic.builder()
.metadata(Metadata.builder().name("ns2-topic1").build())
.build();
when(topicRepository.findAllForCluster("local"))
.thenReturn(List.of(t1, t2, t3, t4));

// all ns4kfk access control entries are not for the topics
when(accessControlEntryService.findResourceOwnerGrantedToNamespace(ns, AccessControlEntry.ResourceType.TOPIC))
.thenReturn(List.of(
AccessControlEntry.builder()
.spec(AccessControlEntry.AccessControlEntrySpec.builder()
.permission(AccessControlEntry.Permission.OWNER)
.grantedTo("namespace")
.resourcePatternType(AccessControlEntry.ResourcePatternType.LITERAL)
.resourceType(AccessControlEntry.ResourceType.TOPIC)
.resource("ns-topic5")
.build())
.build(),
AccessControlEntry.builder()
.spec(AccessControlEntry.AccessControlEntrySpec.builder()
.permission(AccessControlEntry.Permission.OWNER)
.grantedTo("namespace")
.resourcePatternType(AccessControlEntry.ResourcePatternType.PREFIXED)
.resourceType(AccessControlEntry.ResourceType.TOPIC)
.resource("ns0-")
.build())
.build()));

when(accessControlEntryService.isAnyAclOfTopic(any(), anyString())).thenReturn(false);

// list of topics is empty
List<Topic> actual = topicService.findAllForNamespace(ns);
assertTrue(actual.isEmpty());
}

@Test
void findAllForNamespace() {
Namespace ns = Namespace.builder()
Expand Down

0 comments on commit 4bc35b3

Please sign in to comment.