bb9776fc7dee6fbf0297857680788fd7a4bc3adf
[policy/apex-pdp.git] /
1 /*-
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.model.basicmodel.handling;
23
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26
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;
32
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" + "********************************";
40
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" + "********************************";
50
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                     + "********************************";
62
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" + "********************************";
69
70     TestApexModel<AxModel> testApexModel;
71
72     /**
73      * Set up the test.
74      *
75      * @throws Exception any exception thrown by the test
76      */
77     @Before
78     public void setup() throws Exception {
79         testApexModel = new TestApexModel<AxModel>(AxModel.class, new DummyApexBasicModelCreator());
80     }
81
82     @Test
83     public void testModelValid() throws Exception {
84         final AxValidationResult result = testApexModel.testApexModelValid();
85         assertEquals(VALID_MODEL_STRING, result.toString());
86     }
87
88     @Test
89     public void testApexModelVaidateObservation() throws Exception {
90         assertThatThrownBy(testApexModel::testApexModelVaidateObservation)
91             .hasMessage("model should have observations");
92     }
93
94     @Test
95     public void testApexModelVaidateWarning() throws Exception {
96         final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
97         assertEquals(WARNING_MODEL_STRING, result.toString());
98     }
99
100     @Test
101     public void testModelVaidateInvalidModel() throws Exception {
102         final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
103         assertEquals(INVALID_MODEL_STRING, result.toString());
104     }
105
106     @Test
107     public void testModelVaidateMalstructured() throws Exception {
108         final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
109         assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString());
110     }
111
112     @Test
113     public void testModelWriteReadXml() throws Exception {
114         testApexModel.testApexModelWriteReadXml();
115     }
116
117     @Test
118     public void testModelWriteReadJson() throws Exception {
119         testApexModel.testApexModelWriteReadJson();
120     }
121 }