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.assertThatThrownBy;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
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;
35 public class PolicyModelSplitterTest {
37 public void test() throws ApexModelException {
38 final AxPolicyModel apexModel = new SupportApexPolicyModelCreator().getModel();
40 final Set<AxArtifactKey> requiredPolicySet = new TreeSet<AxArtifactKey>();
41 requiredPolicySet.add(new AxArtifactKey("policy", "0.0.1"));
43 // There's only one policy so a split of this model on that policy should return the same
45 AxPolicyModel splitApexModel = null;
46 splitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet);
48 // The only difference between the models should be that the unused event outEvent1 should
49 // not be in the split model
50 apexModel.getEvents().getEventMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
51 apexModel.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
52 assertTrue(apexModel.equals(splitApexModel));
54 final Set<AxArtifactKey> requiredMissingPolicySet = new TreeSet<AxArtifactKey>();
55 requiredPolicySet.add(new AxArtifactKey("MissingPolicy", "0.0.1"));
57 AxPolicyModel missingSplitApexModel = null;
58 missingSplitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredMissingPolicySet);
59 assertNotNull(missingSplitApexModel);
61 splitApexModel = null;
62 splitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet, true);
64 // The only difference between the models should be that the unused event outEvent1 should
65 // not be in the split model
66 apexModel.getEvents().getEventMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
67 apexModel.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
68 assertTrue(apexModel.equals(splitApexModel));
70 // There's only one policy so a split of this model on that policy should return the same
72 apexModel.getKey().setName("InvalidPolicyModelName");
73 assertThatThrownBy(() -> PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet))
74 .hasMessageContaining("source model is invalid: \n***validation of model f");