Changes for checkstyle 8.32
[policy/apex-pdp.git] / model / policy-model / src / test / java / org / onap / policy / apex / model / policymodel / handling / PolicyLogicReaderTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.model.policymodel.handling;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26
27 import org.junit.Test;
28 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
30 import org.onap.policy.apex.model.policymodel.concepts.AxLogic;
31
32 /**
33  * Logic reader for policy tests.
34  * 
35  * @author Liam Fallon (liam.fallon@ericsson.com)
36  */
37 public class PolicyLogicReaderTest {
38
39     @Test
40     public void test() {
41         final AxReferenceKey logicKey = new AxReferenceKey("LogicParent", "0.0.1", "LogicInstanceName");
42
43         final PolicyLogicReader plReader = new PolicyLogicReader();
44
45         plReader.setLogicPackage("somewhere.over.the.rainbow");
46         assertEquals("somewhere.over.the.rainbow", plReader.getLogicPackage());
47
48         plReader.setDefaultLogic("FunkyDefaultLogic");
49         assertEquals("FunkyDefaultLogic", plReader.getDefaultLogic());
50
51         try {
52             new AxLogic(logicKey, "FunkyLogic", plReader);
53             fail("test should throw an exception here");
54         } catch (final Exception e) {
55             assertEquals("logic not found for logic "
56                             + "\"somewhere/over/the/rainbow/funkylogic/FunkyDefaultLogic.funkylogic\"", e.getMessage());
57         }
58
59         plReader.setDefaultLogic(null);
60         try {
61             new AxLogic(logicKey, "FunkyLogic", plReader);
62             fail("test should throw an exception here");
63         } catch (final Exception e) {
64             assertEquals("logic not found for logic "
65                             + "\"somewhere/over/the/rainbow/funkylogic/LogicParentLogicInstanceName.funkylogic\"",
66                             e.getMessage());
67         }
68
69         logicKey.setParentLocalName("LogicParentLocalName");
70         try {
71             new AxLogic(logicKey, "FunkyLogic", plReader);
72             fail("test should throw an exception here");
73         } catch (final Exception e) {
74             assertEquals("logic not found for logic " + "\"somewhere/over/the/rainbow/funkylogic/"
75                             + "LogicParentLogicParentLocalNameLogicInstanceName.funkylogic\"", e.getMessage());
76         }
77
78         plReader.setLogicPackage("path.to.apex.logic");
79         try {
80             final AxLogic logic = new AxLogic(logicKey, "FunkyLogic", plReader);
81             assertTrue(logic.getLogic().endsWith("Way out man, this is funky logic!"));
82         } catch (final Exception e) {
83             fail("test should not throw an exception");
84         }
85
86         plReader.setLogicPackage("somewhere.over.the.rainbow");
87         plReader.setDefaultLogic("JavaLogic");
88
89         try {
90             final AxLogic logic = new AxLogic(logicKey, "JAVA", plReader);
91             assertEquals("somewhere.over.the.rainbow.java.JavaLogic", logic.getLogic());
92         } catch (final Exception e) {
93             fail("test should not throw an exception");
94         }
95
96         plReader.setDefaultLogic(null);
97         try {
98             final AxLogic logic = new AxLogic(logicKey, "JAVA", plReader);
99             assertEquals("somewhere.over.the.rainbow.java.LogicParentLogicParentLocalNameLogicInstanceName",
100                             logic.getLogic());
101         } catch (final Exception e) {
102             fail("test should not throw an exception");
103         }
104
105         logicKey.setParentLocalName(AxKey.NULL_KEY_NAME);
106         try {
107             final AxLogic logic = new AxLogic(logicKey, "JAVA", plReader);
108             assertEquals("somewhere.over.the.rainbow.java.LogicParentLogicInstanceName", logic.getLogic());
109         } catch (final Exception e) {
110             fail("test should not throw an exception");
111         }
112     }
113 }