2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2020,2022 Nordix Foundation.
5 * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.apex.model.policymodel.handling;
25 import static org.junit.Assert.assertEquals;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
30 import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
31 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
33 public class ApexPolicyModelTest {
34 private static final String VALID_MODEL_STRING = "***validation of model successful***";
36 private static final String OBSERVATION_MODEL_STRING = "\n"
37 + "***observations noted during validation of model***\n"
38 + "AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,"
39 + "localName=state):org.onap.policy.apex.model.policymodel.concepts.AxState:OBSERVATION:"
40 + "state output stateOutput0 is not used directly by any task\n"
41 + "********************************";
43 private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
44 + "AxArtifactKey:(name=policy,version=0.0.1)"
45 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicy:WARNING:state AxReferenceKey:"
46 + "(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=anotherState) "
47 + "is not referenced in the policy execution tree\n" + "********************************";
49 private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
50 + "AxArtifactKey:(name=contextAlbum0,version=0.0.1):"
51 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:scope is not defined\n"
52 + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):"
53 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:scope is not defined\n"
54 + "********************************";
56 private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
57 + "AxArtifactKey:(name=policyModel_KeyInfo,version=0.0.1):"
58 + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation:INVALID:"
59 + "keyInfoMap may not be empty\n" + "AxArtifactKey:(name=policyModel,version=0.0.1)"
60 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
61 + "key information not found for key AxArtifactKey:(name=policyModel,version=0.0.1)\n"
62 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
63 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
64 + "key information not found for key AxArtifactKey:(name=policyModel_KeyInfo,version=0.0.1)\n"
65 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
66 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
67 + "key information not found for key AxArtifactKey:(name=policyModel_Schemas,version=0.0.1)\n"
68 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
69 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
70 + "key information not found for key AxArtifactKey:(name=policyModel_Events,version=0.0.1)\n"
71 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
72 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
73 + "key information not found for key AxArtifactKey:(name=policyModel_Albums,version=0.0.1)\n"
74 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
75 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
76 + "key information not found for key AxArtifactKey:(name=policyModel_Tasks,version=0.0.1)\n"
77 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
78 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
79 + "key information not found for key AxArtifactKey:(name=policyModel_Policies,version=0.0.1)\n"
80 + "AxArtifactKey:(name=policyModel_Schemas,version=0.0.1):"
81 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas:INVALID:"
82 + "contextSchemas may not be empty\n" + "AxArtifactKey:(name=policyModel_Events,version=0.0.1):"
83 + "org.onap.policy.apex.model.eventmodel.concepts.AxEvents:INVALID:eventMap may not be empty\n"
84 + "AxArtifactKey:(name=policyModel_Albums,version=0.0.1):"
85 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums:OBSERVATION:albums are empty\n"
86 + "AxArtifactKey:(name=policyModel_Tasks,version=0.0.1)"
87 + ":org.onap.policy.apex.model.policymodel.concepts.AxTasks:INVALID:taskMap may not be empty\n"
88 + "AxArtifactKey:(name=policyModel_Policies,version=0.0.1)"
89 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicies:INVALID:policyMap may not be empty\n"
90 + "********************************";
92 TestApexModel<AxPolicyModel> testApexModel;
95 * Set up the policy model tests.
97 * @throws Exception on setup errors
100 public void setup() throws Exception {
101 testApexModel = new TestApexModel<AxPolicyModel>(AxPolicyModel.class, new SupportApexPolicyModelCreator());
105 public void testModelValid() throws Exception {
106 final AxValidationResult result = testApexModel.testApexModelValid();
107 assertEquals(VALID_MODEL_STRING, result.toString());
111 public void testApexModelVaidateObservation() throws Exception {
112 final AxValidationResult result = testApexModel.testApexModelVaidateObservation();
113 assertEquals(OBSERVATION_MODEL_STRING, result.toString());
117 public void testApexModelVaidateWarning() throws Exception {
118 final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
119 assertEquals(WARNING_MODEL_STRING, result.toString());
123 public void testModelVaidateInvalidModel() throws Exception {
124 final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
125 assertEquals(INVALID_MODEL_STRING, result.toString());
129 public void testModelVaidateMalstructured() throws Exception {
130 final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
131 assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString());
135 public void testModelWriteReadXml() throws Exception {
136 testApexModel.testApexModelWriteReadXml();
140 public void testModelWriteReadJson() throws Exception {
141 testApexModel.testApexModelWriteReadJson();