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.policymodel.handling;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
27 import java.sql.Connection;
28 import java.sql.DriverManager;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
34 import org.onap.policy.apex.model.basicmodel.dao.DAOParameters;
35 import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
36 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
38 public class TestApexPolicyModel {
39 private Connection connection;
40 TestApexModel<AxPolicyModel> testApexModel;
43 public void setup() throws Exception {
44 Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
45 connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true");
47 testApexModel = new TestApexModel<AxPolicyModel>(AxPolicyModel.class, new TestApexPolicyModelCreator());
51 public void teardown() throws Exception {
53 new File("derby.log").delete();
57 public void testModelValid() throws Exception {
58 final AxValidationResult result = testApexModel.testApexModelValid();
59 assertTrue(result.toString().equals(VALID_MODEL_STRING));
63 public void testApexModelVaidateObservation() throws Exception {
64 final AxValidationResult result = testApexModel.testApexModelVaidateObservation();
65 assertTrue(result.toString().equals(OBSERVATION_MODEL_STRING));
70 public void testApexModelVaidateWarning() throws Exception {
71 final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
72 assertTrue(result.toString().equals(WARNING_MODEL_STRING));
76 public void testModelVaidateInvalidModel() throws Exception {
77 final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
78 assertEquals(INVALID_MODEL_STRING, result.toString());
82 public void testModelVaidateMalstructured() throws Exception {
83 final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
84 assertTrue(result.toString().equals(INVALID_MODEL_MALSTRUCTURED_STRING));
88 public void testModelWriteReadXML() throws Exception {
89 testApexModel.testApexModelWriteReadXML();
93 public void testModelWriteReadJSON() throws Exception {
94 testApexModel.testApexModelWriteReadJSON();
98 public void testModelWriteReadJPA() throws Exception {
99 final DAOParameters daoParameters = new DAOParameters();
100 daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
101 daoParameters.setPersistenceUnit("DAOTest");
103 testApexModel.testApexModelWriteReadJPA(daoParameters);
106 private static final String VALID_MODEL_STRING = "***validation of model successful***";
108 private static final String OBSERVATION_MODEL_STRING =
109 "\n" + "***observations noted during validation of model***\n"
110 + "AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=state):org.onap.policy.apex.model.policymodel.concepts.AxState:OBSERVATION:state output stateOutput0 is not used directly by any task\n"
111 + "********************************";
113 private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
114 + "AxArtifactKey:(name=policy,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicy:WARNING:state AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=anotherState) is not referenced in the policy execution tree\n"
115 + "********************************";
117 private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
118 + "AxArtifactKey:(name=contextAlbum0,version=0.0.1):org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:scope is not defined\n"
119 + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:scope is not defined\n"
120 + "AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=state):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:task output field AxOutputField:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=outputFields,localName=OE1PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false) for task task:0.0.1 not in output event outEvent0:0.0.1\n"
121 + "AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=state):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:task output field AxOutputField:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=outputFields,localName=OE1PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false) for task task:0.0.1 not in output event outEvent0:0.0.1\n"
122 + "********************************";
124 private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
125 + "AxArtifactKey:(name=policyModel_KeyInfo,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation:INVALID:keyInfoMap may not be empty\n"
126 + "AxArtifactKey:(name=policyModel,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:key information not found for key AxArtifactKey:(name=policyModel,version=0.0.1)\n"
127 + "AxArtifactKey:(name=policyModel,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:key information not found for key AxArtifactKey:(name=policyModel_KeyInfo,version=0.0.1)\n"
128 + "AxArtifactKey:(name=policyModel,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:key information not found for key AxArtifactKey:(name=policyModel_Schemas,version=0.0.1)\n"
129 + "AxArtifactKey:(name=policyModel,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:key information not found for key AxArtifactKey:(name=policyModel_Events,version=0.0.1)\n"
130 + "AxArtifactKey:(name=policyModel,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:key information not found for key AxArtifactKey:(name=policyModel_Albums,version=0.0.1)\n"
131 + "AxArtifactKey:(name=policyModel,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:key information not found for key AxArtifactKey:(name=policyModel_Tasks,version=0.0.1)\n"
132 + "AxArtifactKey:(name=policyModel,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:key information not found for key AxArtifactKey:(name=policyModel_Policies,version=0.0.1)\n"
133 + "AxArtifactKey:(name=policyModel_Schemas,version=0.0.1):org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas:INVALID:contextSchemas may not be empty\n"
134 + "AxArtifactKey:(name=policyModel_Events,version=0.0.1):org.onap.policy.apex.model.eventmodel.concepts.AxEvents:INVALID:eventMap may not be empty\n"
135 + "AxArtifactKey:(name=policyModel_Albums,version=0.0.1):org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums:OBSERVATION:albums are empty\n"
136 + "AxArtifactKey:(name=policyModel_Tasks,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxTasks:INVALID:taskMap may not be empty\n"
137 + "AxArtifactKey:(name=policyModel_Policies,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicies:INVALID:policyMap may not be empty\n"
138 + "********************************";