2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 * ============LICENSE_START=======================================================
24 * ================================================================================
25 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
26 * ================================================================================
27 * Licensed under the Apache License, Version 2.0 (the "License");
28 * you may not use this file except in compliance with the License.
29 * You may obtain a copy of the License at
31 * http://www.apache.org/licenses/LICENSE-2.0
33 * Unless required by applicable law or agreed to in writing, software
34 * distributed under the License is distributed on an "AS IS" BASIS,
35 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36 * See the License for the specific language governing permissions and
37 * limitations under the License.
38 * ============LICENSE_END=========================================================
41 package org.openecomp.mso.bpmn.core;
43 import java.io.IOException;
46 import org.junit.Assert;
47 import org.junit.Before;
48 import org.junit.Test;
51 public class PropertyConfigurationTest {
53 public void beforeTest() throws IOException {
54 PropertyConfiguration.resetPropertyConfigurationSingletonInstance();
56 Map<String, String> defaultProperties = PropertyConfigurationSetup.createBpmnProperties();
57 defaultProperties.put("testValue", "testKey");
58 PropertyConfigurationSetup.init(defaultProperties);
62 public void testPropertyFileWatcher() throws InterruptedException, IOException {
63 Assert.assertEquals(true, PropertyConfiguration.getInstance().isFileWatcherRunning());
67 public void testPropertyLoading() throws IOException, InterruptedException {
68 PropertyConfiguration propertyConfiguration = PropertyConfiguration.getInstance();
69 Map<String,String> props = propertyConfiguration.getProperties(PropertyConfiguration.MSO_BPMN_PROPERTIES);
70 Assert.assertNotNull(props);
71 Assert.assertEquals("testValue", props.get("testKey"));
75 public void testPropertyReload() throws IOException, InterruptedException {
76 PropertyConfiguration propertyConfiguration = PropertyConfiguration.getInstance();
77 Map<String,String> properties = propertyConfiguration.getProperties(PropertyConfiguration.MSO_BPMN_PROPERTIES);
78 Assert.assertNotNull(properties);
79 Assert.assertEquals("testValue", properties.get("testKey"));
81 Map<String, String> newProperties = PropertyConfigurationSetup.createBpmnProperties();
82 newProperties.put("newKey", "newValue");
83 PropertyConfigurationSetup.addProperties(newProperties, 10000);
85 // Reload and check for the new value
86 properties = propertyConfiguration.getProperties(PropertyConfiguration.MSO_BPMN_PROPERTIES);
87 Assert.assertNotNull(properties);
88 Assert.assertEquals("newValue", properties.get("newKey"));
91 @Test(expected=IllegalArgumentException.class)
92 public void testPropertyFileDoesNotExists_NotIntheList() throws IOException {
93 PropertyConfiguration propertyConfiguration = PropertyConfiguration.getInstance();
94 propertyConfiguration.getProperties("badfile.properties");
95 Assert.fail("Expected IllegalArgumentException");
98 @Test(expected=java.lang.UnsupportedOperationException.class)
99 public void testPropertyModificationException() throws IOException {
100 PropertyConfiguration propertyConfiguration = PropertyConfiguration.getInstance();
101 Map<String,String> props = propertyConfiguration.getProperties(PropertyConfiguration.MSO_BPMN_PROPERTIES);
102 Assert.assertNotNull(props);
103 Assert.assertEquals("testValue", props.get("testKey"));
104 props.put("newKey", "newvalue");