summaryrefslogtreecommitdiffstats
path: root/components/datalake-handler/feeder/src/test/java/org/onap/datalake
diff options
context:
space:
mode:
authorKate Hsuan <kate.hsuan@qct.io>2019-04-25 17:57:49 +0800
committerKate Hsuan <kate.hsuan@qct.io>2019-04-26 17:33:15 +0800
commit292c6a896f98b010029a83c332ec0672af29b939 (patch)
tree24233665400f3957bd40415ebf86aec66fea990c /components/datalake-handler/feeder/src/test/java/org/onap/datalake
parent84d1aec2858ed17b523ca156621000a6ad1c1544 (diff)
Add Topic configuration API
1. Add Topic configuration APIs 2. Remove the "default_topic" DB relationship 3. Fix unit test Issue-ID: DCAEGEN2-1437 Change-Id: I7f992a2439606a1e35dc015e0296ca86375caa87 Signed-off-by: Kate Hsuan <kate.hsuan@qct.io>
Diffstat (limited to 'components/datalake-handler/feeder/src/test/java/org/onap/datalake')
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java92
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/TopicTest.java14
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java7
3 files changed, 40 insertions, 73 deletions
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java
index a770f50f..775bcc3b 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java
@@ -27,6 +27,8 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.datalake.feeder.config.ApplicationConfiguration;
+import org.onap.datalake.feeder.controller.domain.PostReturnBody;
+import org.onap.datalake.feeder.controller.domain.TopicConfig;
import org.onap.datalake.feeder.domain.Db;
import org.onap.datalake.feeder.domain.Topic;
import org.onap.datalake.feeder.repository.TopicRepository;
@@ -61,6 +63,10 @@ public class TopicControllerTest {
@Mock
private TopicRepository topicRepository;
+ @Mock
+
+ private TopicService topicServiceMock;
+
@InjectMocks
private TopicService topicService1;
@@ -95,79 +101,51 @@ public class TopicControllerTest {
}
@Test
+ public void testListTopic() throws IOException, NoSuchFieldException, IllegalAccessException{
+ TopicController topicController = new TopicController();
+ setAccessPrivateFields(topicController);
+ }
+
+ @Test
public void testCreateTopic() throws IOException, NoSuchFieldException, IllegalAccessException {
TopicController topicController = new TopicController();
setAccessPrivateFields(topicController);
- when(topicRepository.findById(DEFAULT_TOPIC_NAME)).thenReturn(Optional.of(new Topic(DEFAULT_TOPIC_NAME)));
- when(config.getDefaultTopicName()).thenReturn(DEFAULT_TOPIC_NAME);
- Topic topicName = topicController.createTopic(new Topic("a"), mockBindingResult, httpServletResponse);
- assertEquals(new Topic("a"), topicName);
+ //when(topicRepository.findById("ab")).thenReturn(Optional.of(new Topic("ab")));
+ // when(config.getDefaultTopicName()).thenReturn(DEFAULT_TOPIC_NAME);
+ PostReturnBody<TopicConfig> postTopic = topicController.createTopic(new TopicConfig(), mockBindingResult, httpServletResponse);
+ assertEquals(postTopic.getStatusCode(), 200);
when(mockBindingResult.hasErrors()).thenReturn(true);
- topicName = topicController.createTopic(new Topic("a"), mockBindingResult, httpServletResponse);
- assertEquals(null, topicName);
+ PostReturnBody<TopicConfig> topicConfig= topicController.createTopic(new TopicConfig(), mockBindingResult, httpServletResponse);
+ assertEquals(null, topicConfig);
when(mockBindingResult.hasErrors()).thenReturn(false);
- Topic a = new Topic("a");
- a.setName("a");
- when(topicRepository.findById("a")).thenReturn(Optional.of(a));
- topicName = topicController.createTopic(new Topic("a"), mockBindingResult, httpServletResponse);
- assertEquals(null, topicName);
+ TopicConfig a = new TopicConfig();
+ a.setName(DEFAULT_TOPIC_NAME);
+ when(topicRepository.findById(DEFAULT_TOPIC_NAME)).thenReturn(Optional.of(new Topic(DEFAULT_TOPIC_NAME)));
+ PostReturnBody<TopicConfig> postTopic2= topicController.createTopic(a, mockBindingResult, httpServletResponse);
+ assertEquals(null, postTopic2);
}
@Test
public void testUpdateTopic() throws IOException, NoSuchFieldException, IllegalAccessException {
TopicController topicController = new TopicController();
setAccessPrivateFields(topicController);
- Topic topicName = topicController.updateTopic(new Topic("a"), mockBindingResult, httpServletResponse);
- assertEquals(null, topicName);
+ PostReturnBody<TopicConfig> postTopic = topicController.updateTopic("a", new TopicConfig(), mockBindingResult, httpServletResponse);
+ assertEquals(null, postTopic);
Topic a = new Topic("a");
a.setName("a");
when(topicRepository.findById("a")).thenReturn(Optional.of(a));
- topicName = topicController.updateTopic(new Topic("a"), mockBindingResult, httpServletResponse);
- assertEquals(new Topic("a"), topicName);
+ TopicConfig ac = new TopicConfig();
+ ac.setName("a");
+ ac.setEnable(true);
+ PostReturnBody<TopicConfig> postConfig1 = topicController.updateTopic("a", ac, mockBindingResult, httpServletResponse);
+ assertEquals(200, postConfig1.getStatusCode());
+ TopicConfig ret = postConfig1.getReturnBody();
+ assertEquals("a", ret.getName());
+ assertEquals(true, ret.isEnable());
when(mockBindingResult.hasErrors()).thenReturn(true);
- topicName = topicController.updateTopic(new Topic("a"), mockBindingResult, httpServletResponse);
- assertEquals(null, topicName);
-
- ArrayList<Topic> topics = new ArrayList<>();
- topics.add(a);
- when(topicRepository.findAll()).thenReturn(topics);
- Iterable<Topic> list = topicController.list();
- for (Topic newTopic : list) {
- assertEquals(a, newTopic);
- }
- }
+ PostReturnBody<TopicConfig> postConfig2 = topicController.updateTopic("a", ac, mockBindingResult, httpServletResponse);
+ assertEquals(null, postConfig2);
- @Test
- public void testAddDb() throws NoSuchFieldException, IllegalAccessException, IOException {
- TopicController topicController = new TopicController();
- setAccessPrivateFields(topicController);
- String dbName = "Elecsticsearch";
- String name = "a";
- Topic topic = new Topic(name);
- topic.setEnabled(true);
- Set<Db> dbSet = new HashSet<>();
- dbSet.add(new Db(dbName));
- topic.setDbs(dbSet);
-
- when(topicRepository.findById(name)).thenReturn(Optional.of(topic));
- topicController.addDb("a", dbName, httpServletResponse);
- topicController.deleteDb("a", dbName, httpServletResponse);
- }
-
- @Test
- public void testGetTopicDbs() throws NoSuchFieldException, IllegalAccessException, IOException {
- TopicController topicController = new TopicController();
- setAccessPrivateFields(topicController);
- String dbName = "Elecsticsearch";
- String name = "a";
- Topic topic = new Topic(name);
- topic.setEnabled(true);
- Set<Db> dbSet = new HashSet<>();
- dbSet.add(new Db(dbName));
- topic.setDbs(dbSet);
-
- when(topicRepository.findById(name)).thenReturn(Optional.of(topic));
- topicController.getTopicDbs("a");
}
@Test
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/TopicTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/TopicTest.java
index 8be45d60..b583473a 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/TopicTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/TopicTest.java
@@ -69,19 +69,16 @@ public class TopicTest {
Topic defaultTopic = new Topic("_DL_DEFAULT_");
Topic testTopic = new Topic("test");
- testTopic.setDefaultTopic(defaultTopic);
assertEquals(3650, testTopic.getTtl());
defaultTopic.setTtl(20);
- assertEquals(20, testTopic.getTtl());
- topic.setDefaultTopic(new Topic("defaultTopic"));
+ assertEquals(20, defaultTopic.getTtl());
topic.setLogin("root");
topic.setPass("root123");
topic.setEnabled(true);
topic.setSaveRaw(true);
topic.setCorrelateClearedMessage(true);
topic.setMessageIdPath("/data/data2/value");
- assertTrue("defaultTopic".equals(topic.getDefaultTopic().toString()));
assertTrue("root".equals(topic.getLogin()));
assertTrue("root123".equals(topic.getPass()));
assertFalse("true".equals(topic.getEnabled()));
@@ -96,14 +93,13 @@ public class TopicTest {
public void testIs() {
Topic defaultTopic = new Topic("_DL_DEFAULT_");
Topic testTopic = new Topic("test");
- testTopic.setDefaultTopic(defaultTopic);
assertTrue(testTopic.equals(new Topic("test")));
assertEquals(testTopic.hashCode(), (new Topic("test")).hashCode());
defaultTopic.setDbs(new HashSet<>());
defaultTopic.getDbs().add(new Db("Elasticsearch"));
- assertTrue(testTopic.supportElasticsearch());
+ assertTrue(defaultTopic.supportElasticsearch());
assertFalse(testTopic.supportCouchbase());
assertFalse(testTopic.supportDruid());
assertFalse(testTopic.supportMongoDB());
@@ -116,9 +112,9 @@ public class TopicTest {
defaultTopic.setDataFormat("XML");
defaultTopic.setEnabled(true);
defaultTopic.setSaveRaw(true);
- assertTrue(testTopic.isCorrelateClearedMessage());
- assertTrue(testTopic.isEnabled());
- assertTrue(testTopic.isSaveRaw());
+ assertTrue(defaultTopic.isCorrelateClearedMessage());
+ assertTrue(defaultTopic.isEnabled());
+ assertTrue(defaultTopic.isSaveRaw());
assertEquals(defaultTopic.getDataFormat(), DataFormat.XML);
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java
index 99f22398..8b25ec53 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java
@@ -79,13 +79,6 @@ public class TopicServiceTest {
assertNull(topicService.getTopic(name));
}
- @Test
- public void testGetDefaultTopic() {
- when(topicRepository.findById(DEFAULT_TOPIC_NAME)).thenReturn(Optional.of(new Topic(DEFAULT_TOPIC_NAME)));
- when(config.getDefaultTopicName()).thenReturn(DEFAULT_TOPIC_NAME);
- assertEquals(topicService.getDefaultTopic(), new Topic(DEFAULT_TOPIC_NAME));
- assertTrue(topicService.istDefaultTopic(new Topic(DEFAULT_TOPIC_NAME)));
- }
@Test(expected = IOException.class)
public void testGetEffectiveTopic() throws IOException {