Changes for checkstyle 8.32
[policy/apex-pdp.git] / model / policy-model / src / test / java / org / onap / policy / apex / model / policymodel / handling / PolicyModelSplitterTest.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.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.junit.Assert.fail;
27
28 import java.util.Set;
29 import java.util.TreeSet;
30 import org.junit.Test;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
32 import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
33 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
34
35 public class PolicyModelSplitterTest {
36     @Test
37     public void test() {
38         final AxPolicyModel apexModel = new SupportApexPolicyModelCreator().getModel();
39
40         final Set<AxArtifactKey> requiredPolicySet = new TreeSet<AxArtifactKey>();
41         requiredPolicySet.add(new AxArtifactKey("policy", "0.0.1"));
42
43         // There's only one policy so a split of this model on that policy should return the same
44         // model
45         AxPolicyModel splitApexModel = null;
46         try {
47             splitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet);
48         } catch (final ApexModelException e) {
49             fail(e.getMessage());
50         }
51
52         // The only difference between the models should be that the unused event outEvent1 should
53         // not be in the split model
54         apexModel.getEvents().getEventMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
55         apexModel.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
56         assertTrue(apexModel.equals(splitApexModel));
57
58         final Set<AxArtifactKey> requiredMissingPolicySet = new TreeSet<AxArtifactKey>();
59         requiredPolicySet.add(new AxArtifactKey("MissingPolicy", "0.0.1"));
60
61         AxPolicyModel missingSplitApexModel = null;
62         try {
63             missingSplitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredMissingPolicySet);
64         } catch (final ApexModelException e) {
65             fail(e.getMessage());
66         }
67         assertNotNull(missingSplitApexModel);
68
69         splitApexModel = null;
70         try {
71             splitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet, true);
72         } catch (final ApexModelException e) {
73             fail(e.getMessage());
74         }
75
76         // The only difference between the models should be that the unused event outEvent1 should
77         // not be in the split model
78         apexModel.getEvents().getEventMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
79         apexModel.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
80         assertTrue(apexModel.equals(splitApexModel));
81
82         // There's only one policy so a split of this model on that policy should return the same
83         // model
84         try {
85             apexModel.getKey().setName("InvalidPolicyModelName");
86             PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet);
87             fail("test should throw an exception here");
88         } catch (final Exception e) {
89             assertEquals("source model is invalid: \n***validation of model f", e.getMessage().substring(0, 50));
90         }
91
92     }
93 }