2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Samsung. All rights reserved.
4 * Modifications Copyright (C) 2019,2021 Nordix Foundation.
5 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.apex.plugins.event.carrier.jms;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNotEquals;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertNull;
30 import static org.junit.Assert.assertTrue;
32 import java.util.Properties;
33 import javax.naming.Context;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.onap.policy.common.parameters.ParameterRuntimeException;
37 import org.onap.policy.common.parameters.ValidationResult;
39 public class JmsCarrierTechnologyParametersTest {
41 JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null;
42 Properties jmsProducerProperties = null;
43 Properties jmsConsumerProperties = null;
44 ValidationResult result = null;
46 public static final String JMS_CARRIER_TECHNOLOGY_LABEL = "JMS";
48 public static final String JMS_EVENT_PRODUCER_PLUGIN_CLASS = ApexJmsProducer.class.getName();
50 public static final String JMS_EVENT_CONSUMER_PLUGIN_CLASS = ApexJmsConsumer.class.getName();
52 private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
53 private static final String DEFAULT_INITIAL_CTXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
54 private static final String DEFAULT_CONSUMER_TOPIC = "apex-in";
55 private static final String DEFAULT_PRODUCER_TOPIC = "apex-out";
56 private static final int DEFAULT_CONSUMER_WAIT_TIME = 100;
57 private static final boolean DEFAULT_TO_OBJECT_MSG_SENDING = true;
62 * @throws Exception on test set up errors.
65 public void setUp() throws Exception {
66 jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
70 public void testValidate() {
71 result = jmsCarrierTechnologyParameters.validate();
72 assertNotNull(result);
73 assertFalse(result.getStatus().isValid());
75 jmsCarrierTechnologyParameters.setProviderUrl("DUMMYURL");
76 jmsCarrierTechnologyParameters.setSecurityPrincipal("DUMMYPRINCIPAL");
77 jmsCarrierTechnologyParameters.setSecurityCredentials("DUMMYCREDENTIALS");
79 result = jmsCarrierTechnologyParameters.validate();
80 assertNotNull(result);
81 assertTrue(result.getStatus().isValid());
85 public void testJmsCarrierTechnologyParameters() {
86 assertNotNull(jmsCarrierTechnologyParameters);
90 public void testGetJmsProducerProperties() {
91 Properties producerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties();
92 assertNotNull(producerProperties);
94 assertNull(producerProperties.get(Context.PROVIDER_URL));
95 assertNull(producerProperties.get(Context.SECURITY_PRINCIPAL));
96 assertNull(producerProperties.get(Context.SECURITY_CREDENTIALS));
98 jmsCarrierTechnologyParameters.setProviderUrl("DUMMYURL");
99 jmsCarrierTechnologyParameters.setSecurityPrincipal("DUMMYPRINCIPAL");
100 jmsCarrierTechnologyParameters.setSecurityCredentials("DUMMYCREDENTIALS");
102 producerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties();
104 assertEquals("DUMMYURL", producerProperties.get(Context.PROVIDER_URL));
105 assertEquals("DUMMYPRINCIPAL", producerProperties.get(Context.SECURITY_PRINCIPAL));
106 assertEquals("DUMMYCREDENTIALS", producerProperties.get(Context.SECURITY_CREDENTIALS));
108 jmsCarrierTechnologyParameters.setProviderUrl(null);
109 jmsCarrierTechnologyParameters.setSecurityPrincipal(null);
110 jmsCarrierTechnologyParameters.setSecurityCredentials(null);
112 producerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties();
114 assertNull(producerProperties.get(Context.PROVIDER_URL));
115 assertNull(producerProperties.get(Context.SECURITY_PRINCIPAL));
116 assertNull(producerProperties.get(Context.SECURITY_CREDENTIALS));
120 public void testGetJmsConsumerProperties() {
121 Properties consumerProperties = jmsCarrierTechnologyParameters.getJmsConsumerProperties();
122 assertNotNull(consumerProperties);
123 assertNull(consumerProperties.get(Context.SECURITY_CREDENTIALS));
125 jmsCarrierTechnologyParameters.setSecurityCredentials("DUMMY");
126 consumerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties();
127 assertEquals("DUMMY", consumerProperties.get(Context.SECURITY_CREDENTIALS));
131 public void testEqualityOfJmsConsumerAndProducerProperties() {
132 assertEquals(jmsCarrierTechnologyParameters.getJmsProducerProperties(),
133 jmsCarrierTechnologyParameters.getJmsConsumerProperties());
137 public void testGetConnectionFactory() {
138 assertEquals(DEFAULT_CONNECTION_FACTORY, jmsCarrierTechnologyParameters.getConnectionFactory());
142 public void testSetConnectionFactory() {
143 jmsCarrierTechnologyParameters.setConnectionFactory("QueueConnectionFactory");
144 assertNotEquals(DEFAULT_CONNECTION_FACTORY, jmsCarrierTechnologyParameters.getConnectionFactory());
148 public void testSetConsumerTopic() {
149 assertEquals(DEFAULT_CONSUMER_TOPIC, jmsCarrierTechnologyParameters.getConsumerTopic());
150 jmsCarrierTechnologyParameters.setConsumerTopic(null);
151 result = jmsCarrierTechnologyParameters.validate();
152 assertFalse(result.getStatus().isValid());
156 public void testSetConsumerWaitTime() {
157 assertEquals(DEFAULT_CONSUMER_WAIT_TIME, jmsCarrierTechnologyParameters.getConsumerWaitTime());
158 jmsCarrierTechnologyParameters.setConsumerWaitTime(-1);
159 assertNotEquals(DEFAULT_CONSUMER_WAIT_TIME, jmsCarrierTechnologyParameters.getConsumerWaitTime());
163 public void testSetEventConsumerPluginClass() {
164 assertEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventConsumerPluginClass());
165 jmsCarrierTechnologyParameters.setEventConsumerPluginClass("TestEventConsumerPluginClass");
166 assertNotEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventConsumerPluginClass());
170 public void testSetEventProducerPluginClass() {
171 assertEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventProducerPluginClass());
172 jmsCarrierTechnologyParameters.setEventProducerPluginClass("TestEventProducerPluginClass");
173 assertNotEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventProducerPluginClass());
177 public void testSetLabel() {
178 assertEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
179 jmsCarrierTechnologyParameters.setLabel("TestLable");
180 assertNotEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
185 public void testSetObjectMessageSending() {
186 assertTrue(jmsCarrierTechnologyParameters.isObjectMessageSending());
187 jmsCarrierTechnologyParameters.setObjectMessageSending(!DEFAULT_TO_OBJECT_MSG_SENDING);
188 assertFalse(jmsCarrierTechnologyParameters.isObjectMessageSending());
192 public void testSetProducerTopic() {
193 assertEquals(DEFAULT_PRODUCER_TOPIC, jmsCarrierTechnologyParameters.getProducerTopic());
194 jmsCarrierTechnologyParameters.setProducerTopic("");
195 result = jmsCarrierTechnologyParameters.validate();
196 assertFalse(result.getStatus().isValid());
200 public void testSetProviderUrl() {
201 assertNull(jmsCarrierTechnologyParameters.getProviderUrl());
202 jmsCarrierTechnologyParameters.setProviderUrl(null);
203 result = jmsCarrierTechnologyParameters.validate();
204 assertFalse(result.getStatus().isValid());
208 public void testSetSecurityCredentials() {
209 assertNull(jmsCarrierTechnologyParameters.getSecurityCredentials());
210 jmsCarrierTechnologyParameters.setSecurityCredentials("");
211 result = jmsCarrierTechnologyParameters.validate();
212 assertFalse(result.getStatus().isValid());
216 public void testSetSecurityPrincipal() {
217 assertNull(jmsCarrierTechnologyParameters.getSecurityPrincipal());
218 jmsCarrierTechnologyParameters.setSecurityPrincipal(null);
219 result = jmsCarrierTechnologyParameters.validate();
220 assertFalse(result.getStatus().isValid());
224 public void testSetInitialContextFactory() {
226 assertEquals(DEFAULT_INITIAL_CTXT_FACTORY, jmsCarrierTechnologyParameters.getInitialContextFactory());
228 jmsCarrierTechnologyParameters.setInitialContextFactory(null);
229 result = jmsCarrierTechnologyParameters.validate();
230 assertFalse(result.getStatus().isValid());
232 jmsCarrierTechnologyParameters.setInitialContextFactory("TestInitialContextFactory");
233 assertNotEquals(DEFAULT_INITIAL_CTXT_FACTORY, jmsCarrierTechnologyParameters.getInitialContextFactory());
236 @Test(expected = ParameterRuntimeException.class)
237 public void testSetName() {
238 jmsCarrierTechnologyParameters.setName("TestName");