summaryrefslogtreecommitdiffstats
path: root/dcaedt_tools/src/test/java/BaseTest.java
blob: 8d163a4230b64218ed7851e5922927daa06738b5 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import org.junit.Before;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.onap.sdc.dcae.composition.restmodels.sdc.Resource;
import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed;
import utilities.IDcaeRestClient;
import utilities.IReport;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;

abstract class BaseTest {
    static final String USER_ID = "userId";
    static final String TEMPLATE_INFO_NAME = "templateInfoName";
    static final String TEMPLATE_INFO_FLOWTYPE = "templateInfoFlowType";
    static final String VFCMT_NAME1 = "my vfcmt1";
    static final String UUID1 = "my uuid1";
    static final String VFCMT_NAME2 = "my vfcmt2";
    static final String UUID2 = "my uuid2";
    static final String VFCMT_NAME3 = "my vfcmt3";
    static final String UUID3 = "my uuid3";
    static final String ELEMENT_NAME1 = "my element1";
    static final String ELEMENT_NAME2 = "my element2";
    static final String ELEMENT_NAME3 = "my element3";
    static final String ALIAS_NAME1 = "my alias1";
    static final String ALIAS_NAME2 = "my alias2";
    static final String ALIAS_NAME3 = "my alias3";
    static final String ITEM_NAME1 = "my item1";
    static final String ITEM_NAME2 = "my item2";
    static final String ITEM_NAME3 = "my item3";

    @Mock
    IReport report;
    @Mock
    IDcaeRestClient dcaeRestClient;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        mockGetCatalog();
    }

    void mockCheckoutVfcmtAndCreateResource() {
        ResourceDetailed resourceDetailed = new ResourceDetailed();
        resourceDetailed.setName(VFCMT_NAME1);
        resourceDetailed.setUuid(UUID1);
        resourceDetailed.setLifecycleState("NOT_CERTIFIED_CHECKOUT");
        resourceDetailed.setLastUpdaterUserId(USER_ID);
        when(dcaeRestClient.createResource(any())).thenReturn(resourceDetailed);
    }

    void mockGetItemType() {
        when(dcaeRestClient.getItemType(any(), any())).thenReturn("{\"data\":{\"type\":{\"itemId\":\"e45ec9d7-01df-4cb1-896f-aff2a6ca5a8b/tosca.dcae.nodes.cdapApp.Map\", \"typeinfo\":\"typeInfo\"}}}");
    }

    void mockGetItemModel() {
        when(dcaeRestClient.getItemModel(any())).thenReturn("{\"data\":{\"model\":{\"itemId\":\"\",\"nodes\":[{\"capability\":{\"type\":\"someType\"}, \"type\":\"type\", \"name\":\"SomeNameFromRequirement\", \"requirements\":[{\"name\":\"SomeNameFromRequirement\"}], \"properties\":[{}], \"capabilities\":[{\"name\":\"SomeNameToCapability\"}],\"type\":\"type\"}]}}}",
                "{\"data\":{\"model\":{\"itemId\":\"\",\"nodes\":[{\"capability\":{\"type\":\"someType\"}, \"type\":\"type\", \"name\":\"SomeNameToCapability\", \"requirements\":[{\"name\":\"SomeNameFromRequirement\"}], \"properties\":[{}], \"capabilities\":[{\"name\":\"SomeNameToCapability\"}],\"type\":\"type\"}]}}}");
    }

	private void mockGetCatalog() {
		Map<String, List<Resource>> catalog = new HashMap<>();
		catalog.put(ELEMENT_NAME1, null);
		List<Resource> items = new ArrayList<>();
		Resource item = new Resource();
		item.setName(ITEM_NAME1);
		items.add(item);
		item = new Resource();
		item.setName(ITEM_NAME2);
		items.add(item);
		catalog.put(ELEMENT_NAME2, items);
		items = new ArrayList<>();
		item = new Resource();
		item.setName(ITEM_NAME3);
		items.add(item);
		catalog.put(ELEMENT_NAME3, items);
	}


    void mockGetAllVfcmt() {
        List<ResourceDetailed> resourceDetaileds = new ArrayList<>();
        ResourceDetailed resourceDetailed = new ResourceDetailed();
        resourceDetailed.setName(VFCMT_NAME1);
        resourceDetailed.setUuid(UUID1);
        resourceDetailed.setLifecycleState("NOT_CERTIFIED_CHECKOUT");
        resourceDetailed.setLastUpdaterUserId(USER_ID);
        resourceDetaileds.add(resourceDetailed);
        resourceDetailed = new ResourceDetailed();
        resourceDetailed.setName(VFCMT_NAME2);
        resourceDetailed.setUuid(UUID2);
        resourceDetaileds.add(resourceDetailed);
        resourceDetailed = new ResourceDetailed();
        resourceDetailed.setName(VFCMT_NAME3);
        resourceDetailed.setUuid(UUID3);
        resourceDetaileds.add(resourceDetailed);

        List<ResourceDetailed> resourceDetailed2 = new ArrayList<>();
        resourceDetailed = new ResourceDetailed();
        resourceDetailed.setName(VFCMT_NAME1);
        resourceDetailed.setUuid(UUID1);
        resourceDetailed.setLifecycleState("NOT_CERTIFIED_CHECKOUT");
        resourceDetailed.setLastUpdaterUserId(USER_ID);
        resourceDetailed2.add(resourceDetailed);
        resourceDetailed = new ResourceDetailed();
        resourceDetailed.setName(VFCMT_NAME2);
        resourceDetailed.setUuid(UUID2);
        resourceDetailed2.add(resourceDetailed);
        resourceDetailed = new ResourceDetailed();
        resourceDetailed.setName(VFCMT_NAME3);
        resourceDetailed.setUuid(UUID3);
        resourceDetailed2.add(resourceDetailed);
        resourceDetailed = new ResourceDetailed();
        resourceDetailed.setName(TEMPLATE_INFO_NAME);
        resourceDetailed.setUuid(UUID3);
        resourceDetailed2.add(resourceDetailed);
        when(dcaeRestClient.getAllVfcmts()).thenReturn(resourceDetaileds, resourceDetailed2);
        when(dcaeRestClient.getAllBaseVfcmts()).thenReturn(new ArrayList<>());
    }
}