2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Samsung. All rights reserved.
4 * Modifications Copyright (C) 2019 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.assertTrue;
30 import java.util.Base64;
31 import java.util.Properties;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.policy.common.parameters.GroupValidationResult;
35 import org.onap.policy.common.parameters.ParameterRuntimeException;
37 public class JmsCarrierTechnologyParametersTest {
39 JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null;
40 Properties jmsProducerProperties = null;
41 Properties jmsConsumerProperties = null;
42 GroupValidationResult result = null;
44 public static final String JMS_CARRIER_TECHNOLOGY_LABEL = "JMS";
46 public static final String JMS_EVENT_PRODUCER_PLUGIN_CLASS =
47 ApexJmsProducer.class.getCanonicalName();
49 public static final String JMS_EVENT_CONSUMER_PLUGIN_CLASS =
50 ApexJmsConsumer.class.getCanonicalName();
52 private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
53 private static final String DEFAULT_INITIAL_CTXT_FACTORY =
54 "org.jboss.naming.remote.client.InitialContextFactory";
55 private static final String DEFAULT_PROVIDER_URL = "remote://localhost:4447";
56 private static final String DEFAULT_SECURITY_PRINCIPAL = "userid";
57 private static final String DEFAULT_SECURITY_CREDENTIALS = "cGFzc3dvcmQ=";
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 assertTrue(result.getStatus().isValid());
81 public void testJmsCarrierTechnologyParameters() {
82 assertNotNull(jmsCarrierTechnologyParameters);
86 public void testGetJmsProducerProperties() {
87 assertNotNull(jmsCarrierTechnologyParameters.getJmsConsumerProperties());
91 public void testGetJmsConsumerProperties() {
92 assertNotNull(jmsCarrierTechnologyParameters.getJmsProducerProperties());
96 public void testEqualityOfJmsConsumerAndProducerProperties() {
97 assertEquals(jmsCarrierTechnologyParameters.getJmsProducerProperties(),
98 jmsCarrierTechnologyParameters.getJmsConsumerProperties());
102 public void testGetConnectionFactory() {
103 assertEquals(DEFAULT_CONNECTION_FACTORY,
104 jmsCarrierTechnologyParameters.getConnectionFactory());
108 public void testSetConnectionFactory() {
109 jmsCarrierTechnologyParameters.setConnectionFactory("QueueConnectionFactory");
110 assertNotEquals(DEFAULT_CONNECTION_FACTORY,
111 jmsCarrierTechnologyParameters.getConnectionFactory());
115 public void testSetConsumerTopic() {
116 assertEquals(DEFAULT_CONSUMER_TOPIC, jmsCarrierTechnologyParameters.getConsumerTopic());
117 jmsCarrierTechnologyParameters.setConsumerTopic(null);
118 result = jmsCarrierTechnologyParameters.validate();
119 assertFalse(result.getStatus().isValid());
123 public void testSetConsumerWaitTime() {
124 assertEquals(DEFAULT_CONSUMER_WAIT_TIME,
125 jmsCarrierTechnologyParameters.getConsumerWaitTime());
126 jmsCarrierTechnologyParameters.setConsumerWaitTime(-1);
127 assertNotEquals(DEFAULT_CONSUMER_WAIT_TIME,
128 jmsCarrierTechnologyParameters.getConsumerWaitTime());
132 public void testSetEventConsumerPluginClass() {
133 assertEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS,
134 jmsCarrierTechnologyParameters.getEventConsumerPluginClass());
135 jmsCarrierTechnologyParameters.setEventConsumerPluginClass("TestEventConsumerPluginClass");
136 assertNotEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS,
137 jmsCarrierTechnologyParameters.getEventConsumerPluginClass());
141 public void testSetEventProducerPluginClass() {
142 assertEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS,
143 jmsCarrierTechnologyParameters.getEventProducerPluginClass());
144 jmsCarrierTechnologyParameters.setEventProducerPluginClass("TestEventProducerPluginClass");
145 assertNotEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS,
146 jmsCarrierTechnologyParameters.getEventProducerPluginClass());
150 public void testSetLabel() {
151 assertEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
152 jmsCarrierTechnologyParameters.setLabel("TestLable");
153 assertNotEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
158 public void testSetObjectMessageSending() {
159 assertTrue(jmsCarrierTechnologyParameters.isObjectMessageSending());
160 jmsCarrierTechnologyParameters.setObjectMessageSending(!DEFAULT_TO_OBJECT_MSG_SENDING);
161 assertFalse(jmsCarrierTechnologyParameters.isObjectMessageSending());
165 public void testSetProducerTopic() {
166 assertEquals(DEFAULT_PRODUCER_TOPIC, jmsCarrierTechnologyParameters.getProducerTopic());
167 jmsCarrierTechnologyParameters.setProducerTopic("");
168 result = jmsCarrierTechnologyParameters.validate();
169 assertFalse(result.getStatus().isValid());
173 public void testSetProviderUrl() {
174 assertEquals(DEFAULT_PROVIDER_URL, jmsCarrierTechnologyParameters.getProviderUrl());
175 jmsCarrierTechnologyParameters.setProviderUrl(null);
176 result = jmsCarrierTechnologyParameters.validate();
177 assertFalse(result.getStatus().isValid());
181 public void testSetSecurityCredentials() {
183 new String(Base64.getDecoder().decode(DEFAULT_SECURITY_CREDENTIALS.getBytes())),
184 jmsCarrierTechnologyParameters.getSecurityCredentials());
185 jmsCarrierTechnologyParameters.setSecurityCredentials("");
186 result = jmsCarrierTechnologyParameters.validate();
187 assertFalse(result.getStatus().isValid());
191 public void testSetSecurityPrincipal() {
192 assertEquals(DEFAULT_SECURITY_PRINCIPAL,
193 jmsCarrierTechnologyParameters.getSecurityPrincipal());
194 jmsCarrierTechnologyParameters.setSecurityPrincipal(null);
195 result = jmsCarrierTechnologyParameters.validate();
196 assertFalse(result.getStatus().isValid());
200 public void testSetInitialContextFactory() {
202 assertEquals(DEFAULT_INITIAL_CTXT_FACTORY,
203 jmsCarrierTechnologyParameters.getInitialContextFactory());
205 jmsCarrierTechnologyParameters.setInitialContextFactory(null);
206 result = jmsCarrierTechnologyParameters.validate();
207 assertFalse(result.getStatus().isValid());
209 jmsCarrierTechnologyParameters.setInitialContextFactory("TestInitialContextFactory");
210 assertNotEquals(DEFAULT_INITIAL_CTXT_FACTORY,
211 jmsCarrierTechnologyParameters.getInitialContextFactory());
214 @Test(expected = ParameterRuntimeException.class)
215 public void testSetName() {
216 jmsCarrierTechnologyParameters.setName("TestName");