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 --- .../org/onap/dcae/commonFunction/ApiExceptionTest.java | 13 +++---------- .../commonFunction/ConfigProcessorAdapterTest.java | 2 +- .../onap/dcae/commonFunction/DmaapPublishersTest.java | 3 ++- .../onap/dcae/commonFunction/EventProcessorTest.java | 8 +++----- .../onap/dcae/commonFunction/TestCommonStartup.java | 18 ++++++------------ 5 files changed, 15 insertions(+), 29 deletions(-) (limited to 'src/test/java/org/onap/dcae/commonFunction') 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()); - } } -- cgit 1.2.3-korg