d55a9da293811a8a4a92591ddc21180e3402e55d
[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
26 import org.junit.Test;
27 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
28 import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
29 import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
30
31 public class SupportBasicModelTest {
32
33     @Test
34     public void testNormalModelCreator() throws ApexException {
35         final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
36             new DummyApexBasicModelCreator());
37
38         testApexModel.testApexModelValid();
39         assertThatThrownBy(testApexModel::testApexModelVaidateObservation)
40             .hasMessage("model should have observations");
41         testApexModel.testApexModelVaidateWarning();
42         testApexModel.testApexModelVaidateInvalidModel();
43         testApexModel.testApexModelVaidateMalstructured();
44
45         testApexModel.testApexModelWriteReadJson();
46     }
47
48     @Test
49     public void testModelsUnequal() throws ApexException {
50         final TestApexModel<AxModel> testApexModel0 = new TestApexModel<AxModel>(AxModel.class,
51             new DummyApexBasicModelCreator());
52         final TestApexModel<AxModel> testApexModel1 = new TestApexModel<AxModel>(AxModel.class,
53             new DummyApexBasicModelCreator());
54
55         testApexModel1.getModel().getKey().setVersion("0.0.2");
56
57         assertThatThrownBy(() -> testApexModel0.checkModelEquality(testApexModel0.getModel(), testApexModel1.getModel(),
58                 "Models are not equal")).hasMessage("Models are not equal");
59     }
60
61     @Test
62     public void testModelCreator0() throws ApexException {
63         final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
64             new SupportApexModelCreator0());
65
66         testApexModel.testApexModelValid();
67         assertThatThrownBy(() -> testApexModel.testApexModelVaidateObservation())
68             .hasMessage("model should have observations");
69         assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning())
70             .hasMessage("model should have warnings");
71         assertThatThrownBy(() -> testApexModel.testApexModelVaidateInvalidModel())
72             .hasMessage("model should not be valid ***validation of model successful***");
73         assertThatThrownBy(() -> testApexModel.testApexModelVaidateMalstructured())
74             .hasMessage("model should not be valid ***validation of model successful***");
75     }
76
77     @Test
78     public void testModelCreator1() throws ApexException {
79         final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
80             new SupportApexModelCreator1());
81
82         assertThatThrownBy(() -> testApexModel.testApexModelValid())
83             .hasMessageStartingWith("model is invalid");
84         assertThatThrownBy(() -> testApexModel.testApexModelVaidateObservation())
85             .hasMessageStartingWith("model is invalid");
86         assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning())
87             .hasMessageStartingWith("model is invalid");
88         testApexModel.testApexModelVaidateInvalidModel();
89         testApexModel.testApexModelVaidateMalstructured();
90     }
91
92     @Test
93     public void testModelCreator2() throws ApexException {
94         final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
95             new SupportApexModelCreator2());
96
97         testApexModel.testApexModelValid();
98         testApexModel.testApexModelVaidateObservation();
99         assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning())
100             .hasMessage("model should have warnings");
101     }
102
103     @Test
104     public void testModelCreator1Json() throws ApexException {
105         final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
106             new SupportApexModelCreator1());
107
108         assertThatThrownBy(() -> testApexModel.testApexModelWriteReadJson())
109             .hasMessageStartingWith("error processing file");
110     }
111 }