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.basicmodel.handling;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
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.AxModel;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
31 import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
33 public class SupportApexBasicModelTest {
34 // As there are no real concepts in a basic model, this is as near to a valid model as we can get
35 private static final String VALID_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
36 + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
37 + ".AxModel:WARNING:key not found for key information entry\n"
38 + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
39 + ".AxModel:WARNING:key not found for key information entry\n" + "********************************";
41 private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
42 + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
43 + ".AxModel:WARNING:key not found for key information entry\n"
44 + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
45 + ".AxModel:WARNING:key not found for key information entry\n"
46 + "AxArtifactKey:(name=Unref0,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
47 + ".AxModel:WARNING:key not found for key information entry\n"
48 + "AxArtifactKey:(name=Unref1,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
49 + ".AxModel:WARNING:key not found for key information entry\n" + "********************************";
51 private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
52 + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
53 + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
54 + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
55 + "AxKeyInfo:OBSERVATION:description is blank\n"
56 + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
57 + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
58 + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
59 + "AxKeyInformation:INVALID:duplicate UUID found on keyInfoMap entry AxArtifactKey:"
60 + "(name=KeyInfoMapKey,version=0.0.1):00000000-0000-0000-0000-000000000000\n"
61 + "********************************";
63 private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
64 + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
65 + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
66 + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
67 + "AxModel:INVALID:key information not found for key "
68 + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n" + "********************************";
70 TestApexModel<AxModel> testApexModel;
75 * @throws Exception any exception thrown by the test
78 public void setup() throws Exception {
79 testApexModel = new TestApexModel<AxModel>(AxModel.class, new DummyApexBasicModelCreator());
83 public void testModelValid() throws Exception {
84 final AxValidationResult result = testApexModel.testApexModelValid();
85 assertEquals(VALID_MODEL_STRING, result.toString());
89 public void testApexModelVaidateObservation() throws Exception {
90 assertThatThrownBy(testApexModel::testApexModelVaidateObservation)
91 .hasMessage("model should have observations");
95 public void testApexModelVaidateWarning() throws Exception {
96 final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
97 assertEquals(WARNING_MODEL_STRING, result.toString());
101 public void testModelVaidateInvalidModel() throws Exception {
102 final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
103 assertEquals(INVALID_MODEL_STRING, result.toString());
107 public void testModelVaidateMalstructured() throws Exception {
108 final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
109 assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString());
113 public void testModelWriteReadXml() throws Exception {
114 testApexModel.testApexModelWriteReadXml();
118 public void testModelWriteReadJson() throws Exception {
119 testApexModel.testApexModelWriteReadJson();