summaryrefslogtreecommitdiffstats
path: root/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/servicefilter/ServiceFilterTests.java
blob: 8be71328ea3a1f05b8bf58d1be7242e1fd709d59 (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
package org.openecomp.sdc.ci.tests.servicefilter;

import java.util.Collections;

import org.junit.Rule;
import org.junit.rules.TestName;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.PropertyReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.ServiceFilterDetails;
import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
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.BaseRestUtils;
import org.openecomp.sdc.ci.tests.utils.rest.ComponentInstanceRestUtils;
import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
import org.openecomp.sdc.ci.tests.utils.rest.PropertyRestUtils;
import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
import org.openecomp.sdc.ci.tests.utils.rest.ServiceFilterUtils;
import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class ServiceFilterTests extends ComponentBaseTest {
    @Rule
    public static TestName name = new TestName();

    private static ServiceReqDetails externalService;
    private static ComponentInstanceReqDetails componentInstanceReqDetails;
    private static User user = null;

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

    @BeforeTest
    public void init() throws Exception {
        user = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);

        ServiceReqDetails internalService;
        //Create External Service
        externalService = ElementFactory.getDefaultService();
        externalService.setName("ExternalService" + Math.random());
        ServiceRestUtils.createService(externalService, user);

        //Create Internal Service
        internalService = ElementFactory.getDefaultService();
        internalService.setName("InternalService" + Math.random());
        ServiceRestUtils.createService(internalService, user);

        //Add property services
        //#PropertyOne
        PropertyReqDetails propertyReqDetails = ElementFactory.getDefaultStringProperty();
        propertyReqDetails.setName("StringProp1");
        String body = propertyReqDetails.propertyToJsonString();
        PropertyRestUtils.createServiceProperty(externalService.getUniqueId(), body, user);
        PropertyRestUtils.createServiceProperty(internalService.getUniqueId(), body, user);
        //#PropertyTwo
        propertyReqDetails.setName("StringProp2");
        body = propertyReqDetails.propertyToJsonString();
        RestResponse response = PropertyRestUtils.createServiceProperty(externalService.getUniqueId(), body, user);
        response = PropertyRestUtils.createServiceProperty(internalService.getUniqueId(), body, user);

        //CheckIn internal Service
        response = LifecycleRestUtils.changeServiceState(internalService, user, "0.1",
                LifeCycleStatesEnum.CHECKIN,
                "{\"userRemarks\":\"CheckIn\"}");
        BaseRestUtils.checkSuccess(response);
        if (response.getErrorCode() == BaseRestUtils.STATUS_CODE_SUCCESS) {
            internalService.setUniqueId(ResponseParser.getUniqueIdFromResponse(response));
        }
        //Make internal service as component instance
        componentInstanceReqDetails =
                ElementFactory.getDefaultComponentInstance(internalService.getUniqueId(), "ServiceProxy");
        response = ComponentInstanceRestUtils.createComponentInstance(componentInstanceReqDetails,
                user, externalService.getUniqueId(), ComponentTypeEnum.SERVICE);
        BaseRestUtils.checkCreateResponse(response);
        if (response.getErrorCode() == BaseRestUtils.STATUS_CODE_CREATED) {
            componentInstanceReqDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(response));
            componentInstanceReqDetails.setName(ResponseParser.getNameFromResponse(response));
        }
        //Mark as dependent
        componentInstanceReqDetails.setDirectives(Collections.singletonList("selectable"));
        response = ComponentInstanceRestUtils.updateComponentInstance(componentInstanceReqDetails,
                user, externalService.getUniqueId(), ComponentTypeEnum.SERVICE);
        BaseRestUtils.checkSuccess(response);
    }

    @Test
    public void createServiceFilter() throws Exception {
        //Add Service Filter
        ServiceFilterDetails serviceFilterDetails = ElementFactory.getDefaultEqualOperatorFilter("StringProp1", "value");
        RestResponse restResponse = ServiceFilterUtils.createServiceFilter(externalService.getUniqueId(),
                componentInstanceReqDetails.getUniqueId(), serviceFilterDetails, user);
        logger.info("CreateServiceFilter Response Code:" + restResponse.getErrorCode());
        Assert.assertEquals((int) restResponse.getErrorCode(), BaseRestUtils.STATUS_CODE_SUCCESS);
    }

    @Test(dependsOnMethods = "createServiceFilter")
    public void updateServiceFilter() throws Exception {
        //Update Service Filter
        ServiceFilterDetails serviceFilterDetails =
                ElementFactory.getDefaultEqualOperatorFilter("StringProp1", "updated");
        RestResponse restResponse = ServiceFilterUtils.updateServiceFilter(externalService.getUniqueId(),
                componentInstanceReqDetails.getUniqueId(), Collections.singletonList(serviceFilterDetails),  user);
        logger.info("UpdateServiceFilter Response Code:" + restResponse.getErrorCode());
        Assert.assertEquals((int) restResponse.getErrorCode(), BaseRestUtils.STATUS_CODE_SUCCESS);
    }

    //    @Test(dependsOnMethods = "updateServiceFilter")
    public void deleteServiceFilter() throws Exception {
        //Delete Service Filter
        RestResponse restResponse = ServiceFilterUtils.deleteServiceFilter(externalService.getUniqueId(),
                componentInstanceReqDetails.getUniqueId(), 0, user);
        logger.info("DeleteServiceFilter Response Code:" + restResponse.getErrorCode());
        Assert.assertEquals((int) restResponse.getErrorCode(), BaseRestUtils.STATUS_CODE_SUCCESS);
    }
}