summaryrefslogtreecommitdiffstats
path: root/bpmn/MSOInfrastructureBPMN/src/test/java
diff options
context:
space:
mode:
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>2018-06-07 15:01:40 +0200
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>2018-07-17 16:10:02 +0200
commit02463bf3e2f8d57ece3b391d392109e2496f2838 (patch)
tree2c150f957d2b17999874d7b40a74fbcedf501971 /bpmn/MSOInfrastructureBPMN/src/test/java
parentb4861ac967c62f67d5a57919d07bf969ef416e03 (diff)
dmaap host and port configuration for pnf feature
Change-Id: I4d13dce0b8819aa3d1e9848b9a39a43456dc1f30 Issue-ID: SO-466 Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
Diffstat (limited to 'bpmn/MSOInfrastructureBPMN/src/test/java')
-rw-r--r--bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/JsonUtilForCorrelationIdTest.java76
-rw-r--r--bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java50
2 files changed, 117 insertions, 9 deletions
diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/JsonUtilForCorrelationIdTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/JsonUtilForCorrelationIdTest.java
new file mode 100644
index 0000000000..95de883dab
--- /dev/null
+++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/JsonUtilForCorrelationIdTest.java
@@ -0,0 +1,76 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T 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.openecomp.mso.bpmn.infrastructure.pnf.dmaap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.List;
+import org.junit.Test;
+
+public class JsonUtilForCorrelationIdTest {
+
+ private static final String JSON_EXAMPLE_WITH_CORRELATION_ID = "[\n"
+ + " {\n"
+ + " \"pnfRegistrationFields\" : {\n"
+ + " \"correlationId\" : \"corrTest1\",\n"
+ + " \"value\" : \"value1\"\n"
+ + " }\n"
+ + " },\n"
+ + " {\n"
+ + " \"pnfRegistrationFields\" : {\n"
+ + " \"correlationId\" : \"corrTest2\",\n"
+ + " \"value\" : \"value2\"\n"
+ + " }\n"
+ + " }\n"
+ + "]";
+
+ private static final String JSON_EXAMPLE_WITH_CORRELATION_ID2 = "{\"pnfRegistrationFields\":{\"correlationId\":\"corrTest3\"}}";
+ private static final String JSON_EXAMPLE_WITH_CORRELATION_ID3 = "[\"\\{\\\"pnfRegistrationFields\\\":"
+ + "{\\\"correlationId\\\":\\\"corrTest4\\\"}}\", \"\\{\\\"pnfRegistrationFields\\\":"
+ + "{\\\"correlationId\\\":\\\"corrTest5\\\"}}\"]";
+ private static final String JSON_EXAMPLE_WITH_CORRELATION_ID4 = "{\"header\":{\"key\":\"value\"}}";
+
+ @Test
+ public void parseJsonSuccessful() {
+ List<String> expectedResult = JsonUtilForCorrelationId
+ .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID);
+ assertThat(expectedResult).containsExactly("corrTest1", "corrTest2");
+
+ List<String> expectedResult2 = JsonUtilForCorrelationId
+ .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID2);
+ assertThat(expectedResult2).containsExactly("corrTest3");
+ }
+
+ @Test
+ public void parseJsonWithEscapeCharacters_Successful() {
+ List<String> expectedResult = JsonUtilForCorrelationId
+ .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID3);
+ assertThat(expectedResult).containsExactly("corrTest4", "corrTest5");
+ }
+
+ @Test
+ public void parseJson_emptyListReturnedWhenNothingFound() {
+ List<String> expectedResult = JsonUtilForCorrelationId
+ .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID4);
+ assertThat(expectedResult).isEmpty();
+ }
+
+}
diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java
index 393730ed43..6ded47d5fa 100644
--- a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java
+++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClientTest.java
@@ -30,6 +30,7 @@ import static org.mockito.Mockito.when;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
+import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledExecutorService;
@@ -42,15 +43,36 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHttpResponse;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
+import org.openecomp.mso.bpmn.core.PropertyConfiguration;
import org.openecomp.mso.bpmn.infrastructure.pnf.dmaap.PnfEventReadyDmaapClient.DmaapTopicListenerThread;
-
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({PropertyConfiguration.class})
+@PowerMockIgnore("javax.net.ssl.*")
public class PnfEventReadyDmaapClientTest {
private static final String CORRELATION_ID = "corrTestId";
private static final String CORRELATION_ID_NOT_FOUND_IN_MAP = "otherCorrId";
- private static final String JSON_EXAMPLE_WITH_CORRELATION_ID =
- "{\"pnfRegistrationFields\":{\"correlationId\":\"%s\"}}";
+ private static final String JSON_EXAMPLE_WITH_CORRELATION_ID = "[\n"
+ + " {\n"
+ + " \"pnfRegistrationFields\" : {\n"
+ + " \"correlationId\" : \"%s\",\n"
+ + " \"value\" : \"value1\"\n"
+ + " }\n"
+ + " },\n"
+ + " {\n"
+ + " \"pnfRegistrationFields\" : {\n"
+ + " \"correlationId\" : \"corr\",\n"
+ + " \"value\" : \"value2\"\n"
+ + " }\n"
+ + " }\n"
+ + "]";
private static final String JSON_EXAMPLE_WITH_NO_CORRELATION_ID =
"{\"pnfRegistrationFields\":{\"field\":\"value\"}}";
@@ -70,9 +92,12 @@ public class PnfEventReadyDmaapClientTest {
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
+ PowerMockito.mockStatic(PropertyConfiguration.class);
+ PropertyConfiguration propertyConfigurationMock = mock(PropertyConfiguration.class);
+ PowerMockito.when(PropertyConfiguration.getInstance()).thenReturn(propertyConfigurationMock);
+ when(propertyConfigurationMock.getProperties(PropertyConfiguration.MSO_BPMN_URN_PROPERTIES)).thenReturn(
+ createProperties());
testedObject = new PnfEventReadyDmaapClient();
- testedObject.setDmaapHost(HOST);
- testedObject.setDmaapPort(PORT);
testedObject.setDmaapProtocol(PROTOCOL);
testedObject.setDmaapUriPathPrefix(URI_PATH_PREFIX);
testedObject.setDmaapTopicName(EVENT_TOPIC_TEST);
@@ -91,8 +116,8 @@ public class PnfEventReadyDmaapClientTest {
* Test run method, where the are following conditions:
* <p> - DmaapThreadListener is running, flag is set to true
* <p> - map is filled with one entry with the key that we get from response
- * <p> run method should invoke thread from map to notify camunda process, remove element from the map (map is empty)
- * and shutdown the executor because of empty map
+ * <p> run method should invoke thread from map to notify camunda process, remove element from the map (map is
+ * empty) and shutdown the executor because of empty map
*/
@Test
public void correlationIdIsFoundInHttpResponse_notifyAboutPnfReady()
@@ -113,8 +138,8 @@ public class PnfEventReadyDmaapClientTest {
* Test run method, where the are following conditions:
* <p> - DmaapThreadListener is running, flag is set to true
* <p> - map is filled with one entry with the correlationId that does not match to correlationId
- * taken from http response. run method should not do anything with the map not run any thread to
- * notify camunda process
+ * taken from http response. run method should not do anything with the map not run any thread to notify camunda
+ * process
*/
@Test
public void correlationIdIsFoundInHttpResponse_NotFoundInMap()
@@ -164,6 +189,13 @@ public class PnfEventReadyDmaapClientTest {
threadRunFlag.setAccessible(false);
}
+ private Map<String, String> createProperties() {
+ Map<String, String> map = new HashMap<>();
+ map.put("dmaapHost", HOST);
+ map.put("dmaapPort", String.valueOf(PORT));
+ return map;
+ }
+
private HttpResponse createResponse(String json) throws UnsupportedEncodingException {
HttpEntity entity = new StringEntity(json);
ProtocolVersion protocolVersion = new ProtocolVersion("", 1, 1);