summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java
blob: 5f1b995005ff077815254c0c2821e4acd88bf0a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*-
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2019 Samsung. All rights reserved.
 *  Modifications Copyright (C) 2019,2021 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.apex.plugins.event.carrier.jms;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.util.Properties;
import javax.naming.Context;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.parameters.ParameterRuntimeException;

public class JmsCarrierTechnologyParametersTest {

    JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null;
    Properties jmsProducerProperties = null;
    Properties jmsConsumerProperties = null;
    GroupValidationResult result = null;

    public static final String JMS_CARRIER_TECHNOLOGY_LABEL = "JMS";

    public static final String JMS_EVENT_PRODUCER_PLUGIN_CLASS = ApexJmsProducer.class.getName();

    public static final String JMS_EVENT_CONSUMER_PLUGIN_CLASS = ApexJmsConsumer.class.getName();

    private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
    private static final String DEFAULT_INITIAL_CTXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
    private static final String DEFAULT_CONSUMER_TOPIC = "apex-in";
    private static final String DEFAULT_PRODUCER_TOPIC = "apex-out";
    private static final int DEFAULT_CONSUMER_WAIT_TIME = 100;
    private static final boolean DEFAULT_TO_OBJECT_MSG_SENDING = true;

    /**
     * Set up testing.
     *
     * @throws Exception on test set up errors.
     */
    @Before
    public void setUp() throws Exception {
        jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
    }

    @Test
    public void testValidate() {
        result = jmsCarrierTechnologyParameters.validate();
        assertNotNull(result);
        assertFalse(result.getStatus().isValid());

        jmsCarrierTechnologyParameters.setProviderUrl("DUMMYURL");
        jmsCarrierTechnologyParameters.setSecurityPrincipal("DUMMYPRINCIPAL");
        jmsCarrierTechnologyParameters.setSecurityCredentials("DUMMYCREDENTIALS");

        result = jmsCarrierTechnologyParameters.validate();
        assertNotNull(result);
        assertTrue(result.getStatus().isValid());
    }

    @Test
    public void testJmsCarrierTechnologyParameters() {
        assertNotNull(jmsCarrierTechnologyParameters);
    }

    @Test
    public void testGetJmsProducerProperties() {
        Properties producerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties();
        assertNotNull(producerProperties);

        assertNull(producerProperties.get(Context.PROVIDER_URL));
        assertNull(producerProperties.get(Context.SECURITY_PRINCIPAL));
        assertNull(producerProperties.get(Context.SECURITY_CREDENTIALS));

        jmsCarrierTechnologyParameters.setProviderUrl("DUMMYURL");
        jmsCarrierTechnologyParameters.setSecurityPrincipal("DUMMYPRINCIPAL");
        jmsCarrierTechnologyParameters.setSecurityCredentials("DUMMYCREDENTIALS");

        producerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties();

        assertEquals("DUMMYURL", producerProperties.get(Context.PROVIDER_URL));
        assertEquals("DUMMYPRINCIPAL", producerProperties.get(Context.SECURITY_PRINCIPAL));
        assertEquals("DUMMYCREDENTIALS", producerProperties.get(Context.SECURITY_CREDENTIALS));

        jmsCarrierTechnologyParameters.setProviderUrl(null);
        jmsCarrierTechnologyParameters.setSecurityPrincipal(null);
        jmsCarrierTechnologyParameters.setSecurityCredentials(null);

        producerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties();

        assertNull(producerProperties.get(Context.PROVIDER_URL));
        assertNull(producerProperties.get(Context.SECURITY_PRINCIPAL));
        assertNull(producerProperties.get(Context.SECURITY_CREDENTIALS));
    }

    @Test
    public void testGetJmsConsumerProperties() {
        Properties consumerProperties = jmsCarrierTechnologyParameters.getJmsConsumerProperties();
        assertNotNull(consumerProperties);
        assertNull(consumerProperties.get(Context.SECURITY_CREDENTIALS));

        jmsCarrierTechnologyParameters.setSecurityCredentials("DUMMY");
        consumerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties();
        assertEquals("DUMMY", consumerProperties.get(Context.SECURITY_CREDENTIALS));
    }

    @Test
    public void testEqualityOfJmsConsumerAndProducerProperties() {
        assertEquals(jmsCarrierTechnologyParameters.getJmsProducerProperties(),
                jmsCarrierTechnologyParameters.getJmsConsumerProperties());
    }

    @Test
    public void testGetConnectionFactory() {
        assertEquals(DEFAULT_CONNECTION_FACTORY, jmsCarrierTechnologyParameters.getConnectionFactory());
    }

    @Test
    public void testSetConnectionFactory() {
        jmsCarrierTechnologyParameters.setConnectionFactory("QueueConnectionFactory");
        assertNotEquals(DEFAULT_CONNECTION_FACTORY, jmsCarrierTechnologyParameters.getConnectionFactory());
    }

    @Test
    public void testSetConsumerTopic() {
        assertEquals(DEFAULT_CONSUMER_TOPIC, jmsCarrierTechnologyParameters.getConsumerTopic());
        jmsCarrierTechnologyParameters.setConsumerTopic(null);
        result = jmsCarrierTechnologyParameters.validate();
        assertFalse(result.getStatus().isValid());
    }

    @Test
    public void testSetConsumerWaitTime() {
        assertEquals(DEFAULT_CONSUMER_WAIT_TIME, jmsCarrierTechnologyParameters.getConsumerWaitTime());
        jmsCarrierTechnologyParameters.setConsumerWaitTime(-1);
        assertNotEquals(DEFAULT_CONSUMER_WAIT_TIME, jmsCarrierTechnologyParameters.getConsumerWaitTime());
    }

    @Test
    public void testSetEventConsumerPluginClass() {
        assertEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventConsumerPluginClass());
        jmsCarrierTechnologyParameters.setEventConsumerPluginClass("TestEventConsumerPluginClass");
        assertNotEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventConsumerPluginClass());
    }

    @Test
    public void testSetEventProducerPluginClass() {
        assertEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventProducerPluginClass());
        jmsCarrierTechnologyParameters.setEventProducerPluginClass("TestEventProducerPluginClass");
        assertNotEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventProducerPluginClass());
    }

    @Test
    public void testSetLabel() {
        assertEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
        jmsCarrierTechnologyParameters.setLabel("TestLable");
        assertNotEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());

    }

    @Test
    public void testSetObjectMessageSending() {
        assertTrue(jmsCarrierTechnologyParameters.isObjectMessageSending());
        jmsCarrierTechnologyParameters.setObjectMessageSending(!DEFAULT_TO_OBJECT_MSG_SENDING);
        assertFalse(jmsCarrierTechnologyParameters.isObjectMessageSending());
    }

    @Test
    public void testSetProducerTopic() {
        assertEquals(DEFAULT_PRODUCER_TOPIC, jmsCarrierTechnologyParameters.getProducerTopic());
        jmsCarrierTechnologyParameters.setProducerTopic("");
        result = jmsCarrierTechnologyParameters.validate();
        assertFalse(result.getStatus().isValid());
    }

    @Test
    public void testSetProviderUrl() {
        assertNull(jmsCarrierTechnologyParameters.getProviderUrl());
        jmsCarrierTechnologyParameters.setProviderUrl(null);
        result = jmsCarrierTechnologyParameters.validate();
        assertFalse(result.getStatus().isValid());
    }

    @Test
    public void testSetSecurityCredentials() {
        assertNull(jmsCarrierTechnologyParameters.getSecurityCredentials());
        jmsCarrierTechnologyParameters.setSecurityCredentials("");
        result = jmsCarrierTechnologyParameters.validate();
        assertFalse(result.getStatus().isValid());
    }

    @Test
    public void testSetSecurityPrincipal() {
        assertNull(jmsCarrierTechnologyParameters.getSecurityPrincipal());
        jmsCarrierTechnologyParameters.setSecurityPrincipal(null);
        result = jmsCarrierTechnologyParameters.validate();
        assertFalse(result.getStatus().isValid());
    }

    @Test
    public void testSetInitialContextFactory() {

        assertEquals(DEFAULT_INITIAL_CTXT_FACTORY, jmsCarrierTechnologyParameters.getInitialContextFactory());

        jmsCarrierTechnologyParameters.setInitialContextFactory(null);
        result = jmsCarrierTechnologyParameters.validate();
        assertFalse(result.getStatus().isValid());

        jmsCarrierTechnologyParameters.setInitialContextFactory("TestInitialContextFactory");
        assertNotEquals(DEFAULT_INITIAL_CTXT_FACTORY, jmsCarrierTechnologyParameters.getInitialContextFactory());
    }

    @Test(expected = ParameterRuntimeException.class)
    public void testSetName() {
        jmsCarrierTechnologyParameters.setName("TestName");
    }
}