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;
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 {
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;
47 splitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet);
48 } catch (final ApexModelException e) {
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));
58 final Set<AxArtifactKey> requiredMissingPolicySet = new TreeSet<AxArtifactKey>();
59 requiredPolicySet.add(new AxArtifactKey("MissingPolicy", "0.0.1"));
61 AxPolicyModel missingSplitApexModel = null;
63 missingSplitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredMissingPolicySet);
64 } catch (final ApexModelException e) {
67 assertNotNull(missingSplitApexModel);
69 splitApexModel = null;
71 splitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet, true);
72 } catch (final ApexModelException e) {
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));
82 // There's only one policy so a split of this model on that policy should return the same
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));