2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2023 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.core.engine.executor.context;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNull;
27 import java.util.LinkedHashMap;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Mock;
33 import org.mockito.Mockito;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
36 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
37 import org.onap.policy.apex.model.basicmodel.service.ModelService;
38 import org.onap.policy.apex.model.policymodel.concepts.AxState;
39 import org.onap.policy.apex.model.policymodel.concepts.AxTask;
40 import org.onap.policy.apex.model.policymodel.concepts.AxTasks;
43 * Test the state facade.
45 @RunWith(MockitoJUnitRunner.class)
46 public class AxStateFacadeTest {
48 private AxState axStateMock;
51 private AxTask axTaskMock;
57 public void startMocking() {
58 AxReferenceKey stateKey = new AxReferenceKey("StateParent:0.0.1:ParentName:StateName");
59 Mockito.doReturn(stateKey).when(axStateMock).getKey();
61 AxArtifactKey task0Key = new AxArtifactKey("Task0:0.0.1");
62 Mockito.doReturn(task0Key).when(axStateMock).getDefaultTask();
64 Map<AxArtifactKey, Object> taskReferences = new LinkedHashMap<>();;
65 taskReferences.put(task0Key, null);
66 Mockito.doReturn(taskReferences).when(axStateMock).getTaskReferences();
68 AxTasks tasks = new AxTasks();
69 tasks.getTaskMap().put(task0Key, axTaskMock);
71 ModelService.registerModel(AxTasks.class, tasks);
72 Mockito.doReturn(task0Key).when(axTaskMock).getKey();
76 public void testAxStateFacade() {
77 AxStateFacade stateFacade = new AxStateFacade(axStateMock);
79 assertEquals("StateName", stateFacade.getStateName());
80 assertEquals("StateParent:0.0.1:ParentName:StateName", stateFacade.getId());
82 assertEquals("Task0", stateFacade.getDefaultTaskKey().getName());
83 assertNull(stateFacade.getTaskKey(null));
84 assertEquals("Task0", stateFacade.getTaskKey("Task0").getName());
85 stateFacade.getTaskNames();