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 = ApexJmsProducer.class.getName();
49 public static final String JMS_EVENT_CONSUMER_PLUGIN_CLASS = ApexJmsConsumer.class.getName();
51 private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
52 private static final String DEFAULT_INITIAL_CTXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
53 private static final String DEFAULT_CONSUMER_TOPIC = "apex-in";
54 private static final String DEFAULT_PRODUCER_TOPIC = "apex-out";
55 private static final int DEFAULT_CONSUMER_WAIT_TIME = 100;
56 private static final boolean DEFAULT_TO_OBJECT_MSG_SENDING = true;
61 * @throws Exception on test set up errors.
64 public void setUp() throws Exception {
65 jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
69 public void testValidate() {
70 result = jmsCarrierTechnologyParameters.validate();
71 assertNotNull(result);
72 assertFalse(result.getStatus().isValid());
74 jmsCarrierTechnologyParameters.setProviderUrl("DUMMYURL");
75 jmsCarrierTechnologyParameters.setSecurityPrincipal("DUMMYPRINCIPAL");
76 jmsCarrierTechnologyParameters.setSecurityCredentials("DUMMYCREDENTIALS");
78 result = jmsCarrierTechnologyParameters.validate();
79 assertNotNull(result);
80 assertTrue(result.getStatus().isValid());
84 public void testJmsCarrierTechnologyParameters() {
85 assertNotNull(jmsCarrierTechnologyParameters);
89 public void testGetJmsProducerProperties() {
90 Properties producerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties();
91 assertNotNull(producerProperties);
93 assertNull(producerProperties.get(Context.PROVIDER_URL));
94 assertNull(producerProperties.get(Context.SECURITY_PRINCIPAL));
95 assertNull(producerProperties.get(Context.SECURITY_CREDENTIALS));
97 jmsCarrierTechnologyParameters.setProviderUrl("DUMMYURL");
98 jmsCarrierTechnologyParameters.setSecurityPrincipal("DUMMYPRINCIPAL");
99 jmsCarrierTechnologyParameters.setSecurityCredentials("DUMMYCREDENTIALS");
101 producerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties();
103 assertEquals("DUMMYURL", producerProperties.get(Context.PROVIDER_URL));
104 assertEquals("DUMMYPRINCIPAL", producerProperties.get(Context.SECURITY_PRINCIPAL));
105 assertEquals("DUMMYCREDENTIALS", producerProperties.get(Context.SECURITY_CREDENTIALS));
107 jmsCarrierTechnologyParameters.setProviderUrl(null);
108 jmsCarrierTechnologyParameters.setSecurityPrincipal(null);
109 jmsCarrierTechnologyParameters.setSecurityCredentials(null);
111 producerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties();
113 assertNull(producerProperties.get(Context.PROVIDER_URL));
114 assertNull(producerProperties.get(Context.SECURITY_PRINCIPAL));
115 assertNull(producerProperties.get(Context.SECURITY_CREDENTIALS));
119 public void testGetJmsConsumerProperties() {
120 Properties consumerProperties = jmsCarrierTechnologyParameters.getJmsConsumerProperties();
121 assertNotNull(consumerProperties);
122 assertNull(consumerProperties.get(Context.SECURITY_CREDENTIALS));
124 jmsCarrierTechnologyParameters.setSecurityCredentials("DUMMY");
125 consumerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties();
126 assertEquals("DUMMY", consumerProperties.get(Context.SECURITY_CREDENTIALS));
130 public void testEqualityOfJmsConsumerAndProducerProperties() {
131 assertEquals(jmsCarrierTechnologyParameters.getJmsProducerProperties(),
132 jmsCarrierTechnologyParameters.getJmsConsumerProperties());
136 public void testGetConnectionFactory() {
137 assertEquals(DEFAULT_CONNECTION_FACTORY, jmsCarrierTechnologyParameters.getConnectionFactory());
141 public void testSetConnectionFactory() {
142 jmsCarrierTechnologyParameters.setConnectionFactory("QueueConnectionFactory");
143 assertNotEquals(DEFAULT_CONNECTION_FACTORY, jmsCarrierTechnologyParameters.getConnectionFactory());
147 public void testSetConsumerTopic() {
148 assertEquals(DEFAULT_CONSUMER_TOPIC, jmsCarrierTechnologyParameters.getConsumerTopic());
149 jmsCarrierTechnologyParameters.setConsumerTopic(null);
150 result = jmsCarrierTechnologyParameters.validate();
151 assertFalse(result.getStatus().isValid());
155 public void testSetConsumerWaitTime() {
156 assertEquals(DEFAULT_CONSUMER_WAIT_TIME, jmsCarrierTechnologyParameters.getConsumerWaitTime());
157 jmsCarrierTechnologyParameters.setConsumerWaitTime(-1);
158 assertNotEquals(DEFAULT_CONSUMER_WAIT_TIME, jmsCarrierTechnologyParameters.getConsumerWaitTime());
162 public void testSetEventConsumerPluginClass() {
163 assertEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventConsumerPluginClass());
164 jmsCarrierTechnologyParameters.setEventConsumerPluginClass("TestEventConsumerPluginClass");
165 assertNotEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventConsumerPluginClass());
169 public void testSetEventProducerPluginClass() {
170 assertEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventProducerPluginClass());
171 jmsCarrierTechnologyParameters.setEventProducerPluginClass("TestEventProducerPluginClass");
172 assertNotEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventProducerPluginClass());
176 public void testSetLabel() {
177 assertEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
178 jmsCarrierTechnologyParameters.setLabel("TestLable");
179 assertNotEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
184 public void testSetObjectMessageSending() {
185 assertTrue(jmsCarrierTechnologyParameters.isObjectMessageSending());
186 jmsCarrierTechnologyParameters.setObjectMessageSending(!DEFAULT_TO_OBJECT_MSG_SENDING);
187 assertFalse(jmsCarrierTechnologyParameters.isObjectMessageSending());
191 public void testSetProducerTopic() {
192 assertEquals(DEFAULT_PRODUCER_TOPIC, jmsCarrierTechnologyParameters.getProducerTopic());
193 jmsCarrierTechnologyParameters.setProducerTopic("");
194 result = jmsCarrierTechnologyParameters.validate();
195 assertFalse(result.getStatus().isValid());
199 public void testSetProviderUrl() {
200 assertNull(jmsCarrierTechnologyParameters.getProviderUrl());
201 jmsCarrierTechnologyParameters.setProviderUrl(null);
202 result = jmsCarrierTechnologyParameters.validate();
203 assertFalse(result.getStatus().isValid());
207 public void testSetSecurityCredentials() {
208 assertNull(jmsCarrierTechnologyParameters.getSecurityCredentials());
209 jmsCarrierTechnologyParameters.setSecurityCredentials("");
210 result = jmsCarrierTechnologyParameters.validate();
211 assertFalse(result.getStatus().isValid());
215 public void testSetSecurityPrincipal() {
216 assertNull(jmsCarrierTechnologyParameters.getSecurityPrincipal());
217 jmsCarrierTechnologyParameters.setSecurityPrincipal(null);
218 result = jmsCarrierTechnologyParameters.validate();
219 assertFalse(result.getStatus().isValid());
223 public void testSetInitialContextFactory() {
225 assertEquals(DEFAULT_INITIAL_CTXT_FACTORY, jmsCarrierTechnologyParameters.getInitialContextFactory());
227 jmsCarrierTechnologyParameters.setInitialContextFactory(null);
228 result = jmsCarrierTechnologyParameters.validate();
229 assertFalse(result.getStatus().isValid());
231 jmsCarrierTechnologyParameters.setInitialContextFactory("TestInitialContextFactory");
232 assertNotEquals(DEFAULT_INITIAL_CTXT_FACTORY, jmsCarrierTechnologyParameters.getInitialContextFactory());
235 @Test(expected = ParameterRuntimeException.class)
236 public void testSetName() {
237 jmsCarrierTechnologyParameters.setName("TestName");