a35af534ee8e2515dc6a3c69be327ca00d9d8816
[policy/apex-pdp.git] / core / core-engine / src / test / java / org / onap / policy / apex / core / engine / executor / context / AxStateFacadeTest.java
1 /*-
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.core.engine.executor.context;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25
26 import java.util.LinkedHashMap;
27 import java.util.Map;
28
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mock;
32 import org.mockito.Mockito;
33 import org.mockito.MockitoAnnotations;
34 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
35 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
36 import org.onap.policy.apex.model.basicmodel.service.ModelService;
37 import org.onap.policy.apex.model.policymodel.concepts.AxState;
38 import org.onap.policy.apex.model.policymodel.concepts.AxTask;
39 import org.onap.policy.apex.model.policymodel.concepts.AxTasks;
40
41 /**
42  * Test the state facade.
43  */
44 public class AxStateFacadeTest {
45     @Mock
46     private AxState axStateMock;
47
48     @Mock
49     private AxTask axTaskMock;
50
51     /**
52      * Set up mocking.
53      */
54     @Before
55     public void startMocking() {
56         MockitoAnnotations.initMocks(this);
57         
58         AxReferenceKey stateKey = new AxReferenceKey("StateParent:0.0.1:ParentName:StateName");
59         Mockito.doReturn(stateKey).when(axStateMock).getKey();
60
61         AxArtifactKey task0Key = new AxArtifactKey("Task0:0.0.1");
62         Mockito.doReturn(task0Key).when(axStateMock).getDefaultTask();
63         
64         Map<AxArtifactKey, Object> taskReferences = new LinkedHashMap<>();;
65         taskReferences.put(task0Key, null);
66         Mockito.doReturn(taskReferences).when(axStateMock).getTaskReferences();
67
68         AxTasks tasks = new AxTasks();
69         tasks.getTaskMap().put(task0Key, axTaskMock);
70         
71         ModelService.registerModel(AxTasks.class, tasks);
72         Mockito.doReturn(task0Key).when(axTaskMock).getKey();
73     }
74
75     @Test
76     public void testAxStateFacade() {
77         AxStateFacade stateFacade = new AxStateFacade(axStateMock);
78         
79         assertEquals("StateName", stateFacade.getStateName());
80         assertEquals("StateParent:0.0.1:ParentName:StateName", stateFacade.getId());
81         
82         assertEquals("Task0", stateFacade.getDefaultTaskKey().getName());
83         assertNull(stateFacade.getTaskKey(null));
84         assertEquals("Task0", stateFacade.getTaskKey("Task0").getName());
85         stateFacade.getTaskNames();
86     }
87 }