2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.testsuites.integration.uservice.executionproperties;
23 import static org.awaitility.Awaitility.await;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
28 import java.io.FileInputStream;
29 import java.util.Properties;
30 import java.util.concurrent.TimeUnit;
32 import org.junit.Before;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain;
36 import org.onap.policy.apex.service.engine.main.ApexMain;
39 * This class runs integration tests for execution properties.
41 public class TestExecutionProperties {
46 public static void compilePolicy() {
48 final String[] cliArgs = {
50 "src/test/resources/policies/executionproperties/policy/ExecutionPropertiesTestPolicyModel.apex",
52 "target/ExecutionPropertiesTestPolicyModel.log",
54 "target/ExecutionPropertiesTestPolicyModel.json"
58 new ApexCommandLineEditorMain(cliArgs);
62 * Clear relative file root environment variable.
65 public void clearRelativeFileRoot() {
66 System.clearProperty("APEX_RELATIVE_FILE_ROOT");
70 * Test read only execution properties are returned from policy.
73 public void testReadOnly() throws Exception {
74 testExecutionProperties("readOnly");
78 * Test where execution properties set in task.
81 public void testEmptyToDefined() throws Exception {
82 testExecutionProperties("emptyToDefined");
86 * Test where execution properties cleared in task.
89 public void testDefinedToEmpty() throws Exception {
90 testExecutionProperties("definedToEmpty");
94 * Test where an execution properties added in task.
97 public void testAddProperty() throws Exception {
98 testExecutionProperties("addProperty");
102 * Test empty properties are transferred correctly.
105 public void testEmptyToEmpty() throws Exception {
106 testExecutionProperties("emptyToEmpty");
109 private void testExecutionProperties(final String testName) throws Exception {
110 File compiledPolicyFile = new File("target/ExecutionPropertiesTestPolicyModel.json");
111 assertTrue(compiledPolicyFile.exists());
113 new File("target/" + testName + "_out.properties").delete();
116 final String[] args = {
120 "src/test/resources/testdata/executionproperties/" + testName + "_conf.json"
123 final ApexMain apexMain = new ApexMain(args);
125 // TODO: Set back to 10 seconds
126 await().atMost(10000, TimeUnit.SECONDS)
127 .until(() -> new File("target/" + testName + "_out.properties").exists());
131 Properties expectedProperties = new Properties();
132 expectedProperties.load(new FileInputStream(
133 new File("src/test/resources/testdata/executionproperties/" + testName + "_out_expected.properties")));
135 Properties actualProperties = new Properties();
136 actualProperties.load(new FileInputStream(new File("target/" + testName + "_out.properties")));
138 assertEquals(expectedProperties, actualProperties);