2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020 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;
31 import org.junit.Before;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain;
35 import org.onap.policy.apex.service.engine.main.ApexMain;
38 * This class runs integration tests for execution properties.
40 public class TestExecutionProperties {
45 public static void compilePolicy() {
47 final String[] cliArgs = {
49 "src/test/resources/policies/executionproperties/policy/ExecutionPropertiesTestPolicyModel.apex",
51 "target/ExecutionPropertiesTestPolicyModel.log",
53 "target/ExecutionPropertiesTestPolicyModel.json"
57 new ApexCommandLineEditorMain(cliArgs);
61 * Clear relative file root environment variable.
64 public void clearRelativeFileRoot() {
65 System.clearProperty("APEX_RELATIVE_FILE_ROOT");
69 * Test read only execution properties are returned from policy.
72 public void testReadOnly() throws Exception {
73 testExecutionProperties("readOnly");
77 * Test where execution properties set in task.
80 public void testEmptyToDefined() throws Exception {
81 testExecutionProperties("emptyToDefined");
85 * Test where execution properties cleared in task.
88 public void testDefinedToEmpty() throws Exception {
89 testExecutionProperties("definedToEmpty");
93 * Test where an execution properties added in task.
96 public void testAddProperty() throws Exception {
97 testExecutionProperties("addProperty");
101 * Test empty properties are transferred correctly.
104 public void testEmptyToEmpty() throws Exception {
105 testExecutionProperties("emptyToEmpty");
108 private void testExecutionProperties(final String testName) throws Exception {
109 File compiledPolicyFile = new File("target/ExecutionPropertiesTestPolicyModel.json");
110 assertTrue(compiledPolicyFile.exists());
112 File outFile = new File("target/" + testName + "_out.properties");
113 outFile.deleteOnExit();
116 final String[] args = {
120 "src/test/resources/testdata/executionproperties/" + testName + "_conf.json"
123 final ApexMain apexMain = new ApexMain(args);
125 await().atMost(1, TimeUnit.SECONDS).until(() -> apexMain.isAlive());
126 await().atMost(10, TimeUnit.SECONDS).until(() -> outFile.exists());
127 await().atMost(1, TimeUnit.SECONDS).until(() -> outFile.length() > 0);
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(outFile));
138 assertEquals(expectedProperties, actualProperties);