2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Samsung. All rights reserved.
4 * Modifications Copyright (C) 2019,2021 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.plugins.event.carrier.jms;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertNull;
29 import static org.junit.Assert.assertTrue;
31 import java.util.Properties;
32 import javax.naming.Context;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.policy.common.parameters.GroupValidationResult;
36 import org.onap.policy.common.parameters.ParameterRuntimeException;
38 public class JmsCarrierTechnologyParametersTest {
40 JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null;
41 Properties jmsProducerProperties = null;
42 Properties jmsConsumerProperties = null;
43 GroupValidationResult result = null;
45 public static final String JMS_CARRIER_TECHNOLOGY_LABEL = "JMS";
47 public static final String JMS_EVENT_PRODUCER_PLUGIN_CLASS =
48 ApexJmsProducer.class.getName();
50 public static final String JMS_EVENT_CONSUMER_PLUGIN_CLASS =
51 ApexJmsConsumer.class.getName();
53 private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
54 private static final String DEFAULT_INITIAL_CTXT_FACTORY =
55 "org.jboss.naming.remote.client.InitialContextFactory";
56 private static final String DEFAULT_PROVIDER_URL = "remote://localhost:4447";
57 private static final String DEFAULT_SECURITY_PRINCIPAL = "userid";
58 private static final String DEFAULT_CONSUMER_TOPIC = "apex-in";
59 private static final String DEFAULT_PRODUCER_TOPIC = "apex-out";
60 private static final int DEFAULT_CONSUMER_WAIT_TIME = 100;
61 private static final boolean DEFAULT_TO_OBJECT_MSG_SENDING = true;
66 * @throws Exception on test set up errors.
69 public void setUp() throws Exception {
70 jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
74 public void testValidate() {
75 result = jmsCarrierTechnologyParameters.validate();
76 assertNotNull(result);
77 assertFalse(result.getStatus().isValid());
79 jmsCarrierTechnologyParameters.setSecurityCredentials("DUMMY");
80 result = jmsCarrierTechnologyParameters.validate();
81 assertNotNull(result);
82 assertTrue(result.getStatus().isValid());
86 public void testJmsCarrierTechnologyParameters() {
87 assertNotNull(jmsCarrierTechnologyParameters);
91 public void testGetJmsProducerProperties() {
92 Properties producerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties();
93 assertNotNull(producerProperties);
94 assertNull(producerProperties.get(Context.SECURITY_CREDENTIALS));
96 jmsCarrierTechnologyParameters.setSecurityCredentials("DUMMY");
97 producerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties();
98 assertEquals("DUMMY", producerProperties.get(Context.SECURITY_CREDENTIALS));
102 public void testGetJmsConsumerProperties() {
103 Properties consumerProperties = jmsCarrierTechnologyParameters.getJmsConsumerProperties();
104 assertNotNull(consumerProperties);
105 assertNull(consumerProperties.get(Context.SECURITY_CREDENTIALS));
107 jmsCarrierTechnologyParameters.setSecurityCredentials("DUMMY");
108 consumerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties();
109 assertEquals("DUMMY", consumerProperties.get(Context.SECURITY_CREDENTIALS));
113 public void testEqualityOfJmsConsumerAndProducerProperties() {
114 assertEquals(jmsCarrierTechnologyParameters.getJmsProducerProperties(),
115 jmsCarrierTechnologyParameters.getJmsConsumerProperties());
119 public void testGetConnectionFactory() {
120 assertEquals(DEFAULT_CONNECTION_FACTORY,
121 jmsCarrierTechnologyParameters.getConnectionFactory());
125 public void testSetConnectionFactory() {
126 jmsCarrierTechnologyParameters.setConnectionFactory("QueueConnectionFactory");
127 assertNotEquals(DEFAULT_CONNECTION_FACTORY,
128 jmsCarrierTechnologyParameters.getConnectionFactory());
132 public void testSetConsumerTopic() {
133 assertEquals(DEFAULT_CONSUMER_TOPIC, jmsCarrierTechnologyParameters.getConsumerTopic());
134 jmsCarrierTechnologyParameters.setConsumerTopic(null);
135 result = jmsCarrierTechnologyParameters.validate();
136 assertFalse(result.getStatus().isValid());
140 public void testSetConsumerWaitTime() {
141 assertEquals(DEFAULT_CONSUMER_WAIT_TIME,
142 jmsCarrierTechnologyParameters.getConsumerWaitTime());
143 jmsCarrierTechnologyParameters.setConsumerWaitTime(-1);
144 assertNotEquals(DEFAULT_CONSUMER_WAIT_TIME,
145 jmsCarrierTechnologyParameters.getConsumerWaitTime());
149 public void testSetEventConsumerPluginClass() {
150 assertEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS,
151 jmsCarrierTechnologyParameters.getEventConsumerPluginClass());
152 jmsCarrierTechnologyParameters.setEventConsumerPluginClass("TestEventConsumerPluginClass");
153 assertNotEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS,
154 jmsCarrierTechnologyParameters.getEventConsumerPluginClass());
158 public void testSetEventProducerPluginClass() {
159 assertEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS,
160 jmsCarrierTechnologyParameters.getEventProducerPluginClass());
161 jmsCarrierTechnologyParameters.setEventProducerPluginClass("TestEventProducerPluginClass");
162 assertNotEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS,
163 jmsCarrierTechnologyParameters.getEventProducerPluginClass());
167 public void testSetLabel() {
168 assertEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
169 jmsCarrierTechnologyParameters.setLabel("TestLable");
170 assertNotEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
175 public void testSetObjectMessageSending() {
176 assertTrue(jmsCarrierTechnologyParameters.isObjectMessageSending());
177 jmsCarrierTechnologyParameters.setObjectMessageSending(!DEFAULT_TO_OBJECT_MSG_SENDING);
178 assertFalse(jmsCarrierTechnologyParameters.isObjectMessageSending());
182 public void testSetProducerTopic() {
183 assertEquals(DEFAULT_PRODUCER_TOPIC, jmsCarrierTechnologyParameters.getProducerTopic());
184 jmsCarrierTechnologyParameters.setProducerTopic("");
185 result = jmsCarrierTechnologyParameters.validate();
186 assertFalse(result.getStatus().isValid());
190 public void testSetProviderUrl() {
191 assertEquals(DEFAULT_PROVIDER_URL, jmsCarrierTechnologyParameters.getProviderUrl());
192 jmsCarrierTechnologyParameters.setProviderUrl(null);
193 result = jmsCarrierTechnologyParameters.validate();
194 assertFalse(result.getStatus().isValid());
198 public void testSetSecurityCredentials() {
199 assertNull(jmsCarrierTechnologyParameters.getSecurityCredentials());
200 jmsCarrierTechnologyParameters.setSecurityCredentials("");
201 result = jmsCarrierTechnologyParameters.validate();
202 assertFalse(result.getStatus().isValid());
206 public void testSetSecurityPrincipal() {
207 assertEquals(DEFAULT_SECURITY_PRINCIPAL,
208 jmsCarrierTechnologyParameters.getSecurityPrincipal());
209 jmsCarrierTechnologyParameters.setSecurityPrincipal(null);
210 result = jmsCarrierTechnologyParameters.validate();
211 assertFalse(result.getStatus().isValid());
215 public void testSetInitialContextFactory() {
217 assertEquals(DEFAULT_INITIAL_CTXT_FACTORY,
218 jmsCarrierTechnologyParameters.getInitialContextFactory());
220 jmsCarrierTechnologyParameters.setInitialContextFactory(null);
221 result = jmsCarrierTechnologyParameters.validate();
222 assertFalse(result.getStatus().isValid());
224 jmsCarrierTechnologyParameters.setInitialContextFactory("TestInitialContextFactory");
225 assertNotEquals(DEFAULT_INITIAL_CTXT_FACTORY,
226 jmsCarrierTechnologyParameters.getInitialContextFactory());
229 @Test(expected = ParameterRuntimeException.class)
230 public void testSetName() {
231 jmsCarrierTechnologyParameters.setName("TestName");