32d712411e884aa694cd8936650791cafad184ca
[policy/apex-pdp.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.policy.apex.plugins.event.carrier.jms;
21
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;
27
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;
34
35 public class JmsCarrierTechnologyParametersTest {
36
37     JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null;
38     Properties jmsProducerProperties = null;
39     Properties jmsConsumerProperties = null;
40     GroupValidationResult result = null;
41
42     public static final String JMS_CARRIER_TECHNOLOGY_LABEL = "JMS";
43
44     public static final String JMS_EVENT_PRODUCER_PLUGIN_CLASS =
45             ApexJmsProducer.class.getCanonicalName();
46
47     public static final String JMS_EVENT_CONSUMER_PLUGIN_CLASS =
48             ApexJmsConsumer.class.getCanonicalName();
49
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;
60
61     /**
62      * Set up testing.
63      *
64      * @throws Exception on test set up errors.
65      */
66     @Before
67     public void setUp() throws Exception {
68         jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
69     }
70
71     @Test
72     public void testValidate() {
73         result = jmsCarrierTechnologyParameters.validate();
74         assertNotNull(result);
75         assertTrue(result.getStatus().isValid());
76     }
77
78     @Test
79     public void testJmsCarrierTechnologyParameters() {
80         assertNotNull(jmsCarrierTechnologyParameters);
81     }
82
83     @Test
84     public void testGetJmsProducerProperties() {
85         assertNotNull(jmsCarrierTechnologyParameters.getJmsConsumerProperties());
86     }
87
88     @Test
89     public void testGetJmsConsumerProperties() {
90         assertNotNull(jmsCarrierTechnologyParameters.getJmsProducerProperties());
91     }
92
93     @Test
94     public void testEqualityOfJmsConsumerAndProducerProperties() {
95         assertEquals(jmsCarrierTechnologyParameters.getJmsProducerProperties(),
96                 jmsCarrierTechnologyParameters.getJmsConsumerProperties());
97     }
98
99     @Test
100     public void testGetConnectionFactory() {
101         assertEquals(DEFAULT_CONNECTION_FACTORY,
102                 jmsCarrierTechnologyParameters.getConnectionFactory());
103     }
104
105     @Test
106     public void testSetConnectionFactory() {
107         jmsCarrierTechnologyParameters.setConnectionFactory("QueueConnectionFactory");
108         assertNotEquals(DEFAULT_CONNECTION_FACTORY,
109                 jmsCarrierTechnologyParameters.getConnectionFactory());
110     }
111
112     @Test
113     public void testSetConsumerTopic() {
114         assertEquals(DEFAULT_CONSUMER_TOPIC, jmsCarrierTechnologyParameters.getConsumerTopic());
115         jmsCarrierTechnologyParameters.setConsumerTopic(null);
116         result = jmsCarrierTechnologyParameters.validate();
117         assertFalse(result.getStatus().isValid());
118     }
119
120     @Test
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());
127     }
128
129     @Test
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());
136     }
137
138     @Test
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());
145     }
146
147     @Test
148     public void testSetLabel() {
149         assertEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
150         jmsCarrierTechnologyParameters.setLabel("TestLable");
151         assertNotEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
152
153     }
154
155     @Test
156     public void testSetObjectMessageSending() {
157         assertTrue(jmsCarrierTechnologyParameters.isObjectMessageSending());
158         jmsCarrierTechnologyParameters.setObjectMessageSending(!DEFAULT_TO_OBJECT_MSG_SENDING);
159         assertFalse(jmsCarrierTechnologyParameters.isObjectMessageSending());
160     }
161
162     @Test
163     public void testSetProducerTopic() {
164         assertEquals(DEFAULT_PRODUCER_TOPIC, jmsCarrierTechnologyParameters.getProducerTopic());
165         jmsCarrierTechnologyParameters.setProducerTopic("");
166         result = jmsCarrierTechnologyParameters.validate();
167         assertFalse(result.getStatus().isValid());
168     }
169
170     @Test
171     public void testSetProviderUrl() {
172         assertEquals(DEFAULT_PROVIDER_URL, jmsCarrierTechnologyParameters.getProviderUrl());
173         jmsCarrierTechnologyParameters.setProviderUrl(null);
174         result = jmsCarrierTechnologyParameters.validate();
175         assertFalse(result.getStatus().isValid());
176     }
177
178     @Test
179     public void testSetSecurityCredentials() {
180         assertEquals(
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());
186     }
187
188     @Test
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());
195     }
196
197     @Test
198     public void testSetInitialContextFactory() {
199
200         assertEquals(DEFAULT_INITIAL_CTXT_FACTORY,
201                 jmsCarrierTechnologyParameters.getInitialContextFactory());
202
203         jmsCarrierTechnologyParameters.setInitialContextFactory(null);
204         result = jmsCarrierTechnologyParameters.validate();
205         assertFalse(result.getStatus().isValid());
206
207         jmsCarrierTechnologyParameters.setInitialContextFactory("TestInitialContextFactory");
208         assertNotEquals(DEFAULT_INITIAL_CTXT_FACTORY,
209                 jmsCarrierTechnologyParameters.getInitialContextFactory());
210     }
211
212     @Test(expected = ParameterRuntimeException.class)
213     public void testSetName() {
214         jmsCarrierTechnologyParameters.setName("TestName");
215     }
216 }