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=========================================================
21 package org.openecomp.mso.bpmn.core;
23 import java.io.IOException;
24 import java.nio.file.Files;
25 import java.nio.file.Path;
26 import java.nio.file.Paths;
27 import java.nio.file.StandardCopyOption;
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.Test;
34 import org.openecomp.mso.bpmn.test.PropertyConfigurationSetup;
36 public class PropertyConfigurationTest {
38 public void beforeTest() throws IOException {
39 Map<String, String> defaultProperties = PropertyConfigurationSetup.createBpmnProperties();
40 defaultProperties.put("testValue", "testKey");
41 PropertyConfigurationSetup.init(defaultProperties);
45 public void testPropertyFileWatcher() throws InterruptedException, IOException {
46 Assert.assertEquals(true, PropertyConfiguration.getInstance().isFileWatcherRunning());
50 public void testPropertyLoading() throws IOException, InterruptedException {
51 PropertyConfiguration propertyConfiguration = PropertyConfiguration.getInstance();
52 Map<String,String> props = propertyConfiguration.getProperties(PropertyConfiguration.MSO_BPMN_PROPERTIES);
53 Assert.assertNotNull(props);
54 Assert.assertEquals("testValue", props.get("testKey"));
58 public void testPropertyReload() throws IOException, InterruptedException {
59 PropertyConfiguration propertyConfiguration = PropertyConfiguration.getInstance();
60 Map<String,String> properties = propertyConfiguration.getProperties(PropertyConfiguration.MSO_BPMN_PROPERTIES);
61 Assert.assertNotNull(properties);
62 Assert.assertEquals("testValue", properties.get("testKey"));
64 Map<String, String> newProperties = PropertyConfigurationSetup.createBpmnProperties();
65 newProperties.put("newKey", "newValue");
66 PropertyConfigurationSetup.addProperties(newProperties, 10000);
68 // Reload and check for the new value
69 properties = propertyConfiguration.getProperties(PropertyConfiguration.MSO_BPMN_PROPERTIES);
70 Assert.assertNotNull(properties);
71 Assert.assertEquals("newValue", properties.get("newKey"));
74 @Test(expected=IllegalArgumentException.class)
75 public void testPropertyFileDoesNotExists_NotIntheList() throws IOException {
76 PropertyConfiguration propertyConfiguration = PropertyConfiguration.getInstance();
77 propertyConfiguration.getProperties("badfile.properties");
78 Assert.fail("Expected IllegalArgumentException");
81 @Test(expected=java.lang.UnsupportedOperationException.class)
82 public void testPropertyModificationException() throws IOException {
83 PropertyConfiguration propertyConfiguration = PropertyConfiguration.getInstance();
84 Map<String,String> props = propertyConfiguration.getProperties(PropertyConfiguration.MSO_BPMN_PROPERTIES);
85 Assert.assertNotNull(props);
86 Assert.assertEquals("testValue", props.get("testKey"));
87 props.put("newKey", "newvalue");
91 public void testNotAllowedPropertyReloading() throws IOException {
92 Path msoConfigPath = Paths.get(System.getProperty("mso.config.path"));
93 Path backupPropFilePath = msoConfigPath.resolve("backup-" + PropertyConfiguration.MSO_BPMN_PROPERTIES);
96 // Create a new file... a backup file
97 Files.createFile(backupPropFilePath);
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"));
105 // Update the backup file
106 Path bpmnPropertiesSourcePath = Paths.get("src", "test", "resources", "mso.bpmn.properties");
107 Files.copy(bpmnPropertiesSourcePath, backupPropFilePath, StandardCopyOption.REPLACE_EXISTING);
109 // Cache size should remain the same
110 Assert.assertEquals(1, PropertyConfiguration.getInstance().cacheSize());
112 backupPropFilePath.toFile().delete();