998469bac5d0d1485a388433608532e3bb3abde3
[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.contextmodel.handling;
23
24 import static org.junit.Assert.assertEquals;
25
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;
31
32 /**
33  * Apex context model tests.
34  *
35  * @author liam
36  *
37  */
38 public class ApexContextModelTest {
39
40     private static final String VALID_MODEL_STRING = "***validation of model successful***";
41
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                     + "********************************";
47
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                     + "********************************";
53
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" + "********************************";
61
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                     + "********************************";
77
78     TestApexModel<AxContextModel> testApexModel;
79
80     /**
81      * Set up tests.
82      *
83      * @throws Exception a testing exception
84      */
85     @Before
86     public void setup() throws Exception {
87         testApexModel = new TestApexModel<AxContextModel>(AxContextModel.class, new TestApexContextModelCreator());
88     }
89
90     @Test
91     public void testModelValid() throws Exception {
92         final AxValidationResult result = testApexModel.testApexModelValid();
93         assertEquals(VALID_MODEL_STRING, result.toString());
94     }
95
96     @Test
97     public void testApexModelVaidateObservation() throws Exception {
98         final AxValidationResult result = testApexModel.testApexModelVaidateObservation();
99         assertEquals(OBSERVATION_MODEL_STRING, result.toString());
100     }
101
102     @Test
103     public void testApexModelVaidateWarning() throws Exception {
104         final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
105         assertEquals(WARNING_MODEL_STRING, result.toString());
106     }
107
108     @Test
109     public void testModelVaidateInvalidModel() throws Exception {
110         final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
111         assertEquals(INVALID_MODEL_STRING, result.toString());
112     }
113
114     @Test
115     public void testModelVaidateMalstructured() throws Exception {
116         final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
117         assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString());
118     }
119
120     @Test
121     public void testModelWriteReadJson() throws Exception {
122         testApexModel.testApexModelWriteReadJson();
123     }
124 }