diff --git a/src/main/java/org/opengroup/osdu/azure/partition/PartitionServiceEventGridClient.java b/src/main/java/org/opengroup/osdu/azure/partition/PartitionServiceEventGridClient.java index c20edd89810ee5ac508dc8f08b79472523b5c624..e6dccb18b0c092cd0ada216768869b593ca6c5b1 100644 --- a/src/main/java/org/opengroup/osdu/azure/partition/PartitionServiceEventGridClient.java +++ b/src/main/java/org/opengroup/osdu/azure/partition/PartitionServiceEventGridClient.java @@ -71,7 +71,7 @@ public class PartitionServiceEventGridClient { Validators.checkNotNullAndNotEmpty(partitionId, "partitionId"); Validators.checkNotNullAndNotEmpty(topicName, "topicName"); - Map eventGridTopicPartitionInfoAzure = getAllEventGridTopicsInPartition(partitionId); + Map eventGridTopicPartitionInfoAzure = getAllRelevantEventGridTopicsInPartition(partitionId, topicName); if (!eventGridTopicPartitionInfoAzure.containsKey(topicName)) { throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Invalid EventGrid Partition configuration for the partition " + partitionId, "Please refer to wiki here <>"); @@ -80,20 +80,21 @@ public class PartitionServiceEventGridClient { } /** - * Get partition info. + * Get relevant event grid topics. * * @param partitionId Partition Id - * @return Partition info + * @param topicName Topic Name + * @return Event Grid Topics * @throws AppException Exception thrown by {@link IPartitionFactory} * @throws PartitionException Exception thrown by {@link IPartitionFactory} */ - Map getAllEventGridTopicsInPartition(final String partitionId) throws AppException, PartitionException { + Map getAllRelevantEventGridTopicsInPartition(final String partitionId, final String topicName) throws AppException, PartitionException { PartitionInfo partitionInfo = getPartitionInfo(partitionId); Map propertyMap = partitionInfo.getProperties(); Map topics = new HashMap<>(); for (Map.Entry property : propertyMap.entrySet()) { - if (isEventGridProperty(property)) { + if (isEventGridProperty(property) && property.getKey().contains(topicName)) { StringTokenizer stringTokenizer = new StringTokenizer(property.getKey(), "-"); if (stringTokenizer.countTokens() == 2) { addEventGridTopicName(topics, property, stringTokenizer); diff --git a/src/test/java/org/opengroup/osdu/azure/partition/PartitionServiceEventGridClientTest.java b/src/test/java/org/opengroup/osdu/azure/partition/PartitionServiceEventGridClientTest.java index e6ceedd12923e474e07fe7bd7b8ef25eb97e3344..d0e30e8149df4fe5fa252c0c80ad723de9ae47fd 100644 --- a/src/test/java/org/opengroup/osdu/azure/partition/PartitionServiceEventGridClientTest.java +++ b/src/test/java/org/opengroup/osdu/azure/partition/PartitionServiceEventGridClientTest.java @@ -66,7 +66,6 @@ public class PartitionServiceEventGridClientTest { final String eventGridTopicName2 = "testEventGridTopicName2"; final String eventGridTopicAccessKey2 = "testEventGridTopicAccessKey2"; final String topicId1 = "recordstopic"; - final String topicId2 = "testtopic"; Map properties = new HashMap<>(); properties.put("id", Property.builder().value(PARTITION_ID).build()); @@ -85,18 +84,15 @@ public class PartitionServiceEventGridClientTest { // Act Map eventGridTopicPartitionInfoAzureMap = - partitionServiceClientSpy.getAllEventGridTopicsInPartition("tenant1"); + partitionServiceClientSpy.getAllRelevantEventGridTopicsInPartition("tenant1", "recordstopic"); // Assert - assertEquals(eventGridTopicPartitionInfoAzureMap.size(), 2); + assertEquals(eventGridTopicPartitionInfoAzureMap.size(), 1); assertTrue(eventGridTopicPartitionInfoAzureMap.containsKey(topicId1)); - assertTrue(eventGridTopicPartitionInfoAzureMap.containsKey(topicId2)); // Validate that the EventGridTopicPartitionInfo is mapped correctly. assertEquals(eventGridTopicPartitionInfoAzureMap.get(topicId1).getTopicName(), eventGridTopicName1); assertEquals(eventGridTopicPartitionInfoAzureMap.get(topicId1).getTopicAccessKey(), eventGridTopicAccessKey1); - assertEquals(eventGridTopicPartitionInfoAzureMap.get(topicId2).getTopicName(), eventGridTopicName2); - assertEquals(eventGridTopicPartitionInfoAzureMap.get(topicId2).getTopicAccessKey(), eventGridTopicAccessKey2); } @Test