aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/onap/dcae/commonFunction/ApiExceptionTest.java13
-rw-r--r--src/test/java/org/onap/dcae/commonFunction/ConfigProcessorAdapterTest.java2
-rw-r--r--src/test/java/org/onap/dcae/commonFunction/DmaapPublishersTest.java3
-rw-r--r--src/test/java/org/onap/dcae/commonFunction/EventProcessorTest.java8
-rw-r--r--src/test/java/org/onap/dcae/commonFunction/TestCommonStartup.java18
-rw-r--r--src/test/java/org/onap/dcae/vestest/AnyNodeTest.java2
-rw-r--r--src/test/java/org/onap/dcae/vestest/DmaapPropertyReaderTest.java5
-rw-r--r--src/test/java/org/onap/dcae/vestest/TestConfigProcessor.java531
-rw-r--r--src/test/java/org/onap/dcae/vestest/TestJsonSchemaValidation.java4
-rw-r--r--src/test/java/org/onap/dcae/vestest/TestLoadDynamicConfig.java5
-rw-r--r--src/test/java/org/onap/dcae/vestest/TestingUtilities.java4
11 files changed, 297 insertions, 298 deletions
diff --git a/src/test/java/org/onap/dcae/commonFunction/ApiExceptionTest.java b/src/test/java/org/onap/dcae/commonFunction/ApiExceptionTest.java
index 0e494030..ef5b477c 100644
--- a/src/test/java/org/onap/dcae/commonFunction/ApiExceptionTest.java
+++ b/src/test/java/org/onap/dcae/commonFunction/ApiExceptionTest.java
@@ -44,7 +44,7 @@ public class ApiExceptionTest {
@Test
public void shouldConvertExceptionToBackwardCompatibleFormat() {
JSONObject responseBody = ApiException.UNAUTHORIZED_USER.toJSON();
- assertJSONEqual(responseBody, asJSON(""
+ assertEquals(responseBody.toString(), new JSONObject(""
+ "{ "
+ " 'requestError': { "
+ " 'PolicyException': { "
@@ -53,14 +53,7 @@ public class ApiExceptionTest {
+ " } "
+ " } "
+ "} "
- ));
- }
-
- private JSONObject asJSON(String jsonString) {
- return new JSONObject(jsonString.replace("'", "\""));
- }
-
- private void assertJSONEqual(JSONObject o1, JSONObject o2) {
- assertEquals(o1.toString(), o2.toString());
+ .replace("'", "\"")
+ ).toString());
}
}
diff --git a/src/test/java/org/onap/dcae/commonFunction/ConfigProcessorAdapterTest.java b/src/test/java/org/onap/dcae/commonFunction/ConfigProcessorAdapterTest.java
index 634424b0..180dfcf1 100644
--- a/src/test/java/org/onap/dcae/commonFunction/ConfigProcessorAdapterTest.java
+++ b/src/test/java/org/onap/dcae/commonFunction/ConfigProcessorAdapterTest.java
@@ -42,7 +42,7 @@ public class ConfigProcessorAdapterTest {
@Test
- public void shouldCallIsFilterMetOnAdapter() throws Exception {
+ public void shouldCallIsFilterMetOnAdapter() {
//given
JSONObject parameter = new JSONObject();
when(configProcessors.isFilterMet(parameter)).thenReturn(true);
diff --git a/src/test/java/org/onap/dcae/commonFunction/DmaapPublishersTest.java b/src/test/java/org/onap/dcae/commonFunction/DmaapPublishersTest.java
index 782b7c25..f4955ac8 100644
--- a/src/test/java/org/onap/dcae/commonFunction/DmaapPublishersTest.java
+++ b/src/test/java/org/onap/dcae/commonFunction/DmaapPublishersTest.java
@@ -57,8 +57,9 @@ public class DmaapPublishersTest {
@Mock
private CambriaBatchingPublisher cambriaPublisher;
private DmaapPublishers cut;
+
@Rule
- public ExpectedException expectedException = ExpectedException.none();
+ public final ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() throws MalformedURLException, GeneralSecurityException {
diff --git a/src/test/java/org/onap/dcae/commonFunction/EventProcessorTest.java b/src/test/java/org/onap/dcae/commonFunction/EventProcessorTest.java
index a3a47720..973ee014 100644
--- a/src/test/java/org/onap/dcae/commonFunction/EventProcessorTest.java
+++ b/src/test/java/org/onap/dcae/commonFunction/EventProcessorTest.java
@@ -27,7 +27,6 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
-import java.io.FileNotFoundException;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@@ -43,11 +42,10 @@ import static org.onap.dcae.commonFunction.EventProcessor.EVENT_LIST_TYPE;
public class EventProcessorTest {
private final String ev = "{\"event\": {\"commonEventHeader\": { \"reportingEntityName\": \"VM name will be provided by ECOMP\", \"startEpochMicrosec\": 1477012779802988,\"lastEpochMicrosec\": 1477012789802988,\"eventId\": \"83\",\"sourceName\": \"Dummy VM name - No Metadata available\",\"sequence\": 83,\"priority\": \"Normal\",\"functionalRole\": \"vFirewall\",\"domain\": \"measurementsForVfScaling\",\"reportingEntityId\": \"VM UUID will be provided by ECOMP\",\"sourceId\": \"Dummy VM UUID - No Metadata available\",\"version\": 1.1},\"measurementsForVfScalingFields\": {\"measurementInterval\": 10,\"measurementsForVfScalingVersion\": 1.1,\"vNicUsageArray\": [{\"multicastPacketsIn\": 0,\"bytesIn\": 3896,\"unicastPacketsIn\": 0, \"multicastPacketsOut\": 0,\"broadcastPacketsOut\": 0, \"packetsOut\": 28,\"bytesOut\": 12178,\"broadcastPacketsIn\": 0,\"packetsIn\": 58,\"unicastPacketsOut\": 0,\"vNicIdentifier\": \"eth0\"}]}}}";
- private String testinput = "src/test/resources/testDmaapConfig_ip.json";
@Before
- public void setUp() throws Exception {
- CommonStartup.streamid = "fault=sec_fault|syslog=sec_syslog|heartbeat=sec_heartbeat|measurementsForVfScaling=sec_measurement|mobileFlow=sec_mobileflow|other=sec_other|stateChange=sec_statechange|thresholdCrossingAlert=sec_thresholdCrossingAlert|voiceQuality=ves_voicequality|sipSignaling=ves_sipsignaling";
+ public void setUp() {
+ CommonStartup.streamID = "fault=sec_fault|syslog=sec_syslog|heartbeat=sec_heartbeat|measurementsForVfScaling=sec_measurement|mobileFlow=sec_mobileflow|other=sec_other|stateChange=sec_statechange|thresholdCrossingAlert=sec_thresholdCrossingAlert|voiceQuality=ves_voicequality|sipSignaling=ves_sipsignaling";
CommonStartup.eventTransformFlag = 1;
}
@@ -65,7 +63,7 @@ public class EventProcessorTest {
}
@Test
- public void shouldParseJsonEvents() throws FileNotFoundException, ReflectiveOperationException {
+ public void shouldParseJsonEvents() throws ReflectiveOperationException {
//given
EventProcessor eventProcessor = new EventProcessor();
String event_json = "[{ \"filter\": {\"event.commonEventHeader.domain\":\"heartbeat\",\"VESversion\":\"v4\"},\"processors\":[" +
diff --git a/src/test/java/org/onap/dcae/commonFunction/TestCommonStartup.java b/src/test/java/org/onap/dcae/commonFunction/TestCommonStartup.java
index 18194864..e0fd5a42 100644
--- a/src/test/java/org/onap/dcae/commonFunction/TestCommonStartup.java
+++ b/src/test/java/org/onap/dcae/commonFunction/TestCommonStartup.java
@@ -19,6 +19,8 @@
*/
package org.onap.dcae.commonFunction;
+import static java.util.Base64.getDecoder;
+import static java.util.Base64.getEncoder;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
@@ -34,7 +36,6 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import java.io.FileReader;
import java.io.IOException;
-import java.util.Base64;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
import org.json.JSONArray;
@@ -77,7 +78,7 @@ public class TestCommonStartup {
@Test
public void testParseStreamIdToStreamHashMapping() {
// given
- CommonStartup.streamid = "fault=sec_fault|syslog=sec_syslog|heartbeat=sec_heartbeat|measurementsForVfScaling=sec_measurement|mobileFlow=sec_mobileflow|other=sec_other|stateChange=sec_statechange|thresholdCrossingAlert=sec_thresholdCrossingAlert|voiceQuality=ves_voicequality|sipSignaling=ves_sipsignaling";
+ CommonStartup.streamID = "fault=sec_fault|syslog=sec_syslog|heartbeat=sec_heartbeat|measurementsForVfScaling=sec_measurement|mobileFlow=sec_mobileflow|other=sec_other|stateChange=sec_statechange|thresholdCrossingAlert=sec_thresholdCrossingAlert|voiceQuality=ves_voicequality|sipSignaling=ves_sipsignaling";
EventProcessor eventProcessor = new EventProcessor();
// when
@@ -95,7 +96,7 @@ public class TestCommonStartup {
String user1 = "secureid";
String password1Hashed = "IWRjYWVSb2FkbTEyMyEt";
- String password1UnHashed = decode("IWRjYWVSb2FkbTEyMyEt");
+ String password1UnHashed = new String(getDecoder().decode("IWRjYWVSb2FkbTEyMyEt"));
String user2 = "sample1";
String password2Hashed = "c2FtcGxlMQ";
@@ -105,24 +106,17 @@ public class TestCommonStartup {
DrumlinRequest drumlinRequestMock = Mockito.mock(DrumlinRequest.class);
- String basicHeaderForUser1 = "Basic " + encode(user1, password1UnHashed);
+ String basicHeaderForUser1 = "Basic " + getEncoder().encodeToString((user1 + ":" + password1UnHashed).getBytes());
when(drumlinRequestMock.getFirstHeader("Authorization")).thenReturn(basicHeaderForUser1);
// when
- SimpleAuthenticator simpleAuthenticator = (SimpleAuthenticator) rsv.AuthlistHandler(authlist);
+ SimpleAuthenticator simpleAuthenticator = (SimpleAuthenticator) rsv.createAuthenticator(authlist);
NsaSimpleApiKey authentic = simpleAuthenticator.isAuthentic(drumlinRequestMock);
// then
assertEquals(authentic.getSecret(), password1UnHashed);
}
- private String decode(String hashedPassword) {
- return new String(Base64.getDecoder().decode(hashedPassword.getBytes()));
- }
-
- private String encode(String user1, String password1UnHashed) {
- return Base64.getEncoder().encodeToString((user1 + ":" + password1UnHashed).getBytes());
- }
}
diff --git a/src/test/java/org/onap/dcae/vestest/AnyNodeTest.java b/src/test/java/org/onap/dcae/vestest/AnyNodeTest.java
index 1613465f..695f53c9 100644
--- a/src/test/java/org/onap/dcae/vestest/AnyNodeTest.java
+++ b/src/test/java/org/onap/dcae/vestest/AnyNodeTest.java
@@ -51,7 +51,7 @@ public class AnyNodeTest {
@Test(expected = IOException.class)
public void testShouldRethrowExceptionWhenFileNotFound() throws IOException {
- AnyNode.parse("not/existng/path");
+ AnyNode.parse("not/existing/path");
}
@Test
diff --git a/src/test/java/org/onap/dcae/vestest/DmaapPropertyReaderTest.java b/src/test/java/org/onap/dcae/vestest/DmaapPropertyReaderTest.java
index eadf62f2..46f5da4b 100644
--- a/src/test/java/org/onap/dcae/vestest/DmaapPropertyReaderTest.java
+++ b/src/test/java/org/onap/dcae/vestest/DmaapPropertyReaderTest.java
@@ -24,7 +24,6 @@ import com.google.common.collect.ImmutableMap;
import org.junit.Test;
import org.onap.dcae.commonFunction.DmaapPropertyReader;
-import java.net.MalformedURLException;
import java.util.Map;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
@@ -53,7 +52,7 @@ public class DmaapPropertyReaderTest {
private static final String FAULT_UEB_CAMBRIA_TOPIC_KEY = FAULT_UEB_KEY_PREFIX + ".cambria.topic";
private static final String VES_ALERT_SND_AUTH_USERNAME_KEY = VES_ALERT_SND_KEY_PREFIX + ".basicAuthUsername";
- public static final String NULL_TOSTRING = "null";
+ private static final String NULL_TOSTRING = "null";
private static final Map<String, String> expectedCompleteGen2DmaapConfig = ImmutableMap.<String, String>builder()
.put(ALERT_BASIC_AUTH_PWD_KEY, "SamplePassWD2")
@@ -106,7 +105,7 @@ public class DmaapPropertyReaderTest {
}
@Test
- public void shouldCreateReaderWithCompleteGen2DmaapConfig() throws MalformedURLException {
+ public void shouldCreateReaderWithCompleteGen2DmaapConfig() {
assertReaderPreservedAllEntriesAfterTransformation(fullGen2DmaapConfig, expectedCompleteGen2DmaapConfig);
}
diff --git a/src/test/java/org/onap/dcae/vestest/TestConfigProcessor.java b/src/test/java/org/onap/dcae/vestest/TestConfigProcessor.java
index 2d6087e5..49b53d24 100644
--- a/src/test/java/org/onap/dcae/vestest/TestConfigProcessor.java
+++ b/src/test/java/org/onap/dcae/vestest/TestConfigProcessor.java
@@ -7,9 +7,9 @@
* 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.
@@ -31,260 +31,279 @@ import org.junit.Test;
import org.onap.dcae.commonFunction.ConfigProcessors;
-
public class TestConfigProcessor {
- public JSONObject getFileAsJsonObject()
- {
- JSONObject jsonObject = null;
- FileReader fr = null;
- final JsonParser parser = new JsonParser();
- String jsonfilepath="src/test/resources/event4xjson.txt";
- try{
- fr = new FileReader ( jsonfilepath );
- final JsonObject jo = (JsonObject) parser.parse (fr);
- final String jsonText = jo.toString ();
- jsonObject = new JSONObject ( jsonText );
- }
- catch(Exception e){
- System.out.println("Exception while opening the file");
- e.printStackTrace();
- }
- finally {
- //close the file
- if (fr != null) {
- try {
- fr.close();
- } catch (IOException e) {
- System.out.println("Error closing file reader stream : " +e.toString());
- }
- }
- }
- return jsonObject;
- }
- @Test
- public void testAttrMap(){
-
- final JSONObject jsonObject = getFileAsJsonObject();
- final String functionRole = (jsonObject.getJSONObject("event")).getJSONObject("commonEventHeader").get("functionalRole").toString();
- System.out.println("event==" + jsonObject.toString());
- System.out.println("functionRole==" + functionRole);
- final JSONObject jsonArgs = new JSONObject ( "{\"field\": \"event.commonEventHeader.nfNamingCode\",\"oldField\": \"event.commonEventHeader.functionalRole\"}" );
- ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
- cpEvent.map(jsonArgs);
- final String responseData = cpEvent.getEventObjectVal("event.commonEventHeader.nfNamingCode").toString();
- System.out.println("modified event==" + jsonObject.toString());
- System.out.println("responseData==" + responseData);
- assertEquals (functionRole, responseData);
- }
-
- @Test
- public void testArrayMap(){
-
- final JSONObject jsonObject = getFileAsJsonObject();
- final String alarmAdditionalInformation = (jsonObject.getJSONObject("event")).getJSONObject("faultFields").get("alarmAdditionalInformation").toString();
- System.out.println("event==" + jsonObject.toString());
- System.out.println("alarmAdditionalInformation==" + alarmAdditionalInformation);
- final JSONObject jsonArgs = new JSONObject ( "{\"field\": \"event.faultFields.eventAdditionalInformation\",\"oldField\": \"event.faultFields.alarmAdditionalInformation\"}" );
- ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
- cpEvent.map(jsonArgs);
- final String responseData = cpEvent.getEventObjectVal("event.faultFields.eventAdditionalInformation").toString();
- System.out.println("modified event==" + jsonObject.toString());
- System.out.println("responseData==" + responseData);
- assertEquals (alarmAdditionalInformation, responseData);
- }
- @Test
- public void testJobjMaptoArray(){
-
- final JSONObject jsonObject = getFileAsJsonObject();
- //final String receiveDiscards = (((jsonObject.getJSONObject("event")).getJSONObject("faultFields")).get("errors")).get("receiveDiscards").toString();
- System.out.println("event==" + jsonObject.toString());
- //System.out.println("alarmAdditionalInformation==" + alarmAdditionalInformation);
- final JSONObject jsonArgs = new JSONObject ( "{\"field\": \"event.faultFields.vNicPerformanceArray[]\",\"oldField\": \"event.faultFields.errors\",\"attrMap\":{\"receiveDiscards\":\"receivedDiscardedPacketsAccumulated\"}}" );
- ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
- final String receiveDiscards = cpEvent.getEventObjectVal("event.faultFields.errors.receiveDiscards").toString();
- System.out.println("receiveDiscards==" + receiveDiscards);
- cpEvent.map(jsonArgs);
- final String responseData = cpEvent.getEventObjectVal("event.faultFields.vNicPerformanceArray[0].receivedDiscardedPacketsAccumulated").toString();
- System.out.println("modified event==" + jsonObject.toString());
- System.out.println("responseData==" + responseData);
- assertEquals (receiveDiscards, responseData);
- }
- @Test
- public void testAttrAdd(){
-
- final JSONObject jsonObject = getFileAsJsonObject();
- //final String functionRole = (jsonObject.getJSONObject("event")).getJSONObject("commonEventHeader").get("functionalRole").toString();
- System.out.println("event==" + jsonObject.toString());
- //System.out.println("functionRole==" + functionRole);
- final JSONObject jsonArgs = new JSONObject ( "{\"field\": \"event.faultFields.version\",\"value\": \"2.0\",\"fieldType\": \"number\"}" );
- ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
- cpEvent.addAttribute(jsonArgs);
- final String responseData = cpEvent.getEventObjectVal("event.faultFields.version").toString();
- System.out.println("modified event==" + jsonObject.toString());
- System.out.println("responseData==" + responseData);
- assertEquals ("2.0", responseData);
- }
-
- @Test
- public void testAttrUpdate(){
-
- final JSONObject jsonObject = getFileAsJsonObject();
- //final String functionRole = (jsonObject.getJSONObject("event")).getJSONObject("commonEventHeader").get("functionalRole").toString();
- System.out.println("event==" + jsonObject.toString());
- //System.out.println("functionRole==" + functionRole);
- final JSONObject jsonArgs = new JSONObject ( "{\"field\": \"event.faultFields.version\",\"value\": \"2.0\",\"fieldType\": \"number\"}" );
- ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
- cpEvent.updateAttribute(jsonArgs);
- final String responseData = cpEvent.getEventObjectVal("event.faultFields.version").toString();
- System.out.println("modified event==" + jsonObject.toString());
- System.out.println("responseData==" + responseData);
- assertEquals ("2.0", responseData);
- }
-
- @Test
- public void testAttrConcatenate(){
-
- final JSONObject jsonObject = getFileAsJsonObject();
- final String eventType = (jsonObject.getJSONObject("event")).getJSONObject("commonEventHeader").get("eventType").toString();
- final String domain = (jsonObject.getJSONObject("event")).getJSONObject("commonEventHeader").get("domain").toString();
- final String alarmCondition = (jsonObject.getJSONObject("event")).getJSONObject("faultFields").get("alarmCondition").toString();
- System.out.println("event==" + jsonObject.toString());
- final String eventName = domain + "_" + eventType + "_" + alarmCondition;
- System.out.println("eventName==" + eventName);
- final JSONObject jsonArgs = new JSONObject ( "{\"field\":\"event.commonEventHeader.eventName\",\"concatenate\": [\"$event.commonEventHeader.domain\",\"$event.commonEventHeader.eventType\",\"$event.faultFields.alarmCondition\"],\"delimiter\":\"_\"}");
- ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
- cpEvent.concatenateValue(jsonArgs);
- final String responseData = cpEvent.getEventObjectVal("event.commonEventHeader.eventName").toString();
- System.out.println("modified event==" + jsonObject.toString());
- System.out.println("responseData==" + responseData);
- assertEquals (eventName, responseData);
- }
-
- @Test
- public void testAttrSubtract(){
-
- final JSONObject jsonObject = getFileAsJsonObject();
- final String memoryConfigured = (jsonObject.getJSONObject("event")).getJSONObject("faultFields").get("memoryConfigured").toString();
- final String memoryUsed = (jsonObject.getJSONObject("event")).getJSONObject("faultFields").get("memoryUsed").toString();
- System.out.println("event==" + jsonObject.toString());
- System.out.println("memoryConfigured==" + memoryConfigured);
- System.out.println("memoryUsed==" + memoryUsed);
- final JSONObject jsonArgs = new JSONObject ( "{\"field\": \"event.faultFields.memoryFree\",\"subtract\": [\"$event.faultFields.memoryConfigured\",\"$event.faultFields.memoryUsed\"]}" );
- ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
- cpEvent.subtractValue(jsonArgs);
- final String responseData = cpEvent.getEventObjectVal("event.faultFields.memoryFree").toString();
- System.out.println("modified event==" + jsonObject.toString());
- System.out.println("responseData==" + responseData);
- assertEquals ("1980.0", responseData);
- }
-
- @Test
- public void testSetValue(){
-
- final JSONObject jsonObject = getFileAsJsonObject();
- System.out.println("event==" + jsonObject.toString());
- System.out.println("Testing SetValue");
- final JSONObject jsonArgs = new JSONObject ( "{\"field\": \"event.faultFields.version\",\"value\": \"2.0\",\"fieldType\": \"number\"}" );
- ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
- cpEvent.setValue(jsonArgs);
- final String responseData = cpEvent.getEventObjectVal("event.faultFields.version").toString();
- System.out.println("modified event==" + jsonObject.toString());
- System.out.println("responseData==" + responseData);
- assertEquals ("2.0", responseData);
- }
-
- @Test
- public void testSetEventObjectVal(){
-
- final JSONObject jsonObject = getFileAsJsonObject();
- System.out.println("event==" + jsonObject.toString());
- System.out.println("Testing SetEventObjectVal");
- //final JSONObject jsonArgs = new JSONObject ( "{\"field\": \"event.faultFields.version\",\"value\": \"2.0\",\"fieldType\": \"number\"}" );
- ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
- cpEvent.setEventObjectVal("event.faultFields.version", "2.0", "number");
- final String responseData = cpEvent.getEventObjectVal("event.faultFields.version").toString();
- System.out.println("modified event==" + jsonObject.toString());
- System.out.println("responseData==" + responseData);
- assertEquals ("2.0", responseData);
- }
-
- @Test
- public void testGetValue(){
-
- final JSONObject jsonObject = getFileAsJsonObject();
- System.out.println("event==" + jsonObject.toString());
- System.out.println("Testing GetValue");
- final JSONObject jsonArgs = new JSONObject ( "{\"field\": \"event.faultFields.eventSeverity\"}" );
- ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
- cpEvent.getValue(jsonArgs);
- final String responseData = cpEvent.getEventObjectVal("event.faultFields.eventSeverity").toString();
- System.out.println("modified event==" + jsonObject.toString());
- System.out.println("responseData==" + responseData);
- assertEquals ("CRITICAL", responseData);
- }
-
- @Test
- public void testGetEventObjectVal(){
-
- final JSONObject jsonObject = getFileAsJsonObject();
- System.out.println("event==" + jsonObject.toString());
- System.out.println("Testing GetEventObjectVal");
- //final JSONObject jsonArgs = new JSONObject ( "{\"field\": \"event.faultFields.eventSeverity\"}" );
- ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
- cpEvent.getEventObjectVal("event.faultFields.eventSeverity");
- final String responseData = cpEvent.getEventObjectVal("event.faultFields.eventSeverity").toString();
- System.out.println("modified event==" + jsonObject.toString());
- System.out.println("responseData==" + responseData);
- assertEquals ("CRITICAL", responseData);
- }
-
- @Test
- public void testRemoveAttribute(){
-
- final JSONObject jsonObject = getFileAsJsonObject();
- System.out.println("event==" + jsonObject.toString());
- System.out.println("Testing removeAttribute");
- final JSONObject jsonArgs = new JSONObject ( "{\"field\": \"event.faultFields.memoryUsed\"}" );
- ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
- cpEvent.removeAttribute(jsonArgs);
- final String responseData = cpEvent.getEventObjectVal("event.faultFields.memoryUsed").toString();
- System.out.println("modified event==" + jsonObject.toString());
- System.out.println("responseData==" + responseData);
- assertEquals ("ObjectNotFound", responseData);
- }
-
- @Test
- public void testIsFilterMet(){
-
- final JSONObject jsonObject = getFileAsJsonObject();
- System.out.println("event==" + jsonObject.toString());
- System.out.println("Testing isFilterMet");
- final JSONObject jsonArgs = new JSONObject ( "{\"event.faultFields.eventSeverity\":\"CRITICAL\"}" );
- ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
-
- final boolean response = cpEvent.isFilterMet(jsonArgs);
- String responseData = "CRITICAL";
- if (response == false)
- responseData = "notCRITICAL";
-
- System.out.println("responseData==" + responseData);
- assertEquals ("CRITICAL", responseData);
- }
-
- @Test
- public void testSuppressEvent(){
-
- final JSONObject jsonObject = getFileAsJsonObject();
- System.out.println("event==" + jsonObject.toString());
- System.out.println("Testing SuppressEvent");
- final JSONObject jsonArgs = new JSONObject ( "{\"event.faultFields.eventSeverity\":\"CRITICAL\"}" );
- ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
-
- cpEvent.suppressEvent(jsonArgs);
- String responseData = cpEvent.getEventObjectVal("suppressEvent").toString();
-
- System.out.println("responseData==" + responseData);
- assertEquals ("true", responseData);
- }
+
+ private JSONObject getFileAsJsonObject() {
+ JSONObject jsonObject = null;
+ FileReader fr = null;
+ final JsonParser parser = new JsonParser();
+ String jsonFilePath = "src/test/resources/event4xjson.txt";
+ try {
+ fr = new FileReader(jsonFilePath);
+ final JsonObject jo = (JsonObject) parser.parse(fr);
+ final String jsonText = jo.toString();
+ jsonObject = new JSONObject(jsonText);
+ } catch (Exception e) {
+ System.out.println("Exception while opening the file");
+ e.printStackTrace();
+ } finally {
+ //close the file
+ if (fr != null) {
+ try {
+ fr.close();
+ } catch (IOException e) {
+ System.out.println("Error closing file reader stream : " + e.toString());
+ }
+ }
+ }
+ return jsonObject;
+ }
+
+ @Test
+ public void testAttrMap() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ final String functionRole = (jsonObject.getJSONObject("event")).getJSONObject("commonEventHeader")
+ .get("functionalRole").toString();
+ System.out.println("event==" + jsonObject.toString());
+ System.out.println("functionRole==" + functionRole);
+ final JSONObject jsonArgs = new JSONObject(
+ "{\"field\": \"event.commonEventHeader.nfNamingCode\",\"oldField\": \"event.commonEventHeader.functionalRole\"}");
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+ cpEvent.map(jsonArgs);
+ final String responseData = cpEvent.getEventObjectVal("event.commonEventHeader.nfNamingCode").toString();
+ System.out.println("modified event==" + jsonObject.toString());
+ System.out.println("responseData==" + responseData);
+ assertEquals(functionRole, responseData);
+ }
+
+ @Test
+ public void testArrayMap() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ final String alarmAdditionalInformation = (jsonObject.getJSONObject("event")).getJSONObject("faultFields")
+ .get("alarmAdditionalInformation").toString();
+ System.out.println("event==" + jsonObject.toString());
+ System.out.println("alarmAdditionalInformation==" + alarmAdditionalInformation);
+ final JSONObject jsonArgs = new JSONObject(
+ "{\"field\": \"event.faultFields.eventAdditionalInformation\",\"oldField\": \"event.faultFields.alarmAdditionalInformation\"}");
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+ cpEvent.map(jsonArgs);
+ final String responseData = cpEvent.getEventObjectVal("event.faultFields.eventAdditionalInformation")
+ .toString();
+ System.out.println("modified event==" + jsonObject.toString());
+ System.out.println("responseData==" + responseData);
+ assertEquals(alarmAdditionalInformation, responseData);
+ }
+
+ @Test
+ public void testJSONObjectMapToArray() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ //final String receiveDiscards = (((jsonObject.getJSONObject("event")).getJSONObject("faultFields")).get("errors")).get("receiveDiscards").toString();
+ System.out.println("event==" + jsonObject.toString());
+ //System.out.println("alarmAdditionalInformation==" + alarmAdditionalInformation);
+ final JSONObject jsonArgs = new JSONObject(
+ "{\"field\": \"event.faultFields.vNicPerformanceArray[]\",\"oldField\": \"event.faultFields.errors\",\"attrMap\":{\"receiveDiscards\":\"receivedDiscardedPacketsAccumulated\"}}");
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+ final String receiveDiscards = cpEvent.getEventObjectVal("event.faultFields.errors.receiveDiscards").toString();
+ System.out.println("receiveDiscards==" + receiveDiscards);
+ cpEvent.map(jsonArgs);
+ final String responseData = cpEvent
+ .getEventObjectVal("event.faultFields.vNicPerformanceArray[0].receivedDiscardedPacketsAccumulated")
+ .toString();
+ System.out.println("modified event==" + jsonObject.toString());
+ System.out.println("responseData==" + responseData);
+ assertEquals(receiveDiscards, responseData);
+ }
+
+ @Test
+ public void testAttrAdd() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ //final String functionRole = (jsonObject.getJSONObject("event")).getJSONObject("commonEventHeader").get("functionalRole").toString();
+ System.out.println("event==" + jsonObject.toString());
+ //System.out.println("functionRole==" + functionRole);
+ final JSONObject jsonArgs = new JSONObject(
+ "{\"field\": \"event.faultFields.version\",\"value\": \"2.0\",\"fieldType\": \"number\"}");
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+ cpEvent.addAttribute(jsonArgs);
+ final String responseData = cpEvent.getEventObjectVal("event.faultFields.version").toString();
+ System.out.println("modified event==" + jsonObject.toString());
+ System.out.println("responseData==" + responseData);
+ assertEquals("2.0", responseData);
+ }
+
+ @Test
+ public void testAttrUpdate() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ //final String functionRole = (jsonObject.getJSONObject("event")).getJSONObject("commonEventHeader").get("functionalRole").toString();
+ System.out.println("event==" + jsonObject.toString());
+ //System.out.println("functionRole==" + functionRole);
+ final JSONObject jsonArgs = new JSONObject(
+ "{\"field\": \"event.faultFields.version\",\"value\": \"2.0\",\"fieldType\": \"number\"}");
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+ cpEvent.updateAttribute(jsonArgs);
+ final String responseData = cpEvent.getEventObjectVal("event.faultFields.version").toString();
+ System.out.println("modified event==" + jsonObject.toString());
+ System.out.println("responseData==" + responseData);
+ assertEquals("2.0", responseData);
+ }
+
+ @Test
+ public void testAttrConcatenate() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ final String eventType = (jsonObject.getJSONObject("event")).getJSONObject("commonEventHeader").get("eventType")
+ .toString();
+ final String domain = (jsonObject.getJSONObject("event")).getJSONObject("commonEventHeader").get("domain")
+ .toString();
+ final String alarmCondition = (jsonObject.getJSONObject("event")).getJSONObject("faultFields")
+ .get("alarmCondition").toString();
+ System.out.println("event==" + jsonObject.toString());
+ final String eventName = domain + "_" + eventType + "_" + alarmCondition;
+ System.out.println("eventName==" + eventName);
+ final JSONObject jsonArgs = new JSONObject(
+ "{\"field\":\"event.commonEventHeader.eventName\",\"concatenate\": [\"$event.commonEventHeader.domain\",\"$event.commonEventHeader.eventType\",\"$event.faultFields.alarmCondition\"],\"delimiter\":\"_\"}");
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+ cpEvent.concatenateValue(jsonArgs);
+ final String responseData = cpEvent.getEventObjectVal("event.commonEventHeader.eventName").toString();
+ System.out.println("modified event==" + jsonObject.toString());
+ System.out.println("responseData==" + responseData);
+ assertEquals(eventName, responseData);
+ }
+
+ @Test
+ public void testAttrSubtract() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ final String memoryConfigured = (jsonObject.getJSONObject("event")).getJSONObject("faultFields")
+ .get("memoryConfigured").toString();
+ final String memoryUsed = (jsonObject.getJSONObject("event")).getJSONObject("faultFields").get("memoryUsed")
+ .toString();
+ System.out.println("event==" + jsonObject.toString());
+ System.out.println("memoryConfigured==" + memoryConfigured);
+ System.out.println("memoryUsed==" + memoryUsed);
+ final JSONObject jsonArgs = new JSONObject(
+ "{\"field\": \"event.faultFields.memoryFree\",\"subtract\": [\"$event.faultFields.memoryConfigured\",\"$event.faultFields.memoryUsed\"]}");
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+ cpEvent.subtractValue(jsonArgs);
+ final String responseData = cpEvent.getEventObjectVal("event.faultFields.memoryFree").toString();
+ System.out.println("modified event==" + jsonObject.toString());
+ System.out.println("responseData==" + responseData);
+ assertEquals("1980.0", responseData);
+ }
+
+ @Test
+ public void testSetValue() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ System.out.println("event==" + jsonObject.toString());
+ System.out.println("Testing SetValue");
+ final JSONObject jsonArgs = new JSONObject(
+ "{\"field\": \"event.faultFields.version\",\"value\": \"2.0\",\"fieldType\": \"number\"}");
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+ cpEvent.setValue(jsonArgs);
+ final String responseData = cpEvent.getEventObjectVal("event.faultFields.version").toString();
+ System.out.println("modified event==" + jsonObject.toString());
+ System.out.println("responseData==" + responseData);
+ assertEquals("2.0", responseData);
+ }
+
+ @Test
+ public void testSetEventObjectVal() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ System.out.println("event==" + jsonObject.toString());
+ System.out.println("Testing SetEventObjectVal");
+ //final JSONObject jsonArgs = new JSONObject ( "{\"field\": \"event.faultFields.version\",\"value\": \"2.0\",\"fieldType\": \"number\"}" );
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+ cpEvent.setEventObjectVal("event.faultFields.version", "2.0", "number");
+ final String responseData = cpEvent.getEventObjectVal("event.faultFields.version").toString();
+ System.out.println("modified event==" + jsonObject.toString());
+ System.out.println("responseData==" + responseData);
+ assertEquals("2.0", responseData);
+ }
+
+ @Test
+ public void testGetValue() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ System.out.println("event==" + jsonObject.toString());
+ System.out.println("Testing GetValue");
+ final JSONObject jsonArgs = new JSONObject("{\"field\": \"event.faultFields.eventSeverity\"}");
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+ cpEvent.getValue(jsonArgs);
+ final String responseData = cpEvent.getEventObjectVal("event.faultFields.eventSeverity").toString();
+ System.out.println("modified event==" + jsonObject.toString());
+ System.out.println("responseData==" + responseData);
+ assertEquals("CRITICAL", responseData);
+ }
+
+ @Test
+ public void testGetEventObjectVal() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ System.out.println("event==" + jsonObject.toString());
+ System.out.println("Testing GetEventObjectVal");
+ //final JSONObject jsonArgs = new JSONObject ( "{\"field\": \"event.faultFields.eventSeverity\"}" );
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+ cpEvent.getEventObjectVal("event.faultFields.eventSeverity");
+ final String responseData = cpEvent.getEventObjectVal("event.faultFields.eventSeverity").toString();
+ System.out.println("modified event==" + jsonObject.toString());
+ System.out.println("responseData==" + responseData);
+ assertEquals("CRITICAL", responseData);
+ }
+
+ @Test
+ public void testRemoveAttribute() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ System.out.println("event==" + jsonObject.toString());
+ System.out.println("Testing removeAttribute");
+ final JSONObject jsonArgs = new JSONObject("{\"field\": \"event.faultFields.memoryUsed\"}");
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+ cpEvent.removeAttribute(jsonArgs);
+ final String responseData = cpEvent.getEventObjectVal("event.faultFields.memoryUsed").toString();
+ System.out.println("modified event==" + jsonObject.toString());
+ System.out.println("responseData==" + responseData);
+ assertEquals("ObjectNotFound", responseData);
+ }
+
+ @Test
+ public void testIsFilterMet() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ System.out.println("event==" + jsonObject.toString());
+ System.out.println("Testing isFilterMet");
+ final JSONObject jsonArgs = new JSONObject("{\"event.faultFields.eventSeverity\":\"CRITICAL\"}");
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+
+ final boolean response = cpEvent.isFilterMet(jsonArgs);
+ String responseData = "CRITICAL";
+ if (!response) {
+ responseData = "notCRITICAL";
+ }
+
+ System.out.println("responseData==" + responseData);
+ assertEquals("CRITICAL", responseData);
+ }
+
+ @Test
+ public void testSuppressEvent() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ System.out.println("event==" + jsonObject.toString());
+ System.out.println("Testing SuppressEvent");
+ final JSONObject jsonArgs = new JSONObject("{\"event.faultFields.eventSeverity\":\"CRITICAL\"}");
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+
+ cpEvent.suppressEvent(jsonArgs);
+ String responseData = cpEvent.getEventObjectVal("suppressEvent").toString();
+
+ System.out.println("responseData==" + responseData);
+ assertEquals("true", responseData);
+ }
}
diff --git a/src/test/java/org/onap/dcae/vestest/TestJsonSchemaValidation.java b/src/test/java/org/onap/dcae/vestest/TestJsonSchemaValidation.java
index 2b392067..0489811d 100644
--- a/src/test/java/org/onap/dcae/vestest/TestJsonSchemaValidation.java
+++ b/src/test/java/org/onap/dcae/vestest/TestJsonSchemaValidation.java
@@ -34,7 +34,7 @@ public class TestJsonSchemaValidation {
@Test
public void shouldValidEventPassSchema_27_2() throws IOException {
- String result = CommonStartup.schemavalidate(
+ String result = CommonStartup.validateAgainstSchema(
readJSONFromFile("src/test/resources/VES_valid.txt").toString(),
readJSONFromFile("etc/CommonEventFormat_27.2.json").toString());
assertEquals(result, "true");
@@ -43,7 +43,7 @@ public class TestJsonSchemaValidation {
@Test
public void shouldInvalidEventDoesNotPassSchema_27_2() throws IOException {
- String result = CommonStartup.schemavalidate(
+ String result = CommonStartup.validateAgainstSchema(
readJSONFromFile("src/test/resources/VES_invalid.txt").toString(),
readJSONFromFile("etc/CommonEventFormat_27.2.json").toString());
assertEquals(result, "false");
diff --git a/src/test/java/org/onap/dcae/vestest/TestLoadDynamicConfig.java b/src/test/java/org/onap/dcae/vestest/TestLoadDynamicConfig.java
index ee0a3cba..03a074d7 100644
--- a/src/test/java/org/onap/dcae/vestest/TestLoadDynamicConfig.java
+++ b/src/test/java/org/onap/dcae/vestest/TestLoadDynamicConfig.java
@@ -21,7 +21,6 @@ package org.onap.dcae.vestest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.onap.dcae.vestest.TestingUtilities.correctQuotes;
import static org.onap.dcae.vestest.TestingUtilities.createTemporaryFile;
import com.github.fge.jackson.JsonLoader;
@@ -46,7 +45,7 @@ public class TestLoadDynamicConfig {
@Test
public void shouldReadFileContent() throws IOException {
// given
- String expectedJSON = correctQuotes("{ 'field' : 1 }");
+ String expectedJSON = "{ \"field\" : 1 }";
Files.write(temporaryFile, expectedJSON.getBytes());
// when
@@ -62,7 +61,7 @@ public class TestLoadDynamicConfig {
LoadDynamicConfig loadDynamicConfig = new LoadDynamicConfig();
loadDynamicConfig.propFile = "src/test/resources/test_collector_ip_op.properties";
loadDynamicConfig.configFile = "src/test/resources/controller-config_dmaap_ip.json";
- loadDynamicConfig.dmaapoutputfile = temporaryFile.toString();
+ loadDynamicConfig.dMaaPOutputFile = temporaryFile.toString();
String sampleConfiguration = LoadDynamicConfig.readFile(loadDynamicConfig.configFile);
// when
diff --git a/src/test/java/org/onap/dcae/vestest/TestingUtilities.java b/src/test/java/org/onap/dcae/vestest/TestingUtilities.java
index 43e7a84e..7c7c09dc 100644
--- a/src/test/java/org/onap/dcae/vestest/TestingUtilities.java
+++ b/src/test/java/org/onap/dcae/vestest/TestingUtilities.java
@@ -36,10 +36,6 @@ final class TestingUtilities {
// utility class, no objects allowed
}
- static String correctQuotes(String s) {
- return s.replace("'", "\"");
- }
-
static JsonObject readJSONFromFile(Path path) {
return rethrow(() -> (JsonObject) new JsonParser().parse(new String(readAllBytes(path))));
}