diff options
author | arkadiusz.adamski <aadamski@est.tech> | 2021-03-11 09:55:54 +0000 |
---|---|---|
committer | arkadiusz.adamski <aadamski@est.tech> | 2021-03-15 09:57:37 +0000 |
commit | 583337cbe603f3548295a1929b7bc7b01f98e405 (patch) | |
tree | b2b088b2fe9df74b220c473006c4f70d1e502b2f | |
parent | 1427ee15da3fc155d96b495925f47bfcccc1c2b5 (diff) |
Increase code coverage
- increased test coverage in the event.protocol.xml package
Issue-ID: POLICY-3092
Change-Id: Ie68f8acf49d258536ddc23a14d05302273687634
Signed-off-by: arkadiusz.adamski <aadamski@est.tech>
2 files changed, 96 insertions, 1 deletions
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventHandlerTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventHandlerTest.java index caa3bd06f..609b0471b 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventHandlerTest.java +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventHandlerTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,9 +29,13 @@ import static org.junit.Assert.assertTrue; import java.util.Date; import java.util.HashMap; import java.util.Map; +import java.util.Random; +import org.apache.commons.lang3.RandomStringUtils; import org.junit.Test; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.service.engine.event.ApexEvent; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -44,6 +48,44 @@ public class XmlEventHandlerTest { private static final XLogger logger = XLoggerFactory.getXLogger(XmlEventHandlerTest.class); /** + * Test XML to apex event. Null value is passed as parameter. + * + * @throws ApexException on Apex event handling errors + */ + @Test(expected = ApexException.class) + public void testApexEventToApexNullObject() throws ApexException { + final Apex2XmlEventConverter xmlEventConverter = new Apex2XmlEventConverter(); + // This is only for code coverage stats. This method does nothing + xmlEventConverter.init(null); + + xmlEventConverter.toApexEvent("XMLEventName", null); + } + + /** + * Test XML to apex event. There is no string passed as parameter. + * + * @throws ApexException on Apex event handling errors + */ + @Test(expected = ApexEventRuntimeException.class) + public void testApexEventToApexNotString() throws ApexException { + final Apex2XmlEventConverter xmlEventConverter = new Apex2XmlEventConverter(); + + xmlEventConverter.toApexEvent("XMLEventName", new Random().nextInt()); + } + + /** + * Test not valid XML to apex event. + * + * @throws ApexException on Apex event handling errors + */ + @Test(expected = ApexException.class) + public void testApexEventToApexNotXml() throws ApexException { + final Apex2XmlEventConverter xmlEventConverter = new Apex2XmlEventConverter(); + + xmlEventConverter.toApexEvent("XMLEventName", RandomStringUtils.randomAlphabetic(25)); + } + + /** * Test XML to apex event. * * @throws ApexException on Apex event handling errors @@ -80,6 +122,17 @@ public class XmlEventHandlerTest { } /** + * Test null as apex event to xml. + * + * @throws ApexEventException on Apex event handling errors + */ + @Test(expected = ApexEventException.class) + public void testApexEventToXmlNullEvent() throws ApexEventException { + final Apex2XmlEventConverter xmlEventConverter = new Apex2XmlEventConverter(); + xmlEventConverter.fromApexEvent(null); + } + + /** * Test apex event to xml. * * @throws ApexException on Apex event handling errors @@ -96,6 +149,7 @@ public class XmlEventHandlerTest { event0000DataMap.put("TestMatchCase", 12345); event0000DataMap.put("TestTimestamp", event0000StartTime.getTime()); event0000DataMap.put("TestTemperature", 34.5445667); + event0000DataMap.put("NullValue", null); final ApexEvent apexEvent0000 = new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.sample.events", "test", "apex"); @@ -109,6 +163,7 @@ public class XmlEventHandlerTest { assertTrue(apexEvent0000XmlString.contains("<version>0.0.1</version>")); assertTrue(apexEvent0000XmlString.contains("<value>This is a test slogan</value>")); assertTrue(apexEvent0000XmlString.contains("<value>12345</value>")); + assertTrue(apexEvent0000XmlString.contains("<value></value>")); assertTrue(apexEvent0000XmlString.contains("<value>" + event0000StartTime.getTime() + "</value>")); assertTrue(apexEvent0000XmlString.contains("<value>34.5445667</value>")); diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventProtocolParametersTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventProtocolParametersTest.java new file mode 100644 index 000000000..27fd22095 --- /dev/null +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventProtocolParametersTest.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.event.protocol.xml; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class XmlEventProtocolParametersTest { + + /** + * Test object creation. + */ + @Test + public void instantiationTest() { + final XmlEventProtocolParameters parameters = new XmlEventProtocolParameters(); + + assertEquals(XmlEventProtocolParameters.XML_EVENT_PROTOCOL_LABEL, parameters.getLabel()); + assertEquals("<?xml", parameters.getStartDelimiterToken()); + assertEquals(Apex2XmlEventConverter.class.getName(), parameters.getEventProtocolPluginClass()); + } +}
\ No newline at end of file |