2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Samsung. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.policy.apex.plugins.event.carrier.jms;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertNotEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
28 import java.util.Base64;
29 import java.util.Properties;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.policy.common.parameters.GroupValidationResult;
33 import org.onap.policy.common.parameters.ParameterRuntimeException;
35 public class JmsCarrierTechnologyParametersTest {
37 JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null;
38 Properties jmsProducerProperties = null;
39 Properties jmsConsumerProperties = null;
40 GroupValidationResult result = null;
42 public static final String JMS_CARRIER_TECHNOLOGY_LABEL = "JMS";
44 public static final String JMS_EVENT_PRODUCER_PLUGIN_CLASS =
45 ApexJmsProducer.class.getCanonicalName();
47 public static final String JMS_EVENT_CONSUMER_PLUGIN_CLASS =
48 ApexJmsConsumer.class.getCanonicalName();
50 private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
51 private static final String DEFAULT_INITIAL_CTXT_FACTORY =
52 "org.jboss.naming.remote.client.InitialContextFactory";
53 private static final String DEFAULT_PROVIDER_URL = "remote://localhost:4447";
54 private static final String DEFAULT_SECURITY_PRINCIPAL = "userid";
55 private static final String DEFAULT_SECURITY_CREDENTIALS = "cGFzc3dvcmQ=";
56 private static final String DEFAULT_CONSUMER_TOPIC = "apex-in";
57 private static final String DEFAULT_PRODUCER_TOPIC = "apex-out";
58 private static final int DEFAULT_CONSUMER_WAIT_TIME = 100;
59 private static final boolean DEFAULT_TO_OBJECT_MSG_SENDING = true;
64 * @throws Exception on test set up errors.
67 public void setUp() throws Exception {
68 jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
72 public void testValidate() {
73 result = jmsCarrierTechnologyParameters.validate();
74 assertNotNull(result);
75 assertTrue(result.getStatus().isValid());
79 public void testJmsCarrierTechnologyParameters() {
80 assertNotNull(jmsCarrierTechnologyParameters);
84 public void testGetJmsProducerProperties() {
85 assertNotNull(jmsCarrierTechnologyParameters.getJmsConsumerProperties());
89 public void testGetJmsConsumerProperties() {
90 assertNotNull(jmsCarrierTechnologyParameters.getJmsProducerProperties());
94 public void testEqualityOfJmsConsumerAndProducerProperties() {
95 assertEquals(jmsCarrierTechnologyParameters.getJmsProducerProperties(),
96 jmsCarrierTechnologyParameters.getJmsConsumerProperties());
100 public void testGetConnectionFactory() {
101 assertEquals(DEFAULT_CONNECTION_FACTORY,
102 jmsCarrierTechnologyParameters.getConnectionFactory());
106 public void testSetConnectionFactory() {
107 jmsCarrierTechnologyParameters.setConnectionFactory("QueueConnectionFactory");
108 assertNotEquals(DEFAULT_CONNECTION_FACTORY,
109 jmsCarrierTechnologyParameters.getConnectionFactory());
113 public void testSetConsumerTopic() {
114 assertEquals(DEFAULT_CONSUMER_TOPIC, jmsCarrierTechnologyParameters.getConsumerTopic());
115 jmsCarrierTechnologyParameters.setConsumerTopic(null);
116 result = jmsCarrierTechnologyParameters.validate();
117 assertFalse(result.getStatus().isValid());
121 public void testSetConsumerWaitTime() {
122 assertEquals(DEFAULT_CONSUMER_WAIT_TIME,
123 jmsCarrierTechnologyParameters.getConsumerWaitTime());
124 jmsCarrierTechnologyParameters.setConsumerWaitTime(-1);
125 assertNotEquals(DEFAULT_CONSUMER_WAIT_TIME,
126 jmsCarrierTechnologyParameters.getConsumerWaitTime());
130 public void testSetEventConsumerPluginClass() {
131 assertEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS,
132 jmsCarrierTechnologyParameters.getEventConsumerPluginClass());
133 jmsCarrierTechnologyParameters.setEventConsumerPluginClass("TestEventConsumerPluginClass");
134 assertNotEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS,
135 jmsCarrierTechnologyParameters.getEventConsumerPluginClass());
139 public void testSetEventProducerPluginClass() {
140 assertEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS,
141 jmsCarrierTechnologyParameters.getEventProducerPluginClass());
142 jmsCarrierTechnologyParameters.setEventProducerPluginClass("TestEventProducerPluginClass");
143 assertNotEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS,
144 jmsCarrierTechnologyParameters.getEventProducerPluginClass());
148 public void testSetLabel() {
149 assertEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
150 jmsCarrierTechnologyParameters.setLabel("TestLable");
151 assertNotEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
156 public void testSetObjectMessageSending() {
157 assertTrue(jmsCarrierTechnologyParameters.isObjectMessageSending());
158 jmsCarrierTechnologyParameters.setObjectMessageSending(!DEFAULT_TO_OBJECT_MSG_SENDING);
159 assertFalse(jmsCarrierTechnologyParameters.isObjectMessageSending());
163 public void testSetProducerTopic() {
164 assertEquals(DEFAULT_PRODUCER_TOPIC, jmsCarrierTechnologyParameters.getProducerTopic());
165 jmsCarrierTechnologyParameters.setProducerTopic("");
166 result = jmsCarrierTechnologyParameters.validate();
167 assertFalse(result.getStatus().isValid());
171 public void testSetProviderUrl() {
172 assertEquals(DEFAULT_PROVIDER_URL, jmsCarrierTechnologyParameters.getProviderUrl());
173 jmsCarrierTechnologyParameters.setProviderUrl(null);
174 result = jmsCarrierTechnologyParameters.validate();
175 assertFalse(result.getStatus().isValid());
179 public void testSetSecurityCredentials() {
181 new String(Base64.getDecoder().decode(DEFAULT_SECURITY_CREDENTIALS.getBytes())),
182 jmsCarrierTechnologyParameters.getSecurityCredentials());
183 jmsCarrierTechnologyParameters.setSecurityCredentials("");
184 result = jmsCarrierTechnologyParameters.validate();
185 assertFalse(result.getStatus().isValid());
189 public void testSetSecurityPrincipal() {
190 assertEquals(DEFAULT_SECURITY_PRINCIPAL,
191 jmsCarrierTechnologyParameters.getSecurityPrincipal());
192 jmsCarrierTechnologyParameters.setSecurityPrincipal(null);
193 result = jmsCarrierTechnologyParameters.validate();
194 assertFalse(result.getStatus().isValid());
198 public void testSetInitialContextFactory() {
200 assertEquals(DEFAULT_INITIAL_CTXT_FACTORY,
201 jmsCarrierTechnologyParameters.getInitialContextFactory());
203 jmsCarrierTechnologyParameters.setInitialContextFactory(null);
204 result = jmsCarrierTechnologyParameters.validate();
205 assertFalse(result.getStatus().isValid());
207 jmsCarrierTechnologyParameters.setInitialContextFactory("TestInitialContextFactory");
208 assertNotEquals(DEFAULT_INITIAL_CTXT_FACTORY,
209 jmsCarrierTechnologyParameters.getInitialContextFactory());
212 @Test(expected = ParameterRuntimeException.class)
213 public void testSetName() {
214 jmsCarrierTechnologyParameters.setName("TestName");