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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.examples.myfirstpolicy;
23 import static org.junit.Assert.assertTrue;
26 import java.sql.Connection;
27 import java.sql.DriverManager;
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;
37 * Test MyFirstPolicy Model.
39 * @author John Keeney (john.keeney@ericsson.com)
41 public class MfpModelTest {
43 private static Connection connection;
44 private static TestApexModel<AxPolicyModel> testApexModel1;
45 private static TestApexModel<AxPolicyModel> testApexModel2;
50 * @throws Exception if there is an error
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());
63 * @throws Exception if there is an error
66 public static void teardown() throws Exception {
68 new File("derby.log").delete();
72 * Test model is valid.
74 * @throws Exception if there is an error
77 public void testModelValid() throws Exception {
78 AxValidationResult result = testApexModel1.testApexModelValid();
79 assertTrue("Model did not validate cleanly", result.isOk());
81 result = testApexModel2.testApexModelValid();
82 assertTrue("Model did not validate cleanly", result.isOk());
86 * Test model write and read XML.
88 * @throws Exception if there is an error
91 public void testModelWriteReadXml() throws Exception {
92 testApexModel1.testApexModelWriteReadXml();
93 testApexModel2.testApexModelWriteReadXml();
97 * Test model write and read JSON.
99 * @throws Exception if there is an error
102 public void testModelWriteReadJson() throws Exception {
103 testApexModel1.testApexModelWriteReadJson();
104 testApexModel2.testApexModelWriteReadJson();