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
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.model.policymodel.handling;
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;
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;
34 * Logic reader for policy tests.
36 * @author Liam Fallon (liam.fallon@ericsson.com)
38 public class PolicyLogicReaderTest {
42 final AxReferenceKey logicKey = new AxReferenceKey("LogicParent", "0.0.1", "LogicInstanceName");
44 final PolicyLogicReader plReader = new PolicyLogicReader();
46 plReader.setLogicPackage("somewhere.over.the.rainbow");
47 assertEquals("somewhere.over.the.rainbow", plReader.getLogicPackage());
49 plReader.setDefaultLogic("FunkyDefaultLogic");
50 assertEquals("FunkyDefaultLogic", plReader.getDefaultLogic());
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");
65 AxLogic logic = new AxLogic(logicKey, "FunkyLogic", plReader);
66 assertThat(logic.getLogic()).endsWith("Way out man, this is funky logic!");
68 plReader.setLogicPackage("somewhere.over.the.rainbow");
69 plReader.setDefaultLogic("JavaLogic");
71 logic = new AxLogic(logicKey, "JAVA", plReader);
72 assertEquals("somewhere.over.the.rainbow.java.JavaLogic", logic.getLogic());
74 plReader.setDefaultLogic(null);
76 logic = new AxLogic(logicKey, "JAVA", plReader);
77 assertEquals("somewhere.over.the.rainbow.java.LogicParentLogicParentLocalNameLogicInstanceName",
80 logicKey.setParentLocalName(AxKey.NULL_KEY_NAME);
81 logic = new AxLogic(logicKey, "JAVA", plReader);
82 assertEquals("somewhere.over.the.rainbow.java.LogicParentLogicInstanceName", logic.getLogic());