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.fail;
27 import org.junit.Test;
28 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
29 import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
30 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
31 import org.onap.policy.apex.model.policymodel.handling.PolicyModelMerger;
36 * @author Liam Fallon (liam.fallon@ericsson.com)
38 public class PolicyModelMergerTest {
41 public void testPolicyModelMerger() {
42 final AxPolicyModel leftPolicyModel = new ApexPolicyModelCreatorTest().getModel();
43 AxPolicyModel rightPolicyModel = new ApexPolicyModelCreatorTest().getModel();
46 final AxPolicyModel mergedPolicyModel = PolicyModelMerger.getMergedPolicyModel(leftPolicyModel,
47 rightPolicyModel, false);
48 assertEquals(leftPolicyModel, mergedPolicyModel);
49 assertEquals(rightPolicyModel, mergedPolicyModel);
50 } catch (final ApexModelException e) {
51 fail("test should not throw an exception");
54 leftPolicyModel.setKey(new AxArtifactKey("LeftPolicyModel", "0.0.1"));
56 PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, false);
57 fail("test should throw an exception here");
58 } catch (final ApexModelException e) {
59 assertEquals("left model is invalid: \n***validation of model fai", e.getMessage().substring(0, 50));
62 leftPolicyModel.setKey(new AxArtifactKey("LeftPolicyModel", "0.0.1"));
64 assertNotNull(PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, false, true));
65 } catch (final ApexModelException e) {
66 fail("test should not throw an exception");
69 leftPolicyModel.getKeyInformation().generateKeyInfo(leftPolicyModel);
71 final AxPolicyModel mergedPolicyModel = PolicyModelMerger.getMergedPolicyModel(leftPolicyModel,
72 rightPolicyModel, true);
73 assertNotNull(mergedPolicyModel);
74 } catch (final ApexModelException e) {
75 fail("test should not throw an exception");
78 rightPolicyModel.setKey(new AxArtifactKey("RightPolicyModel", "0.0.1"));
80 PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, false);
81 fail("test should throw an exception here");
82 } catch (final ApexModelException e) {
83 assertEquals("right model is invalid: \n***validation of model fa", e.getMessage().substring(0, 50));
86 rightPolicyModel.setKey(new AxArtifactKey("RightPolicyModel", "0.0.1"));
88 assertNotNull(PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, false, true));
89 } catch (final ApexModelException e) {
90 fail("test should not throw an exception");
93 rightPolicyModel.getKeyInformation().generateKeyInfo(rightPolicyModel);
95 final AxPolicyModel mergedPolicyModel = PolicyModelMerger.getMergedPolicyModel(leftPolicyModel,
96 rightPolicyModel, false);
97 assertNotNull(mergedPolicyModel);
98 } catch (final ApexModelException e) {
99 fail("test should not throw an exception");
102 rightPolicyModel = new ApexPolicyModelCreatorTest().getAnotherModel();
104 final AxPolicyModel mergedPolicyModel = PolicyModelMerger.getMergedPolicyModel(leftPolicyModel,
105 rightPolicyModel, true);
106 assertNotNull(mergedPolicyModel);
107 } catch (final ApexModelException e) {
108 fail("test should not throw an exception");