d6ec2bb8dc51af568fbef0ece643cc0c482f5544
[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.myfirstpolicy;
22
23 import static org.junit.Assert.assertTrue;
24
25 import java.io.File;
26 import java.sql.Connection;
27 import java.sql.DriverManager;
28
29 import org.junit.AfterClass;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
33 import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
34 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
35
36 /**
37  * Test MyFirstPolicy Model.
38  *
39  * @author John Keeney (john.keeney@ericsson.com)
40  */
41 public class MfpModelTest {
42
43     private static Connection connection;
44     private static TestApexModel<AxPolicyModel> testApexModel1;
45     private static TestApexModel<AxPolicyModel> testApexModel2;
46
47     /**
48      * Setup.
49      *
50      * @throws Exception if there is an error
51      */
52     @BeforeClass
53     public static void setup() throws Exception {
54         Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
55         connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true");
56         testApexModel1 = new TestApexModel<>(AxPolicyModel.class, new TestMfpModelCreator.TestMfp1ModelCreator());
57         testApexModel2 = new TestApexModel<>(AxPolicyModel.class, new TestMfpModelCreator.TestMfp2ModelCreator());
58     }
59
60     /**
61      * Teardown.
62      *
63      * @throws Exception if there is an error
64      */
65     @AfterClass
66     public static void teardown() throws Exception {
67         connection.close();
68         new File("derby.log").delete();
69     }
70
71     /**
72      * Test model is valid.
73      *
74      * @throws Exception if there is an error
75      */
76     @Test
77     public void testModelValid() throws Exception {
78         AxValidationResult result = testApexModel1.testApexModelValid();
79         assertTrue("Model did not validate cleanly", result.isOk());
80
81         result = testApexModel2.testApexModelValid();
82         assertTrue("Model did not validate cleanly", result.isOk());
83     }
84
85     /**
86      * Test model write and read XML.
87      *
88      * @throws Exception if there is an error
89      */
90     @Test
91     public void testModelWriteReadXml() throws Exception {
92         testApexModel1.testApexModelWriteReadXml();
93         testApexModel2.testApexModelWriteReadXml();
94     }
95
96     /**
97      * Test model write and read JSON.
98      *
99      * @throws Exception if there is an error
100      */
101     @Test
102     public void testModelWriteReadJson() throws Exception {
103         testApexModel1.testApexModelWriteReadJson();
104         testApexModel2.testApexModelWriteReadJson();
105     }
106 }