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.contextmodel.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.contextmodel.concepts.AxContextModel;
34 * Apex context model tests.
39 public class ApexContextModelTest {
40 TestApexModel<AxContextModel> testApexModel;
45 * @throws Exception a testing exception
48 public void setup() throws Exception {
49 testApexModel = new TestApexModel<AxContextModel>(AxContextModel.class, new TestApexContextModelCreator());
53 public void testModelValid() throws Exception {
54 final AxValidationResult result = testApexModel.testApexModelValid();
55 assertEquals(VALID_MODEL_STRING, result.toString());
59 public void testApexModelVaidateObservation() throws Exception {
60 final AxValidationResult result = testApexModel.testApexModelVaidateObservation();
61 assertEquals(OBSERVATION_MODEL_STRING, result.toString());
65 public void testApexModelVaidateWarning() throws Exception {
66 final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
67 assertEquals(WARNING_MODEL_STRING, result.toString());
71 public void testModelVaidateInvalidModel() throws Exception {
72 final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
73 assertEquals(INVALID_MODEL_STRING, result.toString());
77 public void testModelVaidateMalstructured() throws Exception {
78 final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
79 assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString());
83 public void testModelWriteReadXml() throws Exception {
84 testApexModel.testApexModelWriteReadXml();
88 public void testModelWriteReadJson() throws Exception {
89 testApexModel.testApexModelWriteReadJson();
93 public void testModelWriteReadJpa() throws Exception {
94 final DaoParameters DaoParameters = new DaoParameters();
95 DaoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
96 DaoParameters.setPersistenceUnit("DAOTest");
98 testApexModel.testApexModelWriteReadJpa(DaoParameters);
101 private static final String VALID_MODEL_STRING = "***validation of model successful***";
103 private static final String OBSERVATION_MODEL_STRING = "\n"
104 + "***observations noted during validation of model***\n"
105 + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):"
106 + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo:OBSERVATION:description is blank\n"
107 + "********************************";
109 private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
110 + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):"
111 + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo:WARNING:"
112 + "UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
113 + "********************************";
115 private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
116 + "AxArtifactKey:(name=StringType,version=0.0.1):"
117 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema:INVALID:"
118 + "no schemaDefinition specified, schemaDefinition may not be blank\n"
119 + "AxArtifactKey:(name=contextAlbum0,version=0.0.1):"
120 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:"
121 + "scope is not defined\n" + "********************************";
123 private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
124 + "AxArtifactKey:(name=ContextModel,version=0.0.1):"
125 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextModel:INVALID:"
126 + "key information not found for key AxArtifactKey:(name=contextAlbum1,version=0.0.2)\n"
127 + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):"
128 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextModel:WARNING:"
129 + "key not found for key information entry\n" + "AxArtifactKey:(name=ContextSchemas,version=0.0.1):"
130 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas:INVALID:"
131 + "key on schemas entry AxArtifactKey:(name=MapType,version=0.0.1) "
132 + "does not equal entry key AxArtifactKey:(name=MapType,version=0.0.2)\n"
133 + "AxArtifactKey:(name=contextAlbums,version=0.0.1):"
134 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums:INVALID:"
135 + "key on context album entry key AxArtifactKey:(name=contextAlbum1,version=0.0.1) "
136 + "does not equal context album value key AxArtifactKey:(name=contextAlbum1,version=0.0.2)\n"
137 + "********************************";