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
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 SupportBasicModelTester {
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();
46 testApexModel.testApexModelWriteReadXml();
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());
56 testApexModel1.getModel().getKey().setVersion("0.0.2");
58 assertThatThrownBy(() -> testApexModel0.checkModelEquality(testApexModel0.getModel(), testApexModel1.getModel(),
59 "Models are not equal")).hasMessage("Models are not equal");
63 public void testModelCreator0() throws ApexException {
64 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
65 new SupportApexModelCreator0());
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***");
79 public void testModelCreator1() throws ApexException {
80 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
81 new SupportApexModelCreator1());
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();
94 public void testModelCreator2() throws ApexException {
95 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
96 new SupportApexModelCreator2());
98 testApexModel.testApexModelValid();
99 testApexModel.testApexModelVaidateObservation();
100 assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning())
101 .hasMessage("model should have warnings");
105 public void testModelCreator1XmlJson() throws ApexException {
106 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
107 new SupportApexModelCreator1());
109 assertThatThrownBy(() -> testApexModel.testApexModelWriteReadJson())
110 .hasMessageStartingWith("error processing file");
112 assertThatThrownBy(() -> testApexModel.testApexModelWriteReadXml())
113 .hasMessageStartingWith("error processing file");