2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020 Nordix Foundation.
4 * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.testsuites.integration.uservice.executionproperties;
24 import static org.awaitility.Awaitility.await;
25 import static org.junit.Assert.assertEquals;
28 import java.io.FileInputStream;
29 import java.util.Properties;
30 import java.util.concurrent.TimeUnit;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaEditorMain;
34 import org.onap.policy.apex.service.engine.main.ApexMain;
37 * This class runs integration tests for execution properties.
39 public class TestExecutionProperties {
42 * Clear relative file root environment variable.
45 public void clearRelativeFileRoot() {
46 System.clearProperty("APEX_RELATIVE_FILE_ROOT");
50 * Test read only execution properties are returned from policy.
53 public void testReadOnly() throws Exception {
54 testExecutionProperties("readOnly");
58 * Test where execution properties set in task.
61 public void testEmptyToDefined() throws Exception {
62 testExecutionProperties("emptyToDefined");
66 * Test where execution properties cleared in task.
69 public void testDefinedToEmpty() throws Exception {
70 testExecutionProperties("definedToEmpty");
74 * Test where an execution properties added in task.
77 public void testAddProperty() throws Exception {
78 testExecutionProperties("addProperty");
82 * Test empty properties are transferred correctly.
85 public void testEmptyToEmpty() throws Exception {
86 testExecutionProperties("emptyToEmpty");
89 private void testExecutionProperties(final String testName) throws Exception {
91 final String[] cliArgs = new String[] {
93 "src/test/resources/policies/executionproperties/policy/ExecutionPropertiesTestPolicyModel.apex",
95 "target/ExecutionPropertiesTestPolicyModel.log",
97 "src/test/resources/testdata/executionproperties/" + testName + "_conf.json",
99 "src/test/resources/tosca/ToscaTemplate.json",
101 "target/classes/APEXPolicy.json"
105 new ApexCliToscaEditorMain(cliArgs);
107 File outFile = new File("target/" + testName + "_out.properties");
108 outFile.deleteOnExit();
111 final String[] args = {
115 "target/classes/APEXPolicy.json"
118 final ApexMain apexMain = new ApexMain(args);
120 await().atMost(1, TimeUnit.SECONDS).until(() -> apexMain.isAlive());
121 await().atMost(10, TimeUnit.SECONDS).until(() -> outFile.exists());
122 await().atMost(1, TimeUnit.SECONDS).until(() -> outFile.length() > 0);
126 Properties expectedProperties = new Properties();
127 expectedProperties.load(new FileInputStream(
128 new File("src/test/resources/testdata/executionproperties/" + testName + "_out_expected.properties")));
130 Properties actualProperties = new Properties();
131 actualProperties.load(new FileInputStream(outFile));
133 assertEquals(expectedProperties, actualProperties);