X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=UniversalVesAdapter%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Funiversalvesadapter%2Futils%2FSmooksUtilsTest.java;fp=UniversalVesAdapter%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Funiversalvesadapter%2Futils%2FSmooksUtilsTest.java;h=41431f70217bc248b1a176d81dab36b2cc15307a;hb=d2009aeed90083a9a4e5d2c3e525ca4b80a183b9;hp=0000000000000000000000000000000000000000;hpb=00a00a68862effd791ce3f127d0ddd5903598b89;p=dcaegen2%2Fservices%2Fmapper.git diff --git a/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/utils/SmooksUtilsTest.java b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/utils/SmooksUtilsTest.java new file mode 100644 index 0000000..41431f7 --- /dev/null +++ b/UniversalVesAdapter/src/test/java/org/onap/universalvesadapter/utils/SmooksUtilsTest.java @@ -0,0 +1,134 @@ +/* +* ============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.utils; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.beans.beancontext.BeanContext; +import java.io.ByteArrayInputStream; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.milyn.Smooks; +import org.milyn.container.ExecutionContext; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.dcaegen2.ves.domain.VesEvent; +import org.onap.universalvesadapter.exception.MapperConfigException; +import org.onap.universalvesadapter.utils.SmooksUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.util.FileCopyUtils; +import org.xml.sax.SAXException; + +public class SmooksUtilsTest { + + private final Logger eLOGGER = LoggerFactory.getLogger(this.getClass()); + + @Test + public void testGetTransformedObjectForInput() { + StringBuffer incomingJsonString = new StringBuffer("{ ") + .append("\"protocol version\":\"v2c\", ") + .append("\"notify OID\":\".1.3.6.1.4.1.74.2.46.12.1.1AAA\", ") + .append("\"cambria.partition\":\"dcae-snmp.client.research.att.com\", ") + .append("\"trap category\":\"UCSNMP-HEARTBEAT\", ") + .append("\"epoch_serno\": 15161177410000, ") + .append("\"community\":\"public\", ") + .append("\"time received\": 1516117741, ") + .append("\"agent name\":\"localhost\", ") + .append("\"agent address\":\"127.0.0.1\", ") + .append("\"community len\": 6, ") + .append("\"notify OID len\": 12, ") + .append("\"varbinds\": [{ ") + .append(" \"varbind_type\":\"octet\", ") + .append(" \"varbind_oid\":\".1.3.6.1.4.1.74.2.46.12.1.1.1\", ") + .append(" \"varbind_value\":\"ucsnmp heartbeat - ignore\" ") + .append(" }, { ") + .append(" \"varbind_type\":\"octet\", ") + .append(" \"varbind_oid\":\".1.3.6.1.4.1.74.2.46.12.1.1.2\", ") + .append(" \"varbind_value\":\"Tue Jan 16 10:49:01 EST 2018\" ") + .append(" }] ") + .append("}"); + StringBuffer configFileData = new StringBuffer(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(" ") + .append(""); + + Smooks smooks = null; + VesEvent vesEvent = new VesEvent(); + 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) { + eLOGGER.error("Error occurred : ", exception ); + } + + assertEquals(vesEvent.getEvent().getCommonEventHeader().getDomain(), "UCSNMP-HEARTBEAT"); + + + } + +}