summaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authorPrudence Au <prudence.au@amdocs.com>2018-07-16 22:02:04 -0400
committerPrudence Au <prudence.au@amdocs.com>2018-08-07 10:19:39 -0400
commit65c5d8b92e759ec4ee9d13f048b069033b4bf097 (patch)
tree237dd5c8d59d5696ae9813ecaac7dfb453a9f0ca /src/test/java
parent4267a59d4454d03a900f46d71e288d6590f162c0 (diff)
POMBA Context Aggregator
Change-Id: I33acc1f46d35447b63e2d5438c9ce6728a2b03eb Issue-ID: LOG-519 Signed-off-by: Prudence Au <prudence.au@amdocs.com> POMBA Context Aggregator with JUnit tests Change-Id: I33acc1f46d35447b63e2d5438c9ce6728a2b03eb Issue-ID: LOG-519 Signed-off-by: Prudence Au <prudence.au@amdocs.com>
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/pomba/contextaggregaotr/config/TestTransportConfig.java22
-rw-r--r--src/test/java/org/onap/pomba/contextaggregator/ApplicationTest.java35
-rw-r--r--src/test/java/org/onap/pomba/contextaggregator/builder/ContextBuilderTest.java58
-rw-r--r--src/test/java/org/onap/pomba/contextaggregator/config/BuilderConfigLoaderTest.java58
-rw-r--r--src/test/java/org/onap/pomba/contextaggregator/config/EventConfigTest.java45
-rw-r--r--src/test/java/org/onap/pomba/contextaggregator/config/EventHeaderConfigTest.java69
-rw-r--r--src/test/java/org/onap/pomba/contextaggregator/config/TransportConfigTest.java61
-rw-r--r--src/test/java/org/onap/pomba/contextaggregator/datatypes/AggregatedModelsTest.java72
-rw-r--r--src/test/java/org/onap/pomba/contextaggregator/datatypes/POAEventTest.java144
-rw-r--r--src/test/java/org/onap/pomba/contextaggregator/exception/ContextAggregatorErrorTest.java40
-rw-r--r--src/test/java/org/onap/pomba/contextaggregator/publisher/EventPublisherFactoryTest.java71
-rw-r--r--src/test/java/org/onap/pomba/contextaggregator/rest/RestRequestTest.java61
-rw-r--r--src/test/java/org/onap/pomba/contextaggregator/service/ContextAggregatorProcessorTest.java135
-rw-r--r--src/test/java/org/onap/pomba/contextaggregator/service/ContextAggregatorServiceTest.java56
14 files changed, 927 insertions, 0 deletions
diff --git a/src/test/java/org/onap/pomba/contextaggregaotr/config/TestTransportConfig.java b/src/test/java/org/onap/pomba/contextaggregaotr/config/TestTransportConfig.java
new file mode 100644
index 0000000..bd37eb5
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextaggregaotr/config/TestTransportConfig.java
@@ -0,0 +1,22 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextaggregaotr.config;
+
+public class TestTransportConfig {
+
+}
diff --git a/src/test/java/org/onap/pomba/contextaggregator/ApplicationTest.java b/src/test/java/org/onap/pomba/contextaggregator/ApplicationTest.java
new file mode 100644
index 0000000..97cbe86
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextaggregator/ApplicationTest.java
@@ -0,0 +1,35 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextaggregator;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest
+public class ApplicationTest
+{
+
+ @Test
+ public void testMain() throws Exception
+ {
+ Application.main(new String[]{"args"});
+ }
+}
diff --git a/src/test/java/org/onap/pomba/contextaggregator/builder/ContextBuilderTest.java b/src/test/java/org/onap/pomba/contextaggregator/builder/ContextBuilderTest.java
new file mode 100644
index 0000000..d96fbce
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextaggregator/builder/ContextBuilderTest.java
@@ -0,0 +1,58 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextaggregator.builder;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.io.File;
+import java.io.IOException;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest
+public class ContextBuilderTest
+{
+ private ContextBuilder contextBuilder;
+
+ @Before
+ public void setUp() throws IOException
+ {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testGetEntity() throws Exception
+ {
+ File configFile =
+ new File("./src/test/resources/GoodProperties/sdnc.properties");
+ contextBuilder = new ContextBuilder(configFile);
+ Assert.assertEquals("sdnc", contextBuilder.getContextName());
+ Assert.assertEquals("sdnchost", contextBuilder.getHost());
+ Assert.assertEquals(1000, contextBuilder.getPort());
+ Assert.assertEquals("http", contextBuilder.getProtocol());
+ Assert.assertEquals("TLS", contextBuilder.getSecurityProtocol());
+ Assert.assertEquals(5000, contextBuilder.getConnectionTimeout());
+ Assert.assertEquals(1000, contextBuilder.getReadTimeout());
+ Assert.assertEquals("/sdnccontextbuilder/service/context", contextBuilder.getBaseUri());
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/pomba/contextaggregator/config/BuilderConfigLoaderTest.java b/src/test/java/org/onap/pomba/contextaggregator/config/BuilderConfigLoaderTest.java
new file mode 100644
index 0000000..5d3b823
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextaggregator/config/BuilderConfigLoaderTest.java
@@ -0,0 +1,58 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextaggregator.config;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.core.io.support.ResourcePatternResolver;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.io.File;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest
+@ConfigurationProperties("classpath:/src/test/resources/GoodProperties/sdnc.properties")
+public class BuilderConfigLoaderTest
+{
+ @InjectMocks
+ private BuilderConfigLoader builderConfigLoader;
+
+ @Mock
+ private ResourcePatternResolver rpr;
+ private String buildersPropertiesPath ;
+
+ @Before
+ public void setUp()
+ {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testContextBuilders()
+ {
+ buildersPropertiesPath = new File(
+ "./src/test/resources/GoodProperties/").getAbsolutePath();
+ builderConfigLoader.contextBuilders();
+ }
+}
diff --git a/src/test/java/org/onap/pomba/contextaggregator/config/EventConfigTest.java b/src/test/java/org/onap/pomba/contextaggregator/config/EventConfigTest.java
new file mode 100644
index 0000000..41f91f6
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextaggregator/config/EventConfigTest.java
@@ -0,0 +1,45 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextaggregator.config;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest
+public class EventConfigTest
+{
+ EventConfig eventConfig = new EventConfig();
+
+ @Test
+ public void testEventHeaderConfig() throws Exception
+ {
+ EventHeaderConfig result = eventConfig
+ .eventHeaderConfig("domain", "sourceName", "eventType",
+ "entityType", "topicEntityType", "topicName");
+ Assert.assertEquals("domain", result.getDomain());
+ Assert.assertEquals("sourceName", result.getSourceName());
+ Assert.assertEquals("eventType", result.getEventType());
+ Assert.assertEquals("entityType", result.getEntityType());
+ Assert.assertEquals("topicEntityType", result.getTopicEntityType());
+ Assert.assertEquals("topicName", result.getTopicName());
+ }
+}
diff --git a/src/test/java/org/onap/pomba/contextaggregator/config/EventHeaderConfigTest.java b/src/test/java/org/onap/pomba/contextaggregator/config/EventHeaderConfigTest.java
new file mode 100644
index 0000000..04db525
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextaggregator/config/EventHeaderConfigTest.java
@@ -0,0 +1,69 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextaggregator.config;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest
+public class EventHeaderConfigTest
+{
+
+ private String domain;
+ private String sourceName;
+ private String eventType;
+ private String entityType;
+ private String topicEntityType;
+ private String topicName;
+
+ EventHeaderConfig eventHeaderConfig = new EventHeaderConfig(
+ domain, sourceName, eventType, entityType, topicEntityType, topicName);
+ @Test
+ public void getDomainTest() {
+ Assert.assertEquals(eventHeaderConfig.getDomain(), domain);
+ }
+
+ @Test
+ public void getSourceNameTest() {
+ Assert.assertEquals(eventHeaderConfig.getSourceName(), sourceName);
+ }
+
+ @Test
+ public void getEventTypeTest() {
+ Assert.assertEquals(eventHeaderConfig.getEventType(), eventType);
+ }
+
+ @Test
+ public void getEntityTypeTest() {
+ Assert.assertEquals(eventHeaderConfig.getEntityType(), entityType);
+ }
+
+ @Test
+ public void getTopEntityTypeTest() {
+ Assert.assertEquals(eventHeaderConfig.getTopicEntityType(), topicEntityType);
+ }
+
+ @Test
+ public void getTopicNameTest() {
+ Assert.assertEquals(eventHeaderConfig.getTopicName(), topicName);
+ }
+}
diff --git a/src/test/java/org/onap/pomba/contextaggregator/config/TransportConfigTest.java b/src/test/java/org/onap/pomba/contextaggregator/config/TransportConfigTest.java
new file mode 100644
index 0000000..af47ff6
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextaggregator/config/TransportConfigTest.java
@@ -0,0 +1,61 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextaggregator.config;
+
+import com.att.nsa.mr.client.MRConsumer;
+import com.att.nsa.mr.client.impl.MRConsumerImpl;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.pomba.contextaggregator.publisher.EventPublisherFactory;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.util.Properties;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest
+public class TransportConfigTest
+{
+ TransportConfig transportConfig = new TransportConfig();
+
+ @Test
+ public void testConsumer() throws Exception
+ {
+ MRConsumer result = transportConfig
+ .consumer("host", "port", "topic", "motsid", "pass",
+ "consumerGroup", "consumerId", 0, 0, 0, "type");
+ final Properties extraProps = new Properties();
+ extraProps.put("Protocol", "http");
+ ((MRConsumerImpl) result).setProps(extraProps);
+ Assert.assertNotEquals(null, result);
+ Assert.assertEquals("host:port", ((MRConsumerImpl) result).getHost());
+ }
+
+ @Test
+ public void testPublisherFactory() throws Exception
+ {
+ EventPublisherFactory result = transportConfig
+ .publisherFactory("host", "port", "topic", "motsid", "pass", 0,
+ 0, 0, "type", "partition", 0);
+ EventPublisherFactory lEventPublisherFactory = new EventPublisherFactory("host:port", "topic", "motsid", "pass", 0,
+ 0, 0, "type", "partition", 0);
+ Assert.assertEquals(lEventPublisherFactory.getPartition(), result.getPartition());
+ Assert.assertEquals(lEventPublisherFactory.getRetries(), result.getRetries());
+ }
+}
diff --git a/src/test/java/org/onap/pomba/contextaggregator/datatypes/AggregatedModelsTest.java b/src/test/java/org/onap/pomba/contextaggregator/datatypes/AggregatedModelsTest.java
new file mode 100644
index 0000000..19bb85e
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextaggregator/datatypes/AggregatedModelsTest.java
@@ -0,0 +1,72 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextaggregator.datatypes;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.onap.pomba.contextaggregator.config.EventHeaderConfig;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest
+public class AggregatedModelsTest
+{
+ AggregatedModels aggregatedModels;
+
+ private String domain;
+ private String sourceName;
+ private String eventType;
+ private String entityType;
+ private String topEntityType;
+ private String topicName;
+
+ EventHeaderConfig eventHeaderConfig = new EventHeaderConfig(
+ domain, sourceName, eventType, entityType, topEntityType, topicName);
+
+ Map<String, String> jsonContextMap = new HashMap<>();
+
+ POAEvent pOAEvent = new POAEvent();
+
+ @Before
+ public void setUp()
+ {
+ MockitoAnnotations.initMocks(this);
+ pOAEvent.setServiceInstanceId("a");
+ pOAEvent.setModelVersionId("b");
+ pOAEvent.setModelInvariantId("c");
+ pOAEvent.setCustomerId("d");
+ pOAEvent.setServiceType("e");
+ pOAEvent.setxFromAppId("e");
+ pOAEvent.setxTransactionId("f");
+ }
+
+ @Test
+ public void testGenerateJsonPayload() throws Exception
+ {
+ aggregatedModels = new AggregatedModels(eventHeaderConfig,jsonContextMap,pOAEvent);
+ Assert.assertNotNull(aggregatedModels.generateJsonPayload());
+ Assert.assertNotNull(aggregatedModels.getEntityHeader());
+ }
+}
diff --git a/src/test/java/org/onap/pomba/contextaggregator/datatypes/POAEventTest.java b/src/test/java/org/onap/pomba/contextaggregator/datatypes/POAEventTest.java
new file mode 100644
index 0000000..016b72a
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextaggregator/datatypes/POAEventTest.java
@@ -0,0 +1,144 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextaggregator.datatypes;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.pomba.contextaggregator.exception.ContextAggregatorException;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import static org.junit.Assert.assertTrue;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest
+public class POAEventTest
+{
+ POAEvent pOAEvent = new POAEvent();
+
+ @Before
+ public void setup()
+ {
+ pOAEvent.setServiceInstanceId("a");
+ pOAEvent.setModelVersionId("b");
+ pOAEvent.setModelInvariantId("c");
+ pOAEvent.setCustomerId("d");
+ pOAEvent.setServiceType("e");
+ pOAEvent.setxFromAppId("e");
+ pOAEvent.setxTransactionId("f");
+ }
+
+ @Test
+ public void testValidate() throws ContextAggregatorException
+ {
+ pOAEvent.validate();
+ }
+
+ @Test
+ public void testValidateEmptyServiceInstanceId() throws ContextAggregatorException {
+ pOAEvent.setServiceInstanceId("");
+ try {
+ pOAEvent.validate();
+ }
+ catch (ContextAggregatorException e){
+ assertTrue(e.getMessage().contains("is missing"));
+ }
+ }
+
+ @Test
+ public void testValidateEmptyModelVersionId() throws ContextAggregatorException {
+ pOAEvent.setModelVersionId("");
+
+ try {
+ pOAEvent.validate();
+ }
+ catch (ContextAggregatorException e){
+ assertTrue(e.getMessage().contains("is missing"));
+ }
+ }
+
+ @Test
+ public void testValidateEmptyModelInvariantId() throws ContextAggregatorException {
+ pOAEvent.setModelInvariantId("");
+
+ try {
+ pOAEvent.validate();
+ }
+ catch (ContextAggregatorException e){
+ assertTrue(e.getMessage().contains("is missing"));
+ }
+ }
+
+ @Test
+ public void testValidateEmptyCustomerId() throws ContextAggregatorException {
+ pOAEvent.setCustomerId("");
+
+ try {
+ pOAEvent.validate();
+ }
+ catch (ContextAggregatorException e){
+ assertTrue(e.getMessage().contains("is missing"));
+ }
+ }
+
+ @Test
+ public void testValidateEmptyServiceType() throws ContextAggregatorException {
+ pOAEvent.setServiceType("");
+
+ try {
+ pOAEvent.validate();
+ }
+ catch (ContextAggregatorException e){
+ assertTrue(e.getMessage().contains("is missing"));
+ }
+ }
+
+ @Test
+ public void testValidateEmptyxFromAppId() throws ContextAggregatorException {
+ pOAEvent.setxFromAppId("");
+
+ try {
+ pOAEvent.validate();
+ }
+ catch (ContextAggregatorException e){
+ assertTrue(e.getMessage().contains("is missing"));
+ }
+ }
+
+ @Test
+ public void testValidateEmptyxTransactionId() throws ContextAggregatorException {
+ pOAEvent.setxTransactionId("");
+
+ try {
+ pOAEvent.validate();
+ }
+ catch (ContextAggregatorException e){
+ assertTrue(e.getMessage().contains("is missing"));
+ }
+ }
+
+ @Test
+ public void testToString()
+ {
+ String result = pOAEvent.toString();
+ Assert.assertNotEquals("", result);
+ }
+}
+
diff --git a/src/test/java/org/onap/pomba/contextaggregator/exception/ContextAggregatorErrorTest.java b/src/test/java/org/onap/pomba/contextaggregator/exception/ContextAggregatorErrorTest.java
new file mode 100644
index 0000000..bd4bad8
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextaggregator/exception/ContextAggregatorErrorTest.java
@@ -0,0 +1,40 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextaggregator.exception;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest
+public class ContextAggregatorErrorTest
+{
+ ContextAggregatorError contextAggregatorError =
+ ContextAggregatorError.GENERAL_ERROR;
+
+ @Test
+ public void testGetMessage() throws Exception
+ {
+ String result = contextAggregatorError.getMessage(null);
+ Assert.assertEquals(contextAggregatorError.GENERAL_ERROR.getMessage(), result);
+ }
+}
+
diff --git a/src/test/java/org/onap/pomba/contextaggregator/publisher/EventPublisherFactoryTest.java b/src/test/java/org/onap/pomba/contextaggregator/publisher/EventPublisherFactoryTest.java
new file mode 100644
index 0000000..7f87e29
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextaggregator/publisher/EventPublisherFactoryTest.java
@@ -0,0 +1,71 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextaggregator.publisher;
+
+import com.att.nsa.mr.client.MRBatchingPublisher;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest
+ public class EventPublisherFactoryTest
+{
+ @Test
+ public void testgetPartition() {
+ EventPublisherFactory pojo = new EventPublisherFactory(
+ "host", "topic", "motsid", "pass", 0, 0, 0, "type", "partition1", 0);
+ assertEquals("other values", pojo.getPartition(),"partition1");
+ }
+
+ @Test
+ public void testgetRetries() {
+ EventPublisherFactory pojo = new EventPublisherFactory(
+ "host", "topic", "motsid", "pass", 0, 0, 0, "type", "partition", 5);
+ assertEquals(5.0, pojo.getRetries(),10.0);
+ }
+
+ @Test
+ public void testCreatePublisherNullPublisher() throws IllegalArgumentException
+ {
+ EventPublisherFactory eventPublisherFactory =
+ new EventPublisherFactory("host", "topic", "motsid", "pass", 0, 0,
+ 0, "type", "partition", 0);
+ try{
+ eventPublisherFactory.createPublisher();
+ }
+ catch (IllegalArgumentException e){
+ // Expected
+ }
+ }
+
+ @Test
+ public void testCreatePublisher()
+ {
+ EventPublisherFactory eventPublisherFactory =
+ new EventPublisherFactory("host", "topic", "motsid", "pass", 0, 0,
+ 1, "type", "partition", 0);
+
+ MRBatchingPublisher result = eventPublisherFactory.createPublisher();
+ Assert.assertNotEquals(null, result);
+ }
+}
diff --git a/src/test/java/org/onap/pomba/contextaggregator/rest/RestRequestTest.java b/src/test/java/org/onap/pomba/contextaggregator/rest/RestRequestTest.java
new file mode 100644
index 0000000..58624b5
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextaggregator/rest/RestRequestTest.java
@@ -0,0 +1,61 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextaggregator.rest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.pomba.contextaggregator.builder.ContextBuilder;
+import org.slf4j.Logger;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.io.File;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest
+@ConfigurationProperties("classpath:/src/test/resources/GoodProperties/sdnc.properties")
+ public class RestRequestTest
+{
+ @Mock
+ Logger log;
+ @InjectMocks
+ RestRequest restRequest;
+
+ @Before
+ public void setUp()
+ {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testGetModelData() throws Exception
+ {
+ File configFile =
+ new File("./src/test/resources/GoodProperties/sdnc.properties");
+ ContextBuilder contextBuilder = new ContextBuilder(configFile);
+// String result = RestRequest
+// .getModelData(new ContextBuilder(is, "resName"),
+// new POAEvent());
+// Assert.assertEquals("replaceMeWithExpectedResult", result);
+ }
+}
diff --git a/src/test/java/org/onap/pomba/contextaggregator/service/ContextAggregatorProcessorTest.java b/src/test/java/org/onap/pomba/contextaggregator/service/ContextAggregatorProcessorTest.java
new file mode 100644
index 0000000..4624e40
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextaggregator/service/ContextAggregatorProcessorTest.java
@@ -0,0 +1,135 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextaggregator.service;
+
+import com.att.nsa.mr.client.MRConsumer;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.pomba.contextaggregator.builder.ContextBuilder;
+import org.onap.pomba.contextaggregator.config.EventHeaderConfig;
+import org.onap.pomba.contextaggregator.publisher.EventPublisherFactory;
+import org.slf4j.Logger;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+
+import static org.mockito.Mockito.*;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest
+@ConfigurationProperties("classpath:/src/test/resources/GoodProperties/sdnc.properties")
+public class ContextAggregatorProcessorTest
+{
+ @Mock
+ Logger log;
+ @Mock
+ ExecutorService executor;
+ @Mock
+ MRConsumer consumer;
+ @Mock
+ EventPublisherFactory publisherFactory;
+ @Mock
+ ContextBuilder contextBuilder;
+ @Mock
+ List<ContextBuilder> contextBuilders;
+ @Mock
+ EventHeaderConfig eventHeaderConfig;
+
+ @InjectMocks
+ ContextAggregatorProcessor contextAggregatorProcessor;
+
+ private String payload = "{" +
+ " \"serviceInstanceId\"" + ": " + "\"8ea56b0d-459d-4668-b363-c9567432d8b7\"" + "," +
+ " \"modelVersionId\"" + ": " + "\"4e3d28cf-d654-41af-a47b-04b4bd0ac58e\"" + "," +
+ " \"modelInvariantId\"" + ": " + "\"74bc1518-282d-4148-860f-8892b6369456\"" + "," +
+ " \"customerId\"" + ": " + "\"junit\"" + "," +
+ " \"serviceType\"" + ": " + "\"vFWCL\"" + "," +
+ " \"xFromAppId\"" + ": " + "\"POMBA\"" + "," +
+ " \"xTransactionId\"" + ": " + "\"8a9ddb25-2e79-449c-a40d-5011bac0da39\"" +
+ "}";
+
+ @Before
+ public void setUp()
+ {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testProcessNullPublisherInvalidPayload() throws Exception
+ {
+ when(publisherFactory.getPartition())
+ .thenReturn("getPartitionResponse");
+ when(publisherFactory.getRetries()).thenReturn(0);
+ when(publisherFactory.createPublisher()).thenReturn(null);
+ contextAggregatorProcessor.process("NoJsonPayload");
+ }
+
+ @Test
+ public void testProcessNullPublisherEmptyPayload() throws Exception {
+ when(publisherFactory.getPartition())
+ .thenReturn("getPartitionResponse");
+ when(publisherFactory.getRetries()).thenReturn(0);
+ when(publisherFactory.createPublisher()).thenReturn(null);
+
+ try {
+ contextAggregatorProcessor.process("");
+ }
+ catch (Exception e){
+ // expected
+ }
+ }
+
+ @Test
+ public void testProcessNullPublisherValidPayload() throws Exception
+ {
+ when(publisherFactory.getPartition())
+ .thenReturn("getPartitionResponse");
+ when(publisherFactory.getRetries()).thenReturn(0);
+ when(publisherFactory.createPublisher()).thenReturn(null);
+ try {
+ contextAggregatorProcessor.process(payload);
+ }
+ catch (NullPointerException e) {
+ //Expected.. No ContextBuilre found
+ }
+ }
+
+// @Test
+// public void testCall() throws Exception
+// {
+// when(publisherFactory.getPartition())
+// .thenReturn("getPartitionResponse");
+// when(publisherFactory.getRetries()).thenReturn(0);
+// when(publisherFactory.createPublisher()).thenReturn(null);
+//
+// try{
+// contextAggregatorProcessor.call();
+// }
+// catch (Exception e)
+// {
+// //expected
+// }
+// }
+}
diff --git a/src/test/java/org/onap/pomba/contextaggregator/service/ContextAggregatorServiceTest.java b/src/test/java/org/onap/pomba/contextaggregator/service/ContextAggregatorServiceTest.java
new file mode 100644
index 0000000..bf4fbb5
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextaggregator/service/ContextAggregatorServiceTest.java
@@ -0,0 +1,56 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextaggregator.service;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest
+public class ContextAggregatorServiceTest
+{
+ @Mock
+ ContextAggregatorProcessor processor;
+ @Mock
+ Future<Void> processorTask;
+ @Mock
+ ExecutorService executor;
+ @InjectMocks
+ ContextAggregatorService contextAggregatorService;
+
+ @Before
+ public void setUp()
+ {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testInit() throws Exception
+ {
+ contextAggregatorService.init();
+ }
+}