Remove GroupValidationResult
[policy/apex-pdp.git] / core / core-engine / src / test / java / org / onap / policy / apex / core / engine / EngineParametersTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 Nordix Foundation.
5  *  Modifications Copyright (C) 2021 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  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.apex.core.engine;
24
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertTrue;
29
30 import java.util.ArrayList;
31 import java.util.LinkedHashMap;
32 import java.util.List;
33 import java.util.Map;
34 import org.junit.Test;
35 import org.onap.policy.apex.context.parameters.ContextParameters;
36 import org.onap.policy.common.parameters.ParameterService;
37
38 /**
39  * Test the executor parameters.
40  *
41  */
42 public class EngineParametersTest {
43
44     @Test
45     public void test() {
46         EngineParameters pars = new EngineParameters();
47         pars.setName("Name");
48         assertEquals("Name", pars.getName());
49
50         ContextParameters contextPars = new ContextParameters();
51
52         pars.setContextParameters(contextPars);
53         assertEquals(contextPars, pars.getContextParameters());
54
55         Map<String, ExecutorParameters> executorParameterMap = new LinkedHashMap<>();
56         executorParameterMap.put("Executor", new ExecutorParameters());
57         pars.setExecutorParameterMap(executorParameterMap);
58         assertEquals(executorParameterMap, pars.getExecutorParameterMap());
59
60         List<TaskParameters> taskParameters = new ArrayList<>();
61         taskParameters.add(new TaskParameters("param1key", "param1value", "param1taskId"));
62         taskParameters.add(new TaskParameters("param1key", "param1value", null));
63         pars.setTaskParameters(taskParameters);
64
65         assertThat(pars.validate().getResult()).isNull();
66         assertTrue(pars.validate().isValid());
67
68         ParameterService.register(pars);
69         ParameterService.deregister(pars);
70     }
71
72     @Test
73     public void test_invalid() {
74         EngineParameters pars = new EngineParameters();
75         pars.setName("Name");
76         assertEquals("Name", pars.getName());
77
78         ContextParameters contextPars = new ContextParameters();
79
80         pars.setContextParameters(contextPars);
81         assertEquals(contextPars, pars.getContextParameters());
82
83         Map<String, ExecutorParameters> executorParameterMap = Map.of("Executor", new ExecutorParameters());
84         pars.setExecutorParameterMap(executorParameterMap);
85         assertEquals(executorParameterMap, pars.getExecutorParameterMap());
86
87         pars.setTaskParameters(List.of(new TaskParameters(null, "param1value", "param1taskId")));
88         assertFalse(pars.validate().isValid());
89         pars.setTaskParameters(List.of(new TaskParameters(" ", "param1value", "param1taskId")));
90         assertFalse(pars.validate().isValid());
91         pars.setTaskParameters(List.of(new TaskParameters("param1key", "", "param1taskId")));
92         assertFalse(pars.validate().isValid());
93     }
94 }