summaryrefslogtreecommitdiffstats
path: root/mod/bpgenerator/onap/src/test
diff options
context:
space:
mode:
authorTomasz Wrobel <tomasz.wrobel@nokia.com>2021-01-15 14:34:18 +0100
committerTomasz Wrobel <tomasz.wrobel@nokia.com>2021-01-21 11:19:39 +0100
commit52b5f5276add6116a14ba671c35ff9d87c140421 (patch)
tree8ccb78489a403eb2c2c83dc192f055a4c1287920 /mod/bpgenerator/onap/src/test
parent87e8c9cb8b1b335e213ad1e4adaabc3e622ebfb1 (diff)
Add Native Kafka streams support in bp-generator
Issue-ID: DCAEGEN2-1179 Signed-off-by: Tomasz Wrobel <tomasz.wrobel@nokia.com> Change-Id: I541dca959707a41c56205e20c9f5a56ccec5ca41
Diffstat (limited to 'mod/bpgenerator/onap/src/test')
-rw-r--r--mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/StreamServiceTest.java63
-rw-r--r--mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/kafka/KafkaStreamServiceTest.java125
-rw-r--r--mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/kafka/KafkaStreamTest.java98
3 files changed, 257 insertions, 29 deletions
diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/StreamServiceTest.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/StreamServiceTest.java
index 09bb176..fe93f5f 100644
--- a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/StreamServiceTest.java
+++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/StreamServiceTest.java
@@ -35,6 +35,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.onap.blueprintgenerator.model.common.BaseStream;
import org.onap.blueprintgenerator.model.common.Dmaap;
import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
import org.onap.blueprintgenerator.model.componentspec.common.Publishes;
@@ -66,7 +67,7 @@ class StreamServiceTest {
void whenStreamsIsNullCreateStreamPublishesShouldReturnEmptyMap() {
when(onapComponentSpecMock.getStreams()).thenReturn(null);
- Map<String, Dmaap> streamPublishes = streamService.createStreamPublishes(
+ Map<String, BaseStream> streamPublishes = streamService.createStreamPublishes(
onapComponentSpecMock,
blueprintHelperServiceMock,
dmaapServiceMock,
@@ -81,7 +82,7 @@ class StreamServiceTest {
when(streamsMock.getPublishes()).thenReturn(null);
when(onapComponentSpecMock.getStreams()).thenReturn(streamsMock);
- Map<String, Dmaap> streamPublishes = streamService.createStreamPublishes(
+ Map<String, BaseStream> streamPublishes = streamService.createStreamPublishes(
onapComponentSpecMock,
blueprintHelperServiceMock,
dmaapServiceMock,
@@ -99,21 +100,22 @@ class StreamServiceTest {
DmaapService dmaapService = new DmaapService();
- Map<String, Dmaap> streamPublishes = streamService.createStreamPublishes(
+ Map<String, BaseStream> streamPublishes = streamService.createStreamPublishes(
onapComponentSpecMock,
blueprintHelperServiceMock,
dmaapService,
createInputs(),
true);
- Map<String, Dmaap> expectedMap = createExpectedMap("_feed");
+ Map<String, BaseStream> expectedMap = createExpectedMap("_feed");
assertNotNull(streamPublishes);
assertEquals(expectedMap.size(), streamPublishes.size());
- for(Map.Entry<String, Dmaap> entry : expectedMap.entrySet()) {
+ for (Map.Entry<String, BaseStream> entry : expectedMap.entrySet()) {
assertTrue(streamPublishes.containsKey(entry.getKey()));
- assertTrue(streamPublishes.get(entry.getKey()).getType().equals(entry.getValue().getType()));
- assertTrue(streamPublishes.get(entry.getKey()).getDmaap_info().equals(entry.getValue().getDmaap_info()));
+ assertEquals(streamPublishes.get(entry.getKey()).getType(), entry.getValue().getType());
+ assertEquals(((Dmaap) streamPublishes.get(entry.getKey())).getDmaap_info(),
+ ((Dmaap) entry.getValue()).getDmaap_info());
}
}
@@ -125,21 +127,22 @@ class StreamServiceTest {
DmaapService dmaapService = new DmaapService();
- Map<String, Dmaap> streamPublishes = streamService.createStreamPublishes(
+ Map<String, BaseStream> streamPublishes = streamService.createStreamPublishes(
onapComponentSpecMock,
blueprintHelperServiceMock,
dmaapService,
createInputs(),
true);
- Map<String, Dmaap> expectedMap = createExpectedMap("_topic");
+ Map<String, BaseStream> expectedMap = createExpectedMap("_topic");
assertNotNull(streamPublishes);
assertEquals(expectedMap.size(), streamPublishes.size());
- for(Map.Entry<String, Dmaap> entry : expectedMap.entrySet()) {
+ for (Map.Entry<String, BaseStream> entry : expectedMap.entrySet()) {
assertTrue(streamPublishes.containsKey(entry.getKey()));
- assertTrue(streamPublishes.get(entry.getKey()).getType().equals(entry.getValue().getType()));
- assertTrue(streamPublishes.get(entry.getKey()).getDmaap_info().equals(entry.getValue().getDmaap_info()));
+ assertEquals(streamPublishes.get(entry.getKey()).getType(), entry.getValue().getType());
+ assertEquals(((Dmaap) streamPublishes.get(entry.getKey())).getDmaap_info(),
+ ((Dmaap) entry.getValue()).getDmaap_info());
}
}
@@ -147,7 +150,7 @@ class StreamServiceTest {
void whenStreamsIsNullCreateStreamSubscribesShouldReturnEmptyMap() {
when(onapComponentSpecMock.getStreams()).thenReturn(null);
- Map<String, Dmaap> streamSubscribes = streamService.createStreamSubscribes(
+ Map<String, BaseStream> streamSubscribes = streamService.createStreamSubscribes(
onapComponentSpecMock,
blueprintHelperServiceMock,
dmaapServiceMock,
@@ -162,7 +165,7 @@ class StreamServiceTest {
when(streamsMock.getPublishes()).thenReturn(null);
when(onapComponentSpecMock.getStreams()).thenReturn(streamsMock);
- Map<String, Dmaap> streamSubscribes = streamService.createStreamSubscribes(
+ Map<String, BaseStream> streamSubscribes = streamService.createStreamSubscribes(
onapComponentSpecMock,
blueprintHelperServiceMock,
dmaapServiceMock,
@@ -180,21 +183,22 @@ class StreamServiceTest {
DmaapService dmaapService = new DmaapService();
- Map<String, Dmaap> streamSubscribes = streamService.createStreamSubscribes(
+ Map<String, BaseStream> streamSubscribes = streamService.createStreamSubscribes(
onapComponentSpecMock,
blueprintHelperServiceMock,
dmaapService,
createInputs(),
true);
- Map<String, Dmaap> expectedMap = createExpectedMap("_feed");
+ Map<String, BaseStream> expectedMap = createExpectedMap("_feed");
assertNotNull(streamSubscribes);
assertEquals(expectedMap.size(), streamSubscribes.size());
- for(Map.Entry<String, Dmaap> entry : expectedMap.entrySet()) {
+ for (Map.Entry<String, BaseStream> entry : expectedMap.entrySet()) {
assertTrue(streamSubscribes.containsKey(entry.getKey()));
- assertTrue(streamSubscribes.get(entry.getKey()).getType().equals(entry.getValue().getType()));
- assertTrue(streamSubscribes.get(entry.getKey()).getDmaap_info().equals(entry.getValue().getDmaap_info()));
+ assertEquals(streamSubscribes.get(entry.getKey()).getType(), entry.getValue().getType());
+ assertEquals(((Dmaap) streamSubscribes.get(entry.getKey())).getDmaap_info(),
+ ((Dmaap) entry.getValue()).getDmaap_info());
}
}
@@ -206,26 +210,27 @@ class StreamServiceTest {
DmaapService dmaapService = new DmaapService();
- Map<String, Dmaap> streamSubscribes = streamService.createStreamSubscribes(
+ Map<String, BaseStream> streamSubscribes = streamService.createStreamSubscribes(
onapComponentSpecMock,
blueprintHelperServiceMock,
dmaapService,
createInputs(),
true);
- Map<String, Dmaap> expectedMap = createExpectedMap("_topic");
+ Map<String, BaseStream> expectedMap = createExpectedMap("_topic");
assertNotNull(streamSubscribes);
assertEquals(expectedMap.size(), streamSubscribes.size());
- for(Map.Entry<String, Dmaap> entry : expectedMap.entrySet()) {
+ for (Map.Entry<String, BaseStream> entry : expectedMap.entrySet()) {
assertTrue(streamSubscribes.containsKey(entry.getKey()));
- assertTrue(streamSubscribes.get(entry.getKey()).getType().equals(entry.getValue().getType()));
- assertTrue(streamSubscribes.get(entry.getKey()).getDmaap_info().equals(entry.getValue().getDmaap_info()));
+ assertEquals(streamSubscribes.get(entry.getKey()).getType(), entry.getValue().getType());
+ assertEquals(((Dmaap) streamSubscribes.get(entry.getKey())).getDmaap_info(),
+ ((Dmaap) entry.getValue()).getDmaap_info());
}
}
- private Map<String, Dmaap> createExpectedMap(String suffix) {
- Map<String, Dmaap> expectedMap = new HashMap<>();
+ private Map<String, BaseStream> createExpectedMap(String suffix) {
+ Map<String, BaseStream> expectedMap = new HashMap<>();
Dmaap dmaap1 = new Dmaap();
dmaap1.setType("t1");
dmaap1.setDmaap_info("<<k1" + suffix + ">>");
@@ -260,21 +265,21 @@ class StreamServiceTest {
return new Subscribes[]{sub1, sub2, sub3};
}
- private Publishes createPublishes(String key, String type){
+ private Publishes createPublishes(String key, String type) {
Publishes publishes = new Publishes();
publishes.setConfig_key(key);
publishes.setType(type);
return publishes;
}
- private Subscribes createSubscribes(String key, String type){
+ private Subscribes createSubscribes(String key, String type) {
Subscribes subscribes = new Subscribes();
subscribes.setConfig_key(key);
subscribes.setType(type);
return subscribes;
}
- private Map<String, LinkedHashMap<String, Object>> createInputs(){
+ private Map<String, LinkedHashMap<String, Object>> createInputs() {
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
map.put("key-1", "obj-1");
diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/kafka/KafkaStreamServiceTest.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/kafka/KafkaStreamServiceTest.java
new file mode 100644
index 0000000..cad3b71
--- /dev/null
+++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/kafka/KafkaStreamServiceTest.java
@@ -0,0 +1,125 @@
+/*
+ *
+ * * ============LICENSE_START=======================================================
+ * * org.onap.dcae
+ * * ================================================================================
+ * * Copyright (c) 2021 Nokia Intellectual Property. All rights reserved.
+ * * ================================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END=========================================================
+ *
+ *
+ */
+
+package org.onap.blueprintgenerator.service.common.kafka;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.junit.Test;
+
+import org.junit.runner.RunWith;
+import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {KafkaStreamService.class, BlueprintHelperService.class},
+ initializers = ConfigFileApplicationContextInitializer.class)
+public class KafkaStreamServiceTest {
+
+ private static final String TEST_STREAM_NAME = "test_stream_name";
+ private static final String PUBLISH_URL_SUFFIX = "_publish_url";
+ private static final String SUBSCRIBE_URL_SUFFIX = "_subscribe_url";
+ private static final String DEFAULT_KEY = "default";
+ private static final String KAFKA_TYPE = "kafka";
+
+ @Autowired
+ private KafkaStreamService kafkaStreamService;
+
+ @Test
+ public void createCorrectStreamCommonInputs() {
+
+ Map<String, LinkedHashMap<String, Object>> publishInputs = kafkaStreamService
+ .createStreamPublishInputs("test_stream_name");
+
+ LinkedHashMap<String, Object> kafka_bootstrap_servers = publishInputs.get("kafka_bootstrap_servers");
+ LinkedHashMap<String, Object> kafka_username = publishInputs.get("kafka_username");
+ LinkedHashMap<String, Object> kafka_password = publishInputs.get("kafka_password");
+
+ assertNotNull(kafka_bootstrap_servers);
+ assertNotNull(kafka_username);
+ assertNotNull(kafka_password);
+
+ assertNotNull(kafka_bootstrap_servers.get(DEFAULT_KEY));
+ assertNotNull(kafka_username.get(DEFAULT_KEY));
+ assertNotNull(kafka_password.get(DEFAULT_KEY));
+ }
+
+ @Test
+ public void createCorrectStreamPublishInput() {
+ Map<String, LinkedHashMap<String, Object>> publishInputs = kafkaStreamService
+ .createStreamPublishInputs(TEST_STREAM_NAME);
+
+ LinkedHashMap<String, Object> kafka_stream_name = publishInputs.get(TEST_STREAM_NAME + PUBLISH_URL_SUFFIX);
+
+ assertNotNull(kafka_stream_name);
+
+ assertNotNull(kafka_stream_name.get(DEFAULT_KEY));
+ }
+
+ @Test
+ public void createCorrectStreamSubscribeInput() {
+ Map<String, LinkedHashMap<String, Object>> publishInputs = kafkaStreamService
+ .createStreamSubscribeInputs(TEST_STREAM_NAME);
+
+ LinkedHashMap<String, Object> kafka_stream_name = publishInputs.get(TEST_STREAM_NAME + SUBSCRIBE_URL_SUFFIX);
+
+ assertNotNull(kafka_stream_name);
+
+ assertNotNull(kafka_stream_name.get(DEFAULT_KEY));
+ }
+
+ @Test
+ public void createCorrectPublishAppConfig() {
+ Map<String, KafkaStream> appPropertiesPublish = kafkaStreamService
+ .createAppPropertiesPublish(TEST_STREAM_NAME);
+
+ KafkaStream kafkaStream = appPropertiesPublish.get(TEST_STREAM_NAME);
+
+ assertEquals(KAFKA_TYPE, kafkaStream.getType());
+ assertNotNull(kafkaStream.getAafCredential());
+ assertNotNull(kafkaStream.getKafkaInfo());
+ assertTrue(kafkaStream.getKafkaInfo().toString().contains(TEST_STREAM_NAME + PUBLISH_URL_SUFFIX));
+
+ }
+
+ @Test
+ public void createCorrectSubscribeAppConfig() {
+ Map<String, KafkaStream> appPropertiesSubscribe = kafkaStreamService
+ .createAppPropertiesSubscribe(TEST_STREAM_NAME);
+
+ KafkaStream kafkaStream = appPropertiesSubscribe.get(TEST_STREAM_NAME);
+
+ assertEquals(KAFKA_TYPE, kafkaStream.getType());
+ assertNotNull(kafkaStream.getAafCredential());
+ assertNotNull(kafkaStream.getKafkaInfo());
+ assertTrue(kafkaStream.getKafkaInfo().toString().contains(TEST_STREAM_NAME + SUBSCRIBE_URL_SUFFIX));
+
+ }
+}
diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/kafka/KafkaStreamTest.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/kafka/KafkaStreamTest.java
new file mode 100644
index 0000000..2ba2274
--- /dev/null
+++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/kafka/KafkaStreamTest.java
@@ -0,0 +1,98 @@
+/*
+ *
+ * * ============LICENSE_START=======================================================
+ * * org.onap.dcae
+ * * ================================================================================
+ * * Copyright (c) 2021 Nokia Intellectual Property. All rights reserved.
+ * * ================================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END=========================================================
+ *
+ *
+ */
+
+package org.onap.blueprintgenerator.service.common.kafka;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
+import org.junit.Before;
+import org.junit.Test;
+
+public class KafkaStreamTest {
+
+ private final static String TEST_TOPIC_NAME = "test_topic";
+ private static final String GET_INPUT_KAFKA_USERNAME = "{\"get_input\":\"kafka_username\"}";
+ private static final String GET_INPUT_KAFKA_PASSWORD = "{\"get_input\":\"kafka_password\"}";
+ private static final String AAF_USERNAME = "username";
+ private static final String AAF_PASSWORD = "password";
+ private static final String AAF_CREDENTIAL_NODE = "aaf_credentials";
+ private static final String KAFKA_TYPE_NODE = "type";
+ private static final String EXPECTED_KAFKA_TYPE = "\"kafka\"";
+ private static final String KAFKA_BOOTSTRAP_SERVERS = "bootstrap_servers";
+ private static final String KAFKA_TOPIC_NAME = "topic_name";
+ private static final String EXPECTED_GET_INPUT_TOPIC = "{\"get_input\":\"" + TEST_TOPIC_NAME + "\"}";
+ private static final String EXPECTED_GET_INPUT_BOOTSTRAP_SERVERS = "{\"get_input\":\"kafka_bootstrap_servers\"}";
+ private static final String KAFKA_INFO_NODE = "kafka_info";
+
+ private KafkaStream kafkaStream;
+ private ObjectMapper mapper = new ObjectMapper();
+
+ @Before
+ public void setUp() {
+ kafkaStream = new KafkaStream(TEST_TOPIC_NAME);
+ }
+
+ @Test
+ public void kafkaStreamHasCorrectAafCredential() throws IOException {
+
+ String kafkaStreamJson = mapper.writeValueAsString(kafkaStream);
+
+ JsonNode kafkaStreamNode = mapper.readTree(kafkaStreamJson);
+ JsonNode aafCredential = kafkaStreamNode.get(AAF_CREDENTIAL_NODE);
+
+ assertNotNull(aafCredential);
+ assertEquals(GET_INPUT_KAFKA_USERNAME, aafCredential.get(AAF_USERNAME).toString());
+ assertEquals(GET_INPUT_KAFKA_PASSWORD, aafCredential.get(AAF_PASSWORD).toString());
+ }
+
+ @Test
+ public void kafkaStreamHasCorrectKafkaInfo() throws IOException {
+
+ String kafkaStreamJson = mapper.writeValueAsString(kafkaStream);
+
+ JsonNode kafkaStreamNode = mapper.readTree(kafkaStreamJson);
+ JsonNode kafkaInfo = kafkaStreamNode.get(KAFKA_INFO_NODE);
+
+ assertNotNull(kafkaInfo);
+ assertEquals(EXPECTED_GET_INPUT_BOOTSTRAP_SERVERS, kafkaInfo.get(KAFKA_BOOTSTRAP_SERVERS).toString());
+ assertEquals(EXPECTED_GET_INPUT_TOPIC, kafkaInfo.get(KAFKA_TOPIC_NAME).toString());
+
+ }
+
+ @Test
+ public void kafkaStreamHasCorrectType() throws IOException {
+
+ String kafkaStreamJson = mapper.writeValueAsString(kafkaStream);
+
+ JsonNode kafkaStreamNode = mapper.readTree(kafkaStreamJson);
+ JsonNode kafkaType = kafkaStreamNode.get(KAFKA_TYPE_NODE);
+
+ assertNotNull(kafkaType);
+ assertEquals(EXPECTED_KAFKA_TYPE, kafkaType.toString());
+ }
+
+}