2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.ci.tests.servicefilter;
23 import java.util.Collections;
25 import org.junit.Rule;
26 import org.junit.rules.TestName;
27 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
28 import org.openecomp.sdc.be.model.User;
29 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
30 import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails;
31 import org.openecomp.sdc.ci.tests.datatypes.PropertyReqDetails;
32 import org.openecomp.sdc.ci.tests.datatypes.ServiceFilterDetails;
33 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
34 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
35 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
36 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
37 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
38 import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
39 import org.openecomp.sdc.ci.tests.utils.rest.ComponentInstanceRestUtils;
40 import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
41 import org.openecomp.sdc.ci.tests.utils.rest.PropertyRestUtils;
42 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
43 import org.openecomp.sdc.ci.tests.utils.rest.ServiceFilterUtils;
44 import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
45 import org.testng.Assert;
46 import org.testng.annotations.BeforeTest;
47 import org.testng.annotations.Test;
49 public class ServiceFilterTests extends ComponentBaseTest {
51 public static TestName name = new TestName();
53 private static ServiceReqDetails externalService;
54 private static ComponentInstanceReqDetails componentInstanceReqDetails;
55 private static User user = null;
57 public ServiceFilterTests() {
58 super(name, ServiceFilterTests.class.getName());
62 public void init() throws Exception {
63 user = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
65 ServiceReqDetails internalService;
66 //Create External Service
67 externalService = ElementFactory.getDefaultService();
68 externalService.setName("ExternalService" + Math.random());
69 ServiceRestUtils.createService(externalService, user);
71 //Create Internal Service
72 internalService = ElementFactory.getDefaultService();
73 internalService.setName("InternalService" + Math.random());
74 ServiceRestUtils.createService(internalService, user);
76 //Add property services
78 PropertyReqDetails propertyReqDetails = ElementFactory.getDefaultStringProperty();
79 propertyReqDetails.setName("StringProp1");
80 String body = propertyReqDetails.propertyToJsonString();
81 PropertyRestUtils.createServiceProperty(externalService.getUniqueId(), body, user);
82 PropertyRestUtils.createServiceProperty(internalService.getUniqueId(), body, user);
84 propertyReqDetails.setName("StringProp2");
85 body = propertyReqDetails.propertyToJsonString();
86 RestResponse response = PropertyRestUtils.createServiceProperty(externalService.getUniqueId(), body, user);
87 response = PropertyRestUtils.createServiceProperty(internalService.getUniqueId(), body, user);
89 //CheckIn internal Service
90 response = LifecycleRestUtils.changeServiceState(internalService, user, "0.1",
91 LifeCycleStatesEnum.CHECKIN,
92 "{\"userRemarks\":\"CheckIn\"}");
93 BaseRestUtils.checkSuccess(response);
94 if (response.getErrorCode() == BaseRestUtils.STATUS_CODE_SUCCESS) {
95 internalService.setUniqueId(ResponseParser.getUniqueIdFromResponse(response));
97 //Make internal service as component instance
98 componentInstanceReqDetails =
99 ElementFactory.getDefaultComponentInstance(internalService.getUniqueId(), "ServiceProxy");
100 response = ComponentInstanceRestUtils.createComponentInstance(componentInstanceReqDetails,
101 user, externalService.getUniqueId(), ComponentTypeEnum.SERVICE);
102 BaseRestUtils.checkCreateResponse(response);
103 if (response.getErrorCode() == BaseRestUtils.STATUS_CODE_CREATED) {
104 componentInstanceReqDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(response));
105 componentInstanceReqDetails.setName(ResponseParser.getNameFromResponse(response));
108 componentInstanceReqDetails.setDirectives(Collections.singletonList("selectable"));
109 response = ComponentInstanceRestUtils.updateComponentInstance(componentInstanceReqDetails,
110 user, externalService.getUniqueId(), ComponentTypeEnum.SERVICE);
111 BaseRestUtils.checkSuccess(response);
115 public void createServiceFilter() throws Exception {
117 ServiceFilterDetails serviceFilterDetails = ElementFactory.getDefaultEqualOperatorFilter("StringProp1", "value");
118 RestResponse restResponse = ServiceFilterUtils.createServiceFilter(externalService.getUniqueId(),
119 componentInstanceReqDetails.getUniqueId(), serviceFilterDetails, user);
120 logger.info("CreateServiceFilter Response Code:" + restResponse.getErrorCode());
121 Assert.assertEquals((int) restResponse.getErrorCode(), BaseRestUtils.STATUS_CODE_SUCCESS);
124 @Test(dependsOnMethods = "createServiceFilter")
125 public void updateServiceFilter() throws Exception {
126 //Update Service Filter
127 ServiceFilterDetails serviceFilterDetails =
128 ElementFactory.getDefaultEqualOperatorFilter("StringProp1", "updated");
129 RestResponse restResponse = ServiceFilterUtils.updateServiceFilter(externalService.getUniqueId(),
130 componentInstanceReqDetails.getUniqueId(), Collections.singletonList(serviceFilterDetails), user);
131 logger.info("UpdateServiceFilter Response Code:" + restResponse.getErrorCode());
132 Assert.assertEquals((int) restResponse.getErrorCode(), BaseRestUtils.STATUS_CODE_SUCCESS);
135 // @Test(dependsOnMethods = "updateServiceFilter")
136 public void deleteServiceFilter() throws Exception {
137 //Delete Service Filter
138 RestResponse restResponse = ServiceFilterUtils.deleteServiceFilter(externalService.getUniqueId(),
139 componentInstanceReqDetails.getUniqueId(), 0, user);
140 logger.info("DeleteServiceFilter Response Code:" + restResponse.getErrorCode());
141 Assert.assertEquals((int) restResponse.getErrorCode(), BaseRestUtils.STATUS_CODE_SUCCESS);