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.model.enginemodel.handling;
23 import static org.junit.Assert.assertTrue;
26 import java.sql.Connection;
27 import java.sql.DriverManager;
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
33 import org.onap.policy.apex.model.basicmodel.dao.DaoParameters;
34 import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
35 import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel;
37 public class ApexEngineModelTest {
38 private Connection connection;
39 TestApexModel<AxEngineModel> testApexModel;
44 * @throws Exception errors from test setup
47 public void setup() throws Exception {
48 Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
49 connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true");
51 testApexModel = new TestApexModel<AxEngineModel>(AxEngineModel.class, new DummyTestApexEngineModelCreator());
55 public void teardown() throws Exception {
57 new File("derby.log").delete();
61 public void testModelValid() throws Exception {
62 final AxValidationResult result = testApexModel.testApexModelValid();
63 assertTrue(result.toString().equals(VALID_MODEL_STRING));
67 public void testModelVaidateInvalidModel() throws Exception {
68 final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
69 assertTrue(result.toString().equals(INVALID_MODEL_STRING));
73 public void testModelVaidateMalstructured() throws Exception {
74 final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
75 assertTrue(result.toString().equals(INVALID_MODEL_MALSTRUCTURED_STRING));
79 public void testModelWriteReadXml() throws Exception {
80 testApexModel.testApexModelWriteReadXml();
84 public void testModelWriteReadJson() throws Exception {
85 testApexModel.testApexModelWriteReadJson();
89 public void testModelWriteReadJpa() throws Exception {
90 final DaoParameters DaoParameters = new DaoParameters();
91 DaoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
92 DaoParameters.setPersistenceUnit("DAOTest");
94 testApexModel.testApexModelWriteReadJpa(DaoParameters);
97 private static final String VALID_MODEL_STRING = "***validation of model successful***";
99 private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
100 + "AxArtifactKey:(name=AnEngine,version=0.0.1):"
101 + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:"
102 + "AxEngineModel - state is UNDEFINED\n" + "********************************";
104 private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
105 + "AxArtifactKey:(name=AnEngine,version=0.0.1):"
106 + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:"
107 + "AxEngineModel - timestamp is not set\n" + "AxArtifactKey:(name=AnEngine,version=0.0.1):"
108 + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:"
109 + "AxEngineModel - state is UNDEFINED\n" + "********************************";