2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2020,2022 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.test.TestApexModel;
30 import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel;
33 * Apex context model tests.
38 public class ApexContextModelTest {
40 private static final String VALID_MODEL_STRING = "***validation of model successful***";
42 private static final String OBSERVATION_MODEL_STRING = "\n"
43 + "***observations noted during validation of model***\n"
44 + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):"
45 + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo:OBSERVATION:description is blank\n"
46 + "********************************";
48 private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
49 + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):"
50 + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo:WARNING:"
51 + "UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
52 + "********************************";
54 private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
55 + "AxArtifactKey:(name=StringType,version=0.0.1):"
56 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema:INVALID:"
57 + "no schemaDefinition specified, schemaDefinition may not be blank\n"
58 + "AxArtifactKey:(name=contextAlbum0,version=0.0.1):"
59 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:"
60 + "scope is not defined\n" + "********************************";
62 private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
63 + "AxArtifactKey:(name=ContextModel,version=0.0.1):"
64 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextModel:INVALID:"
65 + "key information not found for key AxArtifactKey:(name=contextAlbum1,version=0.0.2)\n"
66 + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):"
67 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextModel:WARNING:"
68 + "key not found for key information entry\n" + "AxArtifactKey:(name=ContextSchemas,version=0.0.1):"
69 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas:INVALID:"
70 + "key on schemas entry AxArtifactKey:(name=MapType,version=0.0.1) "
71 + "does not equal entry key AxArtifactKey:(name=MapType,version=0.0.2)\n"
72 + "AxArtifactKey:(name=contextAlbums,version=0.0.1):"
73 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums:INVALID:"
74 + "key on context album entry key AxArtifactKey:(name=contextAlbum1,version=0.0.1) "
75 + "does not equal context album value key AxArtifactKey:(name=contextAlbum1,version=0.0.2)\n"
76 + "********************************";
78 TestApexModel<AxContextModel> testApexModel;
83 * @throws Exception a testing exception
86 public void setup() throws Exception {
87 testApexModel = new TestApexModel<AxContextModel>(AxContextModel.class, new TestApexContextModelCreator());
91 public void testModelValid() throws Exception {
92 final AxValidationResult result = testApexModel.testApexModelValid();
93 assertEquals(VALID_MODEL_STRING, result.toString());
97 public void testApexModelVaidateObservation() throws Exception {
98 final AxValidationResult result = testApexModel.testApexModelVaidateObservation();
99 assertEquals(OBSERVATION_MODEL_STRING, result.toString());
103 public void testApexModelVaidateWarning() throws Exception {
104 final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
105 assertEquals(WARNING_MODEL_STRING, result.toString());
109 public void testModelVaidateInvalidModel() throws Exception {
110 final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
111 assertEquals(INVALID_MODEL_STRING, result.toString());
115 public void testModelVaidateMalstructured() throws Exception {
116 final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
117 assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString());
121 public void testModelWriteReadJson() throws Exception {
122 testApexModel.testApexModelWriteReadJson();