f41c39fd2faaa4bc3fd740e72563e58f72192117
[policy/apex-pdp.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.model.contextmodel.handling;
22
23 import static org.junit.Assert.assertTrue;
24
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;
31
32 /**
33  * Apex context model tests.
34  *
35  * @author liam
36  *
37  */
38 public class ApexContextModelTest {
39     TestApexModel<AxContextModel> testApexModel;
40
41     /**
42      * Set up tests.
43      *
44      * @throws Exception a testing exception
45      */
46     @Before
47     public void setup() throws Exception {
48         testApexModel = new TestApexModel<AxContextModel>(AxContextModel.class, new TestApexContextModelCreator());
49     }
50
51     @Test
52     public void testModelValid() throws Exception {
53         final AxValidationResult result = testApexModel.testApexModelValid();
54         assertTrue(result.toString().equals(VALID_MODEL_STRING));
55     }
56
57     @Test
58     public void testApexModelVaidateObservation() throws Exception {
59         final AxValidationResult result = testApexModel.testApexModelVaidateObservation();
60         assertTrue(result.toString().equals(OBSERVATION_MODEL_STRING));
61     }
62
63     @Test
64     public void testApexModelVaidateWarning() throws Exception {
65         final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
66         assertTrue(result.toString().equals(WARNING_MODEL_STRING));
67     }
68
69     @Test
70     public void testModelVaidateInvalidModel() throws Exception {
71         final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
72         assertTrue(result.toString().equals(INVALID_MODEL_STRING));
73     }
74
75     @Test
76     public void testModelVaidateMalstructured() throws Exception {
77         final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
78         assertTrue(result.toString().equals(INVALID_MODEL_MALSTRUCTURED_STRING));
79     }
80
81     @Test
82     public void testModelWriteReadXml() throws Exception {
83         testApexModel.testApexModelWriteReadXml();
84     }
85
86     @Test
87     public void testModelWriteReadJson() throws Exception {
88         testApexModel.testApexModelWriteReadJson();
89     }
90
91     @Test
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");
96
97         testApexModel.testApexModelWriteReadJpa(DaoParameters);
98     }
99
100     private static final String VALID_MODEL_STRING = "***validation of model successful***";
101
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                     + "********************************";
107
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                     + "********************************";
113
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" + "********************************";
121
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                     + "********************************";
137
138 }