summaryrefslogtreecommitdiffstats
path: root/dcaedt_tools/src/test/java/DeployTemplateTest.java
blob: 78d27c73bb3f1f3cf137a36357130583d5e4fbdc (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
import com.google.gson.JsonObject;
import json.templateInfo.TemplateInfo;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import tools.DeployTemplate;

import java.util.*;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class DeployTemplateTest extends BaseTest {

    @InjectMocks
    DeployTemplate deployTemplate;

    private Map<TemplateInfo, JsonObject> templateInfoToJsonObjectMap;

    @Before
    @Override
    public void setup() {
        super.setup();
        super.mockGetAllVfcmt();
        super.mockCheckoutVfcmtAndCreateResource();
        when(dcaeRestClient.getUserId()).thenReturn(USER_ID);
        when(dcaeRestClient.saveComposition(any(), any())).thenReturn("Composition Created");

        templateInfoToJsonObjectMap = new HashMap<>();
        TemplateInfo templateInfo = new TemplateInfo();
        templateInfo.setName(VFCMT_NAME1);
        templateInfo.setFlowType(TEMPLATE_INFO_FLOWTYPE);
        templateInfo.setCategory("category");
        templateInfo.setSubCategory("subCategory");
        templateInfo.setDescription("description");
        templateInfo.setUpdateIfExist(true);
        templateInfoToJsonObjectMap.put(templateInfo, new JsonObject());
        templateInfo = new TemplateInfo();
        templateInfo.setName(TEMPLATE_INFO_NAME);
        templateInfo.setFlowType(TEMPLATE_INFO_FLOWTYPE);
        templateInfo.setCategory("category");
        templateInfo.setSubCategory("subCategory");
        templateInfo.setDescription("description");
        templateInfoToJsonObjectMap.put(templateInfo, new JsonObject());
    }

    @Test
    public void deployHappyFlow() {
        deployTemplate.deploy(templateInfoToJsonObjectMap);
        verify(report, times(0)).addErrorMessage(anyString());
    }

    @Test
    public void deploy_failedSaving_failedVerify() {
        when(dcaeRestClient.saveComposition(anyString(), anyString())).thenReturn("failed");
        deployTemplate.deploy(templateInfoToJsonObjectMap);
        verify(report, times(4)).addErrorMessage(anyString());
    }
}