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