summaryrefslogtreecommitdiffstats
path: root/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/resource/GetLeftPaletteTest.java
blob: 4ad008633a23466db0ad789a940128496f165bf4 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package org.openecomp.sdc.ci.tests.execute.resource;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.rules.TestName;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.AssertJUnit;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.Arrays;

import static org.testng.AssertJUnit.assertTrue;

/**
 * Created by chaya on 6/15/2017.
 */
public class GetLeftPaletteTest extends ComponentBaseTest {

    private static Logger logger = LoggerFactory.getLogger(GetLeftPaletteTest.class.getName());
    protected User designerDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
    protected ResourceReqDetails vlResourceDetails;
    protected ResourceReqDetails cpResourceDetails;
    protected ResourceReqDetails vfcResourceDetails;
    protected ResourceReqDetails vfcmtResourceDetails;
    protected ResourceReqDetails vfResourceDetails;


    public static TestName name = new TestName();

    public GetLeftPaletteTest() {
        super(name, GetLeftPaletteTest.class.getName());
    }

    @BeforeClass
    public void setUp() throws Exception {
        // create VL
        vlResourceDetails = createResource(vlResourceDetails, "vlRes", ResourceTypeEnum.VL);
        checkInResource(vlResourceDetails);

        // create CP
        cpResourceDetails = createResource(cpResourceDetails, "cpRes", ResourceTypeEnum.CP);
        checkInResource(cpResourceDetails);

        // create VFC
        vfcResourceDetails = createResource(vfcResourceDetails, "vfcRes", ResourceTypeEnum.VFC);
        checkInResource(vfcResourceDetails);

        // create VFCMT
        vfcmtResourceDetails = createResource(vfcmtResourceDetails, "vfcmtRes", ResourceTypeEnum.VFCMT);
        checkInResource(vfcmtResourceDetails);

        // create VF
        vfResourceDetails = createResource(vfResourceDetails, "vfRes", ResourceTypeEnum.VF);
        checkInResource(vfResourceDetails);
    }



    @Test
    public void testGetLeftPaletteForPNF() throws IOException {

        RestResponse getResourceLatestVersionResponse = ResourceRestUtils.getResourceLatestVersionListMetadata(designerDetails, "PNF");
        assertTrue("response code is not 200, returned :" + getResourceLatestVersionResponse.getErrorCode(),
                getResourceLatestVersionResponse.getErrorCode() == 200);

        String json = getResourceLatestVersionResponse.getResponse();
        JSONArray jsonResp = (JSONArray) JSONValue.parse(json);

        AssertJUnit.assertTrue("check vlResource is in response",
                isComponentInArray(vlResourceDetails.getUniqueId(), jsonResp));

        AssertJUnit.assertTrue("check cpResource is in response",
                isComponentInArray(cpResourceDetails.getUniqueId(), jsonResp));

        AssertJUnit.assertFalse("check vfcResource is not in response",
                isComponentInArray(vfcResourceDetails.getUniqueId(), jsonResp));

        AssertJUnit.assertFalse("check vfResource is not in response",
                isComponentInArray(vfResourceDetails.getUniqueId(), jsonResp));

        AssertJUnit.assertFalse("check vfcmtResource is not in response",
                isComponentInArray(vfcmtResourceDetails.getUniqueId(), jsonResp));

    }

    @Test
    public void testGetLeftPaletteForVF() throws IOException {

        RestResponse getResourceLatestVersionResponse = ResourceRestUtils.getResourceLatestVersionListMetadata(designerDetails, "VF");
        assertTrue("response code is not 200, returned :" + getResourceLatestVersionResponse.getErrorCode(),
                getResourceLatestVersionResponse.getErrorCode() == 200);

        String json = getResourceLatestVersionResponse.getResponse();
        JSONArray jsonResp = (JSONArray) JSONValue.parse(json);

        AssertJUnit.assertTrue("check vlResource is in response",
                isComponentInArray(vlResourceDetails.getUniqueId(), jsonResp));

        AssertJUnit.assertTrue("check cpResource is in response",
                isComponentInArray(cpResourceDetails.getUniqueId(), jsonResp));

        AssertJUnit.assertTrue("check vfcResource is not in response",
                isComponentInArray(vfcResourceDetails.getUniqueId(), jsonResp));

        AssertJUnit.assertFalse("check vfResource is not in response",
                isComponentInArray(vfResourceDetails.getUniqueId(), jsonResp));

        AssertJUnit.assertFalse("check vfcmtResource is not in response",
                isComponentInArray(vfcmtResourceDetails.getUniqueId(), jsonResp));

    }

    @Test
    public void testGetLeftPaletteForService() throws IOException {

        RestResponse getResourceLatestVersionResponse = ResourceRestUtils.getResourceLatestVersionListMetadata(designerDetails, "SERVICE");
        assertTrue("response code is not 200, returned :" + getResourceLatestVersionResponse.getErrorCode(),
                getResourceLatestVersionResponse.getErrorCode() == 200);

        String json = getResourceLatestVersionResponse.getResponse();
        JSONArray jsonResp = (JSONArray) JSONValue.parse(json);

        AssertJUnit.assertTrue("check vlResource is in response",
                isComponentInArray(vlResourceDetails.getUniqueId(), jsonResp));

        AssertJUnit.assertTrue("check cpResource is in response",
                isComponentInArray(cpResourceDetails.getUniqueId(), jsonResp));

        AssertJUnit.assertFalse("check vfcResource is not in response",
                isComponentInArray(vfcResourceDetails.getUniqueId(), jsonResp));

        AssertJUnit.assertTrue("check vfResource is not in response",
                isComponentInArray(vfResourceDetails.getUniqueId(), jsonResp));

        AssertJUnit.assertFalse("check vfcmtResource is not in response",
                isComponentInArray(vfcmtResourceDetails.getUniqueId(), jsonResp));

    }

    private ResourceReqDetails createResource(ResourceReqDetails resDetails, String name, ResourceTypeEnum resType) throws Exception {
        resDetails = new ResourceReqDetails(name, "desc",Arrays.asList(name), "Generic", Arrays.asList("tosca.nodes.Root"), "c", "1", "111", "myIcon", resType.name());
        resDetails.addCategoryChain(ResourceCategoryEnum.GENERIC_NETWORK_ELEMENTS.getCategory(),
                ResourceCategoryEnum.GENERIC_NETWORK_ELEMENTS.getSubCategory());
        RestResponse response = ResourceRestUtils.createResource(resDetails, designerDetails);
        assertTrue("response code is not 200, returned :" + response.getErrorCode(),
                response.getErrorCode() == 201);
        resDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(response));
        return resDetails;
    }

    private void checkInResource(ResourceReqDetails resDetails) throws IOException {
        RestResponse checkInResponse = LifecycleRestUtils.changeResourceState(resDetails, designerDetails, "0.1",
                LifeCycleStatesEnum.CHECKIN);
        AssertJUnit.assertEquals("check in operation failed", 200, checkInResponse.getErrorCode().intValue());

    }

    protected boolean isComponentInArray(String id, JSONArray component) {
        for (int i = 0; i < component.size(); i++) {
            JSONObject jobject = (JSONObject) component.get(i);
            if (jobject.get("uniqueId").toString().equals(id.toLowerCase())) {
                return true;
            }
        }
        return false;
    }

    @AfterClass
    public void tearDown() throws IOException {
        ResourceRestUtils.deleteResource(vlResourceDetails.getUniqueId(), designerDetails.getUserId());
        ResourceRestUtils.deleteResource(cpResourceDetails.getUniqueId(), designerDetails.getUserId());
        ResourceRestUtils.deleteResource(vfcResourceDetails.getUniqueId(), designerDetails.getUserId());
        ResourceRestUtils.deleteResource(vfcmtResourceDetails.getUniqueId(), designerDetails.getUserId());
        ResourceRestUtils.deleteResource(vfResourceDetails.getUniqueId(), designerDetails.getUserId());
    }
}