From 5e76fbd802ca4dcf48dac5c9a8f262470a326ef7 Mon Sep 17 00:00:00 2001 From: Pooja03 Date: Wed, 20 Mar 2019 19:39:58 +0530 Subject: Resolving warning reported in build - VES Mapper Changes made to resolve warnings in the build. Change-Id: I03dee6780941881afc65c4b907ade078febb5e39 Issue-ID: DCAEGEN2-604 Signed-off-by: Pooja03 --- .../adapter/UniversalEventAdapterTest.java | 236 ++++++++++---------- .../configs/DMaaPMRBaseConfigTest.java | 75 ------- .../configs/DmaapMrBaseConfigTest.java | 78 +++++++ .../controller/VesControllerTest.java | 134 +++++------ .../ConfigFileSmooksConversionExceptionTest.java | 72 +++--- .../exception/DMaapExceptionTest.java | 84 +++---- .../exception/MapperConfigExceptionTest.java | 65 +++--- .../mappingconfig/EntryTest.java | 119 +++++----- .../mappingconfig/EvaluationTest.java | 140 ++++++------ .../mappingconfig/MapperConfigTest.java | 109 ++++----- .../service/VesServiceTest.java | 244 +++++++++------------ .../universalvesadapter/utils/SmooksUtilsTest.java | 217 +++++++++--------- 12 files changed, 781 insertions(+), 792 deletions(-) delete mode 100644 UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/configs/DMaaPMRBaseConfigTest.java create mode 100644 UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/configs/DmaapMrBaseConfigTest.java (limited to 'UniversalVesAdapter/src/test/java/org/onap/universalvesadapter') diff --git a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/adapter/UniversalEventAdapterTest.java b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/adapter/UniversalEventAdapterTest.java index c866235..b016cc7 100644 --- a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/adapter/UniversalEventAdapterTest.java +++ b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/adapter/UniversalEventAdapterTest.java @@ -1,22 +1,22 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* 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========================================================= -*/ +/*- + * ============LICENSE_START======================================================= + * ONAP : DCAE + * ================================================================================ + * Copyright 2018-2019 TechMahindra + * ================================================================================ + * 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.universalvesadapter.adapter; @@ -25,6 +25,7 @@ import static org.junit.Assert.assertNotNull; import java.util.HashMap; import java.util.Map; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,97 +46,108 @@ import org.springframework.boot.test.context.SpringBootTest; @RunWith(PowerMockRunner.class) @SpringBootTest(classes = Application.class) public class UniversalEventAdapterTest { - - private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); - - @Mock - private VESAdapterInitializer vesAdapterInitializer; - - @InjectMocks - private UniversalEventAdapter universalVesAdapter; - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - } - - @PrepareForTest({ CollectorConfigPropertyRetrival.class }) - @Test - public void testtransform() { - - StringBuffer incomingJsonString = new StringBuffer("{\n" + " \"rule-id\": \"12121\",\n" - + " \"notification\": {\n" + " \"event-time\": \"2018-03-15T08:15:32.000Z\",\n" - + " \"notification-id\": \"2541256\",\n" + " \"message\": {\n" - + " \"topic\":\"resource\",\n" + " \"object-type\":\"onu\", \n" - + " \"version\": \"v1\", \n" + " \"operation\": \"create\", \n" - + " \"target\": \"ont/ont=23hk1231231232\", \n" + " \"content\": {\n" - + " \"onu\": {\n" + " \"sn\": \"48575443FA637D1A\",\n" - + " \"refParentNE\": \"550e8400-e29b-41d4-a716-446655440000\",\n" - + " \"refParentNeNativeId\": \"FDN\",\n" - + " \"refParentLTP\": \"8c0db89e-218c-4e18-b0de-7a6788b3dda4\",\n" - + " \"refParentLTPNativeId\": \"FDN\",\n" - + " \"onuId\": \"213\",\n" + " \"accessID\": \"HG65875420001\"\n" - + " }\n" + " }\n" + " }\n" + " }\n" + "}"); - Map testMap = new HashMap(); - testMap.put("defaultMappingFile-" + Thread.currentThread().getName(), - "\n" - + "\n" - + " \n" - + " \n" - + " \n" - + " \n" + " \n" - + " \n" - + " \n" + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + "" - + "org.onap.dcaegen2.ves.domain.ves7_0.CommonEventHeader.Version._4_0_1 \n" - + "\"pnfRegistration\"\n" - + "" - + "org.onap.dcaegen2.ves.domain.ves7_0.CommonEventHeader.VesEventListenerVersion._7_0_1\n" - + " " - + "\"registration_\"+commonEventHeader.ts1\n" - + "\"VESMapper\"\n" - + " " - + "org.onap.dcaegen2.ves.domain.ves7_0.CommonEventHeader.Domain.PNF_REGISTRATION\n" - + " " - + "commonEventHeader.domain\n" - + "\n" - + "" - + "commonEventHeader.ts1\n" - + " " - + "commonEventHeader.ts1\n" + " " - + "org.onap.dcaegen2.ves.domain.ves7_0.CommonEventHeader.Priority.NORMAL\n" - + " \n" - + " \n" - + " \n" + " \n" - + " " - + "org.onap.dcaegen2.ves.domain.ves7_0.PnfRegistrationFields.PnfRegistrationFieldsVersion._2_0" - + "\n" - + " \n" - + " \n" + " \n" + ""); - - try { - vesAdapterInitializer.setMappingFiles(testMap); - - String identifiertest[] = CollectorConfigPropertyRetrival.getProperyArray("identifier", "kvTest.json"); - PowerMockito.mockStatic(CollectorConfigPropertyRetrival.class); - PowerMockito.when(CollectorConfigPropertyRetrival.getProperyArray("identifier", null)) - .thenReturn(identifiertest); - - String actualResult = universalVesAdapter.transform(incomingJsonString.toString()); - assertNotNull(actualResult); - assertNotEquals("", actualResult); - } catch (VesException exception) { - errorLogger.error("Error occurred : {}", exception); - } - } - + + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); + + @Mock + private VESAdapterInitializer vesAdapterInitializer; + + @InjectMocks + private UniversalEventAdapter universalVesAdapter; + + @Before + public void init() { + MockitoAnnotations.initMocks(this); + } + + @PrepareForTest({CollectorConfigPropertyRetrival.class}) + @Test + public void testtransform() { + + StringBuffer incomingJsonString = new StringBuffer("{\n" + " \"rule-id\": \"12121\",\n" + + " \"notification\": {\n" + + " \"event-time\": \"2018-03-15T08:15:32.000Z\",\n" + + " \"notification-id\": \"2541256\",\n" + " \"message\": {\n" + + " \"topic\":\"resource\",\n" + + " \"object-type\":\"onu\", \n" + + " \"version\": \"v1\", \n" + + " \"operation\": \"create\", \n" + + " \"target\": \"ont/ont=23hk1231231232\", \n" + + " \"content\": {\n" + " \"onu\": {\n" + + " \"sn\": \"48575443FA637D1A\",\n" + + " \"refParentNE\": \"550e8400-e29b-41d4-a716-446655440000\",\n" + + " \"refParentNeNativeId\": \"FDN\",\n" + + " \"refParentLTP\": \"8c0db89e-218c-4e18-b0de-7a6788b3dda4\",\n" + + " \"refParentLTPNativeId\": \"FDN\",\n" + + " \"onuId\": \"213\",\n" + + " \"accessID\": \"HG65875420001\"\n" + " }\n" + + " }\n" + " }\n" + " }\n" + "}"); + Map testMap = new HashMap(); + testMap.put("defaultMappingFile-" + Thread.currentThread().getName(), + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "" + + "org.onap.dcaegen2.ves.domain.ves70.CommonEventHeader.Version._4_0_1 \n" + + "\"pnfRegistration\"\n" + + "" + + "org.onap.dcaegen2.ves.domain.ves70.CommonEventHeader.VesEventListenerVersion._7_0_1" + + "\n" + + " " + + "\"registration_\"+commonEventHeader.ts1\n" + + "\"VESMapper\"\n" + + " " + + "org.onap.dcaegen2.ves.domain.ves70.CommonEventHeader.Domain.PNF_REGISTRATION" + + "\n" + + " " + + "commonEventHeader.domain\n" + + "\n" + + "" + + "commonEventHeader.ts1\n" + + " " + + "commonEventHeader.ts1\n" + + " " + + "org.onap.dcaegen2.ves.domain.ves70.CommonEventHeader.Priority.NORMAL\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " " + + "org.onap.dcaegen2.ves.domain.ves70.PnfRegistrationFields.PnfRegistrationFieldsVersion._2_0" + + "\n" + + " \n" + + " \n" + " \n" + ""); + + try { + vesAdapterInitializer.setMappingFiles(testMap); + + String [] identifiertest = + CollectorConfigPropertyRetrival.getProperyArray("identifier", "kvTest.json"); + PowerMockito.mockStatic(CollectorConfigPropertyRetrival.class); + PowerMockito.when(CollectorConfigPropertyRetrival.getProperyArray("identifier", null)) + .thenReturn(identifiertest); + + String actualResult = universalVesAdapter.transform(incomingJsonString.toString()); + assertNotNull(actualResult); + assertNotEquals("", actualResult); + } catch (VesException exception) { + errorLogger.error("Error occurred : {}", exception); + } + } + } diff --git a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/configs/DMaaPMRBaseConfigTest.java b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/configs/DMaaPMRBaseConfigTest.java deleted file mode 100644 index 0ec9557..0000000 --- a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/configs/DMaaPMRBaseConfigTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Samsung. 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.onap.universalvesadapter.configs; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.onap.universalvesadapter.exception.DMaapException; - -public class DMaaPMRBaseConfigTest { - DMaaPMRBaseConfig dmaapMRBaseConfig = null; - public static final String JSON_APPLICATION_TYPE = "application/json"; - - @Before - public void setUp() throws Exception { - dmaapMRBaseConfig = Mockito.mock(DMaaPMRBaseConfig.class, Mockito.CALLS_REAL_METHODS); - } - - @Test - public void testDMaaPMRBaseConfigGetMethods() { - assertNotNull(dmaapMRBaseConfig); - assertNull(dmaapMRBaseConfig.getHostName()); - assertNull(dmaapMRBaseConfig.getPortNumber()); - assertNull(dmaapMRBaseConfig.getTopicName()); - assertNull(dmaapMRBaseConfig.getProtocol()); - assertNull(dmaapMRBaseConfig.getContentType()); - assertNull(dmaapMRBaseConfig.getUserName()); - assertNull(dmaapMRBaseConfig.getUserPassword()); - } - - @Test(expected = DMaapException.class) - public void testNormalizeValidateProtocol() { - DMaaPMRBaseConfig.normalizeValidateProtocol(""); - } - - @Test(expected = DMaapException.class) - public void testNormalizeValidateProtocolWithDifferentProtocol() { - DMaaPMRBaseConfig.normalizeValidateProtocol("FTP"); - } - - @Test - public void testNormalizeValidateProtocolWithProperValue() { - assertEquals("https", DMaaPMRBaseConfig.normalizeValidateProtocol("HTTPS")); - assertEquals("http", DMaaPMRBaseConfig.normalizeValidateProtocol("HTTP")); - } - - @Test(expected = DMaapException.class) - public void testNormalizeValidateContentType() { - DMaaPMRBaseConfig.normalizeValidateContentType(""); - } - - @Test - public void testNormalizeValidateContentTypeWithProperValue() { - assertEquals(JSON_APPLICATION_TYPE, DMaaPMRBaseConfig.normalizeValidateContentType("application/json")); - } -} diff --git a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/configs/DmaapMrBaseConfigTest.java b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/configs/DmaapMrBaseConfigTest.java new file mode 100644 index 0000000..495722f --- /dev/null +++ b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/configs/DmaapMrBaseConfigTest.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Samsung. 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.onap.universalvesadapter.configs; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.universalvesadapter.exception.DMaapException; + +public class DmaapMrBaseConfigTest { + DMaaPMRBaseConfig dmaapMrBaseConfig = null; + public static final String JSON_APPLICATION_TYPE = "application/json"; + + @Before + public void setUp() throws Exception { + dmaapMrBaseConfig = Mockito.mock(DMaaPMRBaseConfig.class, Mockito.CALLS_REAL_METHODS); + } + + @Test + public void testDmaapMrBaseConfigGetMethods() { + assertNotNull(dmaapMrBaseConfig); + assertNull(dmaapMrBaseConfig.getHostName()); + assertNull(dmaapMrBaseConfig.getPortNumber()); + assertNull(dmaapMrBaseConfig.getTopicName()); + assertNull(dmaapMrBaseConfig.getProtocol()); + assertNull(dmaapMrBaseConfig.getContentType()); + assertNull(dmaapMrBaseConfig.getUserName()); + assertNull(dmaapMrBaseConfig.getUserPassword()); + } + + @Test(expected = DMaapException.class) + public void testNormalizeValidateProtocol() { + DMaaPMRBaseConfig.normalizeValidateProtocol(""); + } + + @Test(expected = DMaapException.class) + public void testNormalizeValidateProtocolWithDifferentProtocol() { + DMaaPMRBaseConfig.normalizeValidateProtocol("FTP"); + } + + @Test + public void testNormalizeValidateProtocolWithProperValue() { + assertEquals("https", DMaaPMRBaseConfig.normalizeValidateProtocol("HTTPS")); + assertEquals("http", DMaaPMRBaseConfig.normalizeValidateProtocol("HTTP")); + } + + @Test(expected = DMaapException.class) + public void testNormalizeValidateContentType() { + DMaaPMRBaseConfig.normalizeValidateContentType(""); + } + + @Test + public void testNormalizeValidateContentTypeWithProperValue() { + assertEquals(JSON_APPLICATION_TYPE, + DMaaPMRBaseConfig.normalizeValidateContentType("application/json")); + } +} diff --git a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/controller/VesControllerTest.java b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/controller/VesControllerTest.java index cbacc61..829ae0d 100644 --- a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/controller/VesControllerTest.java +++ b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/controller/VesControllerTest.java @@ -1,65 +1,69 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* 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.universalvesadapter.controller; - -import static org.junit.Assert.assertEquals; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.universalvesadapter.Application; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.MvcResult; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes=Application.class) -@AutoConfigureMockMvc -@Ignore -public class VesControllerTest { - - @Autowired - private MockMvc mockMvc; - - @Test - public void startShouldReturnApplicationStartedMessage() throws Exception { - - MvcResult mvcResult = this.mockMvc.perform(get("/start")).andDo(print()).andExpect(status().isOk()) - .andReturn();//Expect(jsonPath("$.content").value("Application started")); - assertEquals("Application started", mvcResult.getResponse().getContentAsString()); - } - - @Test - public void stopShouldReturnApplicationStoppingMessage() throws Exception { - - MvcResult mvcResult = this.mockMvc.perform(get("/stop")).andDo(print()).andExpect(status().isOk()) - .andReturn();//.andExpect(jsonPath("$.content").value("Application will be stopped soon")); - assertEquals("Application will be stopped soon", mvcResult.getResponse().getContentAsString()); - } - - - -} +/*- + * ============LICENSE_START======================================================= + * ONAP : DCAE + * ================================================================================ + * Copyright 2018-2019 TechMahindra + * ================================================================================ + * 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.universalvesadapter.controller; + +import static org.junit.Assert.assertEquals; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.universalvesadapter.Application; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class) +@AutoConfigureMockMvc +@Ignore +public class VesControllerTest { + + @Autowired + private MockMvc mockMvc; + + @Test + public void startShouldReturnApplicationStartedMessage() throws Exception { + + MvcResult mvcResult = this.mockMvc.perform(get("/start")).andDo(print()) + .andExpect(status().isOk()).andReturn(); + // Expect(jsonPath("$.content").value("Application started")); + assertEquals("Application started", mvcResult.getResponse().getContentAsString()); + } + + @Test + public void stopShouldReturnApplicationStoppingMessage() throws Exception { + + MvcResult mvcResult = this.mockMvc.perform(get("/stop")).andDo(print()) + .andExpect(status().isOk()).andReturn(); + // .andExpect(jsonPath("$.content").value("Application will be stopped soon")); + assertEquals("Application will be stopped soon", + mvcResult.getResponse().getContentAsString()); + } + + + +} diff --git a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/exception/ConfigFileSmooksConversionExceptionTest.java b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/exception/ConfigFileSmooksConversionExceptionTest.java index ac60be1..ff30305 100644 --- a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/exception/ConfigFileSmooksConversionExceptionTest.java +++ b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/exception/ConfigFileSmooksConversionExceptionTest.java @@ -1,35 +1,37 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* 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.universalvesadapter.exception; - -import org.junit.Test; - -public class ConfigFileSmooksConversionExceptionTest { - - - @Test - public void test() { - ConfigFileSmooksConversionException se = new ConfigFileSmooksConversionException("message"); - ConfigFileSmooksConversionException se1 = new ConfigFileSmooksConversionException("message", se); - - - } - -} +/*- + * ============LICENSE_START======================================================= + * ONAP : DCAE + * ================================================================================ + * Copyright 2018-2019 TechMahindra + * ================================================================================ + * 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.universalvesadapter.exception; + +import org.junit.Test; + +public class ConfigFileSmooksConversionExceptionTest { + + + @Test + public void test() { + ConfigFileSmooksConversionException se = new ConfigFileSmooksConversionException("message"); + ConfigFileSmooksConversionException se1 = + new ConfigFileSmooksConversionException("message", se); + + + } + +} diff --git a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/exception/DMaapExceptionTest.java b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/exception/DMaapExceptionTest.java index 4da29de..0f24229 100644 --- a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/exception/DMaapExceptionTest.java +++ b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/exception/DMaapExceptionTest.java @@ -1,41 +1,43 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* 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.universalvesadapter.exception; - -import static org.junit.Assert.assertNotNull; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DMaapExceptionTest { - private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); - - @Test - public void test() { - DMaapException se = new DMaapException("message"); - assertNotNull(se); - DMaapException se1 = new DMaapException("message", se); - assertNotNull(se1); - DMaapException se2 = new DMaapException("message", se.getCause()); - assertNotNull(se2); - DMaapException se3 = new DMaapException("message", debugLogger, se); - assertNotNull(se3); - } -} +/*- + * ============LICENSE_START======================================================= + * ONAP : DCAE + * ================================================================================ + * Copyright 2018-2019 TechMahindra + * ================================================================================ + * 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.universalvesadapter.exception; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DMaapExceptionTest { + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + + @Test + public void test() { + DMaapException se = new DMaapException("message"); + assertNotNull(se); + DMaapException se1 = new DMaapException("message", se); + assertNotNull(se1); + DMaapException se2 = new DMaapException("message", se.getCause()); + assertNotNull(se2); + DMaapException se3 = new DMaapException("message", debugLogger, se); + assertNotNull(se3); + } +} diff --git a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/exception/MapperConfigExceptionTest.java b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/exception/MapperConfigExceptionTest.java index 19dfd87..966bf4a 100644 --- a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/exception/MapperConfigExceptionTest.java +++ b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/exception/MapperConfigExceptionTest.java @@ -1,32 +1,33 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* 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.universalvesadapter.exception; - -import org.junit.Test; - -public class MapperConfigExceptionTest { - - @Test - public void test() { - MapperConfigException se = new MapperConfigException("message"); - MapperConfigException se1 = new MapperConfigException("message", se); - } - -} +/*- + * ============LICENSE_START======================================================= + * ONAP : DCAE + * ================================================================================ + * Copyright 2018-2019 TechMahindra + * ================================================================================ + * 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.universalvesadapter.exception; + +import org.junit.Test; + +public class MapperConfigExceptionTest { + + @Test + public void test() { + MapperConfigException se = new MapperConfigException("message"); + MapperConfigException se1 = new MapperConfigException("message", se); + } + +} diff --git a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/mappingconfig/EntryTest.java b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/mappingconfig/EntryTest.java index d72892b..0097658 100644 --- a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/mappingconfig/EntryTest.java +++ b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/mappingconfig/EntryTest.java @@ -1,59 +1,60 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* 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.universalvesadapter.mappingconfig; - -import static org.junit.Assert.*; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; -import org.mockito.Mock; -import org.springframework.beans.factory.annotation.Autowired; - -public class EntryTest { - - @Autowired - Entry entry = new Entry(); - @Mock - Evaluation evaluation = new Evaluation(); - Object value = new Object(); - Map additionalProperties = new HashMap(); - - @Test - public void test() { - entry.setPriority(1); - entry.setEvaluation(evaluation); - entry.setResult("result"); - entry.setAdditionalProperty("name", value); - - additionalProperties.put("name", value); - assertEquals(entry.getEvaluation(), evaluation); - assertEquals(entry.getPriority(), new Integer(1)); - assertEquals(entry.getResult(),"result"); - assertEquals(entry.getAdditionalProperties(), additionalProperties); - assert (entry.toString() != null); - assert (entry.hashCode() != 0); - - assert (entry.equals(entry)); - - } - -} +/*- + * ============LICENSE_START======================================================= + * ONAP : DCAE + * ================================================================================ + * Copyright 2018-2019 TechMahindra + * ================================================================================ + * 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.universalvesadapter.mappingconfig; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.mockito.Mock; +import org.springframework.beans.factory.annotation.Autowired; + +public class EntryTest { + + @Autowired + Entry entry = new Entry(); + @Mock + Evaluation evaluation = new Evaluation(); + Object value = new Object(); + Map additionalProperties = new HashMap(); + + @Test + public void test() { + entry.setPriority(1); + entry.setEvaluation(evaluation); + entry.setResult("result"); + entry.setAdditionalProperty("name", value); + + additionalProperties.put("name", value); + assertEquals(entry.getEvaluation(), evaluation); + assertEquals(entry.getPriority(), new Integer(1)); + assertEquals(entry.getResult(), "result"); + assertEquals(entry.getAdditionalProperties(), additionalProperties); + assert (entry.toString() != null); + assert (entry.hashCode() != 0); + + assert (entry.equals(entry)); + + } + +} diff --git a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/mappingconfig/EvaluationTest.java b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/mappingconfig/EvaluationTest.java index a3b9db6..5799d01 100644 --- a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/mappingconfig/EvaluationTest.java +++ b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/mappingconfig/EvaluationTest.java @@ -1,70 +1,70 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* 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.universalvesadapter.mappingconfig; - -import static org.junit.Assert.*; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; - -public class EvaluationTest { - - @Autowired - Evaluation evaluation =new Evaluation(); - Evaluation lhs =new Evaluation(); - Evaluation rhs =new Evaluation(); - Object value = new Object(); - Map additionalProperties = new HashMap(); - - @Test - public void test() { - evaluation.setAdditionalProperty("name", value); - evaluation.setDatatype("datatype"); - evaluation.setField("field"); - evaluation.setLhs(lhs); - evaluation.setOperand("operand"); - evaluation.setRhs(rhs); - evaluation.setValue("value"); - additionalProperties.put("name", value); - - assertEquals(evaluation.getAdditionalProperties(), additionalProperties); - assertEquals(evaluation.getDatatype(),"datatype"); - assertEquals(evaluation.getField(),"field"); - assertEquals(evaluation.getLhs(),lhs); - assertEquals(evaluation.getOperand(),"operand"); - assertEquals(evaluation.getRhs(),rhs); - assertEquals(evaluation.getValue(),"value"); - - assert (evaluation.toString() != null); - assert (evaluation.hashCode() != 0); - - assert (evaluation.equals(evaluation)); - assertEquals(evaluation.equals(value),false); - assertEquals(evaluation.equals(null),false); - - - - - } - -} +/*- + * ============LICENSE_START======================================================= + * ONAP : DCAE + * ================================================================================ + * Copyright 2018-2019 TechMahindra + * ================================================================================ + * 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.universalvesadapter.mappingconfig; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +public class EvaluationTest { + + @Autowired + Evaluation evaluation = new Evaluation(); + Evaluation lhs = new Evaluation(); + Evaluation rhs = new Evaluation(); + Object value = new Object(); + Map additionalProperties = new HashMap(); + + @Test + public void test() { + evaluation.setAdditionalProperty("name", value); + evaluation.setDatatype("datatype"); + evaluation.setField("field"); + evaluation.setLhs(lhs); + evaluation.setOperand("operand"); + evaluation.setRhs(rhs); + evaluation.setValue("value"); + additionalProperties.put("name", value); + + assertEquals(evaluation.getAdditionalProperties(), additionalProperties); + assertEquals(evaluation.getDatatype(), "datatype"); + assertEquals(evaluation.getField(), "field"); + assertEquals(evaluation.getLhs(), lhs); + assertEquals(evaluation.getOperand(), "operand"); + assertEquals(evaluation.getRhs(), rhs); + assertEquals(evaluation.getValue(), "value"); + + assert (evaluation.toString() != null); + assert (evaluation.hashCode() != 0); + + assert (evaluation.equals(evaluation)); + assertEquals(evaluation.equals(value), false); + assertEquals(evaluation.equals(null), false); + + + + } + +} diff --git a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/mappingconfig/MapperConfigTest.java b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/mappingconfig/MapperConfigTest.java index 474ba05..a9cf2b0 100644 --- a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/mappingconfig/MapperConfigTest.java +++ b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/mappingconfig/MapperConfigTest.java @@ -1,54 +1,55 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* 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.universalvesadapter.mappingconfig; - -import static org.junit.Assert.*; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; - -public class MapperConfigTest { - - @Autowired - MapperConfig mapperConfig = new MapperConfig(); - Map additionalProperties = new HashMap(); - Object value = new Object(); - Set entries = null; - - @Test - public void test() { - mapperConfig.setAdditionalProperty("name", value); - mapperConfig.setEntries(entries); - additionalProperties.put("name", value); - - assertEquals(mapperConfig.getAdditionalProperties(),additionalProperties); - assertEquals(mapperConfig.getEntries(),entries); - assert (mapperConfig.toString() != null); - assert (mapperConfig.hashCode() != 0); - - assert (mapperConfig.equals(mapperConfig)); - - } - -} +/*- + * ============LICENSE_START======================================================= + * ONAP : DCAE + * ================================================================================ + * Copyright 2018-2019 TechMahindra + * ================================================================================ + * 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.universalvesadapter.mappingconfig; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +public class MapperConfigTest { + + @Autowired + MapperConfig mapperConfig = new MapperConfig(); + Map additionalProperties = new HashMap(); + Object value = new Object(); + Set entries = null; + + @Test + public void test() { + mapperConfig.setAdditionalProperty("name", value); + mapperConfig.setEntries(entries); + additionalProperties.put("name", value); + + assertEquals(mapperConfig.getAdditionalProperties(), additionalProperties); + assertEquals(mapperConfig.getEntries(), entries); + assert (mapperConfig.toString() != null); + assert (mapperConfig.hashCode() != 0); + + assert (mapperConfig.equals(mapperConfig)); + + } + +} diff --git a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/service/VesServiceTest.java b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/service/VesServiceTest.java index 3ad47f0..2e6ed56 100644 --- a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/service/VesServiceTest.java +++ b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/service/VesServiceTest.java @@ -1,144 +1,100 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* 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.universalvesadapter.service; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; - -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.onap.universalvesadapter.Application; -import org.onap.universalvesadapter.exception.DMaapException; -import org.onap.universalvesadapter.service.DMaapService; -import org.onap.universalvesadapter.service.VesService; -import org.onap.universalvesadapter.utils.ParallelTasks; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.att.nsa.mr.client.MRConsumer; -@Ignore -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Application.class) -public class VesServiceTest { - - @InjectMocks - @Autowired - private VesService vesService; - - @Mock - private DMaapService dmaapService; - - private final Logger eLOGGER = LoggerFactory.getLogger(this.getClass()); - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - } - - - @Test - public void testStart() throws IOException { - - String[] incomingMessages = {"{ " - + " \"protocol version \": \"v2c \", " - + " \"notify OID \": \".1.3.6.1.4.1.74.2.46.12.1.1AAA \", " - + " \"cambria.partition \": \"dcae-snmp.client.research.att.com \", " - + " \"trap category \": \"UCSNMP-HEARTBEAT \", " - + " \"epoch_serno \": 15161177410000, " - + " \"community \": \"public \", " - + " \"time received \": 1516117741, " - + " \"agent name \": \"localhost \", " - + " \"agent address \": \"127.0.0.1 \", " - + " \"community len \": 6, " - + " \"notify OID len \": 12, " - + " \"varbinds \": [{ " - + " \"varbind_type \": \"octet \", " - + " \"varbind_oid \": \".1.3.6.1.4.1.74.2.46.12.1.1.1 \", " - + " \"varbind_value \": \"ucsnmp heartbeat - ignore \" " - + " }, { " - + " \"varbind_type \": \"octet \", " - + " \"varbind_oid \": \".1.3.6.1.4.1.74.2.46.12.1.1.2 \", " - + " \"varbind_value \": \"Tue Jan 16 10:49:01 EST 2018 \" " - + " }] " - + "}"}; - try { - // Mockito.when(dmaapService.fetchAndPublishInDMaaP(null,null)).thenReturn(Arrays.asList(incomingMessages)).thenReturn(() -> Collections.emptyIterator()); - } catch (Exception e) { - eLOGGER.error("Error occurred : " + e.getMessage()); - } - - ArgumentCaptor valueCapture = ArgumentCaptor.forClass(String.class); - try { - //doNothing().when(dmaapService).fetchAndPublishInDMaaP((String) valueCapture.capture()); - } catch (DMaapException e) { - eLOGGER.error("Error occurred : " + e.getMessage()); - } - - - new Thread(new Runnable() { - - @Override - public void run() { - // TODO Auto-generated method stub - vesService.start(); - - } - }).start(); - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - new Thread(new Runnable() { - - @Override - public void run() { - // TODO Auto-generated method stub - vesService.stop(); - - } - }).start(); - String result = "{\"event\":{\"commonEventHeader\":{},\"faultFields\":{},\"measurementsForVfScalingFields\":{\"additionalMeasurements\":[]}}}"; - assertEquals(result, valueCapture.getValue()); - } - - @Test - public void testStop() { - fail("Not yet implemented"); - } - -} -*/ \ No newline at end of file +/*- + * ============LICENSE_START======================================================= + * ONAP : DCAE + * ================================================================================ + * Copyright 2018-2019 TechMahindra + * ================================================================================ + * 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.universalvesadapter.service; + * + * import static org.junit.Assert.*; import static org.mockito.Mockito.doNothing; import static + * org.mockito.Mockito.doReturn; + * + * import java.io.IOException; import java.util.Arrays; import java.util.Collections; + * + * import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import + * org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; + * import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; + * import org.onap.universalvesadapter.Application; import + * org.onap.universalvesadapter.exception.DMaapException; import + * org.onap.universalvesadapter.service.DMaapService; import + * org.onap.universalvesadapter.service.VesService; import + * org.onap.universalvesadapter.utils.ParallelTasks; import org.slf4j.Logger; import + * org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import + * org.springframework.boot.test.context.SpringBootTest; import + * org.springframework.test.context.junit4.SpringRunner; + * + * import com.att.nsa.mr.client.MRConsumer; + * + * @Ignore + * + * @RunWith(SpringRunner.class) + * + * @SpringBootTest(classes = Application.class) public class VesServiceTest { + * + * @InjectMocks + * + * @Autowired private VesService vesService; + * + * @Mock private DMaapService dmaapService; + * + * private final Logger eLOGGER = LoggerFactory.getLogger(this.getClass()); + * + * @Before public void init() { MockitoAnnotations.initMocks(this); } + * + * + * @Test public void testStart() throws IOException { + * + * String[] incomingMessages = {"{ " + " \"protocol version \": \"v2c \", " + + * " \"notify OID \": \".1.3.6.1.4.1.74.2.46.12.1.1AAA \", " + + * " \"cambria.partition \": \"dcae-snmp.client.research.att.com \", " + + * " \"trap category \": \"UCSNMP-HEARTBEAT \", " + " \"epoch_serno \": 15161177410000, " + + * " \"community \": \"public \", " + " \"time received \": 1516117741, " + + * " \"agent name \": \"localhost \", " + " \"agent address \": \"127.0.0.1 \", " + + * " \"community len \": 6, " + " \"notify OID len \": 12, " + " \"varbinds \": [{ " + + * " \"varbind_type \": \"octet \", " + + * " \"varbind_oid \": \".1.3.6.1.4.1.74.2.46.12.1.1.1 \", " + + * " \"varbind_value \": \"ucsnmp heartbeat - ignore \" " + " }, { " + + * " \"varbind_type \": \"octet \", " + + * " \"varbind_oid \": \".1.3.6.1.4.1.74.2.46.12.1.1.2 \", " + + * " \"varbind_value \": \"Tue Jan 16 10:49:01 EST 2018 \" " + " }] " + "}"}; try { // + * Mockito.when(dmaapService.fetchAndPublishInDMaaP(null,null)). + * thenReturn(Arrays.asList(incomingMessages)).thenReturn(() -> Collections.emptyIterator()); + * + * } catch (Exception e) { eLOGGER.error("Error occurred : " + e.getMessage()); } + * + * ArgumentCaptor valueCapture = ArgumentCaptor.forClass(String.class); try { + * //doNothing().when(dmaapService).fetchAndPublishInDMaaP((String) valueCapture.capture()); } catch + * (DMaapException e) { eLOGGER.error("Error occurred : " + e.getMessage()); } + * + * + * new Thread(new Runnable() { + * + * @Override public void run() { // TODO Auto-generated method stub vesService.start(); + * + * } }).start(); try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated + * catch block e.printStackTrace(); } new Thread(new Runnable() { + * + * @Override public void run() { // TODO Auto-generated method stub vesService.stop(); + * + * } }).start(); String result = "{\"event\":{\"commonEventHeader\":{},\"faultFields\":{}, + * \"measurementsForVfScalingFields\":{\"additionalMeasurements\":[]}}}"; assertEquals(result, + * valueCapture.getValue()); } + * + * @Test public void testStop() { fail("Not yet implemented"); } + * + * } + */ diff --git a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/utils/SmooksUtilsTest.java b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/utils/SmooksUtilsTest.java index 13a5e78..19fcaa2 100644 --- a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/utils/SmooksUtilsTest.java +++ b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/utils/SmooksUtilsTest.java @@ -1,121 +1,128 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* 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========================================================= -*/ - +/*- + * ============LICENSE_START======================================================= + * ONAP : DCAE + * ================================================================================ + * Copyright 2018-2019 TechMahindra + * ================================================================================ + * 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.universalvesadapter.utils; import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; + import org.junit.Test; import org.milyn.Smooks; -import org.onap.dcaegen2.ves.domain.ves7_0.VesEvent; +import org.onap.dcaegen2.ves.domain.ves70.VesEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; public class SmooksUtilsTest { - - - VesEvent vesEvent; - private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); - - @Test - public void testGetTransformedObjectForInput() { - StringBuffer incomingJsonString = new StringBuffer("{\n" + " \"rule-id\": \"12121\",\n" - + " \"notification\": {\n" + " \"event-time\": \"2018-03-15T08:15:32.000Z\",\n" - + " \"notification-id\": \"2541256\",\n" + " \"message\": {\n" - + " \"topic\":\"resource\",\n" - + " \"object-type\":\"onu\", \n" - + " \"version\": \"v1\", \n" - + " \"operation\": \"create\", \n" - + " \"target\": \"ont/ont=23hk1231231232\", \n" - + " \"content\": {\n" + " \"onu\": {\n" - + " \"sn\": \"48575443FA637D1A\",\n" - + " \"refParentNE\": \"550e8400-e29b-41d4-a716-446655440000\",\n" - + " \"refParentNeNativeId\": \"FDN\",\n" - + " \"refParentLTP\": \"8c0db89e-218c-4e18-b0de-7a6788b3dda4\",\n" - + " \"refParentLTPNativeId\": \"FDN\",\n" - + " \"onuId\": \"213\",\n" - + " \"accessID\": \"HG65875420001\"\n" + " }\n" - + " }\n" + " }\n" + " }\n" + "}"); - StringBuffer configFileData = new StringBuffer("\n" - + "\n" - + " \n" - + " \n" - + " \n" - + " \n" + " \n" - + " \n" - + " \n" + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + "" - + "org.onap.dcaegen2.ves.domain.ves7_0.CommonEventHeader.Version._4_0_1 \n" - + "\"pnfRegistration\"\n" - + "" - + "org.onap.dcaegen2.ves.domain.ves7_0.CommonEventHeader.VesEventListenerVersion._7_0_1\n" - + " " - + "\"registration_\"+commonEventHeader.ts1\n" - + "\"VESMapper\"\n" - + " " - + "org.onap.dcaegen2.ves.domain.ves7_0.CommonEventHeader.Domain.PNF_REGISTRATION\n" - + " " - + "commonEventHeader.domain\n" - + "\n" - + "" - + "commonEventHeader.ts1\n" - + " " - + "commonEventHeader.ts1\n" + " " - + "org.onap.dcaegen2.ves.domain.ves7_0.CommonEventHeader.Priority.NORMAL\n" - + " \n" - + " \n" - + " \n" + " \n" - + " " - + "org.onap.dcaegen2.ves.domain.ves7_0.PnfRegistrationFields.PnfRegistrationFieldsVersion._2_0" - + "\n" - + " \n" - + " \n" + " \n" + ""); - - Smooks smooks = null; - - try { - // reading config file.. for now, looking at it as just one time operation - if (null == smooks) { - - smooks = new Smooks( - new ByteArrayInputStream(configFileData.toString().getBytes(StandardCharsets.UTF_8))); - } - - vesEvent = SmooksUtils.getTransformedObjectForInput(smooks, incomingJsonString.toString()); - } catch (IOException | SAXException exception) { - errorLogger.error("Error occurred : ", exception); + + + VesEvent vesEvent; + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); + + @Test + public void testGetTransformedObjectForInput() { + StringBuffer incomingJsonString = new StringBuffer("{\n" + " \"rule-id\": \"12121\",\n" + + " \"notification\": {\n" + + " \"event-time\": \"2018-03-15T08:15:32.000Z\",\n" + + " \"notification-id\": \"2541256\",\n" + " \"message\": {\n" + + " \"topic\":\"resource\",\n" + + " \"object-type\":\"onu\", \n" + + " \"version\": \"v1\", \n" + + " \"operation\": \"create\", \n" + + " \"target\": \"ont/ont=23hk1231231232\", \n" + + " \"content\": {\n" + " \"onu\": {\n" + + " \"sn\": \"48575443FA637D1A\",\n" + + " \"refParentNE\": \"550e8400-e29b-41d4-a716-446655440000\",\n" + + " \"refParentNeNativeId\": \"FDN\",\n" + + " \"refParentLTP\": \"8c0db89e-218c-4e18-b0de-7a6788b3dda4\",\n" + + " \"refParentLTPNativeId\": \"FDN\",\n" + + " \"onuId\": \"213\",\n" + + " \"accessID\": \"HG65875420001\"\n" + " }\n" + + " }\n" + " }\n" + " }\n" + "}"); + StringBuffer configFileData = + new StringBuffer("\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "" + + "org.onap.dcaegen2.ves.domain.ves70.CommonEventHeader.Version._4_0_1 \n" + + "\"pnfRegistration\"\n" + + "" + + "org.onap.dcaegen2.ves.domain.ves70.CommonEventHeader.VesEventListenerVersion._7_0_1" + + "\n" + + " " + + "\"registration_\"+commonEventHeader.ts1\n" + + "\"VESMapper\"\n" + + " " + + "org.onap.dcaegen2.ves.domain.ves70.CommonEventHeader.Domain.PNF_REGISTRATION" + + "\n" + + " " + + "commonEventHeader.domain\n" + + "\n" + + "" + + "commonEventHeader.ts1\n" + + " " + + "commonEventHeader.ts1\n" + + " " + + "org.onap.dcaegen2.ves.domain.ves70.CommonEventHeader.Priority.NORMAL\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " " + + "org.onap.dcaegen2.ves.domain.ves70.PnfRegistrationFields.PnfRegistrationFieldsVersion._2_0" + + "\n" + + " \n" + + " \n" + " \n" + ""); + + Smooks smooks = null; + + try { + // reading config file.. for now, looking at it as just one time operation + if (null == smooks) { + + smooks = new Smooks(new ByteArrayInputStream( + configFileData.toString().getBytes(StandardCharsets.UTF_8))); + } + + vesEvent = + SmooksUtils.getTransformedObjectForInput(smooks, incomingJsonString.toString()); + } catch (IOException | SAXException exception) { + errorLogger.error("Error occurred : ", exception); + } } - } } - - \ No newline at end of file + -- cgit 1.2.3-korg