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.plugins.executor.test.script.handling;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.junit.Assert.fail;
28 import java.io.IOException;
30 import org.junit.Test;
31 import org.onap.policy.apex.context.ContextAlbum;
32 import org.onap.policy.apex.core.engine.EngineParameters;
33 import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory;
34 import org.onap.policy.apex.core.engine.engine.impl.ApexEngineImpl;
35 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
36 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
37 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
38 import org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters;
39 import org.onap.policy.apex.plugins.executor.test.script.engine.TestApexActionListener;
40 import org.onap.policy.apex.test.common.model.SampleDomainModelFactory;
41 import org.slf4j.ext.XLogger;
42 import org.slf4j.ext.XLoggerFactory;
45 * The Class TestApexEngine.
47 * @author Liam Fallon (liam.fallon@ericsson.com)
49 public class TestContextUpdateDifferentModels {
50 // Logger for this class
51 private static final XLogger logger = XLoggerFactory.getXLogger(TestContextUpdateDifferentModels.class);
54 public void testContextUpdateDifferentModels() throws ApexException, InterruptedException, IOException {
55 logger.debug("Running test testContextUpdateDifferentModels . . .");
57 final AxPolicyModel apexModelSample = new SampleDomainModelFactory().getSamplePolicyModel("MVEL");
58 assertNotNull(apexModelSample);
60 final EngineParameters parameters = new EngineParameters();
61 parameters.getExecutorParameterMap().put("MVEL", new MVELExecutorParameters());
63 final ApexEngineImpl apexEngine =
64 (ApexEngineImpl) new ApexEngineFactory().createApexEngine(new AxArtifactKey("TestApexEngine", "0.0.1"));
65 final TestApexActionListener listener = new TestApexActionListener("Test");
66 apexEngine.addEventListener("listener", listener);
67 apexEngine.updateModel(apexModelSample);
72 final AxPolicyModel someSpuriousModel = new AxPolicyModel(new AxArtifactKey("SomeSpuriousModel", "0.0.1"));
73 assertNotNull(someSpuriousModel);
76 apexEngine.updateModel(null);
77 fail("null model should throw an exception");
78 } catch (final ApexException e) {
79 assertEquals("updateModel()<-TestApexEngine:0.0.1, Apex model is not defined, it has a null value",
82 assertEquals(apexEngine.getInternalContext().getContextAlbums().size(),
83 apexModelSample.getAlbums().getAlbumsMap().size());
84 for (final ContextAlbum contextAlbum : apexEngine.getInternalContext().getContextAlbums().values()) {
86 contextAlbum.getAlbumDefinition().equals(apexModelSample.getAlbums().get(contextAlbum.getKey())));
89 apexEngine.updateModel(someSpuriousModel);
90 assertEquals(apexEngine.getInternalContext().getContextAlbums().size(),
91 someSpuriousModel.getAlbums().getAlbumsMap().size());
92 for (final ContextAlbum contextAlbum : apexEngine.getInternalContext().getContextAlbums().values()) {
94 contextAlbum.getAlbumDefinition().equals(someSpuriousModel.getAlbums().get(contextAlbum.getKey())));
99 logger.debug("Ran test testContextUpdateDifferentModels");