2 * ============LICENSE_START=======================================================
3 * Copyright (C) 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.core.engine.executor.context;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.fail;
27 import java.util.LinkedHashMap;
28 import java.util.LinkedHashSet;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.mockito.Mock;
34 import org.mockito.Mockito;
35 import org.mockito.MockitoAnnotations;
36 import org.onap.policy.apex.context.ContextAlbum;
37 import org.onap.policy.apex.core.engine.context.ApexInternalContext;
38 import org.onap.policy.apex.core.engine.executor.StateFinalizerExecutor;
39 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
40 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
41 import org.onap.policy.apex.model.policymodel.concepts.AxState;
44 * Test Task Execution Context.
46 public class StateFinalizerExecutionContextTest {
48 private StateFinalizerExecutor stateFinalizerExecutorMock;
51 private StateFinalizerExecutor parentExecutorMock;
54 private AxState axStateMock;
57 private ApexInternalContext internalContextMock;
63 public void startMocking() {
64 MockitoAnnotations.initMocks(this);
66 Set<AxArtifactKey> contextAlbumReferences = new LinkedHashSet<>();
67 contextAlbumReferences.add(new AxArtifactKey(("AlbumKey0:0.0.1")));
68 contextAlbumReferences.add(new AxArtifactKey(("AlbumKey1:0.0.1")));
70 Mockito.doReturn(contextAlbumReferences).when(axStateMock).getContextAlbumReferences();
71 Mockito.doReturn(new AxReferenceKey("Parent:0.0.1:ParentName:StateName")).when(axStateMock).getKey();
73 Map<AxArtifactKey, ContextAlbum> contextAlbumMap = new LinkedHashMap<>();
74 AxArtifactKey album0Key = new AxArtifactKey("AlbumKey0:0.0.1");
75 AxArtifactKey album1Key = new AxArtifactKey("AlbumKey1:0.0.1");
77 contextAlbumMap.put(album0Key, new DummyContextAlbum(album0Key));
78 contextAlbumMap.put(album1Key, new DummyContextAlbum(album1Key));
80 Mockito.doReturn(contextAlbumMap).when(internalContextMock).getContextAlbums();
82 Mockito.doReturn(parentExecutorMock).when(stateFinalizerExecutorMock).getParent();
83 Mockito.doReturn(new AxReferenceKey("Parent:0.0.1:ParentName:LocalName")).when(parentExecutorMock).getKey();
88 final Map<String, Object> fields = new LinkedHashMap<>();
89 final Set<String> stateOutputNames = new LinkedHashSet<>();
91 StateFinalizerExecutionContext sfec = new StateFinalizerExecutionContext(stateFinalizerExecutorMock, 0, null,
92 axStateMock, fields, stateOutputNames, internalContextMock);
95 sfec.setMessage("SFEC Message");
96 assertEquals("SFEC Message", sfec.getMessage());
98 sfec.setSelectedStateOutputName("SomeOutput");
99 assertEquals("SomeOutput", sfec.getSelectedStateOutputName());
101 ContextAlbum contextAlbum = sfec.getContextAlbum("AlbumKey0");
102 assertEquals("AlbumKey0:0.0.1", contextAlbum.getKey().getId());
105 sfec.getContextAlbum("AlbumKeyNonExistant");
106 fail("test should throw an exception");
107 } catch (Exception exc) {
108 assertEquals("cannot find definition of context album \"AlbumKeyNonExistant\" "
109 + "on state \"Parent:0.0.1:ParentName:StateName\"", exc.getMessage());