2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.model.contextmodel.handling;
23 import static org.junit.Assert.assertTrue;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
28 import org.onap.policy.apex.model.basicmodel.dao.DaoParameters;
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 {
39 TestApexModel<AxContextModel> testApexModel;
44 * @throws Exception a testing exception
47 public void setup() throws Exception {
48 testApexModel = new TestApexModel<AxContextModel>(AxContextModel.class, new TestApexContextModelCreator());
52 public void testModelValid() throws Exception {
53 final AxValidationResult result = testApexModel.testApexModelValid();
54 assertTrue(result.toString().equals(VALID_MODEL_STRING));
58 public void testApexModelVaidateObservation() throws Exception {
59 final AxValidationResult result = testApexModel.testApexModelVaidateObservation();
60 assertTrue(result.toString().equals(OBSERVATION_MODEL_STRING));
64 public void testApexModelVaidateWarning() throws Exception {
65 final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
66 assertTrue(result.toString().equals(WARNING_MODEL_STRING));
70 public void testModelVaidateInvalidModel() throws Exception {
71 final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
72 assertTrue(result.toString().equals(INVALID_MODEL_STRING));
76 public void testModelVaidateMalstructured() throws Exception {
77 final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
78 assertTrue(result.toString().equals(INVALID_MODEL_MALSTRUCTURED_STRING));
82 public void testModelWriteReadXml() throws Exception {
83 testApexModel.testApexModelWriteReadXml();
87 public void testModelWriteReadJson() throws Exception {
88 testApexModel.testApexModelWriteReadJson();
92 public void testModelWriteReadJpa() throws Exception {
93 final DaoParameters DaoParameters = new DaoParameters();
94 DaoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
95 DaoParameters.setPersistenceUnit("DAOTest");
97 testApexModel.testApexModelWriteReadJpa(DaoParameters);
100 private static final String VALID_MODEL_STRING = "***validation of model successful***";
102 private static final String OBSERVATION_MODEL_STRING = "\n"
103 + "***observations noted during validation of model***\n"
104 + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):"
105 + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo:OBSERVATION:description is blank\n"
106 + "********************************";
108 private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
109 + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):"
110 + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo:WARNING:"
111 + "UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
112 + "********************************";
114 private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
115 + "AxArtifactKey:(name=StringType,version=0.0.1):"
116 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema:INVALID:"
117 + "no schemaDefinition specified, schemaDefinition may not be blank\n"
118 + "AxArtifactKey:(name=contextAlbum0,version=0.0.1):"
119 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:"
120 + "scope is not defined\n" + "********************************";
122 private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
123 + "AxArtifactKey:(name=ContextModel,version=0.0.1):"
124 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextModel:INVALID:"
125 + "key information not found for key AxArtifactKey:(name=contextAlbum1,version=0.0.2)\n"
126 + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):"
127 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextModel:WARNING:"
128 + "key not found for key information entry\n" + "AxArtifactKey:(name=ContextSchemas,version=0.0.1):"
129 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas:INVALID:"
130 + "key on schemas entry AxArtifactKey:(name=MapType,version=0.0.1) "
131 + "does not equal entry key AxArtifactKey:(name=MapType,version=0.0.2)\n"
132 + "AxArtifactKey:(name=contextAlbums,version=0.0.1):"
133 + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums:INVALID:"
134 + "key on context album entry key AxArtifactKey:(name=contextAlbum1,version=0.0.1) "
135 + "does not equal context album value key AxArtifactKey:(name=contextAlbum1,version=0.0.2)\n"
136 + "********************************";