a2cbe7415db71734c28b0dc115e22067aa29a5ea
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 Nordix Foundation
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.model.policymodel.handling;
23
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.assertj.core.api.Assertions.assertThatThrownBy;
26 import static org.junit.Assert.assertEquals;
27
28 import org.junit.Test;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
31 import org.onap.policy.apex.model.policymodel.concepts.AxLogic;
32
33 /**
34  * Logic reader for policy tests.
35  *
36  * @author Liam Fallon (liam.fallon@ericsson.com)
37  */
38 public class PolicyLogicReaderTest {
39
40     @Test
41     public void test() {
42         final AxReferenceKey logicKey = new AxReferenceKey("LogicParent", "0.0.1", "LogicInstanceName");
43
44         final PolicyLogicReader plReader = new PolicyLogicReader();
45
46         plReader.setLogicPackage("somewhere.over.the.rainbow");
47         assertEquals("somewhere.over.the.rainbow", plReader.getLogicPackage());
48
49         plReader.setDefaultLogic("FunkyDefaultLogic");
50         assertEquals("FunkyDefaultLogic", plReader.getDefaultLogic());
51
52         assertThatThrownBy(() -> new AxLogic(logicKey, "FunkyLogic", plReader))
53             .hasMessage("logic not found for logic "
54                             + "\"somewhere/over/the/rainbow/funkylogic/FunkyDefaultLogic.funkylogic\"");
55         plReader.setDefaultLogic(null);
56         assertThatThrownBy(() -> new AxLogic(logicKey, "FunkyLogic", plReader))
57             .hasMessage("logic not found for logic "
58                             + "\"somewhere/over/the/rainbow/funkylogic/LogicParentLogicInstanceName.funkylogic\"");
59         logicKey.setParentLocalName("LogicParentLocalName");
60         assertThatThrownBy(() -> new AxLogic(logicKey, "FunkyLogic", plReader))
61             .hasMessage("logic not found for logic " + "\"somewhere/over/the/rainbow/funkylogic/"
62                             + "LogicParentLogicParentLocalNameLogicInstanceName.funkylogic\"");
63         plReader.setLogicPackage("path.to.apex.logic");
64
65         AxLogic logic = new AxLogic(logicKey, "FunkyLogic", plReader);
66         assertThat(logic.getLogic()).endsWith("Way out man, this is funky logic!");
67
68         plReader.setLogicPackage("somewhere.over.the.rainbow");
69         plReader.setDefaultLogic("JavaLogic");
70
71         logic = new AxLogic(logicKey, "JAVA", plReader);
72         assertEquals("somewhere.over.the.rainbow.java.JavaLogic", logic.getLogic());
73
74         plReader.setDefaultLogic(null);
75
76         logic = new AxLogic(logicKey, "JAVA", plReader);
77         assertEquals("somewhere.over.the.rainbow.java.LogicParentLogicParentLocalNameLogicInstanceName",
78                         logic.getLogic());
79
80         logicKey.setParentLocalName(AxKey.NULL_KEY_NAME);
81         logic = new AxLogic(logicKey, "JAVA", plReader);
82         assertEquals("somewhere.over.the.rainbow.java.LogicParentLogicInstanceName", logic.getLogic());
83     }
84 }