summaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/PollServiceTest.java
blob: 60826705fd32abe3d88e61de49aaf4552baeba83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package org.onap.so.adapters.tasks.orchestration;

import org.camunda.bpm.client.task.ExternalTask;
import org.camunda.bpm.client.task.ExternalTaskService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.eq;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.so.adapters.tasks.orchestration.PollService;
import org.onap.so.adapters.vnf.VnfAdapterUtils;
import org.onap.so.logging.tasks.AuditMDCSetup;
import org.onap.so.openstack.exceptions.MsoException;
import org.onap.so.openstack.utils.MsoHeatUtils;
import com.woorea.openstack.heat.model.Stack;

@RunWith(MockitoJUnitRunner.class)
public class PollServiceTest {

    private String RESOURCE_PATH = "src/test/resources/__files/";

    @Mock
    private ExternalTask mockExternalTask;

    @Mock
    private ExternalTaskService mockExternalTaskService;

    @Mock
    private MsoHeatUtils msoHeatUtils;

    @Mock
    private VnfAdapterUtils vnfAdapterUtils;

    @Mock
    private AuditMDCSetup mdcSetup;

    @InjectMocks
    private PollService pollService;

    @Test
    public void testExecuteExternalTask() throws MsoException, IOException {
        String xmlString =
                new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "/vnfAdapterTaskRequestCreate.xml")));

        Mockito.when(vnfAdapterUtils.isMulticloudMode(Mockito.any(), Mockito.any())).thenReturn(false);
        Mockito.when(mockExternalTask.getVariable("openstackAdapterTaskRequest")).thenReturn(xmlString);
        Mockito.when(mockExternalTask.getVariable("PollRollbackStatus")).thenReturn(false);
        Mockito.when(mockExternalTask.getVariable("stackId")).thenReturn("stackId/stack123");
        Mockito.when(msoHeatUtils.pollStackForStatus(eq(1), any(Stack.class), eq("CREATE_IN_PROGRESS"), eq("regionOne"),
                eq("0422ffb57ba042c0800a29dc85ca70f8"), eq(false))).thenReturn(new Stack());
        // Mockito.doNothing().when(msoHeatUtils).postProcessStackCreate(Mockito.any(), Mockito.any(), Mockito.any(),
        // Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());

        pollService.executeExternalTask(mockExternalTask, mockExternalTaskService);

        Mockito.verify(msoHeatUtils).pollStackForStatus(eq(1), any(Stack.class), eq("CREATE_IN_PROGRESS"),
                eq("regionOne"), eq("0422ffb57ba042c0800a29dc85ca70f8"), eq(false));

    }

    @Test
    public void testExecuteExternalTask_rollback() throws MsoException, IOException {
        String xmlString =
                new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "/vnfAdapterTaskRequestCreate.xml")));

        Mockito.when(mockExternalTask.getVariable("openstackAdapterTaskRequest")).thenReturn(xmlString);
        Mockito.when(mockExternalTask.getVariable("PollRollbackStatus")).thenReturn(true);
        Mockito.when(mockExternalTask.getVariable("stackId")).thenReturn("stackId/stack123");
        Mockito.when(msoHeatUtils.pollStackForStatus(eq(1), any(), eq("DELETE_IN_PROGRESS"), eq("regionOne"),
                eq("0422ffb57ba042c0800a29dc85ca70f8"), eq(true))).thenReturn(new Stack());
        Mockito.doNothing().when(msoHeatUtils).postProcessStackDelete(Mockito.any());


        pollService.executeExternalTask(mockExternalTask, mockExternalTaskService);

        Mockito.verify(msoHeatUtils).pollStackForStatus(eq(1), any(), eq("DELETE_IN_PROGRESS"), eq("regionOne"),
                eq("0422ffb57ba042c0800a29dc85ca70f8"), eq(true));

    }

}