From 943a47187dbb1393d720b2fdf0019d48270edb4d Mon Sep 17 00:00:00 2001 From: PawelSzalapski Date: Thu, 21 Jun 2018 12:12:30 +0200 Subject: Remove dead code from VESCollector Many things there are unused or have inproper modifiers, spelling etc. I run static analysis tool (Intellij code inspect) and clear those things up. It will be easier to maintain now. No actual behavior changes were done. Issue-ID: DCAEGEN2-526 Signed-off-by: PawelSzalapski Change-Id: I1a4ad0c896bd32165cba654344ffc5245648c615 --- .../java/org/onap/dcae/vestest/AnyNodeTest.java | 2 +- .../onap/dcae/vestest/DmaapPropertyReaderTest.java | 5 +- .../org/onap/dcae/vestest/TestConfigProcessor.java | 531 +++++++++++---------- .../dcae/vestest/TestJsonSchemaValidation.java | 4 +- .../onap/dcae/vestest/TestLoadDynamicConfig.java | 5 +- .../org/onap/dcae/vestest/TestingUtilities.java | 4 - 6 files changed, 282 insertions(+), 269 deletions(-) (limited to 'src/test/java/org/onap/dcae/vestest') 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 expectedCompleteGen2DmaapConfig = ImmutableMap.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)))); } -- cgit 1.2.3-korg