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.assertNull;
26 import java.util.LinkedHashMap;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.mockito.Mock;
31 import org.mockito.Mockito;
32 import org.mockito.MockitoAnnotations;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
34 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
35 import org.onap.policy.apex.model.basicmodel.service.ModelService;
36 import org.onap.policy.apex.model.policymodel.concepts.AxState;
37 import org.onap.policy.apex.model.policymodel.concepts.AxTask;
38 import org.onap.policy.apex.model.policymodel.concepts.AxTasks;
41 * Test the state facade.
43 public class AxStateFacadeTest {
45 private AxState axStateMock;
48 private AxTask axTaskMock;
54 public void startMocking() {
55 MockitoAnnotations.initMocks(this);
57 AxReferenceKey stateKey = new AxReferenceKey("StateParent:0.0.1:ParentName:StateName");
58 Mockito.doReturn(stateKey).when(axStateMock).getKey();
60 AxArtifactKey task0Key = new AxArtifactKey("Task0:0.0.1");
61 Mockito.doReturn(task0Key).when(axStateMock).getDefaultTask();
63 Map<AxArtifactKey, Object> taskReferences = new LinkedHashMap<>();;
64 taskReferences.put(task0Key, null);
65 Mockito.doReturn(taskReferences).when(axStateMock).getTaskReferences();
67 AxTasks tasks = new AxTasks();
68 tasks.getTaskMap().put(task0Key, axTaskMock);
70 ModelService.registerModel(AxTasks.class, tasks);
71 Mockito.doReturn(task0Key).when(axTaskMock).getKey();
75 public void testAxStateFacade() {
76 AxStateFacade stateFacade = new AxStateFacade(axStateMock);
78 assertEquals("StateName", stateFacade.getStateName());
79 assertEquals("StateParent:0.0.1:ParentName:StateName", stateFacade.getId());
81 assertEquals("Task0", stateFacade.getDefaultTaskKey().getName());
82 assertNull(stateFacade.getTaskKey(null));
83 assertEquals("Task0", stateFacade.getTaskKey("Task0").getName());
84 stateFacade.getTaskNames();