2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2020 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.model.policymodel.handling;
24 import static org.junit.Assert.assertEquals;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
29 import org.onap.policy.apex.model.basicmodel.dao.DaoParameters;
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 TestApexModel<AxPolicyModel> testApexModel;
37 * Set up the policy model tests.
39 * @throws Exception on setup errors
42 public void setup() throws Exception {
43 testApexModel = new TestApexModel<AxPolicyModel>(AxPolicyModel.class, new SupportApexPolicyModelCreator());
47 public void testModelValid() throws Exception {
48 final AxValidationResult result = testApexModel.testApexModelValid();
49 assertEquals(VALID_MODEL_STRING, result.toString());
53 public void testApexModelVaidateObservation() throws Exception {
54 final AxValidationResult result = testApexModel.testApexModelVaidateObservation();
55 assertEquals(OBSERVATION_MODEL_STRING, result.toString());
59 public void testApexModelVaidateWarning() throws Exception {
60 final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
61 assertEquals(WARNING_MODEL_STRING, result.toString());
65 public void testModelVaidateInvalidModel() throws Exception {
66 final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
67 assertEquals(INVALID_MODEL_STRING, result.toString());
71 public void testModelVaidateMalstructured() throws Exception {
72 final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
73 assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString());
77 public void testModelWriteReadXml() throws Exception {
78 testApexModel.testApexModelWriteReadXml();
82 public void testModelWriteReadJson() throws Exception {
83 testApexModel.testApexModelWriteReadJson();
87 public void testModelWriteReadJpa() throws Exception {
88 final DaoParameters DaoParameters = new DaoParameters();
89 DaoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
90 DaoParameters.setPersistenceUnit("DAOTest");
92 testApexModel.testApexModelWriteReadJpa(DaoParameters);
95 private static final String VALID_MODEL_STRING = "***validation of model successful***";
97 private static final String OBSERVATION_MODEL_STRING = "\n"
98 + "***observations noted during validation of model***\n"
99 + "AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,"
100 + "localName=state):org.onap.policy.apex.model.policymodel.concepts.AxState:OBSERVATION:"
101 + "state output stateOutput0 is not used directly by any task\n"
102 + "********************************";
104 private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
105 + "AxArtifactKey:(name=policy,version=0.0.1)"
106 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicy:WARNING:state AxReferenceKey:"
107 + "(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=anotherState) "
108 + "is not referenced in the policy execution tree\n" + "********************************";
110 private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
111 + "AxArtifactKey:(name=contextAlbum0,version=0.0.1):"
112 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:scope is not defined\n"
113 + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):"
114 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:scope is not defined\n"
116 + "(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=state):"
117 + "org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
118 + "task output field AxOutputField:(key=AxReferenceKey:"
119 + "(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=outputFields,localName=OE1PAR0),"
120 + "fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false) for task "
121 + "task:0.0.1 not in output event outEvent0:0.0.1\n" + "AxReferenceKey:"
122 + "(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=state):"
123 + "org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
124 + "task output field AxOutputField:(key=AxReferenceKey:"
125 + "(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=outputFields,localName=OE1PAR1),"
126 + "fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false) for task "
127 + "task:0.0.1 not in output event outEvent0:0.0.1\n" + "********************************";
129 private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
130 + "AxArtifactKey:(name=policyModel_KeyInfo,version=0.0.1):"
131 + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation:INVALID:"
132 + "keyInfoMap may not be empty\n" + "AxArtifactKey:(name=policyModel,version=0.0.1)"
133 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
134 + "key information not found for key AxArtifactKey:(name=policyModel,version=0.0.1)\n"
135 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
136 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
137 + "key information not found for key AxArtifactKey:(name=policyModel_KeyInfo,version=0.0.1)\n"
138 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
139 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
140 + "key information not found for key AxArtifactKey:(name=policyModel_Schemas,version=0.0.1)\n"
141 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
142 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
143 + "key information not found for key AxArtifactKey:(name=policyModel_Events,version=0.0.1)\n"
144 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
145 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
146 + "key information not found for key AxArtifactKey:(name=policyModel_Albums,version=0.0.1)\n"
147 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
148 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
149 + "key information not found for key AxArtifactKey:(name=policyModel_Tasks,version=0.0.1)\n"
150 + "AxArtifactKey:(name=policyModel,version=0.0.1)"
151 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
152 + "key information not found for key AxArtifactKey:(name=policyModel_Policies,version=0.0.1)\n"
153 + "AxArtifactKey:(name=policyModel_Schemas,version=0.0.1):"
154 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas:INVALID:"
155 + "contextSchemas may not be empty\n" + "AxArtifactKey:(name=policyModel_Events,version=0.0.1):"
156 + "org.onap.policy.apex.model.eventmodel.concepts.AxEvents:INVALID:eventMap may not be empty\n"
157 + "AxArtifactKey:(name=policyModel_Albums,version=0.0.1):"
158 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums:OBSERVATION:albums are empty\n"
159 + "AxArtifactKey:(name=policyModel_Tasks,version=0.0.1)"
160 + ":org.onap.policy.apex.model.policymodel.concepts.AxTasks:INVALID:taskMap may not be empty\n"
161 + "AxArtifactKey:(name=policyModel_Policies,version=0.0.1)"
162 + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicies:INVALID:policyMap may not be empty\n"
163 + "********************************";