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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.model.basicmodel.handling;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
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;
31 public class SupportBasicModelTest {
34 public void testNormalModelCreator() throws ApexException {
35 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
36 new DummyApexBasicModelCreator());
38 testApexModel.testApexModelValid();
39 assertThatThrownBy(testApexModel::testApexModelVaidateObservation)
40 .hasMessage("model should have observations");
41 testApexModel.testApexModelVaidateWarning();
42 testApexModel.testApexModelVaidateInvalidModel();
43 testApexModel.testApexModelVaidateMalstructured();
45 testApexModel.testApexModelWriteReadJson();
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());
55 testApexModel1.getModel().getKey().setVersion("0.0.2");
57 assertThatThrownBy(() -> testApexModel0.checkModelEquality(testApexModel0.getModel(), testApexModel1.getModel(),
58 "Models are not equal")).hasMessage("Models are not equal");
62 public void testModelCreator0() throws ApexException {
63 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
64 new SupportApexModelCreator0());
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***");
78 public void testModelCreator1() throws ApexException {
79 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
80 new SupportApexModelCreator1());
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();
93 public void testModelCreator2() throws ApexException {
94 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
95 new SupportApexModelCreator2());
97 testApexModel.testApexModelValid();
98 testApexModel.testApexModelVaidateObservation();
99 assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning())
100 .hasMessage("model should have warnings");
104 public void testModelCreator1Json() throws ApexException {
105 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
106 new SupportApexModelCreator1());
108 assertThatThrownBy(() -> testApexModel.testApexModelWriteReadJson())
109 .hasMessageStartingWith("error processing file");