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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.model.policymodel.handling;
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;
29 import java.util.TreeSet;
31 import org.junit.Test;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
33 import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
34 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
35 import org.onap.policy.apex.model.policymodel.handling.PolicyModelSplitter;
37 public class PolicyModelSplitterTest {
40 final AxPolicyModel apexModel = new SupportApexPolicyModelCreator().getModel();
42 final Set<AxArtifactKey> requiredPolicySet = new TreeSet<AxArtifactKey>();
43 requiredPolicySet.add(new AxArtifactKey("policy", "0.0.1"));
45 // There's only one policy so a split of this model on that policy should return the same
47 AxPolicyModel splitApexModel = null;
49 splitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet);
50 } catch (final ApexModelException e) {
54 // The only difference between the models should be that the unused event outEvent1 should
55 // not be in the split model
56 apexModel.getEvents().getEventMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
57 apexModel.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
58 assertTrue(apexModel.equals(splitApexModel));
60 final Set<AxArtifactKey> requiredMissingPolicySet = new TreeSet<AxArtifactKey>();
61 requiredPolicySet.add(new AxArtifactKey("MissingPolicy", "0.0.1"));
63 AxPolicyModel missingSplitApexModel = null;
65 missingSplitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredMissingPolicySet);
66 } catch (final ApexModelException e) {
69 assertNotNull(missingSplitApexModel);
71 splitApexModel = null;
73 splitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet, true);
74 } catch (final ApexModelException e) {
78 // The only difference between the models should be that the unused event outEvent1 should
79 // not be in the split model
80 apexModel.getEvents().getEventMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
81 apexModel.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
82 assertTrue(apexModel.equals(splitApexModel));
84 // There's only one policy so a split of this model on that policy should return the same
87 apexModel.getKey().setName("InvalidPolicyModelName");
88 PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet);
89 fail("test should throw an exception here");
90 } catch (final Exception e) {
91 assertEquals("source model is invalid: \n***validation of model f", e.getMessage().substring(0, 50));