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 / 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.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26
27 import org.junit.Before;
28 import org.junit.Test;
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         assertThatThrownBy(testApexModel::testApexModelVaidateObservation)
56             .hasMessage("model should have observations");
57     }
58
59     @Test
60     public void testApexModelVaidateWarning() throws Exception {
61         final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
62         assertEquals(WARNING_MODEL_STRING, result.toString());
63     }
64
65     @Test
66     public void testModelVaidateInvalidModel() throws Exception {
67         final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
68         assertEquals(INVALID_MODEL_STRING, result.toString());
69     }
70
71     @Test
72     public void testModelVaidateMalstructured() throws Exception {
73         final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
74         assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString());
75     }
76
77     @Test
78     public void testModelWriteReadXml() throws Exception {
79         testApexModel.testApexModelWriteReadXml();
80     }
81
82     @Test
83     public void testModelWriteReadJson() throws Exception {
84         testApexModel.testApexModelWriteReadJson();
85     }
86
87     @Test
88     public void testModelWriteReadJpa() throws Exception {
89         final DaoParameters daoParameters = new DaoParameters();
90         daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
91         daoParameters.setPersistenceUnit("DaoTest");
92
93         testApexModel.testApexModelWriteReadJpa(daoParameters);
94     }
95
96     // As there are no real concepts in a basic model, this is as near to a valid model as we can get
97     private static final String VALID_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
98                     + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
99                     + ".AxModel:WARNING:key not found for key information entry\n"
100                     + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
101                     + ".AxModel:WARNING:key not found for key information entry\n" + "********************************";
102
103     private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
104                     + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
105                     + ".AxModel:WARNING:key not found for key information entry\n"
106                     + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
107                     + ".AxModel:WARNING:key not found for key information entry\n"
108                     + "AxArtifactKey:(name=Unref0,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
109                     + ".AxModel:WARNING:key not found for key information entry\n"
110                     + "AxArtifactKey:(name=Unref1,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
111                     + ".AxModel:WARNING:key not found for key information entry\n" + "********************************";
112
113     private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
114                     + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
115                     + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
116                     + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
117                     + "AxKeyInfo:OBSERVATION:description is blank\n"
118                     + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
119                     + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
120                     + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
121                     + "AxKeyInformation:INVALID:duplicate UUID found on keyInfoMap entry AxArtifactKey:"
122                     + "(name=KeyInfoMapKey,version=0.0.1):00000000-0000-0000-0000-000000000000\n"
123                     + "********************************";
124
125     private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
126                     + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
127                     + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
128                     + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
129                     + "AxModel:INVALID:key information not found for key "
130                     + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n" + "********************************";
131 }