summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/dmaap/dmf/mr/service/impl/TopicServiceImpl.java17
-rw-r--r--src/test/java/org/onap/dmaap/dmf/mr/service/impl/TopicServiceImplTest.java53
2 files changed, 19 insertions, 51 deletions
diff --git a/src/main/java/org/onap/dmaap/dmf/mr/service/impl/TopicServiceImpl.java b/src/main/java/org/onap/dmaap/dmf/mr/service/impl/TopicServiceImpl.java
index 386fb97..69c1414 100644
--- a/src/main/java/org/onap/dmaap/dmf/mr/service/impl/TopicServiceImpl.java
+++ b/src/main/java/org/onap/dmaap/dmf/mr/service/impl/TopicServiceImpl.java
@@ -198,8 +198,9 @@ public class TopicServiceImpl implements TopicService {
LOGGER.info("Creating topic {}",topicName);
String key = authorizeClient(dmaapContext, topicName, TOPIC_CREATE_OP);
try {
- final int partitions = getValueOrDefault(topicBean.getPartitionCount(), "default.partitions");
- final int replicas = getValueOrDefault(topicBean.getReplicationCount(), "default.replicas");
+ final int partitions = getIntValueOrDefault("default.partitions");
+ final int replicas = getIntValueOrDefault("default.replicas");
+ LOGGER.info("Attempting to create topic {} with replicas={}, partitions={}", topicName, replicas, partitions);
final Topic t = getMetaBroker(dmaapContext).createTopic(topicName, topicBean.getTopicDescription(),
key, partitions, replicas, topicBean.isTransactionEnabled());
LOGGER.info("Topic {} created successfully. Sending response", topicName);
@@ -258,13 +259,11 @@ public class TopicServiceImpl implements TopicService {
return enfTopicNamespace != null && topicName.startsWith(enfTopicNamespace);
}
- int getValueOrDefault(int value, String defaultProperty) {
- int returnValue = value;
- if (returnValue <= 0) {
- String defaultValue = getPropertyFromAJSCmap(defaultProperty);
- returnValue = StringUtils.isNotEmpty(defaultValue) ? NumberUtils.toInt(defaultValue) : 1;
- returnValue = (returnValue <= 0) ? 1 : returnValue;
- }
+ int getIntValueOrDefault(String defaultProperty) {
+ int returnValue;
+ String defaultValue = getPropertyFromAJSCmap(defaultProperty);
+ returnValue = StringUtils.isNotEmpty(defaultValue) ? NumberUtils.toInt(defaultValue) : 1;
+ returnValue = (returnValue <= 0) ? 1 : returnValue;
return returnValue;
}
diff --git a/src/test/java/org/onap/dmaap/dmf/mr/service/impl/TopicServiceImplTest.java b/src/test/java/org/onap/dmaap/dmf/mr/service/impl/TopicServiceImplTest.java
index 4424aa9..90c379e 100644
--- a/src/test/java/org/onap/dmaap/dmf/mr/service/impl/TopicServiceImplTest.java
+++ b/src/test/java/org/onap/dmaap/dmf/mr/service/impl/TopicServiceImplTest.java
@@ -290,73 +290,42 @@ public class TopicServiceImplTest {
}
@Test
- public void getValueOrDefault_shouldParseDeafultAndReturnIt_whenGivenValueIsZero() {
+ public void getIntValueOrDefault_shouldReturnOne_whenDefaultNotProvided() {
//given
- int value = 0;
String defaultPropertyName = "propertyName";
- when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("6");
-
- //when
- int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
-
- //then
- assertEquals(6, extracted);
- }
-
- @Test
- public void getValueOrDefault_shouldReturnGivenValue_whenGreaterThanZero() {
- //given
- int value = 3;
- String defaultPropertyName = "propertyName";
-
- //when
- int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
-
- //then
- assertEquals(value, extracted);
- verify(topicService, never()).getPropertyFromAJSCmap(defaultPropertyName);
- }
-
- @Test
- public void getValueOrDefault_shouldParseDeafultAndReturnIt_whenGivenValueIsNegative() {
- //given
- int value = -3;
- String defaultPropertyName = "propertyName";
- when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("6");
+ when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("");
//when
- int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
+ int extracted = topicService.getIntValueOrDefault(defaultPropertyName);
//then
- assertEquals(6, extracted);
+ assertEquals(1, extracted);
}
@Test
- public void getValueOrDefault_shouldReturnOne_whenGivenValueIsZero_andDefaultNotProvided() {
+ public void getIntValueOrDefault_shouldReturnOne_whenValueIsNegative() {
//given
- int value = 0;
String defaultPropertyName = "propertyName";
- when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("");
+ when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("-1");
//when
- int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
+ int extracted = topicService.getIntValueOrDefault(defaultPropertyName);
//then
assertEquals(1, extracted);
}
@Test
- public void getValueOrDefault_shouldReturnOne_whenGivenValueIsZero_andDefaultNaN() {
+ public void getIntValueOrDefault_shouldParseDefaultAndReturnIt_whenGivenValueIsPositive() {
//given
- int value = 0;
String defaultPropertyName = "propertyName";
- when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("a");
+ when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("3");
//when
- int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
+ int extracted = topicService.getIntValueOrDefault(defaultPropertyName);
//then
- assertEquals(1, extracted);
+ assertEquals(3, extracted);
}
@Test(expected = TopicExistsException.class)