80e2e15b46bda35c4f949886ed872c4ebba5a44c
[policy/apex-pdp.git] / model / basic-model / src / test / java / org / onap / policy / apex / model / basicmodel / handling / SupportApexBasicModelTester.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 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.junit.Assert.assertEquals;
25
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
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.dao.DaoParameters;
32 import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
33
34 public class SupportApexBasicModelTester {
35     TestApexModel<AxModel> testApexModel;
36
37     /**
38      * Set up the test.
39      *
40      * @throws Exception any exception thrown by the test
41      */
42     @Before
43     public void setup() throws Exception {
44         testApexModel = new TestApexModel<AxModel>(AxModel.class, new DummyApexBasicModelCreator());
45     }
46
47     @Test
48     public void testModelValid() throws Exception {
49         final AxValidationResult result = testApexModel.testApexModelValid();
50         assertEquals(VALID_MODEL_STRING, result.toString());
51     }
52
53     @Test
54     public void testApexModelVaidateObservation() throws Exception {
55         try {
56             testApexModel.testApexModelVaidateObservation();
57         } catch (final ApexException e) {
58             assertEquals("model should have observations", e.getMessage());
59         }
60     }
61
62     @Test
63     public void testApexModelVaidateWarning() throws Exception {
64         final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
65         assertEquals(WARNING_MODEL_STRING, result.toString());
66     }
67
68     @Test
69     public void testModelVaidateInvalidModel() throws Exception {
70         final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
71         assertEquals(INVALID_MODEL_STRING, result.toString());
72     }
73
74     @Test
75     public void testModelVaidateMalstructured() throws Exception {
76         final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
77         assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString());
78     }
79
80     @Test
81     public void testModelWriteReadXml() throws Exception {
82         testApexModel.testApexModelWriteReadXml();
83     }
84
85     @Test
86     public void testModelWriteReadJson() throws Exception {
87         testApexModel.testApexModelWriteReadJson();
88     }
89
90     @Test
91     public void testModelWriteReadJpa() throws Exception {
92         final DaoParameters daoParameters = new DaoParameters();
93         daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
94         daoParameters.setPersistenceUnit("DaoTest");
95
96         testApexModel.testApexModelWriteReadJpa(daoParameters);
97     }
98
99     // As there are no real concepts in a basic model, this is as near to a valid model as we can get
100     private static final String VALID_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
101                     + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
102                     + ".AxModel:WARNING:key not found for key information entry\n"
103                     + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
104                     + ".AxModel:WARNING:key not found for key information entry\n" + "********************************";
105
106     private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
107                     + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
108                     + ".AxModel:WARNING:key not found for key information entry\n"
109                     + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
110                     + ".AxModel:WARNING:key not found for key information entry\n"
111                     + "AxArtifactKey:(name=Unref0,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
112                     + ".AxModel:WARNING:key not found for key information entry\n"
113                     + "AxArtifactKey:(name=Unref1,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
114                     + ".AxModel:WARNING:key not found for key information entry\n" + "********************************";
115
116     private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
117                     + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
118                     + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
119                     + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
120                     + "AxKeyInfo:OBSERVATION:description is blank\n"
121                     + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
122                     + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
123                     + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
124                     + "AxKeyInformation:INVALID:duplicate UUID found on keyInfoMap entry AxArtifactKey:"
125                     + "(name=KeyInfoMapKey,version=0.0.1):00000000-0000-0000-0000-000000000000\n"
126                     + "********************************";
127
128     private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
129                     + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
130                     + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
131                     + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
132                     + "AxModel:INVALID:key information not found for key "
133                     + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n" + "********************************";
134 }