5a36d4070335836906ba744236ffd8423c66cab1
[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.examples.adaptive;
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.policymodel.concepts.AxPolicyModel;
31
32 public class AnomalyDetectionModelTest {
33     TestApexModel<AxPolicyModel> testApexModel;
34
35     /**
36      * Sets up embedded Derby database and the Apex anomaly detection model for the tests.
37      * @throws Exception exception to be thrown while setting up the database connection
38      */
39     @Before
40     public void setup() throws Exception {
41         testApexModel = new TestApexModel<>(AxPolicyModel.class, new TestAnomalyDetectionModelCreator());
42     }
43
44     @Test
45     public void testModelValid() throws Exception {
46         final AxValidationResult result = testApexModel.testApexModelValid();
47         assertTrue(result.toString().equals(VALID_MODEL_STRING));
48     }
49
50     @Test
51     public void testModelWriteReadXml() throws Exception {
52         testApexModel.testApexModelWriteReadXml();
53     }
54
55     @Test
56     public void testModelWriteReadJson() throws Exception {
57         testApexModel.testApexModelWriteReadJson();
58     }
59
60     @Test
61     public void testModelWriteReadJpa() throws Exception {
62         final DaoParameters DaoParameters = new DaoParameters();
63         DaoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
64         DaoParameters.setPersistenceUnit("AdaptiveModelsTest");
65
66         testApexModel.testApexModelWriteReadJpa(DaoParameters);
67     }
68
69     private static final String VALID_MODEL_STRING = "***validation of model successful***";
70 }