2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2020 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.dao.DaoParameters;
31 import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
32 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
34 public class ApexPolicyModelTest {
35 TestApexModel<AxPolicyModel> testApexModel;
38 * Set up the policy model tests.
40 * @throws Exception on setup errors
43 public void setup() throws Exception {
44 testApexModel = new TestApexModel<AxPolicyModel>(AxPolicyModel.class, new SupportApexPolicyModelCreator());
48 public void testModelValid() throws Exception {
49 final AxValidationResult result = testApexModel.testApexModelValid();
50 assertEquals(VALID_MODEL_STRING, result.toString());
54 public void testApexModelVaidateObservation() throws Exception {
55 final AxValidationResult result = testApexModel.testApexModelVaidateObservation();
56 assertEquals(OBSERVATION_MODEL_STRING, result.toString());
60 public void testApexModelVaidateWarning() throws Exception {
61 final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
62 assertEquals(WARNING_MODEL_STRING, result.toString());
66 public void testModelVaidateInvalidModel() throws Exception {
67 final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
68 assertEquals(INVALID_MODEL_STRING, result.toString());
72 public void testModelVaidateMalstructured() throws Exception {
73 final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
74 assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString());
78 public void testModelWriteReadXml() throws Exception {
79 testApexModel.testApexModelWriteReadXml();
83 public void testModelWriteReadJson() throws Exception {
84 testApexModel.testApexModelWriteReadJson();
88 public void testModelWriteReadJpa() throws Exception {
89 final DaoParameters DaoParameters = new DaoParameters();
90 DaoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
91 DaoParameters.setPersistenceUnit("DAOTest");
93 testApexModel.testApexModelWriteReadJpa(DaoParameters);
96 private static final String VALID_MODEL_STRING = "***validation of model successful***";
98 private static final String OBSERVATION_MODEL_STRING = "\n"
99 + "***observations noted during validation of model***\n"
100 + "AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,"
101 + "localName=state):org.onap.policy.apex.model.policymodel.concepts.AxState:OBSERVATION:"
102 + "state output stateOutput0 is not used directly by any task\n"
103 + "********************************";
105 private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
106 + "AxArtifactKey:(name=policy,version=0.0.1)"
107 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicy:WARNING:state AxReferenceKey:"
108 + "(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=anotherState) "
109 + "is not referenced in the policy execution tree\n" + "********************************";
111 private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
112 + "AxArtifactKey:(name=contextAlbum0,version=0.0.1):"
113 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:scope is not defined\n"
114 + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):"
115 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:scope is not defined\n"
116 + "********************************";
118 private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
119 + "AxArtifactKey:(name=policyModel_KeyInfo,version=0.0.1):"
120 + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation:INVALID:"
121 + "keyInfoMap may not be empty\n" + "AxArtifactKey:(name=policyModel,version=0.0.1)"
122 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
123 + "key information not found for key AxArtifactKey:(name=policyModel,version=0.0.1)\n"
124 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
125 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
126 + "key information not found for key AxArtifactKey:(name=policyModel_KeyInfo,version=0.0.1)\n"
127 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
128 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
129 + "key information not found for key AxArtifactKey:(name=policyModel_Schemas,version=0.0.1)\n"
130 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
131 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
132 + "key information not found for key AxArtifactKey:(name=policyModel_Events,version=0.0.1)\n"
133 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
134 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
135 + "key information not found for key AxArtifactKey:(name=policyModel_Albums,version=0.0.1)\n"
136 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
137 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
138 + "key information not found for key AxArtifactKey:(name=policyModel_Tasks,version=0.0.1)\n"
139 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
140 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
141 + "key information not found for key AxArtifactKey:(name=policyModel_Policies,version=0.0.1)\n"
142 + "AxArtifactKey:(name=policyModel_Schemas,version=0.0.1):"
143 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas:INVALID:"
144 + "contextSchemas may not be empty\n" + "AxArtifactKey:(name=policyModel_Events,version=0.0.1):"
145 + "org.onap.policy.apex.model.eventmodel.concepts.AxEvents:INVALID:eventMap may not be empty\n"
146 + "AxArtifactKey:(name=policyModel_Albums,version=0.0.1):"
147 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums:OBSERVATION:albums are empty\n"
148 + "AxArtifactKey:(name=policyModel_Tasks,version=0.0.1)"
149 + ":org.onap.policy.apex.model.policymodel.concepts.AxTasks:INVALID:taskMap may not be empty\n"
150 + "AxArtifactKey:(name=policyModel_Policies,version=0.0.1)"
151 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicies:INVALID:policyMap may not be empty\n"
152 + "********************************";