Remove try/catch blocks with assertj - apex-pdp
[policy/apex-pdp.git] / model / basic-model / src / test / java / org / onap / policy / apex / model / basicmodel / handling / SupportBasicModelTester.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.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 SupportBasicModelTester {
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         testApexModel.testApexModelWriteReadXml();
47     }
48
49     @Test
50     public void testModelsUnequal() throws ApexException {
51         final TestApexModel<AxModel> testApexModel0 = new TestApexModel<AxModel>(AxModel.class,
52             new DummyApexBasicModelCreator());
53         final TestApexModel<AxModel> testApexModel1 = new TestApexModel<AxModel>(AxModel.class,
54             new DummyApexBasicModelCreator());
55
56         testApexModel1.getModel().getKey().setVersion("0.0.2");
57
58         assertThatThrownBy(() -> testApexModel0.checkModelEquality(testApexModel0.getModel(), testApexModel1.getModel(),
59                 "Models are not equal")).hasMessage("Models are not equal");
60     }
61
62     @Test
63     public void testModelCreator0() throws ApexException {
64         final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
65             new SupportApexModelCreator0());
66
67         testApexModel.testApexModelValid();
68         assertThatThrownBy(() -> testApexModel.testApexModelVaidateObservation())
69             .hasMessage("model should have observations");
70         assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning())
71             .hasMessage("model should have warnings");
72         assertThatThrownBy(() -> testApexModel.testApexModelVaidateInvalidModel())
73             .hasMessage("model should not be valid ***validation of model successful***");
74         assertThatThrownBy(() -> testApexModel.testApexModelVaidateMalstructured())
75             .hasMessage("model should not be valid ***validation of model successful***");
76     }
77
78     @Test
79     public void testModelCreator1() throws ApexException {
80         final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
81             new SupportApexModelCreator1());
82
83         assertThatThrownBy(() -> testApexModel.testApexModelValid())
84             .hasMessageStartingWith("model is invalid");
85         assertThatThrownBy(() -> testApexModel.testApexModelVaidateObservation())
86             .hasMessageStartingWith("model is invalid");
87         assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning())
88             .hasMessageStartingWith("model is invalid");
89         testApexModel.testApexModelVaidateInvalidModel();
90         testApexModel.testApexModelVaidateMalstructured();
91     }
92
93     @Test
94     public void testModelCreator2() throws ApexException {
95         final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
96             new SupportApexModelCreator2());
97
98         testApexModel.testApexModelValid();
99         testApexModel.testApexModelVaidateObservation();
100         assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning())
101             .hasMessage("model should have warnings");
102     }
103
104     @Test
105     public void testModelCreator1XmlJson() throws ApexException {
106         final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
107             new SupportApexModelCreator1());
108
109         assertThatThrownBy(() -> testApexModel.testApexModelWriteReadJson())
110             .hasMessageStartingWith("error processing file");
111
112         assertThatThrownBy(() -> testApexModel.testApexModelWriteReadXml())
113             .hasMessageStartingWith("error processing file");
114     }
115 }