Commit 85955c2c authored by Komal Makkar's avatar Komal Makkar
Browse files

minor changes

parent 4988e4ab
Pipeline #28185 failed with stage
in 16 seconds
...@@ -39,6 +39,8 @@ import java.util.StringTokenizer; ...@@ -39,6 +39,8 @@ import java.util.StringTokenizer;
@Service @Service
@Lazy @Lazy
public class PartitionServiceEventGridClient { public class PartitionServiceEventGridClient {
private static final String ACCESS_KEY_REGEX = "^eventgrid-([a-zA-Z0-9]*)topic-accesskey$";
private static final String TOPIC_NAME_REGEX = "^eventgrid-([a-zA-Z0-9]*)topic$";
@Autowired @Autowired
private IPartitionFactory partitionFactory; private IPartitionFactory partitionFactory;
...@@ -93,7 +95,7 @@ public class PartitionServiceEventGridClient { ...@@ -93,7 +95,7 @@ public class PartitionServiceEventGridClient {
} else if (stringTokenizer.countTokens() == 3) { } else if (stringTokenizer.countTokens() == 3) {
addEventGridAccessKey(topics, property, stringTokenizer); addEventGridAccessKey(topics, property, stringTokenizer);
} else { } else {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Invalid EventGrid Partition configuration for the partition " + partitionId, "Please refer to wiki here <>"); throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Invalid EventGrid Partition configuration for the partition " + partitionId, "Please reconfigure the partition service");
} }
} }
} }
...@@ -117,9 +119,7 @@ public class PartitionServiceEventGridClient { ...@@ -117,9 +119,7 @@ public class PartitionServiceEventGridClient {
* @return isEventGridProperty * @return isEventGridProperty
*/ */
private boolean isEventGridProperty(final Map.Entry<String, Property> property) { private boolean isEventGridProperty(final Map.Entry<String, Property> property) {
String accessKeyRegex = "^eventgrid-([a-zA-Z0-9]*)topic-accesskey$"; return property.getKey().matches((ACCESS_KEY_REGEX)) || property.getKey().matches((TOPIC_NAME_REGEX));
String topicNameRegex = "^eventgrid-([a-zA-Z0-9]*)topic$";
return property.getKey().matches((accessKeyRegex)) || property.getKey().matches((topicNameRegex));
} }
/** /**
......
...@@ -92,7 +92,7 @@ public class PartitionServiceEventGridClientTest { ...@@ -92,7 +92,7 @@ public class PartitionServiceEventGridClientTest {
} }
@Test @Test
public void getTopicName() throws PartitionException { public void should_throwWhenInvalid_getEventGridTopicInPartition() throws PartitionException {
final String eventGridTopicName1 = "testEventGridTopicName1"; final String eventGridTopicName1 = "testEventGridTopicName1";
final String eventGridTopicAccessKey1 = "testEventGridTopicAccessKey1"; final String eventGridTopicAccessKey1 = "testEventGridTopicAccessKey1";
Map<String, Property> properties = new HashMap<>(); Map<String, Property> properties = new HashMap<>();
...@@ -115,9 +115,7 @@ public class PartitionServiceEventGridClientTest { ...@@ -115,9 +115,7 @@ public class PartitionServiceEventGridClientTest {
assertEquals(eventGridTopicPartitionInfoAzure.getTopicAccessKey().getValue(), eventGridTopicAccessKey1); assertEquals(eventGridTopicPartitionInfoAzure.getTopicAccessKey().getValue(), eventGridTopicAccessKey1);
// Assert negative // Assert negative
AppException exception = assertThrows(AppException.class, () -> { AppException exception = assertThrows(AppException.class, () -> partitionServiceClientSpy.getEventGridTopicInPartition("tenant1", "recordschangedtopic"));
partitionServiceClientSpy.getEventGridTopicInPartition("tenant1", "recordschangedtopic");
});
assertEquals(500, exception.getError().getCode()); assertEquals(500, exception.getError().getCode());
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment