2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.listener;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertNotNull;
30 import static org.junit.Assert.assertNull;
31 import static org.junit.Assert.assertTrue;
32 import static org.junit.Assert.fail;
34 import java.util.Properties;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.onap.appc.adapter.factory.MessageService;
39 import org.onap.appc.listener.AbstractListener;
40 import org.onap.appc.listener.ListenerProperties;
41 import org.onap.appc.listener.ListenerProperties.KEYS;
43 public class ListenerPropertiesTest {
45 private Properties good, bad, both;
46 private String prefix;
48 private ListenerProperties props;
53 good = new Properties();
54 bad = new Properties();
55 both = new Properties();
57 good.setProperty(String.format("%s.%s", prefix, "a"), "1");
58 good.setProperty(String.format("%s.%s", prefix, "a.b"), "2");
59 good.setProperty(String.format("%s.%s", prefix, "a.b.c"), "3");
61 bad.setProperty(prefix, "NA");
62 bad.setProperty(prefix + ".", "NA");
63 bad.setProperty(String.format("%s.%s", prefix + "x", "bad"), "NA");
64 bad.setProperty(String.format("%s.%s", "x" + prefix, "bad"), "NA");
66 for (String key : good.stringPropertyNames()) {
67 both.put(key, good.getProperty(key));
69 for (String key : bad.stringPropertyNames()) {
70 both.put(key, bad.getProperty(key));
73 props = new ListenerProperties(prefix, both);
77 public void testConstructor() {
78 props = new ListenerProperties(prefix, good);
79 assertEquals(prefix, props.getPrefix());
80 assertEquals(good.size(), props.getProperties().size());
82 props = new ListenerProperties(prefix, bad);
83 assertEquals(prefix, props.getPrefix());
84 assertTrue(props.getProperties().isEmpty());
86 props = new ListenerProperties(prefix, both);
87 assertEquals(prefix, props.getPrefix());
88 assertEquals(good.size(), props.getProperties().size());
90 for (Object val : props.getProperties().values()) {
91 assertFalse("NA".equals(val.toString()));
94 assertTrue(props.toString().contains(prefix));
98 public void testGetClass() {
99 assertNull(props.getListenerClass());
100 props.setListenerClass(AbstractListener.class);
101 assertNotNull(props.getListenerClass());
102 assertEquals(AbstractListener.class, props.getListenerClass());
106 public void testMessageServices() {
107 // Hardcode count so tests must be updated when values are added
108 assertEquals(1, MessageService.values().length);
111 MessageService def = MessageService.DMaaP;
112 assertEquals(def, MessageService.parse(null));
113 assertEquals(def, MessageService.parse(""));
114 assertEquals(def, MessageService.parse("NotDMaaP"));
116 // DMaaP case sensitivity
117 assertEquals(MessageService.DMaaP, MessageService.parse("dmaap"));
118 assertEquals(MessageService.DMaaP, MessageService.parse("DMAAP"));
119 assertEquals(MessageService.DMaaP, MessageService.parse("DMaaP"));
123 public void testKeys() {
124 // Hardcode count so tests must be updated when values are added
125 assertEquals(15, ListenerProperties.KEYS.values().length);
127 Properties tmp = new Properties();
129 tmp.load(getClass().getResourceAsStream("/org/onap/appc/default.properties"));
130 } catch (Exception e) {
131 fail("Could not load properties to test");
133 String realPrefix = tmp.getProperty("test.prefix");
134 assertNotNull(realPrefix);
135 props = new ListenerProperties(realPrefix, tmp);
137 for (KEYS key : ListenerProperties.KEYS.values()) {
138 assertNotNull(key.getFullProp(realPrefix));
139 assertNotNull(props.getProperty(key));
140 assertNotNull(props.getProperty(key.getPropertySuffix()));
145 public void testDisabled() throws Exception {
146 assertFalse(props.isDisabled());
147 props.getProperties().put(KEYS.DISABLED.getPropertySuffix(), "TRUE");
148 assertTrue(props.isDisabled());
149 props.getProperties().put(KEYS.DISABLED.getPropertySuffix(), "N/A");
150 assertFalse(props.isDisabled());
151 props.getProperties().put(KEYS.DISABLED.getPropertySuffix(), "fAlse");
152 assertFalse(props.isDisabled());
153 props.getProperties().remove(KEYS.DISABLED.getPropertySuffix());
154 assertFalse(props.isDisabled());