50b9a53f049309b8dec49b6d65bf514abcfdfecb
[so.git] / bpmn / MSOCoreBPMN / src / test / java / org / openecomp / mso / bpmn / core / PropertyConfigurationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 /*- 
22  * ============LICENSE_START======================================================= 
23  * OPENECOMP - MSO 
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 
30  * 
31  *      http://www.apache.org/licenses/LICENSE-2.0 
32  * 
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========================================================= 
39  */ 
40
41 package org.openecomp.mso.bpmn.core;
42
43 import java.io.IOException;
44 import java.nio.file.Files;
45 import java.nio.file.Path;
46 import java.nio.file.Paths;
47 import java.nio.file.StandardCopyOption;
48 import java.util.Map;
49
50 import org.junit.Assert;
51 import org.junit.Before;
52 import org.junit.Test;
53
54
55 public class PropertyConfigurationTest {
56         @Before
57         public void beforeTest() throws IOException {
58                 Map<String, String> defaultProperties = PropertyConfigurationSetup.createBpmnProperties();
59                 defaultProperties.put("testValue", "testKey");
60                 PropertyConfigurationSetup.init(defaultProperties);
61         }
62         
63         @Test
64         public void testPropertyFileWatcher() throws InterruptedException, IOException {
65                 Assert.assertEquals(true, PropertyConfiguration.getInstance().isFileWatcherRunning());
66         }
67         
68         @Test
69         public void testPropertyLoading() throws IOException, InterruptedException {
70                 PropertyConfiguration propertyConfiguration = PropertyConfiguration.getInstance();
71                 Map<String,String> props = propertyConfiguration.getProperties(PropertyConfiguration.MSO_BPMN_PROPERTIES);
72                 Assert.assertNotNull(props);
73                 Assert.assertEquals("testValue", props.get("testKey"));
74         }
75         
76         @Test
77         public void testPropertyReload() throws IOException, InterruptedException {
78                 PropertyConfiguration propertyConfiguration = PropertyConfiguration.getInstance();
79                 Map<String,String> properties = propertyConfiguration.getProperties(PropertyConfiguration.MSO_BPMN_PROPERTIES);
80                 Assert.assertNotNull(properties);
81                 Assert.assertEquals("testValue", properties.get("testKey"));
82
83                 Map<String, String> newProperties = PropertyConfigurationSetup.createBpmnProperties();
84                 newProperties.put("newKey", "newValue");
85                 PropertyConfigurationSetup.addProperties(newProperties, 10000);
86
87                 // Reload and check for the new value
88                 properties = propertyConfiguration.getProperties(PropertyConfiguration.MSO_BPMN_PROPERTIES);
89                 Assert.assertNotNull(properties);
90                 Assert.assertEquals("newValue", properties.get("newKey"));
91         }
92         
93         @Test(expected=IllegalArgumentException.class)
94         public void testPropertyFileDoesNotExists_NotIntheList() throws IOException {
95                 PropertyConfiguration propertyConfiguration = PropertyConfiguration.getInstance();
96                 propertyConfiguration.getProperties("badfile.properties");
97                 Assert.fail("Expected IllegalArgumentException");
98         }
99         
100         @Test(expected=java.lang.UnsupportedOperationException.class)
101         public void testPropertyModificationException() throws IOException {
102                 PropertyConfiguration propertyConfiguration = PropertyConfiguration.getInstance();
103                 Map<String,String> props = propertyConfiguration.getProperties(PropertyConfiguration.MSO_BPMN_PROPERTIES);
104                 Assert.assertNotNull(props);
105                 Assert.assertEquals("testValue", props.get("testKey"));
106                 props.put("newKey", "newvalue");
107         }
108 }