CSIT Fix for SDC-2585
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / distribution / servlet / DistributionCatalogServletTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 Nokia. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.distribution.servlet;
22
23 import fj.data.Either;
24 import org.apache.commons.text.StrSubstitutor;
25 import org.apache.http.HttpStatus;
26 import org.glassfish.hk2.utilities.binding.AbstractBinder;
27 import org.glassfish.jersey.server.ResourceConfig;
28 import org.glassfish.jersey.test.JerseyTest;
29 import org.junit.Before;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32 import org.mockito.Mockito;
33 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
34 import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
35 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
36 import org.openecomp.sdc.be.config.ConfigurationManager;
37 import org.openecomp.sdc.be.config.SpringConfig;
38 import org.openecomp.sdc.be.dao.api.ActionStatus;
39 import org.openecomp.sdc.be.impl.ComponentsUtils;
40 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
41 import org.openecomp.sdc.be.user.UserBusinessLogic;
42 import org.openecomp.sdc.common.api.ConfigurationSource;
43 import org.openecomp.sdc.common.api.Constants;
44 import org.openecomp.sdc.common.impl.ExternalConfiguration;
45 import org.openecomp.sdc.common.impl.FSConfigurationSource;
46 import org.openecomp.sdc.exception.ResponseFormat;
47 import org.springframework.context.ApplicationContext;
48 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
49 import org.springframework.web.context.WebApplicationContext;
50
51 import javax.servlet.ServletContext;
52 import javax.servlet.http.HttpServletRequest;
53 import javax.ws.rs.core.Application;
54 import javax.ws.rs.core.MediaType;
55 import javax.ws.rs.core.Response;
56 import java.util.HashMap;
57 import java.util.Map;
58 import java.util.UUID;
59
60 import static org.assertj.core.api.Assertions.assertThat;
61 import static org.junit.Assert.assertTrue;
62 import static org.mockito.ArgumentMatchers.any;
63 import static org.mockito.ArgumentMatchers.eq;
64 import static org.mockito.Mockito.reset;
65 import static org.mockito.Mockito.when;
66 import static org.openecomp.sdc.TestUtils.downloadedPayloadMatchesExpected;
67
68 public class DistributionCatalogServletTest extends JerseyTest {
69
70     private static final HttpServletRequest HTTP_SERVLET_REQUEST = Mockito.mock(HttpServletRequest.class);
71     private static final UserBusinessLogic USER_BUSINESS_LOGIC = Mockito.mock(UserBusinessLogic.class);
72     private static final ArtifactsBusinessLogic ARTIFACTS_BUSINESS_LOGIC = Mockito.mock(ArtifactsBusinessLogic.class);
73     private static final ServletContext SERVLET_CONTEXT = Mockito.mock(ServletContext.class);
74     private static final WebAppContextWrapper WEB_APP_CONTEXT_WRAPPER = Mockito.mock(WebAppContextWrapper.class);
75     private static final WebApplicationContext WEB_APPLICATION_CONTEXT = Mockito.mock(WebApplicationContext.class);
76     private static final ComponentsUtils COMPONENT_UTILS = Mockito.mock(ComponentsUtils.class);
77     private static final ResponseFormat OK_RESPONSE_FORMAT = new ResponseFormat(HttpStatus.SC_OK);
78     private static final ResponseFormat GENERAL_ERROR_RESPONSE_FORMAT = new ResponseFormat(HttpStatus.SC_INTERNAL_SERVER_ERROR);
79     private static final ResponseFormat CREATED_RESPONSE_FORMAT = new ResponseFormat(HttpStatus.SC_CREATED);
80     private static final ResponseFormat NO_CONTENT_RESPONSE_FORMAT = new ResponseFormat(HttpStatus.SC_NO_CONTENT);
81     private static final ResponseFormat UNAUTHORIZED_RESPONSE_FORMAT = new ResponseFormat(HttpStatus.SC_UNAUTHORIZED);
82     private static final ResponseFormat NOT_FOUND_RESPONSE_FORMAT = new ResponseFormat(HttpStatus.SC_NOT_FOUND);
83     private static final ResponseFormat BAD_REQUEST_RESPONSE_FORMAT = new ResponseFormat(HttpStatus.SC_BAD_REQUEST);
84     private static final String SERVICE_VERSION = "serviceVersion";
85     private static final String ARTIFACT_NAME = "artifactName";
86     private static final String SERVICE_NAME = "serviceName";
87     private static final String RESOURCE_NAME = "resourceName";
88     private static final String RESOURCE_VERSION = "resourceVersion";
89     private static final String RESOURCE_INSTANCE_NAME = "resourceInstanceName";
90     private static final byte[] BYTE_ARRAY = new byte[]{0xA, 0xB, 0xC, 0xD};
91
92     @BeforeClass
93     public static void setup() {
94         when(SERVLET_CONTEXT.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(WEB_APP_CONTEXT_WRAPPER);
95         when(WEB_APP_CONTEXT_WRAPPER.getWebAppContext(SERVLET_CONTEXT)).thenReturn(WEB_APPLICATION_CONTEXT);
96
97         setUpResponseFormatsForMocks();
98         setUpMockTestConfiguration();
99     }
100
101     private static void setUpMockTestConfiguration() {
102         String appConfigDir = "src/test/resources/config";
103         ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
104         ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
105
106         org.openecomp.sdc.be.config.Configuration configuration = new org.openecomp.sdc.be.config.Configuration();
107         configuration.setJanusGraphInMemoryGraph(true);
108
109         configurationManager.setConfiguration(configuration);
110         ExternalConfiguration.setAppName("catalog-be");
111     }
112
113     private static void setUpResponseFormatsForMocks() {
114         when(COMPONENT_UTILS.getResponseFormat(ActionStatus.RESTRICTED_OPERATION)).thenReturn(UNAUTHORIZED_RESPONSE_FORMAT);
115         when(COMPONENT_UTILS.getResponseFormat(ActionStatus.OK)).thenReturn(OK_RESPONSE_FORMAT);
116         when(COMPONENT_UTILS.getResponseFormat(ActionStatus.CREATED)).thenReturn(CREATED_RESPONSE_FORMAT);
117         when(COMPONENT_UTILS.getResponseFormat(ActionStatus.NO_CONTENT)).thenReturn(NO_CONTENT_RESPONSE_FORMAT);
118         when(COMPONENT_UTILS.getResponseFormat(ActionStatus.INVALID_CONTENT)).thenReturn(BAD_REQUEST_RESPONSE_FORMAT);
119         when(COMPONENT_UTILS.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(GENERAL_ERROR_RESPONSE_FORMAT);
120         when(COMPONENT_UTILS.getResponseFormat(any(ComponentException.class)))
121                 .thenReturn(GENERAL_ERROR_RESPONSE_FORMAT);
122         when(COMPONENT_UTILS.getResponseFormat(eq(ActionStatus.RESOURCE_NOT_FOUND), any())).thenReturn(NOT_FOUND_RESPONSE_FORMAT);
123         when(COMPONENT_UTILS.getResponseFormat(eq(ActionStatus.COMPONENT_VERSION_NOT_FOUND), any())).thenReturn(NOT_FOUND_RESPONSE_FORMAT);
124         when(COMPONENT_UTILS.getResponseFormat(eq(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND), any())).thenReturn(NOT_FOUND_RESPONSE_FORMAT);
125         when(COMPONENT_UTILS.getResponseFormat(eq(ActionStatus.EXT_REF_NOT_FOUND), any())).thenReturn(NOT_FOUND_RESPONSE_FORMAT);
126         when(COMPONENT_UTILS.getResponseFormat(eq(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID), any())).thenReturn(BAD_REQUEST_RESPONSE_FORMAT);
127         ByResponseFormatComponentException ce = Mockito.mock(ByResponseFormatComponentException.class);
128         when(ce.getResponseFormat()).thenReturn(UNAUTHORIZED_RESPONSE_FORMAT);
129     }
130
131     @Before
132     public void resetSomeMocks() {
133         reset(ARTIFACTS_BUSINESS_LOGIC);
134     }
135
136     @Test
137     public void downloadServiceArtifactMissingInstanceIdHeaderTest() {
138         Map<String, String> parametersMap = new HashMap<>();
139         parametersMap.put(SERVICE_NAME, SERVICE_NAME);
140         parametersMap.put(SERVICE_VERSION, SERVICE_VERSION);
141         parametersMap.put(ARTIFACT_NAME, ARTIFACT_NAME);
142
143         String formatEndpoint = "/v1/catalog/services/{serviceName}/{serviceVersion}/artifacts/{artifactName}";
144         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
145
146         Response response = target()
147                 .path(path)
148                 .request()
149                 .accept(MediaType.APPLICATION_OCTET_STREAM)
150                 .get();
151
152         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
153     }
154
155     @Test
156     public void downloadServiceArtifactNoArtifactFoundTest() {
157         String serviceName = SERVICE_NAME;
158         String serviceVersion = SERVICE_VERSION;
159         String artifactName = ARTIFACT_NAME;
160
161         Map<String, String> parametersMap = new HashMap<>();
162         parametersMap.put(SERVICE_NAME, serviceName);
163         parametersMap.put(SERVICE_VERSION, serviceVersion);
164         parametersMap.put(ARTIFACT_NAME, artifactName);
165
166         String formatEndpoint = "/v1/catalog/services/{serviceName}/{serviceVersion}/artifacts/{artifactName}";
167         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
168
169         Either<byte[], ResponseFormat> downloadServiceArtifactEither = Either.right(NOT_FOUND_RESPONSE_FORMAT);
170
171         when(ARTIFACTS_BUSINESS_LOGIC.downloadServiceArtifactByNames(serviceName, serviceVersion, artifactName))
172                 .thenReturn(downloadServiceArtifactEither);
173
174         Response response = target()
175                 .path(path)
176                 .request()
177                 .header(Constants.X_ECOMP_INSTANCE_ID_HEADER, UUID.randomUUID().toString())
178                 .accept(MediaType.APPLICATION_OCTET_STREAM)
179                 .get();
180
181         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
182     }
183
184     @Test
185     public void downloadServiceArtifactExceptionDuringProcessingTest() {
186         String serviceName = SERVICE_NAME;
187         String serviceVersion = SERVICE_VERSION;
188         String artifactName = ARTIFACT_NAME;
189
190         Map<String, String> parametersMap = new HashMap<>();
191         parametersMap.put(SERVICE_NAME, serviceName);
192         parametersMap.put(SERVICE_VERSION, serviceVersion);
193         parametersMap.put(ARTIFACT_NAME, artifactName);
194
195         String formatEndpoint = "/v1/catalog/services/{serviceName}/{serviceVersion}/artifacts/{artifactName}";
196         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
197
198         when(ARTIFACTS_BUSINESS_LOGIC.downloadServiceArtifactByNames(serviceName, serviceVersion, artifactName))
199                 .thenThrow(new RuntimeException("Test exception: downloadServiceArtifact"));
200
201         Response response = target()
202                 .path(path)
203                 .request()
204                 .header(Constants.X_ECOMP_INSTANCE_ID_HEADER, UUID.randomUUID().toString())
205                 .accept(MediaType.APPLICATION_OCTET_STREAM)
206                 .get();
207
208         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
209     }
210
211     @Test
212     public void downloadServiceArtifactTest() {
213         String serviceName = SERVICE_NAME;
214         String serviceVersion = SERVICE_VERSION;
215         String artifactName = ARTIFACT_NAME;
216
217         Map<String, String> parametersMap = new HashMap<>();
218         parametersMap.put(SERVICE_NAME, serviceName);
219         parametersMap.put(SERVICE_VERSION, serviceVersion);
220         parametersMap.put(ARTIFACT_NAME, artifactName);
221
222         String formatEndpoint = "/v1/catalog/services/{serviceName}/{serviceVersion}/artifacts/{artifactName}";
223         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
224
225         Either<byte[], ResponseFormat> downloadServiceArtifactEither = Either.left(BYTE_ARRAY);
226         when(ARTIFACTS_BUSINESS_LOGIC.downloadServiceArtifactByNames(serviceName, serviceVersion, artifactName))
227                 .thenReturn(downloadServiceArtifactEither);
228
229         Response response = target()
230                 .path(path)
231                 .request()
232                 .header(Constants.X_ECOMP_INSTANCE_ID_HEADER, UUID.randomUUID().toString())
233                 .accept(MediaType.APPLICATION_OCTET_STREAM)
234                 .get();
235
236         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
237         assertTrue(response.getHeaders().containsKey(Constants.CONTENT_DISPOSITION_HEADER));
238         assertTrue(downloadedPayloadMatchesExpected(response, BYTE_ARRAY));
239     }
240
241     @Test
242     public void downloadResouceArtifactNoArtifactFoundTest() {
243         String serviceName = SERVICE_NAME;
244         String serviceVersion = SERVICE_VERSION;
245         String resourceName = RESOURCE_NAME;
246         String resourceVersion = RESOURCE_VERSION;
247         String artifactName = ARTIFACT_NAME;
248
249         Map<String, String> parametersMap = new HashMap<>();
250         parametersMap.put(SERVICE_NAME, serviceName);
251         parametersMap.put(SERVICE_VERSION, serviceVersion);
252         parametersMap.put(RESOURCE_NAME, resourceName);
253         parametersMap.put(RESOURCE_VERSION, resourceVersion);
254         parametersMap.put(ARTIFACT_NAME, artifactName);
255
256         String formatEndpoint = "/v1/catalog/services/{serviceName}/{serviceVersion}/resources/{resourceName}/{resourceVersion}/artifacts/{artifactName}";
257         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
258
259         Either<byte[], ResponseFormat> downloadResourceArtifactEither = Either.right(NOT_FOUND_RESPONSE_FORMAT);
260         when(ARTIFACTS_BUSINESS_LOGIC.downloadRsrcArtifactByNames(serviceName, serviceVersion, resourceName,
261                 resourceVersion, artifactName))
262                 .thenReturn(downloadResourceArtifactEither);
263
264         Response response = target()
265                 .path(path)
266                 .request()
267                 .header(Constants.X_ECOMP_INSTANCE_ID_HEADER, UUID.randomUUID().toString())
268                 .accept(MediaType.APPLICATION_OCTET_STREAM)
269                 .get();
270
271         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
272     }
273
274     @Test
275     public void downloadResouceArtifactExceptionDuringProcessingTest() {
276         String serviceName = SERVICE_NAME;
277         String serviceVersion = SERVICE_VERSION;
278         String resourceName = RESOURCE_NAME;
279         String resourceVersion = RESOURCE_VERSION;
280         String artifactName = ARTIFACT_NAME;
281
282         Map<String, String> parametersMap = new HashMap<>();
283         parametersMap.put(SERVICE_NAME, serviceName);
284         parametersMap.put(SERVICE_VERSION, serviceVersion);
285         parametersMap.put(RESOURCE_NAME, resourceName);
286         parametersMap.put(RESOURCE_VERSION, resourceVersion);
287         parametersMap.put(ARTIFACT_NAME, artifactName);
288
289         String formatEndpoint = "/v1/catalog/services/{serviceName}/{serviceVersion}/resources/{resourceName}/{resourceVersion}/artifacts/{artifactName}";
290         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
291
292         when(ARTIFACTS_BUSINESS_LOGIC.downloadRsrcArtifactByNames(serviceName, serviceVersion, resourceName,
293                 resourceVersion, artifactName))
294                 .thenThrow(new RuntimeException("Test exception: downloadResouceArtifact"));
295
296         Response response = target()
297                 .path(path)
298                 .request()
299                 .header(Constants.X_ECOMP_INSTANCE_ID_HEADER, UUID.randomUUID().toString())
300                 .accept(MediaType.APPLICATION_OCTET_STREAM)
301                 .get();
302
303         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
304     }
305
306     @Test
307     public void downloadResouceArtifactTest() {
308         String serviceName = SERVICE_NAME;
309         String serviceVersion = SERVICE_VERSION;
310         String resourceName = RESOURCE_NAME;
311         String resourceVersion = RESOURCE_VERSION;
312         String artifactName = ARTIFACT_NAME;
313
314         Map<String, String> parametersMap = new HashMap<>();
315         parametersMap.put(SERVICE_NAME, serviceName);
316         parametersMap.put(SERVICE_VERSION, serviceVersion);
317         parametersMap.put(RESOURCE_NAME, resourceName);
318         parametersMap.put(RESOURCE_VERSION, resourceVersion);
319         parametersMap.put(ARTIFACT_NAME, artifactName);
320
321         String formatEndpoint = "/v1/catalog/services/{serviceName}/{serviceVersion}/resources/{resourceName}/{resourceVersion}/artifacts/{artifactName}";
322         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
323
324         Either<byte[], ResponseFormat> downloadResourceArtifactEither = Either.left(BYTE_ARRAY);
325         when(ARTIFACTS_BUSINESS_LOGIC.downloadRsrcArtifactByNames(serviceName, serviceVersion, resourceName,
326                 resourceVersion, artifactName))
327                 .thenReturn(downloadResourceArtifactEither);
328
329         Response response = target()
330                 .path(path)
331                 .request()
332                 .header(Constants.X_ECOMP_INSTANCE_ID_HEADER, UUID.randomUUID().toString())
333                 .accept(MediaType.APPLICATION_OCTET_STREAM)
334                 .get();
335
336         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
337         assertTrue(response.getHeaders().containsKey(Constants.CONTENT_DISPOSITION_HEADER));
338         assertTrue(downloadedPayloadMatchesExpected(response, BYTE_ARRAY));
339     }
340
341     @Test
342     public void downloadResourceInstanceArtifactNoArtifactFoundTest() {
343         String serviceName = SERVICE_NAME;
344         String serviceVersion = SERVICE_VERSION;
345         String resourceInstanceName = RESOURCE_INSTANCE_NAME;
346         String artifactName = ARTIFACT_NAME;
347
348         Map<String, String> parametersMap = new HashMap<>();
349         parametersMap.put(SERVICE_NAME, serviceName);
350         parametersMap.put(SERVICE_VERSION, serviceVersion);
351         parametersMap.put(RESOURCE_INSTANCE_NAME, resourceInstanceName);
352         parametersMap.put(ARTIFACT_NAME, artifactName);
353
354         String formatEndpoint = "/v1/catalog/services/{serviceName}/{serviceVersion}/resourceInstances/{resourceInstanceName}/artifacts/{artifactName}";
355         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
356
357         Either<byte[], ResponseFormat> downloadResourceArtifactEither = Either.right(NOT_FOUND_RESPONSE_FORMAT);
358         when(ARTIFACTS_BUSINESS_LOGIC.downloadRsrcInstArtifactByNames(serviceName, serviceVersion, resourceInstanceName,
359                 artifactName))
360                 .thenReturn(downloadResourceArtifactEither);
361
362         Response response = target()
363                 .path(path)
364                 .request()
365                 .header(Constants.X_ECOMP_INSTANCE_ID_HEADER, UUID.randomUUID().toString())
366                 .accept(MediaType.APPLICATION_OCTET_STREAM)
367                 .get();
368
369         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
370     }
371
372     @Test
373     public void downloadResourceInstanceArtifactExceptionDuringProcessingTest() {
374         String serviceName = SERVICE_NAME;
375         String serviceVersion = SERVICE_VERSION;
376         String resourceInstanceName = RESOURCE_INSTANCE_NAME;
377         String artifactName = ARTIFACT_NAME;
378
379         Map<String, String> parametersMap = new HashMap<>();
380         parametersMap.put(SERVICE_NAME, serviceName);
381         parametersMap.put(SERVICE_VERSION, serviceVersion);
382         parametersMap.put(RESOURCE_INSTANCE_NAME, resourceInstanceName);
383         parametersMap.put(ARTIFACT_NAME, artifactName);
384
385         String formatEndpoint = "/v1/catalog/services/{serviceName}/{serviceVersion}/resourceInstances/{resourceInstanceName}/artifacts/{artifactName}";
386         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
387
388         when(ARTIFACTS_BUSINESS_LOGIC.downloadRsrcInstArtifactByNames(serviceName, serviceVersion, resourceInstanceName,
389                 artifactName))
390                 .thenThrow(new RuntimeException("Test exception: ownloadResourceInstanceArtifact"));
391
392         Response response = target()
393                 .path(path)
394                 .request()
395                 .header(Constants.X_ECOMP_INSTANCE_ID_HEADER, UUID.randomUUID().toString())
396                 .accept(MediaType.APPLICATION_OCTET_STREAM)
397                 .get();
398
399         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
400     }
401
402     @Test
403     public void downloadResourceInstanceArtifactTest() {
404         String serviceName = SERVICE_NAME;
405         String serviceVersion = SERVICE_VERSION;
406         String resourceInstanceName = RESOURCE_INSTANCE_NAME;
407         String artifactName = ARTIFACT_NAME;
408
409         Map<String, String> parametersMap = new HashMap<>();
410         parametersMap.put(SERVICE_NAME, serviceName);
411         parametersMap.put(SERVICE_VERSION, serviceVersion);
412         parametersMap.put(RESOURCE_INSTANCE_NAME, resourceInstanceName);
413         parametersMap.put(ARTIFACT_NAME, artifactName);
414
415         String formatEndpoint = "/v1/catalog/services/{serviceName}/{serviceVersion}/resourceInstances/{resourceInstanceName}/artifacts/{artifactName}";
416         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
417
418         Either<byte[], ResponseFormat> downloadResourceArtifactEither = Either.left(BYTE_ARRAY);
419         when(ARTIFACTS_BUSINESS_LOGIC.downloadRsrcInstArtifactByNames(serviceName, serviceVersion, resourceInstanceName,
420                 artifactName))
421                 .thenReturn(downloadResourceArtifactEither);
422
423         Response response = target()
424                 .path(path)
425                 .request()
426                 .header(Constants.X_ECOMP_INSTANCE_ID_HEADER, UUID.randomUUID().toString())
427                 .accept(MediaType.APPLICATION_OCTET_STREAM)
428                 .get();
429
430         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
431         assertTrue(response.getHeaders().containsKey(Constants.CONTENT_DISPOSITION_HEADER));
432         assertTrue(downloadedPayloadMatchesExpected(response, BYTE_ARRAY));
433     }
434
435     @Override
436     protected Application configure() {
437         ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
438         return new ResourceConfig(DistributionCatalogServlet.class)
439                 .register(new AbstractBinder() {
440
441                     @Override
442                     protected void configure() {
443                         bind(HTTP_SERVLET_REQUEST).to(HttpServletRequest.class);
444                         bind(USER_BUSINESS_LOGIC).to(UserBusinessLogic.class);
445                         bind(COMPONENT_UTILS).to(ComponentsUtils.class);
446                         bind(ARTIFACTS_BUSINESS_LOGIC).to(ArtifactsBusinessLogic.class);
447                     }
448                 })
449                 .property("contextConfig", context);
450     }
451 }