Fix for radio buttons
[sdc.git] / asdc-tests / src / main / java / org / openecomp / sdc / externalApis / GetFilteredAssetServlet.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.externalApis;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNotNull;
25
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.List;
29
30 import org.junit.Rule;
31 import org.junit.rules.TestName;
32 import org.openecomp.sdc.be.dao.api.ActionStatus;
33 import org.openecomp.sdc.be.datatypes.enums.AssetTypeEnum;
34 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
35 import org.openecomp.sdc.be.model.DistributionStatusEnum;
36 import org.openecomp.sdc.be.model.Resource;
37 import org.openecomp.sdc.be.model.Service;
38 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
39 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
40 import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
41 import org.openecomp.sdc.ci.tests.datatypes.ResourceAssetStructure;
42 import org.openecomp.sdc.ci.tests.datatypes.ServiceAssetStructure;
43 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
44 import org.openecomp.sdc.ci.tests.datatypes.enums.ErrorInfo;
45 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
46 import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
47 import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
48 import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum;
49 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
50 import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedExternalAudit;
51 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
52 import org.openecomp.sdc.ci.tests.utils.Utils;
53 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
54 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
55 import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
56 import org.openecomp.sdc.ci.tests.utils.rest.AssetRestUtils;
57 import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
58 import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
59 import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils;
60 import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils;
61 import org.testng.annotations.BeforeMethod;
62 import org.testng.annotations.Test;
63
64 public class GetFilteredAssetServlet extends ComponentBaseTest {
65
66         protected final static String categoryFilterKey = "category";
67         protected final static String subCategoryFilterKey = "subCategory";
68         protected final static String distributionStatusFilterKey = "distributionStatus";
69         protected final static String serviceKey = "service";
70         protected final static String resourceKey = "resource";
71
72         @Rule
73         public static TestName name = new TestName();
74
75         public GetFilteredAssetServlet() {
76                 super(name, GetFilteredAssetServlet.class.getName());
77         }
78
79         @BeforeMethod
80         public void setup() throws Exception {
81                 AtomicOperationUtils.createDefaultConsumer(true);
82         }
83
84         // RESOURCE
85         // Success
86
87         @Test // (enabled = false)
88         public void getResourceAssetBySpecifiedCategory() throws Exception {
89                 String[] filter = { categoryFilterKey + "=" + ResourceCategoryEnum.GENERIC_ABSTRACT.getCategory() };
90                 List<String> expectedAssetNamesList = new ArrayList<>();
91
92                 Resource resource1 = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF, NormativeTypesEnum.COMPUTE, ResourceCategoryEnum.GENERIC_ABSTRACT, UserRoleEnum.DESIGNER, true).left().value();
93                 expectedAssetNamesList.add(resource1.getName());
94                 Resource resource2 = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF, NormativeTypesEnum.DATABASE, ResourceCategoryEnum.GENERIC_NETWORK_ELEMENTS, UserRoleEnum.DESIGNER, true).left().value();
95                 expectedAssetNamesList.add(resource2.getName());
96                 Resource resource3 = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF, NormativeTypesEnum.COMPUTE, ResourceCategoryEnum.NETWORK_CONNECTIVITY_CON_POINT, UserRoleEnum.DESIGNER, true).left().value();
97
98                 RestResponse assetResponse = AssetRestUtils.getComponentListByAssetType(true, AssetTypeEnum.RESOURCES, filter);
99                 BaseRestUtils.checkSuccess(assetResponse);
100
101                 List<ResourceAssetStructure> resourceAssetList = AssetRestUtils.getResourceAssetList(assetResponse);
102                 List<String> getActualAssetNamesList = AssetRestUtils.getResourceNamesList(resourceAssetList);
103                 Utils.compareArrayLists(getActualAssetNamesList, expectedAssetNamesList, "Element");
104
105                 // Validate audit message
106                 ExpectedExternalAudit expectedAssetListAudit = ElementFactory.getDefaultAssetListAudit(AssetTypeEnum.RESOURCES, AuditingActionEnum.GET_FILTERED_ASSET_LIST);
107                 expectedAssetListAudit.setRESOURCE_URL(AssetRestUtils.buildUrlWithFilter(expectedAssetListAudit.getRESOURCE_URL(), filter));
108                 AuditValidationUtils.validateExternalAudit(expectedAssetListAudit, AuditingActionEnum.GET_FILTERED_ASSET_LIST.getName(), null);
109         }
110
111         // 2 resources has the same category and different subcategory
112         @Test // (enabled = false)
113         public void getResourceAssetBySpecifiedCategoryAndSubCategory() throws Exception {
114                 String[] filter = { categoryFilterKey + "=" + ResourceCategoryEnum.GENERIC_ABSTRACT.getCategory(), subCategoryFilterKey + "=" + ResourceCategoryEnum.GENERIC_ABSTRACT.getSubCategory() };
115                 // String[] filter2 = {categoryFilterKey + "=" +
116                 // ResourceCategoryEnum.GENERIC_NETWORK_ELEMENTS.getCategory(),
117                 // subCategoryFilterKey + "=" +
118                 // ResourceCategoryEnum.GENERIC_NETWORK_ELEMENTS.getSubCategory()};
119                 List<String> expectedAssetNamesList = new ArrayList<>();
120
121                 Resource resource1 = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF, NormativeTypesEnum.COMPUTE, ResourceCategoryEnum.GENERIC_ABSTRACT, UserRoleEnum.DESIGNER, true).left().value();
122                 expectedAssetNamesList.add(resource1.getName());
123                 Resource resource2 = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF, NormativeTypesEnum.DATABASE, ResourceCategoryEnum.GENERIC_NETWORK_ELEMENTS, UserRoleEnum.DESIGNER, true).left().value();
124
125                 RestResponse assetResponse = AssetRestUtils.getComponentListByAssetType(true, AssetTypeEnum.RESOURCES, filter);
126                 BaseRestUtils.checkSuccess(assetResponse);
127
128                 List<ServiceAssetStructure> resourceAssetList = AssetRestUtils.getServiceAssetList(assetResponse);
129                 List<String> getActualAssetNamesList = AssetRestUtils.getServiceNamesList(resourceAssetList);
130                 Utils.compareArrayLists(getActualAssetNamesList, expectedAssetNamesList, "Element");
131
132                 // Validate audit message
133                 ExpectedExternalAudit expectedAssetListAudit = ElementFactory.getDefaultAssetListAudit(AssetTypeEnum.RESOURCES, AuditingActionEnum.GET_FILTERED_ASSET_LIST);
134                 expectedAssetListAudit.setRESOURCE_URL(AssetRestUtils.buildUrlWithFilter(expectedAssetListAudit.getRESOURCE_URL(), filter));
135                 AuditValidationUtils.validateExternalAudit(expectedAssetListAudit, AuditingActionEnum.GET_FILTERED_ASSET_LIST.getName(), null);
136         }
137
138         @Test // (enabled = false)
139         public void getResourceAssetBySpecifiedSubCategoryAndCategory() throws Exception {
140                 String[] filter = { subCategoryFilterKey + "=" + ResourceCategoryEnum.GENERIC_DATABASE.getSubCategory(), categoryFilterKey + "=" + ResourceCategoryEnum.GENERIC_DATABASE.getCategory(), };
141                 List<String> expectedAssetNamesList = new ArrayList<>();
142
143                 Resource resource1 = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF, NormativeTypesEnum.COMPUTE, ResourceCategoryEnum.GENERIC_ABSTRACT, UserRoleEnum.DESIGNER, true).left().value();
144                 Resource resource2 = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF, NormativeTypesEnum.DATABASE, ResourceCategoryEnum.GENERIC_DATABASE, UserRoleEnum.DESIGNER, true).left().value();
145                 expectedAssetNamesList.add(resource2.getName());
146
147                 RestResponse assetResponse = AssetRestUtils.getComponentListByAssetType(true, AssetTypeEnum.RESOURCES, filter);
148                 BaseRestUtils.checkSuccess(assetResponse);
149
150                 List<ServiceAssetStructure> resourceAssetList = AssetRestUtils.getServiceAssetList(assetResponse);
151                 List<String> getActualAssetNamesList = AssetRestUtils.getServiceNamesList(resourceAssetList);
152                 Utils.compareArrayLists(getActualAssetNamesList, expectedAssetNamesList, "Element");
153
154                 // Validate audit message
155                 ExpectedExternalAudit expectedAssetListAudit = ElementFactory.getDefaultAssetListAudit(AssetTypeEnum.RESOURCES, AuditingActionEnum.GET_FILTERED_ASSET_LIST);
156                 expectedAssetListAudit.setRESOURCE_URL(AssetRestUtils.buildUrlWithFilter(expectedAssetListAudit.getRESOURCE_URL(), filter));
157                 AuditValidationUtils.validateExternalAudit(expectedAssetListAudit, AuditingActionEnum.GET_FILTERED_ASSET_LIST.getName(), null);
158         }
159
160         // Failure
161         @Test // (enabled = false)
162         public void getResourceAssetCategoryNotExists() throws Exception {
163                 String[] filter = { categoryFilterKey + "=" + "NotExistingCategory" };
164
165                 RestResponse assetResponse = AssetRestUtils.getComponentListByAssetType(true, AssetTypeEnum.RESOURCES, filter);
166                 ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.COMPONENT_CATEGORY_NOT_FOUND.name());
167
168                 assertNotNull("check response object is not null after create resouce", assetResponse);
169                 assertNotNull("check error code exists in response after create resource", assetResponse.getErrorCode());
170                 assertEquals("Check response code after create resource", errorInfo.getCode(), assetResponse.getErrorCode());
171
172                 List<String> variables = Arrays.asList(resourceKey, categoryFilterKey, "NotExistingCategory");
173                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_CATEGORY_NOT_FOUND.name(), variables, assetResponse.getResponse());
174
175                 // Validate audit message
176                 ExpectedExternalAudit expectedAssetListAudit = ElementFactory.getDefaultAssetListAudit(AssetTypeEnum.RESOURCES, AuditingActionEnum.GET_FILTERED_ASSET_LIST);
177                 expectedAssetListAudit.setRESOURCE_URL(AssetRestUtils.buildUrlWithFilter(expectedAssetListAudit.getRESOURCE_URL(), filter));
178                 expectedAssetListAudit.setSTATUS(errorInfo.getCode().toString());
179                 expectedAssetListAudit.setDESC(AuditValidationUtils.buildAuditDescription(errorInfo, variables));
180                 AuditValidationUtils.validateExternalAudit(expectedAssetListAudit, AuditingActionEnum.GET_FILTERED_ASSET_LIST.getName(), null);
181         }
182
183         @Test // (enabled = false)
184         public void getResourceAssetSubCategoryNotExists() throws Exception {
185                 String[] filter = { categoryFilterKey + "=" + ResourceCategoryEnum.GENERIC_ABSTRACT.getCategory(), subCategoryFilterKey + "=" + "NotExistingSubCategory" };
186
187                 RestResponse assetResponse = AssetRestUtils.getComponentListByAssetType(true, AssetTypeEnum.RESOURCES, filter);
188                 ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY.name());
189
190                 assertNotNull("check response object is not null after create resouce", assetResponse);
191                 assertNotNull("check error code exists in response after create resource", assetResponse.getErrorCode());
192                 assertEquals("Check response code after create resource", errorInfo.getCode(), assetResponse.getErrorCode());
193
194                 List<String> variables = Arrays.asList("Resource", "NotExistingSubCategory", ResourceCategoryEnum.GENERIC_ABSTRACT.getCategory());
195                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY.name(), variables, assetResponse.getResponse());
196
197                 // Validate audit message
198                 ExpectedExternalAudit expectedAssetListAudit = ElementFactory.getDefaultAssetListAudit(AssetTypeEnum.RESOURCES, AuditingActionEnum.GET_FILTERED_ASSET_LIST);
199                 expectedAssetListAudit.setRESOURCE_URL(AssetRestUtils.buildUrlWithFilter(expectedAssetListAudit.getRESOURCE_URL(), filter));
200                 expectedAssetListAudit.setSTATUS(errorInfo.getCode().toString());
201                 expectedAssetListAudit.setDESC(AuditValidationUtils.buildAuditDescription(errorInfo, variables));
202                 AuditValidationUtils.validateExternalAudit(expectedAssetListAudit, AuditingActionEnum.GET_FILTERED_ASSET_LIST.getName(), null);
203         }
204
205         @Test // (enabled = false)
206         public void getResourceAssetCategoryNotExistsSubCategoryExists() throws Exception {
207                 String[] filter = { subCategoryFilterKey + "=" + ResourceCategoryEnum.NETWORK_L2_3_GETEWAY.getSubCategory(), categoryFilterKey + "=" + "NotExistingCategory" };
208
209                 RestResponse assetResponse = AssetRestUtils.getComponentListByAssetType(true, AssetTypeEnum.RESOURCES, filter);
210                 ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.COMPONENT_CATEGORY_NOT_FOUND.name());
211
212                 assertNotNull("check response object is not null after create resouce", assetResponse);
213                 assertNotNull("check error code exists in response after create resource", assetResponse.getErrorCode());
214                 assertEquals("Check response code after create resource", errorInfo.getCode(), assetResponse.getErrorCode());
215
216                 List<String> variables = Arrays.asList(resourceKey, categoryFilterKey, "NotExistingCategory");
217                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_CATEGORY_NOT_FOUND.name(), variables, assetResponse.getResponse());
218
219                 // Validate audit message
220                 ExpectedExternalAudit expectedAssetListAudit = ElementFactory.getDefaultAssetListAudit(AssetTypeEnum.RESOURCES, AuditingActionEnum.GET_FILTERED_ASSET_LIST);
221                 expectedAssetListAudit.setRESOURCE_URL(AssetRestUtils.buildUrlWithFilter(expectedAssetListAudit.getRESOURCE_URL(), filter));
222                 expectedAssetListAudit.setSTATUS(errorInfo.getCode().toString());
223                 expectedAssetListAudit.setDESC(AuditValidationUtils.buildAuditDescription(errorInfo, variables));
224                 AuditValidationUtils.validateExternalAudit(expectedAssetListAudit, AuditingActionEnum.GET_FILTERED_ASSET_LIST.getName(), null);
225         }
226
227         @Test // (enabled = false)
228         public void getResourceAssetInvalidFilterKey() throws Exception {
229                 String[] filter = { subCategoryFilterKey + "1=" + ResourceCategoryEnum.NETWORK_L2_3_GETEWAY.getSubCategory(), categoryFilterKey + "=" + "NotExistingCategory" };
230
231                 RestResponse assetResponse = AssetRestUtils.getComponentListByAssetType(true, AssetTypeEnum.RESOURCES, filter);
232                 ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.INVALID_FILTER_KEY.name());
233
234                 assertNotNull("check response object is not null after create resouce", assetResponse);
235                 assertNotNull("check error code exists in response after create resource", assetResponse.getErrorCode());
236                 assertEquals("Check response code after create resource", errorInfo.getCode(), assetResponse.getErrorCode());
237
238                 List<String> variables = Arrays.asList(subCategoryFilterKey + "1", "[" + subCategoryFilterKey + ", " + categoryFilterKey + "]");
239                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_FILTER_KEY.name(), variables, assetResponse.getResponse());
240
241                 // Validate audit message
242                 ExpectedExternalAudit expectedAssetListAudit = ElementFactory.getDefaultAssetListAudit(AssetTypeEnum.RESOURCES, AuditingActionEnum.GET_FILTERED_ASSET_LIST);
243                 expectedAssetListAudit.setRESOURCE_URL(AssetRestUtils.buildUrlWithFilter(expectedAssetListAudit.getRESOURCE_URL(), filter));
244                 expectedAssetListAudit.setSTATUS(errorInfo.getCode().toString());
245                 expectedAssetListAudit.setDESC(AuditValidationUtils.buildAuditDescription(errorInfo, variables));
246                 AuditValidationUtils.validateExternalAudit(expectedAssetListAudit, AuditingActionEnum.GET_FILTERED_ASSET_LIST.getName(), null);
247         }
248
249         // ---------------------------------------------------------------------------------------------------------
250         // SERVICE
251         // Success
252         @Test // (enabled = false)
253         public void getServiceAssetBySpecifiedCategory() throws Exception {
254                 String[] filter = { categoryFilterKey + "=" + ServiceCategoriesEnum.MOBILITY.getValue() };
255                 List<String> expectedAssetNamesList = new ArrayList<>();
256
257                 Service service1 = AtomicOperationUtils.createServiceByCategory(ServiceCategoriesEnum.MOBILITY, UserRoleEnum.DESIGNER, true).left().value();
258                 expectedAssetNamesList.add(service1.getName());
259
260                 RestResponse assetResponse = AssetRestUtils.getComponentListByAssetType(true, AssetTypeEnum.SERVICES, filter);
261                 BaseRestUtils.checkSuccess(assetResponse);
262
263                 List<ServiceAssetStructure> serviceAssetList = AssetRestUtils.getServiceAssetList(assetResponse);
264                 List<String> getActualAssetNamesList = AssetRestUtils.getServiceNamesList(serviceAssetList);
265                 Utils.compareArrayLists(getActualAssetNamesList, expectedAssetNamesList, "Element");
266
267                 // Validate audit message
268                 ExpectedExternalAudit expectedAssetListAudit = ElementFactory.getDefaultAssetListAudit(AssetTypeEnum.SERVICES, AuditingActionEnum.GET_FILTERED_ASSET_LIST);
269                 expectedAssetListAudit.setRESOURCE_URL(AssetRestUtils.buildUrlWithFilter(expectedAssetListAudit.getRESOURCE_URL(), filter));
270                 AuditValidationUtils.validateExternalAudit(expectedAssetListAudit, AuditingActionEnum.GET_FILTERED_ASSET_LIST.getName(), null);
271
272         }
273
274         @Test // (enabled = false)
275         public void getServiceAssetBySpecifiedCategoryAndDistributionStatus() throws Exception {
276                 String[] filter = { categoryFilterKey + "=" + ServiceCategoriesEnum.MOBILITY.getValue(), distributionStatusFilterKey + "=" + DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED };
277                 List<String> expectedAssetNamesList = new ArrayList<>();
278                 ArtifactReqDetails artifactDetails = ElementFactory.getArtifactByType(ArtifactTypeEnum.OTHER, ArtifactTypeEnum.OTHER, true);
279
280                 Service service1 = AtomicOperationUtils.createServiceByCategory(ServiceCategoriesEnum.MOBILITY, UserRoleEnum.DESIGNER, true).left().value();
281                 expectedAssetNamesList.add(service1.getName());
282                 Service service2 = AtomicOperationUtils.createServiceByCategory(ServiceCategoriesEnum.MOBILITY, UserRoleEnum.DESIGNER, true).left().value();
283                 RestResponse addInformationalArtifactToService = ArtifactRestUtils.addInformationalArtifactToService(artifactDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), service2.getUniqueId());
284                 BaseRestUtils.checkSuccess(addInformationalArtifactToService);
285                 service2 = (Service) AtomicOperationUtils.changeComponentState(service2, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
286                 expectedAssetNamesList.add(service2.getName());
287
288                 RestResponse assetResponse = AssetRestUtils.getComponentListByAssetType(true, AssetTypeEnum.SERVICES, filter);
289                 BaseRestUtils.checkSuccess(assetResponse);
290
291                 List<ServiceAssetStructure> serviceAssetList = AssetRestUtils.getServiceAssetList(assetResponse);
292                 List<String> getActualAssetNamesList = AssetRestUtils.getServiceNamesList(serviceAssetList);
293                 Utils.compareArrayLists(getActualAssetNamesList, expectedAssetNamesList, "Element");
294
295                 // Validate audit message
296                 ExpectedExternalAudit expectedAssetListAudit = ElementFactory.getDefaultAssetListAudit(AssetTypeEnum.SERVICES, AuditingActionEnum.GET_FILTERED_ASSET_LIST);
297                 expectedAssetListAudit.setRESOURCE_URL(AssetRestUtils.buildUrlWithFilter(expectedAssetListAudit.getRESOURCE_URL(), filter));
298                 AuditValidationUtils.validateExternalAudit(expectedAssetListAudit, AuditingActionEnum.GET_FILTERED_ASSET_LIST.getName(), null);
299         }
300
301         @Test // (enabled = false)
302         public void getServiceAssetByDistributionStatus() throws Exception {
303                 String[] filter = { distributionStatusFilterKey + "=" + DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED };
304                 List<String> expectedAssetNamesList = new ArrayList<>();
305                 ArtifactReqDetails artifactDetails = ElementFactory.getArtifactByType(ArtifactTypeEnum.OTHER, ArtifactTypeEnum.OTHER, true);
306
307                 Service service1 = AtomicOperationUtils.createServiceByCategory(ServiceCategoriesEnum.MOBILITY, UserRoleEnum.DESIGNER, true).left().value();
308                 expectedAssetNamesList.add(service1.getName());
309                 Service service2 = AtomicOperationUtils.createServiceByCategory(ServiceCategoriesEnum.MOBILITY, UserRoleEnum.DESIGNER, true).left().value();
310                 RestResponse addInformationalArtifactToService = ArtifactRestUtils.addInformationalArtifactToService(artifactDetails, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), service2.getUniqueId());
311                 BaseRestUtils.checkSuccess(addInformationalArtifactToService);
312                 service2 = (Service) AtomicOperationUtils.changeComponentState(service2, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
313                 ServiceRestUtils.approveServiceDistribution(service2.getUniqueId(), UserRoleEnum.GOVERNOR.getUserId());
314
315                 RestResponse assetResponse = AssetRestUtils.getComponentListByAssetType(true, AssetTypeEnum.SERVICES, filter);
316                 BaseRestUtils.checkSuccess(assetResponse);
317
318                 List<ServiceAssetStructure> serviceAssetList = AssetRestUtils.getServiceAssetList(assetResponse);
319                 List<String> getActualAssetNamesList = AssetRestUtils.getServiceNamesList(serviceAssetList);
320                 Utils.compareArrayLists(getActualAssetNamesList, expectedAssetNamesList, "Element");
321
322                 // Validate audit message
323                 ExpectedExternalAudit expectedAssetListAudit = ElementFactory.getDefaultAssetListAudit(AssetTypeEnum.SERVICES, AuditingActionEnum.GET_FILTERED_ASSET_LIST);
324                 expectedAssetListAudit.setRESOURCE_URL(AssetRestUtils.buildUrlWithFilter(expectedAssetListAudit.getRESOURCE_URL(), filter));
325                 AuditValidationUtils.validateExternalAudit(expectedAssetListAudit, AuditingActionEnum.GET_FILTERED_ASSET_LIST.getName(), null);
326         }
327
328         // Failure
329         @Test // (enabled = false)
330         public void getServiceAssetCategoryNotExists() throws Exception {
331                 String[] filter = { categoryFilterKey + "=" + "NotExistingCategory" };
332
333                 RestResponse assetResponse = AssetRestUtils.getComponentListByAssetType(true, AssetTypeEnum.SERVICES, filter);
334                 ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.COMPONENT_CATEGORY_NOT_FOUND.name());
335
336                 assertNotNull("check response object is not null after create resouce", assetResponse);
337                 assertNotNull("check error code exists in response after create resource", assetResponse.getErrorCode());
338                 assertEquals("Check response code after create resource", errorInfo.getCode(), assetResponse.getErrorCode());
339
340                 List<String> variables = Arrays.asList(serviceKey, categoryFilterKey, "NotExistingCategory");
341                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_CATEGORY_NOT_FOUND.name(), variables, assetResponse.getResponse());
342
343                 // Validate audit message
344                 ExpectedExternalAudit expectedAssetListAudit = ElementFactory.getDefaultAssetListAudit(AssetTypeEnum.SERVICES, AuditingActionEnum.GET_FILTERED_ASSET_LIST);
345                 expectedAssetListAudit.setRESOURCE_URL(AssetRestUtils.buildUrlWithFilter(expectedAssetListAudit.getRESOURCE_URL(), filter));
346                 expectedAssetListAudit.setSTATUS(errorInfo.getCode().toString());
347                 expectedAssetListAudit.setDESC(AuditValidationUtils.buildAuditDescription(errorInfo, variables));
348                 AuditValidationUtils.validateExternalAudit(expectedAssetListAudit, AuditingActionEnum.GET_FILTERED_ASSET_LIST.getName(), null);
349         }
350
351         @Test // (enabled = false)
352         public void getServiceAssetInvalidDistributionStatus() throws Exception {
353                 String[] filter = { distributionStatusFilterKey + "=" + "NotExistingDistributionStatus" };
354                 RestResponse assetResponse = AssetRestUtils.getComponentListByAssetType(true, AssetTypeEnum.SERVICES, filter);
355                 ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.COMPONENT_CATEGORY_NOT_FOUND.name());
356
357                 assertNotNull("check response object is not null after create resouce", assetResponse);
358                 assertNotNull("check error code exists in response after create resource", assetResponse.getErrorCode());
359                 assertEquals("Check response code after create resource", errorInfo.getCode(), assetResponse.getErrorCode());
360
361                 List<String> variables = Arrays.asList(serviceKey, distributionStatusFilterKey, "NotExistingDistributionStatus");
362                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_CATEGORY_NOT_FOUND.name(), variables, assetResponse.getResponse());
363
364                 // Validate audit message
365                 ExpectedExternalAudit expectedAssetListAudit = ElementFactory.getDefaultAssetListAudit(AssetTypeEnum.SERVICES, AuditingActionEnum.GET_FILTERED_ASSET_LIST);
366                 expectedAssetListAudit.setRESOURCE_URL(AssetRestUtils.buildUrlWithFilter(expectedAssetListAudit.getRESOURCE_URL(), filter));
367                 expectedAssetListAudit.setSTATUS(errorInfo.getCode().toString());
368                 expectedAssetListAudit.setDESC(AuditValidationUtils.buildAuditDescription(errorInfo, variables));
369                 AuditValidationUtils.validateExternalAudit(expectedAssetListAudit, AuditingActionEnum.GET_FILTERED_ASSET_LIST.getName(), null);
370         }
371
372         @Test // (enabled = false)
373         public void getServiceAssetCategoryExitsDistributionStatusInvalid() throws Exception {
374                 String[] filter = { categoryFilterKey + "=" + ServiceCategoriesEnum.MOBILITY.getValue(), distributionStatusFilterKey + "=" + "NotExistingDistributionStatus" };
375
376                 RestResponse assetResponse = AssetRestUtils.getComponentListByAssetType(true, AssetTypeEnum.SERVICES, filter);
377                 ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.COMPONENT_CATEGORY_NOT_FOUND.name());
378
379                 assertNotNull("check response object is not null after create resouce", assetResponse);
380                 assertNotNull("check error code exists in response after create resource", assetResponse.getErrorCode());
381                 assertEquals("Check response code after create resource", errorInfo.getCode(), assetResponse.getErrorCode());
382
383                 List<String> variables = Arrays.asList(serviceKey, distributionStatusFilterKey, "NotExistingDistributionStatus");
384                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_CATEGORY_NOT_FOUND.name(), variables, assetResponse.getResponse());
385
386                 // Validate audit message
387                 ExpectedExternalAudit expectedAssetListAudit = ElementFactory.getDefaultAssetListAudit(AssetTypeEnum.SERVICES, AuditingActionEnum.GET_FILTERED_ASSET_LIST);
388                 expectedAssetListAudit.setRESOURCE_URL(AssetRestUtils.buildUrlWithFilter(expectedAssetListAudit.getRESOURCE_URL(), filter));
389                 expectedAssetListAudit.setSTATUS(errorInfo.getCode().toString());
390                 expectedAssetListAudit.setDESC(AuditValidationUtils.buildAuditDescription(errorInfo, variables));
391                 AuditValidationUtils.validateExternalAudit(expectedAssetListAudit, AuditingActionEnum.GET_FILTERED_ASSET_LIST.getName(), null);
392         }
393
394         @Test // (enabled = false)
395         public void getServiceAssetCategoryNotExistsDistributionStatus() throws Exception {
396                 String[] filter = { distributionStatusFilterKey + "=" + DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED, categoryFilterKey + "=" + "NotExistingCategory" };
397
398                 RestResponse assetResponse = AssetRestUtils.getComponentListByAssetType(true, AssetTypeEnum.SERVICES, filter);
399                 ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.COMPONENT_CATEGORY_NOT_FOUND.name());
400
401                 assertNotNull("check response object is not null after create resouce", assetResponse);
402                 assertNotNull("check error code exists in response after create resource", assetResponse.getErrorCode());
403                 assertEquals("Check response code after create resource", errorInfo.getCode(), assetResponse.getErrorCode());
404
405                 List<String> variables = Arrays.asList(serviceKey, categoryFilterKey, "NotExistingCategory");
406                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_CATEGORY_NOT_FOUND.name(), variables, assetResponse.getResponse());
407
408                 // Validate audit message
409                 ExpectedExternalAudit expectedAssetListAudit = ElementFactory.getDefaultAssetListAudit(AssetTypeEnum.SERVICES, AuditingActionEnum.GET_FILTERED_ASSET_LIST);
410                 expectedAssetListAudit.setRESOURCE_URL(AssetRestUtils.buildUrlWithFilter(expectedAssetListAudit.getRESOURCE_URL(), filter));
411                 expectedAssetListAudit.setSTATUS(errorInfo.getCode().toString());
412                 expectedAssetListAudit.setDESC(AuditValidationUtils.buildAuditDescription(errorInfo, variables));
413                 AuditValidationUtils.validateExternalAudit(expectedAssetListAudit, AuditingActionEnum.GET_FILTERED_ASSET_LIST.getName(), null);
414         }
415
416         @Test // (enabled = false)
417         public void getServiceAssetInvalidFilterKey() throws Exception {
418                 String[] filter = { distributionStatusFilterKey + "1=" + DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED, categoryFilterKey + "=" + ServiceCategoriesEnum.MOBILITY.getValue() };
419
420                 RestResponse assetResponse = AssetRestUtils.getComponentListByAssetType(true, AssetTypeEnum.SERVICES, filter);
421                 ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.INVALID_FILTER_KEY.name());
422
423                 assertNotNull("check response object is not null after create resouce", assetResponse);
424                 assertNotNull("check error code exists in response after create resource", assetResponse.getErrorCode());
425                 assertEquals("Check response code after create resource", errorInfo.getCode(), assetResponse.getErrorCode());
426
427                 List<String> variables = Arrays.asList(distributionStatusFilterKey + "1", "[" + categoryFilterKey + ", " + distributionStatusFilterKey + "]");
428                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_FILTER_KEY.name(), variables, assetResponse.getResponse());
429
430                 // Validate audit message
431                 ExpectedExternalAudit expectedAssetListAudit = ElementFactory.getDefaultAssetListAudit(AssetTypeEnum.SERVICES, AuditingActionEnum.GET_FILTERED_ASSET_LIST);
432                 expectedAssetListAudit.setRESOURCE_URL(AssetRestUtils.buildUrlWithFilter(expectedAssetListAudit.getRESOURCE_URL(), filter));
433                 expectedAssetListAudit.setSTATUS(errorInfo.getCode().toString());
434                 expectedAssetListAudit.setDESC(AuditValidationUtils.buildAuditDescription(errorInfo, variables));
435                 AuditValidationUtils.validateExternalAudit(expectedAssetListAudit, AuditingActionEnum.GET_FILTERED_ASSET_LIST.getName(), null);
436
437         }
438 }