770c29a939e32bc208e46781dcb5df00250830dc
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.model.enginemodel.handling;
22
23 import static org.junit.Assert.assertTrue;
24
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
28 import org.onap.policy.apex.model.basicmodel.dao.DaoParameters;
29 import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
30 import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel;
31
32 public class ApexEngineModelTest {
33     TestApexModel<AxEngineModel> testApexModel;
34
35     /**
36      * Set up the test.
37      *
38      * @throws Exception errors from test setup
39      */
40     @Before
41     public void setup() throws Exception {
42         testApexModel = new TestApexModel<AxEngineModel>(AxEngineModel.class, new DummyTestApexEngineModelCreator());
43     }
44
45     @Test
46     public void testModelValid() throws Exception {
47         final AxValidationResult result = testApexModel.testApexModelValid();
48         assertTrue(result.toString().equals(VALID_MODEL_STRING));
49     }
50
51     @Test
52     public void testModelVaidateInvalidModel() throws Exception {
53         final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
54         assertTrue(result.toString().equals(INVALID_MODEL_STRING));
55     }
56
57     @Test
58     public void testModelVaidateMalstructured() throws Exception {
59         final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
60         assertTrue(result.toString().equals(INVALID_MODEL_MALSTRUCTURED_STRING));
61     }
62
63     @Test
64     public void testModelWriteReadXml() throws Exception {
65         testApexModel.testApexModelWriteReadXml();
66     }
67
68     @Test
69     public void testModelWriteReadJson() throws Exception {
70         testApexModel.testApexModelWriteReadJson();
71     }
72
73     @Test
74     public void testModelWriteReadJpa() throws Exception {
75         final DaoParameters DaoParameters = new DaoParameters();
76         DaoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
77         DaoParameters.setPersistenceUnit("DAOTest");
78
79         testApexModel.testApexModelWriteReadJpa(DaoParameters);
80     }
81
82     private static final String VALID_MODEL_STRING = "***validation of model successful***";
83
84     private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
85                     + "AxArtifactKey:(name=AnEngine,version=0.0.1):"
86                     + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:"
87                     + "AxEngineModel - state is UNDEFINED\n" + "********************************";
88
89     private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
90                     + "AxArtifactKey:(name=AnEngine,version=0.0.1):"
91                     + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:"
92                     + "AxEngineModel - timestamp is not set\n" + "AxArtifactKey:(name=AnEngine,version=0.0.1):"
93                     + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:"
94                     + "AxEngineModel - state is UNDEFINED\n" + "********************************";
95 }