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;
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.enginemodel.concepts.AxEngineModel;
32 public class ApexEngineModelTest {
33 TestApexModel<AxEngineModel> testApexModel;
38 * @throws Exception errors from test setup
41 public void setup() throws Exception {
42 testApexModel = new TestApexModel<AxEngineModel>(AxEngineModel.class, new DummyTestApexEngineModelCreator());
46 public void testModelValid() throws Exception {
47 final AxValidationResult result = testApexModel.testApexModelValid();
48 assertTrue(result.toString().equals(VALID_MODEL_STRING));
52 public void testModelVaidateInvalidModel() throws Exception {
53 final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
54 assertTrue(result.toString().equals(INVALID_MODEL_STRING));
58 public void testModelVaidateMalstructured() throws Exception {
59 final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
60 assertTrue(result.toString().equals(INVALID_MODEL_MALSTRUCTURED_STRING));
64 public void testModelWriteReadXml() throws Exception {
65 testApexModel.testApexModelWriteReadXml();
69 public void testModelWriteReadJson() throws Exception {
70 testApexModel.testApexModelWriteReadJson();
74 public void testModelWriteReadJpa() throws Exception {
75 final DaoParameters DaoParameters = new DaoParameters();
76 DaoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
77 DaoParameters.setPersistenceUnit("DAOTest");
79 testApexModel.testApexModelWriteReadJpa(DaoParameters);
82 private static final String VALID_MODEL_STRING = "***validation of model successful***";
84 private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
85 + "AxArtifactKey:(name=AnEngine,version=0.0.1):"
86 + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:"
87 + "AxEngineModel - state is UNDEFINED\n" + "********************************";
89 private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
90 + "AxArtifactKey:(name=AnEngine,version=0.0.1):"
91 + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:"
92 + "AxEngineModel - timestamp is not set\n" + "AxArtifactKey:(name=AnEngine,version=0.0.1):"
93 + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:"
94 + "AxEngineModel - state is UNDEFINED\n" + "********************************";