diff options
author | arkadiusz.adamski <aadamski@est.tech> | 2021-04-12 09:52:25 +0100 |
---|---|---|
committer | arkadiusz.adamski <aadamski@est.tech> | 2021-04-20 12:44:43 +0100 |
commit | 5e59b82e346ce619513bafd7c01dd2cbfb9123d5 (patch) | |
tree | 7bc527839df4ca6a6a48a2c16e051f03f1f896be /plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java | |
parent | 7e30c78bc1b37d311f045b90e0cda41a6b0bf94d (diff) |
Code coverage for plugins jms event carrier
- Increase code coverage for plugins jms event carrier
Issue-ID: POLICY-3109
Signed-off-by: arkadiusz.adamski <aadamski@est.tech>
Change-Id: I28dd8c5b32eb91f8f5047916e8899439d4c62374
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java')
2 files changed, 34 insertions, 9 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumer.java index 538b63546..4bad4cb7a 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumer.java @@ -30,6 +30,7 @@ import javax.jms.MessageListener; import javax.jms.Session; import javax.jms.Topic; import javax.naming.InitialContext; +import javax.naming.NamingException; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.service.engine.event.ApexEventException; import org.onap.policy.apex.service.engine.event.ApexEventReceiver; @@ -77,10 +78,10 @@ public class ApexJmsConsumer extends ApexPluginsEventConsumer implements Message jmsConsumerProperties = (JmsCarrierTechnologyParameters) consumerParameters.getCarrierTechnologyParameters(); // Look up the JMS connection factory - InitialContext jmsContext = null; - ConnectionFactory connectionFactory = null; + InitialContext jmsContext; + ConnectionFactory connectionFactory; try { - jmsContext = new InitialContext(jmsConsumerProperties.getJmsConsumerProperties()); + jmsContext = getInitialContext(); connectionFactory = (ConnectionFactory) jmsContext.lookup(jmsConsumerProperties.getConnectionFactory()); // Check if we actually got a connection factory @@ -124,6 +125,17 @@ public class ApexJmsConsumer extends ApexPluginsEventConsumer implements Message } /** + * Construct InitialContext. This function should not be run directly. + * Package-private access is set for testing purposes only. + * + * @return InitialContext + * @throws NamingException if a naming exception is encountered + */ + InitialContext getInitialContext() throws NamingException { + return new InitialContext(jmsConsumerProperties.getJmsConsumerProperties()); + } + + /** * {@inheritDoc}. */ @Override diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducer.java index 4e5c7a31c..44ed810fd 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducer.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-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. @@ -32,6 +32,7 @@ import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.Topic; import javax.naming.InitialContext; +import javax.naming.NamingException; import org.onap.policy.apex.service.engine.event.ApexEventException; import org.onap.policy.apex.service.engine.event.ApexEventProducer; import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; @@ -72,7 +73,8 @@ public class ApexJmsProducer implements ApexEventProducer { private String name = null; // The peer references for this event handler - private Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap = new EnumMap<>(EventHandlerPeeredMode.class); + private final Map<EventHandlerPeeredMode, PeeredReference> peerReferenceMap = + new EnumMap<>(EventHandlerPeeredMode.class); /** * {@inheritDoc}. @@ -91,10 +93,10 @@ public class ApexJmsProducer implements ApexEventProducer { jmsProducerProperties = (JmsCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters(); // Look up the JMS connection factory - InitialContext jmsContext = null; - ConnectionFactory connectionFactory = null; + InitialContext jmsContext; + ConnectionFactory connectionFactory; try { - jmsContext = new InitialContext(jmsProducerProperties.getJmsProducerProperties()); + jmsContext = getInitialContext(); connectionFactory = (ConnectionFactory) jmsContext.lookup(jmsProducerProperties.getConnectionFactory()); // Check if we actually got a connection factory @@ -159,6 +161,17 @@ public class ApexJmsProducer implements ApexEventProducer { } /** + * Construct InitialContext. This function should not be run directly. + * Package-private access is set for testing purposes only. + * + * @return InitialContext + * @throws NamingException if a naming exception is encountered + */ + public InitialContext getInitialContext() throws NamingException { + return new InitialContext(jmsProducerProperties.getJmsProducerProperties()); + } + + /** * {@inheritDoc}. */ @Override @@ -204,7 +217,7 @@ public class ApexJmsProducer implements ApexEventProducer { } // The JMS message to send is constructed using the JMS session - Message jmsMessage = null; + Message jmsMessage; // Check the type of JMS message to send if (jmsProducerProperties.isObjectMessageSending()) { |