Fix locally failing TCs in catalog-be
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / servlets / ResourceServletTest.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  * Modifications copyright (c) 2019 Nokia
20  * ================================================================================
21  */
22
23 package org.openecomp.sdc.be.servlets;
24
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.junit.Assert.assertEquals;
27 import static org.mockito.ArgumentMatchers.any;
28 import static org.mockito.ArgumentMatchers.eq;
29 import static org.mockito.BDDMockito.given;
30 import static org.mockito.Mockito.when;
31
32 import com.google.gson.Gson;
33 import com.google.gson.GsonBuilder;
34 import fj.data.Either;
35 import java.io.IOException;
36 import java.util.Arrays;
37 import java.util.Collections;
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41 import javax.servlet.ServletContext;
42 import javax.servlet.http.HttpServletRequest;
43 import javax.servlet.http.HttpSession;
44 import javax.ws.rs.client.Entity;
45 import javax.ws.rs.core.Application;
46 import javax.ws.rs.core.MediaType;
47 import javax.ws.rs.core.Response;
48 import org.apache.commons.codec.binary.Base64;
49 import org.apache.commons.lang3.tuple.ImmutablePair;
50 import org.apache.commons.text.StrSubstitutor;
51 import org.apache.http.HttpStatus;
52 import org.glassfish.hk2.utilities.binding.AbstractBinder;
53 import org.glassfish.jersey.media.multipart.MultiPartFeature;
54 import org.glassfish.jersey.server.ResourceConfig;
55 import org.glassfish.jersey.test.JerseyTest;
56 import org.glassfish.jersey.test.TestProperties;
57 import org.json.JSONException;
58 import org.junit.jupiter.api.AfterEach;
59 import org.junit.jupiter.api.BeforeAll;
60 import org.junit.jupiter.api.BeforeEach;
61 import org.junit.jupiter.api.Test;
62 import org.mockito.Mockito;
63 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
64 import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
65 import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
66 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
67 import org.openecomp.sdc.be.config.ConfigurationManager;
68 import org.openecomp.sdc.be.config.SpringConfig;
69 import org.openecomp.sdc.be.dao.api.ActionStatus;
70 import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
71 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
72 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
73 import org.openecomp.sdc.be.impl.ComponentsUtils;
74 import org.openecomp.sdc.be.impl.ServletUtils;
75 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
76 import org.openecomp.sdc.be.model.Resource;
77 import org.openecomp.sdc.be.model.UploadResourceInfo;
78 import org.openecomp.sdc.be.model.User;
79 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
80 import org.openecomp.sdc.be.user.Role;
81 import org.openecomp.sdc.be.user.UserBusinessLogic;
82 import org.openecomp.sdc.common.api.ConfigurationSource;
83 import org.openecomp.sdc.common.api.Constants;
84 import org.openecomp.sdc.common.impl.ExternalConfiguration;
85 import org.openecomp.sdc.common.impl.FSConfigurationSource;
86 import org.openecomp.sdc.common.util.GeneralUtility;
87 import org.openecomp.sdc.exception.ResponseFormat;
88 import org.springframework.context.ApplicationContext;
89 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
90 import org.springframework.web.context.WebApplicationContext;
91
92 class ResourceServletTest extends JerseyTest {
93
94     private final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
95     private final ResourceImportManager resourceImportManager = Mockito.mock(ResourceImportManager.class);
96     private final HttpSession session = Mockito.mock(HttpSession.class);
97     private final ServletContext servletContext = Mockito.mock(ServletContext.class);
98     private final WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
99     private final WebApplicationContext webApplicationContext = Mockito.mock(WebApplicationContext.class);
100     private final ServletUtils servletUtils = Mockito.mock(ServletUtils.class);
101     private final ComponentsUtils componentUtils = Mockito.mock(ComponentsUtils.class);
102     private final UserBusinessLogic userAdmin = Mockito.mock(UserBusinessLogic.class);
103     private final UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class);
104     private final GroupBusinessLogic groupBL = Mockito.mock(GroupBusinessLogic.class);
105     private final ComponentInstanceBusinessLogic componentInstanceBL = Mockito.mock(ComponentInstanceBusinessLogic.class);
106     private final ResourceBusinessLogic resourceBusinessLogic = Mockito.mock(ResourceBusinessLogic.class);
107     private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
108     private static final ResponseFormat okResponseFormat = new ResponseFormat(HttpStatus.SC_OK);
109     private static final ResponseFormat conflictResponseFormat = new ResponseFormat(HttpStatus.SC_CONFLICT);
110     private static final ResponseFormat generalErrorResponseFormat = new ResponseFormat(HttpStatus.SC_INTERNAL_SERVER_ERROR);
111     private static final ResponseFormat createdResponseFormat = new ResponseFormat(HttpStatus.SC_CREATED);
112     private static final ResponseFormat noContentResponseFormat = new ResponseFormat(HttpStatus.SC_NO_CONTENT);
113     private static final ResponseFormat notFoundResponseFormat = new ResponseFormat(HttpStatus.SC_NOT_FOUND);
114     private static final ResponseFormat badRequestResponseFormat = new ResponseFormat(HttpStatus.SC_BAD_REQUEST);
115     private static final ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
116         "src/test/resources/config/catalog-be");
117     private static final ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
118     private static final String RESOURCE_NAME = "resourceName";
119     private static final String VERSION = "version";
120     private static final String RESOURCE_ID = "resourceId";
121     private static final String RESOURCE_VERSION = "resourceVersion";
122     private static final String SUBTYPE = "subtype";
123     private static final String CSAR_UUID = "csaruuid";
124     private static final String EMPTY_JSON = "{}";
125     private static final String NON_UI_IMPORT_JSON = "{\n" +
126         "  \"node1\": \"value1\",\n" +
127         "  \"node2\": {\n" +
128         "    \"level21\": \"value21\",\n" +
129         "    \"level22\": \"value22\"\n" +
130         "  }\n" +
131         "}";
132     private static User user;
133
134     @BeforeAll
135     public static void setup() {
136         ExternalConfiguration.setAppName("catalog-be");
137     }
138
139     @AfterEach
140     void after() throws Exception {
141         super.tearDown();
142     }
143
144     @BeforeEach
145     public void beforeTest() throws Exception {
146         super.setUp();
147         Mockito.reset(componentUtils);
148         Mockito.reset(resourceBusinessLogic);
149
150         when(request.getSession()).thenReturn(session);
151         when(session.getServletContext()).thenReturn(servletContext);
152         when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
153         when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
154         when(webApplicationContext.getBean(ResourceImportManager.class)).thenReturn(resourceImportManager);
155         when(webApplicationContext.getBean(ServletUtils.class)).thenReturn(servletUtils);
156         when(servletUtils.getComponentsUtils()).thenReturn(componentUtils);
157         when(servletUtils.getUserAdmin()).thenReturn(userAdmin);
158         String userId = "jh0003";
159         user = new User();
160         user.setUserId(userId);
161         user.setRole(Role.ADMIN.name());
162         when(userAdmin.getUser(userId)).thenReturn(user);
163         when(request.getHeader(Constants.USER_ID_HEADER)).thenReturn(userId);
164         ImmutablePair<Resource, ActionStatus> pair = new ImmutablePair<>(new Resource(), ActionStatus.OK);
165         when(resourceImportManager
166             .importUserDefinedResource(Mockito.anyString(), Mockito.any(UploadResourceInfo.class), Mockito.any(User.class), Mockito.anyBoolean()))
167             .thenReturn(pair);
168         when(webApplicationContext.getBean(ResourceBusinessLogic.class)).thenReturn(resourceBusinessLogic);
169
170         when(componentUtils.getResponseFormat(ActionStatus.OK)).thenReturn(okResponseFormat);
171         when(componentUtils.getResponseFormat(ActionStatus.CREATED)).thenReturn(createdResponseFormat);
172         when(componentUtils.getResponseFormat(ActionStatus.NO_CONTENT)).thenReturn(noContentResponseFormat);
173         when(componentUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)).thenReturn(badRequestResponseFormat);
174         when(componentUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(generalErrorResponseFormat);
175         when(componentUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND)).thenReturn(notFoundResponseFormat);
176     }
177
178     @Test
179     void testHappyScenarioTest() {
180         when(componentUtils.getResponseFormat(ActionStatus.OK)).thenReturn(createdResponseFormat);
181
182         UploadResourceInfo validJson = buildValidJson();
183         setMD5OnRequest(true, validJson);
184         Response response = target().path("/v1/catalog/resources").request(MediaType.APPLICATION_JSON)
185             .post(Entity.json(gson.toJson(validJson)), Response.class);
186         Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(Mockito.any(ActionStatus.class));
187         Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(ActionStatus.OK);
188         assertEquals(HttpStatus.SC_CREATED, response.getStatus());
189
190     }
191
192     @Test
193     void testNonValidMd5Fail() {
194         UploadResourceInfo validJson = buildValidJson();
195
196         setMD5OnRequest(false, validJson);
197
198         Response response = target().path("/v1/catalog/resources").request(MediaType.APPLICATION_JSON)
199             .post(Entity.json(gson.toJson(validJson)), Response.class);
200         Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(Mockito.any(ActionStatus.class));
201         Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(ActionStatus.INVALID_RESOURCE_CHECKSUM);
202         assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
203
204     }
205
206     @Test
207     void testNonValidPayloadNameFail() {
208         UploadResourceInfo mdJson = buildValidJson();
209         mdJson.setPayloadName("myCompute.xml");
210
211         runAndVerifyActionStatusError(mdJson, ActionStatus.INVALID_TOSCA_FILE_EXTENSION);
212
213     }
214
215     @Test
216     void testNullPayloadFail() {
217         UploadResourceInfo mdJson = buildValidJson();
218         mdJson.setPayloadData(null);
219         runAndVerifyActionStatusError(mdJson, ActionStatus.INVALID_RESOURCE_PAYLOAD);
220
221     }
222
223     @Test
224     void testNonYmlPayloadFail() {
225         UploadResourceInfo mdJson = buildValidJson();
226         String payload = "{ json : { isNot : yaml } ";
227         encodeAndSetPayload(mdJson, payload);
228         runAndVerifyActionStatusError(mdJson, ActionStatus.INVALID_YAML_FILE);
229
230     }
231
232     @Test
233     void testNonToscaPayloadFail() {
234         UploadResourceInfo mdJson = buildValidJson();
235
236         String payload = "node_types: \r\n" + "  org.openecomp.resource.importResource4test:\r\n" + "    derived_from: tosca.nodes.Root\r\n"
237             + "    description: update update";
238         encodeAndSetPayload(mdJson, payload);
239         runAndVerifyActionStatusError(mdJson, ActionStatus.INVALID_TOSCA_TEMPLATE);
240
241     }
242
243     @Test
244     void testServiceToscaPayloadFail() {
245         UploadResourceInfo mdJson = buildValidJson();
246
247         String payload =
248             "tosca_definitions_version: tosca_simple_yaml_1_0_0\r\n" + "node_types: \r\n" + "  org.openecomp.resource.importResource4test:\r\n"
249                 + "    derived_from: tosca.nodes.Root\r\n" + "    topology_template: thisIsService\r\n"
250                 + "    description: update update";
251
252         encodeAndSetPayload(mdJson, payload);
253         runAndVerifyActionStatusError(mdJson, ActionStatus.NOT_RESOURCE_TOSCA_TEMPLATE);
254
255     }
256
257     @Test
258     void testMultipleResourcesInPayloadFail() {
259         UploadResourceInfo mdJson = buildValidJson();
260
261         String payload =
262             "tosca_definitions_version: tosca_simple_yaml_1_0_0\r\n" + "node_types: \r\n" + "  org.openecomp.resource.importResource4test2:\r\n"
263                 + "    derived_from: tosca.nodes.Root\r\n" + "  org.openecomp.resource.importResource4test:\r\n"
264                 + "    derived_from: tosca.nodes.Root\r\n" + "    description: update update";
265
266         encodeAndSetPayload(mdJson, payload);
267         runAndVerifyActionStatusError(mdJson, ActionStatus.NOT_SINGLE_RESOURCE);
268
269     }
270
271     @Test
272     void testNonValidNameSpaceInPayloadFail() {
273         UploadResourceInfo mdJson = buildValidJson();
274
275         String payload = "tosca_definitions_version: tosca_simple_yaml_1_0_0\r\n" + "node_types: \r\n"
276             + "  org.openecomp.resourceX.importResource4test:\r\n" + "    derived_from: tosca.nodes.Root\r\n"
277             + "    description: update update";
278
279         encodeAndSetPayload(mdJson, payload);
280         runAndVerifyActionStatusError(mdJson, ActionStatus.INVALID_RESOURCE_NAMESPACE);
281     }
282
283     @Test
284     void deleteResourceTryDeleteNonExistingResourceTest() {
285         String resourceId = "resourceId";
286         Map<String, String> parametersMap = new HashMap<>();
287         parametersMap.put("resourceId", resourceId);
288
289         String formatEndpoint = "/v1/catalog/resources/{resourceId}";
290         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
291
292         when(resourceBusinessLogic.deleteResource(any(), any(User.class)))
293             .thenReturn(notFoundResponseFormat);
294
295         Response response = target()
296             .path(path)
297             .request()
298             .accept(MediaType.APPLICATION_JSON)
299             .header(Constants.USER_ID_HEADER, user.getUserId())
300             .delete();
301
302         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
303     }
304
305     @Test
306     void deleteResourceExceptionDuringDeletingTest() {
307         String resourceId = RESOURCE_ID;
308         Map<String, String> parametersMap = new HashMap<>();
309         parametersMap.put(RESOURCE_ID, resourceId);
310
311         String formatEndpoint = "/v1/catalog/resources/{resourceId}";
312         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
313
314         when(resourceBusinessLogic.deleteResource(any(), any(User.class)))
315             .thenThrow(new JSONException("Test exception: deleteResource"));
316
317         Response response = target()
318             .path(path)
319             .request()
320             .accept(MediaType.APPLICATION_JSON)
321             .header(Constants.USER_ID_HEADER, user.getUserId())
322             .delete();
323
324         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
325     }
326
327     @Test
328     void deleteResourceCategoryTest() {
329         String resourceId = "resourceId";
330         Map<String, String> parametersMap = new HashMap<>();
331         parametersMap.put("resourceId", resourceId);
332
333         String formatEndpoint = "/v1/catalog/resources/{resourceId}";
334         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
335
336         when(resourceBusinessLogic.deleteResource(eq(resourceId.toLowerCase()), any(User.class)))
337             .thenReturn(noContentResponseFormat);
338
339         Response response = target()
340             .path(path)
341             .request()
342             .accept(MediaType.APPLICATION_JSON)
343             .header(Constants.USER_ID_HEADER, user.getUserId())
344             .delete();
345
346         assertThat(response.getStatus()).isEqualTo(org.apache.http.HttpStatus.SC_NO_CONTENT);
347     }
348
349     @Test
350     void deleteResourceByNameAndVersionTryDeleteNonExistingResourceTest() {
351         String resourceName = RESOURCE_NAME;
352         String version = VERSION;
353         Map<String, String> parametersMap = new HashMap<>();
354         parametersMap.put(RESOURCE_NAME, resourceName);
355         parametersMap.put(VERSION, version);
356
357         String formatEndpoint = "/v1/catalog/resources/{resourceName}/{version}";
358         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
359
360         when(resourceBusinessLogic.deleteResourceByNameAndVersion(eq(resourceName), eq(version), any(User.class)))
361             .thenReturn(notFoundResponseFormat);
362
363         Response response = target()
364             .path(path)
365             .request()
366             .accept(MediaType.APPLICATION_JSON)
367             .header(Constants.USER_ID_HEADER, user.getUserId())
368             .delete();
369
370         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
371     }
372
373     @Test
374     void deleteResourceByNameAndVersionExceptionDuringDeletingTest() {
375         String resourceName = RESOURCE_NAME;
376         String version = VERSION;
377         Map<String, String> parametersMap = new HashMap<>();
378         parametersMap.put(RESOURCE_NAME, resourceName);
379         parametersMap.put(VERSION, version);
380
381         String formatEndpoint = "/v1/catalog/resources/{resourceName}/{version}";
382         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
383
384         when(resourceBusinessLogic.deleteResourceByNameAndVersion(eq(resourceName), eq(version), any(User.class)))
385             .thenThrow(new JSONException("Test exception: deleteResourceByNameAndVersion"));
386
387         Response response = target()
388             .path(path)
389             .request()
390             .accept(MediaType.APPLICATION_JSON)
391             .header(Constants.USER_ID_HEADER, user.getUserId())
392             .delete();
393
394         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
395     }
396
397     @Test
398     void deleteResourceByNameAndVersionCategoryTest() {
399         String resourceName = RESOURCE_NAME;
400         String version = VERSION;
401         Map<String, String> parametersMap = new HashMap<>();
402         parametersMap.put(RESOURCE_NAME, resourceName);
403         parametersMap.put(VERSION, version);
404
405         String formatEndpoint = "/v1/catalog/resources/{resourceName}/{version}";
406         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
407
408         when(resourceBusinessLogic.deleteResourceByNameAndVersion(eq(resourceName), eq(version), any(User.class)))
409             .thenReturn(noContentResponseFormat);
410
411         Response response = target()
412             .path(path)
413             .request()
414             .accept(MediaType.APPLICATION_JSON)
415             .header(Constants.USER_ID_HEADER, user.getUserId())
416             .delete();
417
418         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
419     }
420
421     @Test
422     void getResourceByIdTryGetNonExistingResourceTest() {
423         String resourceId = RESOURCE_ID;
424         Map<String, String> parametersMap = new HashMap<>();
425         parametersMap.put(RESOURCE_ID, resourceId);
426
427         String formatEndpoint = "/v1/catalog/resources/{resourceId}";
428         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
429
430         Either<Resource, ResponseFormat> getResourceByIdEither = Either.right(notFoundResponseFormat);
431         when(resourceBusinessLogic.getResource(eq(resourceId.toLowerCase()), any(User.class)))
432             .thenReturn(getResourceByIdEither);
433
434         Response response = target()
435             .path(path)
436             .request()
437             .accept(MediaType.APPLICATION_JSON)
438             .header(Constants.USER_ID_HEADER, user.getUserId())
439             .get();
440
441         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
442     }
443
444     @Test
445     void getResourceByIdExceptionDuringSearchingTest() {
446         String resourceId = RESOURCE_ID;
447         Map<String, String> parametersMap = new HashMap<>();
448         parametersMap.put(RESOURCE_ID, resourceId);
449
450         String formatEndpoint = "/v1/catalog/resources/{resourceId}";
451         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
452
453         given(resourceBusinessLogic.getResource(eq(resourceId.toLowerCase()), any(User.class)))
454             .willAnswer(invocation -> {
455                 throw new IOException("Test exception: getResourceById");
456             });
457
458         Response response = target()
459             .path(path)
460             .request()
461             .accept(MediaType.APPLICATION_JSON)
462             .header(Constants.USER_ID_HEADER, user.getUserId())
463             .get();
464
465         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
466     }
467
468     @Test
469     void getResourceByIdTest() {
470         String resourceId = RESOURCE_ID;
471         Map<String, String> parametersMap = new HashMap<>();
472         parametersMap.put(RESOURCE_ID, resourceId);
473
474         String formatEndpoint = "/v1/catalog/resources/{resourceId}";
475         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
476
477         Either<Resource, ResponseFormat> getResourceByIdEither = Either.left(new Resource());
478         when(resourceBusinessLogic.getResource(eq(resourceId.toLowerCase()), any(User.class)))
479             .thenReturn(getResourceByIdEither);
480
481         Response response = target()
482             .path(path)
483             .request()
484             .accept(MediaType.APPLICATION_JSON)
485             .header(Constants.USER_ID_HEADER, user.getUserId())
486             .get();
487
488         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
489     }
490
491     @Test
492     void getResourceByNameAndVersionTryGetNonExistingResourceTest() {
493         String resourceName = RESOURCE_NAME;
494         String resourceVersion = RESOURCE_VERSION;
495         Map<String, String> parametersMap = new HashMap<>();
496         parametersMap.put(RESOURCE_NAME, resourceName);
497         parametersMap.put(RESOURCE_VERSION, resourceVersion);
498
499         String formatEndpoint = "/v1/catalog/resources/resourceName/{resourceName}/resourceVersion/{resourceVersion}";
500         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
501
502         Either<Resource, ResponseFormat> getResourceByNameAndVersionEither = Either.right(notFoundResponseFormat);
503         when(resourceBusinessLogic.getResourceByNameAndVersion(eq(resourceName), eq(resourceVersion), eq(user.getUserId())))
504             .thenReturn(getResourceByNameAndVersionEither);
505
506         Response response = target()
507             .path(path)
508             .request()
509             .accept(MediaType.APPLICATION_JSON)
510             .header(Constants.USER_ID_HEADER, user.getUserId())
511             .get();
512
513         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
514     }
515
516     @Test
517     void getResourceByNameAndVersionExceptionDuringSearchingTest() {
518         String resourceName = RESOURCE_NAME;
519         String resourceVersion = RESOURCE_VERSION;
520         Map<String, String> parametersMap = new HashMap<>();
521         parametersMap.put(RESOURCE_NAME, resourceName);
522         parametersMap.put(RESOURCE_VERSION, resourceVersion);
523
524         String formatEndpoint = "/v1/catalog/resources/resourceName/{resourceName}/resourceVersion/{resourceVersion}";
525         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
526
527         given(resourceBusinessLogic.getResourceByNameAndVersion(eq(resourceName), eq(resourceVersion), eq(user.getUserId())))
528             .willAnswer(invocation -> {
529                 throw new IOException("Test exception: getResourceByNameAndVersion");
530             });
531
532         Response response = target()
533             .path(path)
534             .request()
535             .accept(MediaType.APPLICATION_JSON)
536             .header(Constants.USER_ID_HEADER, user.getUserId())
537             .get();
538
539         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
540     }
541
542     @Test
543     void getResourceByNameAndVersionTest() {
544         String resourceName = RESOURCE_NAME;
545         String resourceVersion = RESOURCE_VERSION;
546         Map<String, String> parametersMap = new HashMap<>();
547         parametersMap.put(RESOURCE_NAME, resourceName);
548         parametersMap.put(RESOURCE_VERSION, resourceVersion);
549
550         String formatEndpoint = "/v1/catalog/resources/resourceName/{resourceName}/resourceVersion/{resourceVersion}";
551         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
552
553         Either<Resource, ResponseFormat> getResourceByNameAndVersionEither = Either.left(new Resource());
554         when(resourceBusinessLogic.getResourceByNameAndVersion(eq(resourceName), eq(resourceVersion), eq(user.getUserId())))
555             .thenReturn(getResourceByNameAndVersionEither);
556
557         Response response = target()
558             .path(path)
559             .request()
560             .accept(MediaType.APPLICATION_JSON)
561             .header(Constants.USER_ID_HEADER, user.getUserId())
562             .get();
563
564         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
565     }
566
567     @Test
568     void validateResourceNameTryValidateNonExistingResourceTest() {
569         String resourceName = RESOURCE_NAME;
570         String resourceType = "VFC";
571         Map<String, String> parametersMap = new HashMap<>();
572         parametersMap.put(RESOURCE_NAME, resourceName);
573
574         String formatEndpoint = "/v1/catalog/resources/validate-name/{resourceName}";
575         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
576
577         Either<Map<String, Boolean>, ResponseFormat> validateResourceNameEither =
578             Either.right(notFoundResponseFormat);
579         ResourceTypeEnum resourceTypeEnum = ResourceTypeEnum.valueOf(resourceType);
580         when(resourceBusinessLogic.validateResourceNameExists(eq(resourceName), eq(resourceTypeEnum), eq(user.getUserId())))
581             .thenReturn(validateResourceNameEither);
582
583         Response response = target()
584             .path(path)
585             .queryParam(SUBTYPE, resourceType)
586             .request()
587             .accept(MediaType.APPLICATION_JSON)
588             .header(Constants.USER_ID_HEADER, user.getUserId())
589             .get();
590
591         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
592     }
593
594     @Test
595     void validateResourceNameInvalidContentTest() {
596         String resourceName = RESOURCE_NAME;
597         String resourceType = "ThisIsInvalid";
598         Map<String, String> parametersMap = new HashMap<>();
599         parametersMap.put(RESOURCE_NAME, resourceName);
600
601         String formatEndpoint = "/v1/catalog/resources/validate-name/{resourceName}";
602         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
603
604         Response response = target()
605             .path(path)
606             .queryParam(SUBTYPE, resourceType)
607             .request()
608             .accept(MediaType.APPLICATION_JSON)
609             .header(Constants.USER_ID_HEADER, user.getUserId())
610             .get();
611
612         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
613     }
614
615     @Test
616     void validateResourceNameTest() {
617         String resourceName = RESOURCE_NAME;
618         String resourceType = "VFC";
619         Map<String, String> parametersMap = new HashMap<>();
620         parametersMap.put(RESOURCE_NAME, resourceName);
621
622         String formatEndpoint = "/v1/catalog/resources/validate-name/{resourceName}";
623         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
624
625         Either<Map<String, Boolean>, ResponseFormat> validateResourceNameEither =
626             Either.left(new HashMap<>());
627         ResourceTypeEnum resourceTypeEnum = ResourceTypeEnum.valueOf(resourceType);
628         when(resourceBusinessLogic.validateResourceNameExists(eq(resourceName), eq(resourceTypeEnum), eq(user.getUserId())))
629             .thenReturn(validateResourceNameEither);
630
631         Response response = target()
632             .path(path)
633             .queryParam(SUBTYPE, resourceType)
634             .request()
635             .accept(MediaType.APPLICATION_JSON)
636             .header(Constants.USER_ID_HEADER, user.getUserId())
637             .get();
638
639         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
640     }
641
642     @Test
643     void getCertifiedAbstractResourcesExceptionDuringSearchingTest() {
644         String path = "/v1/catalog/resources/certified/abstract";
645         given(resourceBusinessLogic.getAllCertifiedResources(eq(true), eq(HighestFilterEnum.HIGHEST_ONLY),
646             eq(user.getUserId())))
647             .willAnswer(invocation -> {
648                 throw new IOException("Test exception: getCertifiedAbstractResources");
649             });
650
651         Response response = target()
652             .path(path)
653             .request()
654             .accept(MediaType.APPLICATION_JSON)
655             .header(Constants.USER_ID_HEADER, user.getUserId())
656             .get();
657
658         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
659     }
660
661     @Test
662     void getCertifiedAbstractResourcesTest() {
663         String path = "/v1/catalog/resources/certified/abstract";
664
665         List<Resource> resources = Arrays.asList(new Resource(), new Resource());
666         when(resourceBusinessLogic.getAllCertifiedResources(eq(true), eq(HighestFilterEnum.HIGHEST_ONLY),
667             eq(user.getUserId())))
668             .thenReturn(resources);
669
670         Response response = target()
671             .path(path)
672             .request()
673             .accept(MediaType.APPLICATION_JSON)
674             .header(Constants.USER_ID_HEADER, user.getUserId())
675             .get();
676
677         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
678     }
679
680     @Test
681     void getCertifiedNotAbstractResourcesExceptionDuringSearchingTest() {
682         String path = "/v1/catalog/resources/certified/notabstract";
683         given(resourceBusinessLogic.getAllCertifiedResources(eq(false), eq(HighestFilterEnum.ALL),
684             eq(user.getUserId())))
685             .willAnswer(invocation -> {
686                 throw new IOException("Test exception: getCertifiedNotAbstractResources");
687             });
688
689         Response response = target()
690             .path(path)
691             .request()
692             .accept(MediaType.APPLICATION_JSON)
693             .header(Constants.USER_ID_HEADER, user.getUserId())
694             .get();
695
696         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
697     }
698
699     @Test
700     void getCertifiedNotAbstractResourcesTest() {
701         String path = "/v1/catalog/resources/certified/notabstract";
702
703         List<Resource> resources = Arrays.asList(new Resource(), new Resource());
704         when(resourceBusinessLogic.getAllCertifiedResources(eq(true), eq(HighestFilterEnum.ALL),
705             eq(user.getUserId())))
706             .thenReturn(resources);
707
708         Response response = target()
709             .path(path)
710             .request()
711             .accept(MediaType.APPLICATION_JSON)
712             .header(Constants.USER_ID_HEADER, user.getUserId())
713             .get();
714
715         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
716     }
717
718     @Test
719     void updateResourceMetadataTryUpdateNonExistingResourceTest() {
720         String resourceId = RESOURCE_ID;
721         Map<String, String> parametersMap = new HashMap<>();
722         parametersMap.put(RESOURCE_ID, resourceId);
723
724         String formatEndpoint = "/v1/catalog/resources/{resourceId}/metadata";
725         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
726
727         Either<Resource, ResponseFormat> updateResourceMetadataEither = Either.right(badRequestResponseFormat);
728
729         when(componentUtils.convertJsonToObjectUsingObjectMapper(any(), any(), eq(Resource.class),
730             eq(AuditingActionEnum.UPDATE_RESOURCE_METADATA), eq(ComponentTypeEnum.RESOURCE)))
731             .thenReturn(updateResourceMetadataEither);
732
733         when(resourceBusinessLogic.updateResourceMetadata(eq(resourceId.toLowerCase()), any(), any(), any(User.class),
734             eq(false)))
735             .thenReturn(new Resource());
736
737         Response response = target()
738             .path(path)
739             .request()
740             .accept(MediaType.APPLICATION_JSON)
741             .header(Constants.USER_ID_HEADER, user.getUserId())
742             .put(Entity.json(EMPTY_JSON));
743
744         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
745     }
746
747     @Test
748     void updateResourceMetadataExceptionDuringUpdateTest() {
749         String resourceId = RESOURCE_ID;
750         Map<String, String> parametersMap = new HashMap<>();
751         parametersMap.put(RESOURCE_ID, resourceId);
752
753         String formatEndpoint = "/v1/catalog/resources/{resourceId}/metadata";
754         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
755
756         given(componentUtils.convertJsonToObjectUsingObjectMapper(any(), any(), eq(Resource.class),
757             eq(AuditingActionEnum.UPDATE_RESOURCE_METADATA), eq(ComponentTypeEnum.RESOURCE)))
758             .willAnswer(invocation -> {
759                 throw new IOException("Test exception: updateResourceMetadata");
760             });
761
762         Response response = target()
763             .path(path)
764             .request()
765             .accept(MediaType.APPLICATION_JSON)
766             .header(Constants.USER_ID_HEADER, user.getUserId())
767             .put(Entity.json(EMPTY_JSON));
768
769         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
770     }
771
772     @Test
773     void updateResourceMetadataCategoryTest() {
774         String resourceId = RESOURCE_ID;
775         Map<String, String> parametersMap = new HashMap<>();
776         parametersMap.put(RESOURCE_ID, resourceId);
777
778         String formatEndpoint = "/v1/catalog/resources/{resourceId}/metadata";
779         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
780
781         Resource initialResource = new Resource();
782         Either<Resource, ResponseFormat> updateResourceMetadataEither = Either.left(initialResource);
783
784         when(componentUtils.convertJsonToObjectUsingObjectMapper(any(), any(), eq(Resource.class),
785             eq(AuditingActionEnum.UPDATE_RESOURCE_METADATA), eq(ComponentTypeEnum.RESOURCE)))
786             .thenReturn(updateResourceMetadataEither);
787
788         when(resourceBusinessLogic.updateResourceMetadata(eq(resourceId.toLowerCase()), eq(initialResource), any(),
789             any(User.class), eq(false)))
790             .thenReturn(new Resource());
791
792         Response response = target()
793             .path(path)
794             .request()
795             .accept(MediaType.APPLICATION_JSON)
796             .header(Constants.USER_ID_HEADER, user.getUserId())
797             .put(Entity.json(EMPTY_JSON));
798
799         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
800     }
801
802     @Test
803     void updateResourceParsingUncussessfulTest() {
804         String resourceId = RESOURCE_ID;
805         Map<String, String> parametersMap = new HashMap<>();
806         parametersMap.put(RESOURCE_ID, resourceId);
807
808         String formatEndpoint = "/v1/catalog/resources/{resourceId}";
809         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
810
811         Either<Resource, ResponseFormat> updateResourceEither = Either.right(badRequestResponseFormat);
812
813         when(componentUtils.convertJsonToObjectUsingObjectMapper(eq(NON_UI_IMPORT_JSON), any(User.class),
814             eq(Resource.class), eq(AuditingActionEnum.UPDATE_RESOURCE_METADATA), eq(ComponentTypeEnum.RESOURCE)))
815             .thenReturn(updateResourceEither);
816
817         Response response = target()
818             .path(path)
819             .request()
820             .accept(MediaType.APPLICATION_JSON)
821             .header(Constants.USER_ID_HEADER, user.getUserId())
822             .put(Entity.json(NON_UI_IMPORT_JSON));
823
824         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
825     }
826
827     @Test
828     void updateResourceExceptionDuringUpdateTest() {
829         String resourceId = RESOURCE_ID;
830         Map<String, String> parametersMap = new HashMap<>();
831         parametersMap.put(RESOURCE_ID, resourceId);
832
833         String formatEndpoint = "/v1/catalog/resources/{resourceId}";
834         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
835
836         given(componentUtils.convertJsonToObjectUsingObjectMapper(eq(NON_UI_IMPORT_JSON), any(User.class),
837             eq(Resource.class), eq(AuditingActionEnum.UPDATE_RESOURCE_METADATA), eq(ComponentTypeEnum.RESOURCE)))
838             .willAnswer(invocation -> {
839                 throw new IOException("Test exception: updateResource");
840             });
841
842         Response response = target()
843             .path(path)
844             .request()
845             .accept(MediaType.APPLICATION_JSON)
846             .header(Constants.USER_ID_HEADER, user.getUserId())
847             .put(Entity.json(NON_UI_IMPORT_JSON));
848
849         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
850     }
851
852     @Test
853     void updateResourceNonUiImportTest() {
854         String resourceId = RESOURCE_ID;
855         Map<String, String> parametersMap = new HashMap<>();
856         parametersMap.put(RESOURCE_ID, resourceId);
857
858         String formatEndpoint = "/v1/catalog/resources/{resourceId}";
859         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
860
861         Either<Resource, ResponseFormat> updateResourceEither = Either.left(new Resource());
862
863         when(componentUtils.convertJsonToObjectUsingObjectMapper(eq(NON_UI_IMPORT_JSON), any(User.class), eq(Resource.class),
864             eq(AuditingActionEnum.UPDATE_RESOURCE_METADATA), eq(ComponentTypeEnum.RESOURCE)))
865             .thenReturn(updateResourceEither);
866
867         when(resourceBusinessLogic.validateAndUpdateResourceFromCsar(any(), any(), any(), any(), eq(resourceId)))
868             .thenReturn(new Resource());
869
870         Response response = target()
871             .path(path)
872             .request()
873             .accept(MediaType.APPLICATION_JSON)
874             .header(Constants.USER_ID_HEADER, user.getUserId())
875             .put(Entity.json(NON_UI_IMPORT_JSON));
876
877         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
878     }
879
880     @Test
881     void getResourceFromCsarTryGetNonExistingResourceTest() {
882         String csarUuid = CSAR_UUID;
883         Map<String, String> parametersMap = new HashMap<>();
884         parametersMap.put(CSAR_UUID, csarUuid);
885
886         String formatEndpoint = "/v1/catalog/resources/csar/{csaruuid}";
887         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
888
889         Either<Resource, ResponseFormat> getResourceFromCsarEither = Either.right(notFoundResponseFormat);
890         when(resourceBusinessLogic.getLatestResourceFromCsarUuid(eq(csarUuid), any(User.class)))
891             .thenReturn(getResourceFromCsarEither);
892
893         Response response = target()
894             .path(path)
895             .request()
896             .accept(MediaType.APPLICATION_JSON)
897             .header(Constants.USER_ID_HEADER, user.getUserId())
898             .get();
899
900         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
901     }
902
903     @Test
904     void getResourceFromCsarExceptionDuringGettingTest() {
905         String csarUuid = CSAR_UUID;
906         Map<String, String> parametersMap = new HashMap<>();
907         parametersMap.put(CSAR_UUID, csarUuid);
908
909         String formatEndpoint = "/v1/catalog/resources/csar/{csaruuid}";
910         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
911
912         given(resourceBusinessLogic.getLatestResourceFromCsarUuid(eq(csarUuid), any(User.class)))
913             .willAnswer(invocation -> {
914                 throw new IOException("Test exception: getResourceFromCsar");
915             });
916
917         Response response = target()
918             .path(path)
919             .request()
920             .accept(MediaType.APPLICATION_JSON)
921             .header(Constants.USER_ID_HEADER, user.getUserId())
922             .get();
923
924         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
925     }
926
927     @Test
928     void getResourceFromCsarTest() {
929         String csarUuid = CSAR_UUID;
930         Map<String, String> parametersMap = new HashMap<>();
931         parametersMap.put(CSAR_UUID, csarUuid);
932
933         String formatEndpoint = "/v1/catalog/resources/csar/{csaruuid}";
934         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
935
936         Either<Resource, ResponseFormat> getResourceFromCsarEither = Either.left(new Resource());
937         when(resourceBusinessLogic.getLatestResourceFromCsarUuid(eq(csarUuid), any(User.class)))
938             .thenReturn(getResourceFromCsarEither);
939
940         Response response = target()
941             .path(path)
942             .request()
943             .accept(MediaType.APPLICATION_JSON)
944             .header(Constants.USER_ID_HEADER, user.getUserId())
945             .get();
946
947         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
948     }
949
950     @Test
951     void createResourceExceptionDuringCreateTest() {
952         String path = "/v1/catalog/resources";
953
954         given(componentUtils.convertJsonToObjectUsingObjectMapper(eq(NON_UI_IMPORT_JSON), any(User.class),
955             eq(Resource.class), eq(AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.RESOURCE)))
956             .willAnswer(invocation -> {
957                 throw new IOException("Test exception: createResource");
958             });
959
960         Response response = target()
961             .path(path)
962             .request()
963             .accept(MediaType.APPLICATION_JSON)
964             .header(Constants.USER_ID_HEADER, user.getUserId())
965             .post(Entity.json(NON_UI_IMPORT_JSON));
966
967         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
968     }
969
970     @Test
971     void createResourceNonUiImportProcessingFailedTest() {
972         String path = "/v1/catalog/resources";
973
974         Either<Resource, ResponseFormat> createResourceEither = Either.right(badRequestResponseFormat);
975
976         when(componentUtils.convertJsonToObjectUsingObjectMapper(eq(NON_UI_IMPORT_JSON), any(User.class),
977             eq(Resource.class), eq(AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.RESOURCE)))
978             .thenReturn(createResourceEither);
979
980         Response response = target()
981             .path(path)
982             .request()
983             .accept(MediaType.APPLICATION_JSON)
984             .header(Constants.USER_ID_HEADER, user.getUserId())
985             .post(Entity.json(NON_UI_IMPORT_JSON));
986
987         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
988     }
989
990     @Test
991     void createResourceNonUiImportTest() {
992         String path = "/v1/catalog/resources";
993
994         Either<Resource, ResponseFormat> createResourceEither = Either.left(new Resource());
995
996         when(componentUtils.convertJsonToObjectUsingObjectMapper(eq(NON_UI_IMPORT_JSON), any(User.class),
997             eq(Resource.class), eq(AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.RESOURCE)))
998             .thenReturn(createResourceEither);
999
1000         when(resourceBusinessLogic.createResource(eq(createResourceEither.left().value()), eq(AuditingActionEnum.CREATE_RESOURCE),
1001             any(User.class), any(), any()))
1002             .thenReturn(new Resource());
1003
1004         Response response = target()
1005             .path(path)
1006             .request()
1007             .accept(MediaType.APPLICATION_JSON)
1008             .header(Constants.USER_ID_HEADER, user.getUserId())
1009             .post(Entity.json(NON_UI_IMPORT_JSON));
1010
1011         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CREATED);
1012     }
1013
1014     private void encodeAndSetPayload(UploadResourceInfo mdJson, String payload) {
1015         byte[] encodedBase64Payload = Base64.encodeBase64(payload.getBytes());
1016         mdJson.setPayloadData(new String(encodedBase64Payload));
1017     }
1018
1019     private void runAndVerifyActionStatusError(UploadResourceInfo mdJson, ActionStatus invalidResourcePayload) {
1020         setMD5OnRequest(true, mdJson);
1021         Response response = target().path("/v1/catalog/resources").request(MediaType.APPLICATION_JSON)
1022             .post(Entity.json(gson.toJson(mdJson)), Response.class);
1023         Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(Mockito.any(ActionStatus.class));
1024         Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(invalidResourcePayload);
1025         assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
1026     }
1027
1028     private void setMD5OnRequest(boolean isValid, UploadResourceInfo json) {
1029         String md5 = (isValid) ? GeneralUtility.calculateMD5Base64EncodedByString(gson.toJson(json)) : "stam=";
1030         when(request.getHeader(Constants.MD5_HEADER)).thenReturn(md5);
1031
1032     }
1033
1034     private UploadResourceInfo buildValidJson() {
1035         UploadResourceInfo ret = new UploadResourceInfo();
1036         ret.setName("ciMyCompute");
1037         ret.setPayloadName("ciMyCompute.yml");
1038         ret.addSubCategory("Application Layer 4+", "Application Servers");
1039         ret.setDescription("ResourceDescription");
1040         ret.setVendorName("VendorName");
1041         ret.setVendorRelease("VendorRelease");
1042         ret.setContactId("AT1234");
1043         ret.setIcon("router");
1044         ret.setTags(Collections.singletonList("ciMyCompute"));
1045         ret.setPayloadData(
1046             "dG9zY2FfZGVmaW5pdGlvbnNfdmVyc2lvbjogdG9zY2Ffc2ltcGxlX3lhbWxfMV8wXzANCm5vZGVfdHlwZXM6IA0KICBvcmcub3BlbmVjb21wLnJlc291cmNlLk15Q29tcHV0ZToNCiAgICBkZXJpdmVkX2Zyb206IHRvc2NhLm5vZGVzLlJvb3QNCiAgICBhdHRyaWJ1dGVzOg0KICAgICAgcHJpdmF0ZV9hZGRyZXNzOg0KICAgICAgICB0eXBlOiBzdHJpbmcNCiAgICAgIHB1YmxpY19hZGRyZXNzOg0KICAgICAgICB0eXBlOiBzdHJpbmcNCiAgICAgIG5ldHdvcmtzOg0KICAgICAgICB0eXBlOiBtYXANCiAgICAgICAgZW50cnlfc2NoZW1hOg0KICAgICAgICAgIHR5cGU6IHRvc2NhLmRhdGF0eXBlcy5uZXR3b3JrLk5ldHdvcmtJbmZvDQogICAgICBwb3J0czoNCiAgICAgICAgdHlwZTogbWFwDQogICAgICAgIGVudHJ5X3NjaGVtYToNCiAgICAgICAgICB0eXBlOiB0b3NjYS5kYXRhdHlwZXMubmV0d29yay5Qb3J0SW5mbw0KICAgIHJlcXVpcmVtZW50czoNCiAgICAgIC0gbG9jYWxfc3RvcmFnZTogDQogICAgICAgICAgY2FwYWJpbGl0eTogdG9zY2EuY2FwYWJpbGl0aWVzLkF0dGFjaG1lbnQNCiAgICAgICAgICBub2RlOiB0b3NjYS5ub2Rlcy5CbG9ja1N0b3JhZ2UNCiAgICAgICAgICByZWxhdGlvbnNoaXA6IHRvc2NhLnJlbGF0aW9uc2hpcHMuQXR0YWNoZXNUbw0KICAgICAgICAgIG9jY3VycmVuY2VzOiBbMCwgVU5CT1VOREVEXSAgDQogICAgY2FwYWJpbGl0aWVzOg0KICAgICAgaG9zdDogDQogICAgICAgIHR5cGU6IHRvc2NhLmNhcGFiaWxpdGllcy5Db250YWluZXINCiAgICAgICAgdmFsaWRfc291cmNlX3R5cGVzOiBbdG9zY2Eubm9kZXMuU29mdHdhcmVDb21wb25lbnRdIA0KICAgICAgZW5kcG9pbnQgOg0KICAgICAgICB0eXBlOiB0b3NjYS5jYXBhYmlsaXRpZXMuRW5kcG9pbnQuQWRtaW4gDQogICAgICBvczogDQogICAgICAgIHR5cGU6IHRvc2NhLmNhcGFiaWxpdGllcy5PcGVyYXRpbmdTeXN0ZW0NCiAgICAgIHNjYWxhYmxlOg0KICAgICAgICB0eXBlOiB0b3NjYS5jYXBhYmlsaXRpZXMuU2NhbGFibGUNCiAgICAgIGJpbmRpbmc6DQogICAgICAgIHR5cGU6IHRvc2NhLmNhcGFiaWxpdGllcy5uZXR3b3JrLkJpbmRhYmxl");
1047         return ret;
1048     }
1049
1050     @Override
1051     protected Application configure() {
1052         ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
1053         forceSet(TestProperties.CONTAINER_PORT, "0");
1054         return new ResourceConfig(ResourcesServlet.class)
1055             .register(new AbstractBinder() {
1056                 @Override
1057                 protected void configure() {
1058                     bind(request).to(HttpServletRequest.class);
1059                     bind(servletUtils).to(ServletUtils.class);
1060                     bind(componentUtils).to(ComponentsUtils.class);
1061                     bind(userBusinessLogic).to(UserBusinessLogic.class);
1062                     bind(resourceBusinessLogic).to(ResourceBusinessLogic.class);
1063                     bind(groupBL).to(GroupBusinessLogic.class);
1064                     bind(componentInstanceBL).to(ComponentInstanceBusinessLogic.class);
1065                     bind(resourceImportManager).to(ResourceImportManager.class);
1066                 }
1067             })
1068             .register(MultiPartFeature.class)
1069             .property("contextConfig", context);
1070     }
1071 }