2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.listener;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertNull;
29 import static org.junit.Assert.assertTrue;
30 import static org.junit.Assert.fail;
32 import java.util.Properties;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.openecomp.appc.adapter.factory.MessageService;
37 import org.openecomp.appc.listener.AbstractListener;
38 import org.openecomp.appc.listener.ListenerProperties;
39 import org.openecomp.appc.listener.ListenerProperties.KEYS;
41 public class TestListenerProperties {
43 private Properties good, bad, both;
44 private String prefix;
46 private ListenerProperties props;
51 good = new Properties();
52 bad = new Properties();
53 both = new Properties();
55 good.setProperty(String.format("%s.%s", prefix, "a"), "1");
56 good.setProperty(String.format("%s.%s", prefix, "a.b"), "2");
57 good.setProperty(String.format("%s.%s", prefix, "a.b.c"), "3");
59 bad.setProperty(prefix, "NA");
60 bad.setProperty(prefix + ".", "NA");
61 bad.setProperty(String.format("%s.%s", prefix + "x", "bad"), "NA");
62 bad.setProperty(String.format("%s.%s", "x" + prefix, "bad"), "NA");
64 for (String key : good.stringPropertyNames()) {
65 both.put(key, good.getProperty(key));
67 for (String key : bad.stringPropertyNames()) {
68 both.put(key, bad.getProperty(key));
71 props = new ListenerProperties(prefix, both);
75 public void testConstructor() {
76 props = new ListenerProperties(prefix, good);
77 assertEquals(prefix, props.getPrefix());
78 assertEquals(good.size(), props.getProperties().size());
80 props = new ListenerProperties(prefix, bad);
81 assertEquals(prefix, props.getPrefix());
82 assertTrue(props.getProperties().isEmpty());
84 props = new ListenerProperties(prefix, both);
85 assertEquals(prefix, props.getPrefix());
86 assertEquals(good.size(), props.getProperties().size());
88 for (Object val : props.getProperties().values()) {
89 assertFalse("NA".equals(val.toString()));
92 assertTrue(props.toString().contains(prefix));
96 public void testGetClass() {
97 assertNull(props.getListenerClass());
98 props.setListenerClass(AbstractListener.class);
99 assertNotNull(props.getListenerClass());
100 assertEquals(AbstractListener.class, props.getListenerClass());
104 public void testMessageServices() {
105 // Hardcode count so tests must be updated when values are added
106 assertEquals(1, MessageService.values().length);
109 MessageService def = MessageService.DMaaP;
110 assertEquals(def, MessageService.parse(null));
111 assertEquals(def, MessageService.parse(""));
112 assertEquals(def, MessageService.parse("NotDMaaP"));
114 // DMaaP case sensitivity
115 assertEquals(MessageService.DMaaP, MessageService.parse("dmaap"));
116 assertEquals(MessageService.DMaaP, MessageService.parse("DMAAP"));
117 assertEquals(MessageService.DMaaP, MessageService.parse("DMaaP"));
121 public void testKeys() {
122 // Hardcode count so tests must be updated when values are added
123 assertEquals(15, ListenerProperties.KEYS.values().length);
125 Properties tmp = new Properties();
127 tmp.load(getClass().getResourceAsStream("/org/openecomp/appc/default.properties"));
128 } catch (Exception e) {
129 fail("Could not load properties to test");
131 String realPrefix = tmp.getProperty("test.prefix");
132 assertNotNull(realPrefix);
133 props = new ListenerProperties(realPrefix, tmp);
135 for (KEYS key : ListenerProperties.KEYS.values()) {
136 assertNotNull(key.getFullProp(realPrefix));
137 assertNotNull(props.getProperty(key));
138 assertNotNull(props.getProperty(key.getPropertySuffix()));
143 public void testDisabled() throws Exception {
144 assertFalse(props.isDisabled());
145 props.getProperties().put(KEYS.DISABLED.getPropertySuffix(), "TRUE");
146 assertTrue(props.isDisabled());
147 props.getProperties().put(KEYS.DISABLED.getPropertySuffix(), "N/A");
148 assertFalse(props.isDisabled());
149 props.getProperties().put(KEYS.DISABLED.getPropertySuffix(), "fAlse");
150 assertFalse(props.isDisabled());
151 props.getProperties().remove(KEYS.DISABLED.getPropertySuffix());
152 assertFalse(props.isDisabled());