1bd67f9618c985c605e7fc6b81deeffb61ca6063
[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 org.junit.BeforeClass;
26 import org.junit.Test;
27 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
28 import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
29 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
30
31 /**
32  * Test MyFirstPolicy Model.
33  *
34  * @author John Keeney (john.keeney@ericsson.com)
35  */
36 public class MfpModelTest {
37     private static TestApexModel<AxPolicyModel> testApexModel1;
38     private static TestApexModel<AxPolicyModel> testApexModel2;
39
40     /**
41      * Setup.
42      *
43      * @throws Exception if there is an error
44      */
45     @BeforeClass
46     public static void setup() throws Exception {
47         testApexModel1 = new TestApexModel<>(AxPolicyModel.class, new TestMfpModelCreator.TestMfp1ModelCreator());
48         testApexModel2 = new TestApexModel<>(AxPolicyModel.class, new TestMfpModelCreator.TestMfp2ModelCreator());
49     }
50
51     /**
52      * Test model is valid.
53      *
54      * @throws Exception if there is an error
55      */
56     @Test
57     public void testModelValid() throws Exception {
58         AxValidationResult result = testApexModel1.testApexModelValid();
59         assertTrue("Model did not validate cleanly", result.isOk());
60
61         result = testApexModel2.testApexModelValid();
62         assertTrue("Model did not validate cleanly", result.isOk());
63     }
64
65     /**
66      * Test model write and read XML.
67      *
68      * @throws Exception if there is an error
69      */
70     @Test
71     public void testModelWriteReadXml() throws Exception {
72         testApexModel1.testApexModelWriteReadXml();
73         testApexModel2.testApexModelWriteReadXml();
74     }
75
76     /**
77      * Test model write and read JSON.
78      *
79      * @throws Exception if there is an error
80      */
81     @Test
82     public void testModelWriteReadJson() throws Exception {
83         testApexModel1.testApexModelWriteReadJson();
84         testApexModel2.testApexModelWriteReadJson();
85     }
86 }