aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/StackStatusHandlerTest.java
blob: 0d5cd6a118cf7895d211e4eedbd4fe84ff61064a (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
package org.onap.so.openstack.utils;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.so.db.request.beans.RequestProcessingData;
import org.onap.so.db.request.client.RequestsDbClient;
import org.onap.so.openstack.exceptions.MsoException;
import com.woorea.openstack.heat.model.Stack;

@RunWith(MockitoJUnitRunner.class)
public class StackStatusHandlerTest {

    @InjectMocks
    StackStatusHandler statusHandler;

    @Mock
    RequestsDbClient requestDBClient;

    @Test
    public final void recordExists_Test() throws MsoException, IOException {
        RequestProcessingData requestProcessingData = new RequestProcessingData();
        requestProcessingData.setValue("testMe");

        doReturn(requestProcessingData).when(requestDBClient)
                .getRequestProcessingDataBySoRequestIdAndNameAndGrouping(null, "stackName", "id");
        Stack latestStack = new Stack();
        latestStack.setId("id");
        latestStack.setStackName("stackName");
        latestStack.setStackStatus("CREATE_COMPLETE");
        latestStack.setStackStatusReason("Stack Finished");

        statusHandler.updateStackStatus(latestStack);
        Mockito.verify(requestDBClient, times(1)).updateRequestProcessingData(requestProcessingData);
        assertNotEquals("testMe", requestProcessingData.getValue());
    }

    @Test
    public final void record_Not_Exists_Test() throws MsoException, IOException {
        ArgumentCaptor<RequestProcessingData> requestCaptor = ArgumentCaptor.forClass(RequestProcessingData.class);
        doReturn(null).when(requestDBClient).getRequestProcessingDataBySoRequestIdAndNameAndGrouping(null, "stackName",
                "id");
        Stack latestStack = new Stack();
        latestStack.setId("id");
        latestStack.setStackName("stackName");
        latestStack.setStackStatus("CREATE_COMPLETE");
        latestStack.setStackStatusReason("Stack Finished");
        statusHandler.updateStackStatus(latestStack);
        Mockito.verify(requestDBClient, times(1)).saveRequestProcessingData(requestCaptor.capture());
        RequestProcessingData actualRequest = requestCaptor.getValue();
        assertEquals("id", actualRequest.getGroupingId());
        assertEquals("StackInformation", actualRequest.getTag());
        assertEquals("stackName", actualRequest.getName());
        assertNotNull(actualRequest.getValue());

    }


}