Catalog alignment
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / servlets / ArchiveEndpointTest.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 fj.data.Either;
26 import org.glassfish.jersey.server.ResourceConfig;
27 import org.glassfish.jersey.test.JerseyTest;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.mockito.Mockito;
31 import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum;
32 import org.openecomp.sdc.be.components.impl.ArchiveBusinessLogic;
33 import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
34 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
35 import org.openecomp.sdc.be.components.path.utils.GraphTestUtils;
36 import org.openecomp.sdc.be.components.validation.AccessValidations;
37 import org.openecomp.sdc.be.components.validation.ComponentValidations;
38 import org.openecomp.sdc.be.config.ConfigurationManager;
39 import org.openecomp.sdc.be.dao.DAOJanusGraphStrategy;
40 import org.openecomp.sdc.be.dao.JanusGraphClientStrategy;
41 import org.openecomp.sdc.be.dao.api.ActionStatus;
42 import org.openecomp.sdc.be.dao.impl.HealingPipelineDao;
43 import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao;
44 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient;
45 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
46 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
47 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
48 import org.openecomp.sdc.be.dao.jsongraph.HealingJanusGraphDao;
49 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
50 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
51 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
52 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
53 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
54 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
55 import org.openecomp.sdc.be.facade.operations.CatalogOperation;
56 import org.openecomp.sdc.be.impl.ComponentsUtils;
57 import org.openecomp.sdc.be.impl.ServletUtils;
58 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
59 import org.openecomp.sdc.be.model.Component;
60 import org.openecomp.sdc.be.model.LifecycleStateEnum;
61 import org.openecomp.sdc.be.model.User;
62 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
63 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArchiveOperation;
64 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.CategoryOperation;
65 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.GroupsOperation;
66 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTemplateOperation;
67 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTypeOperation;
68 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation;
69 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
70 import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
71 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
72 import org.openecomp.sdc.be.servlets.exception.ComponentExceptionMapper;
73 import org.openecomp.sdc.be.servlets.exception.DefaultExceptionMapper;
74 import org.openecomp.sdc.be.servlets.exception.StorageExceptionMapper;
75 import org.openecomp.sdc.be.user.Role;
76 import org.openecomp.sdc.be.user.UserBusinessLogic;
77 import org.openecomp.sdc.common.api.ConfigurationSource;
78 import org.openecomp.sdc.common.api.Constants;
79 import org.openecomp.sdc.common.impl.ExternalConfiguration;
80 import org.openecomp.sdc.common.impl.FSConfigurationSource;
81 import org.openecomp.sdc.exception.ResponseFormat;
82 import org.springframework.context.ApplicationContext;
83 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
84 import org.springframework.context.annotation.Bean;
85 import org.springframework.context.annotation.Configuration;
86 import org.springframework.context.annotation.PropertySource;
87 import org.springframework.http.HttpStatus;
88 import org.springframework.web.context.WebApplicationContext;
89
90 import javax.servlet.ServletContext;
91 import javax.servlet.http.HttpServletRequest;
92 import javax.ws.rs.client.Entity;
93 import javax.ws.rs.core.Application;
94 import javax.ws.rs.core.GenericType;
95 import javax.ws.rs.core.MediaType;
96 import javax.ws.rs.core.Response;
97 import java.util.HashMap;
98 import java.util.LinkedList;
99 import java.util.List;
100 import java.util.Map;
101
102 import static org.assertj.core.api.Assertions.assertThat;
103 import static org.mockito.ArgumentMatchers.any;
104 import static org.mockito.ArgumentMatchers.anyString;
105 import static org.mockito.ArgumentMatchers.eq;
106 import static org.mockito.Mockito.doThrow;
107 import static org.mockito.Mockito.mock;
108 import static org.mockito.Mockito.when;
109
110 public class ArchiveEndpointTest extends JerseyTest {
111
112     private static final ServletContext servletContext = mock(ServletContext.class);
113     private static final String CSAR_UUID1 = "123456789abcdefgh";
114     private static final String CSAR_UUID2 = "987654321abcdefgh";
115
116     public static final WebAppContextWrapper webAppContextWrapper = mock(WebAppContextWrapper.class);
117     private static final WebApplicationContext webApplicationContext = mock(WebApplicationContext.class);
118     private static final ServletUtils servletUtils = mock(ServletUtils.class);
119     private static final UserBusinessLogic userAdmin = mock(UserBusinessLogic.class);
120     private static final ComponentsUtils componentUtils = mock(ComponentsUtils.class);
121     private static final CatalogOperation catalogOperations = mock(CatalogOperation.class);
122 //    private static final ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class);
123     private static final ToscaOperationFacade toscaOperationFacade = Mockito.spy(new ToscaOperationFacade());
124
125
126     private static final ResponseFormat responseFormat = mock(ResponseFormat.class);
127     private static final ResponseFormat notFoundResponseFormat = mock(ResponseFormat.class);
128     private static final ResponseFormat badRequestResponseFormat = mock(ResponseFormat.class);
129     private static final ResponseFormat invalidServiceStateResponseFormat = mock(ResponseFormat.class);
130     private static final AccessValidations accessValidationsMock = mock(AccessValidations.class);
131     private static final ComponentValidations componentValidationsMock = mock(ComponentValidations.class);
132     private static final IGraphLockOperation graphLockOperation = mock(IGraphLockOperation.class);
133     private static final HealingJanusGraphGenericDao
134         janusGraphGenericDao = mock(HealingJanusGraphGenericDao.class);
135     private static final HealingPipelineDao HEALING_PIPELINE_DAO = mock(HealingPipelineDao.class);
136     private static GraphVertex serviceVertex;
137     private static GraphVertex resourceVertex;
138     private static GraphVertex resourceVertexVspArchived;
139
140     private static HealingJanusGraphDao janusGraphDao;
141
142     @Configuration
143     @PropertySource("classpath:dao.properties")
144     static class TestSpringConfig {
145         private ArchiveOperation archiveOperation;
146         private GraphVertex catalogVertex;
147
148         @Bean
149         ArchiveEndpoint archiveEndpoint() {
150             UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class);
151             ComponentsUtils componentsUtils = mock(ComponentsUtils.class);
152             return new ArchiveEndpoint(userBusinessLogic, componentsUtils, archiveBusinessLogic());
153         }
154
155         @Bean
156         ComponentExceptionMapper componentExceptionMapper() {
157             return new ComponentExceptionMapper(componentUtils);
158         }
159
160         @Bean
161         StorageExceptionMapper storageExceptionMapper() {
162             return new StorageExceptionMapper(componentUtils);
163         }
164
165         @Bean
166         DefaultExceptionMapper defaultExceptionMapper() {
167             return new DefaultExceptionMapper();
168         }
169
170         @Bean
171         ArchiveBusinessLogic archiveBusinessLogic() {
172             return new ArchiveBusinessLogic(janusGraphDao(), accessValidations(), archiveOperation(), toscaOperationFacade(), componentUtils, catalogOperations);
173         }
174
175         @Bean
176         ArchiveOperation archiveOperation() {
177             this.archiveOperation = new ArchiveOperation(janusGraphDao(), graphLockOperation());
178             GraphTestUtils.clearGraph(janusGraphDao);
179             initGraphForTest();
180             return this.archiveOperation;
181         }
182
183         @Bean
184         ComponentValidations componentValidations() {
185             return componentValidationsMock;
186         }
187
188         @Bean
189         AccessValidations accessValidations() {
190             return accessValidationsMock;
191         }
192
193         @Bean
194         ToscaOperationFacade toscaOperationFacade() {
195             return toscaOperationFacade;
196         }
197
198         @Bean
199         TopologyTemplateOperation topologyTemplateOperation() {
200             return new TopologyTemplateOperation();
201         }
202
203         @Bean
204         NodeTypeOperation nodeTypeOpertaion() {
205             return new NodeTypeOperation(null);
206         }
207
208         @Bean
209         NodeTemplateOperation nodeTemplateOperation() {
210             return new NodeTemplateOperation();
211         }
212
213         @Bean
214         GroupsOperation groupsOperation() {
215             return new GroupsOperation();
216         }
217
218         @Bean
219         HealingJanusGraphDao janusGraphDao() {
220             janusGraphDao = new HealingJanusGraphDao(healingPipelineDao(), janusGraphClient());
221             return janusGraphDao;
222         }
223
224         @Bean
225         JanusGraphClient janusGraphClient() {
226             return new JanusGraphClient(janusGraphClientStrategy());
227         }
228
229         @Bean
230         JanusGraphClientStrategy janusGraphClientStrategy() {
231             return new DAOJanusGraphStrategy();
232         }
233
234         @Bean
235         CategoryOperation categoryOperation() {
236             return new CategoryOperation();
237         }
238
239         @Bean
240         IGraphLockOperation graphLockOperation() {
241             return graphLockOperation;
242         }
243
244         @Bean
245         JanusGraphGenericDao janusGraphGenericDao() {
246             return janusGraphGenericDao;
247         }
248
249         @Bean
250         HealingPipelineDao healingPipelineDao(){
251             return HEALING_PIPELINE_DAO;
252         }
253
254         private void initGraphForTest() {
255             //Create Catalog Root
256             catalogVertex = GraphTestUtils.createRootCatalogVertex(janusGraphDao);
257             //Create Archive Root
258             GraphTestUtils.createRootArchiveVertex(janusGraphDao);
259
260             createSingleVersionServiceAndResource();
261         }
262
263         private void createSingleVersionServiceAndResource() {
264             //Create Service for Scenario 1 Tests (1 Service)
265             serviceVertex = GraphTestUtils.createServiceVertex(janusGraphDao, propsForHighestVersion());
266
267
268             Map<GraphPropertyEnum, Object> props = propsForHighestVersion();
269             props.put(GraphPropertyEnum.IS_VSP_ARCHIVED, false);
270             props.put(GraphPropertyEnum.CSAR_UUID, CSAR_UUID1);
271             resourceVertex = GraphTestUtils.createResourceVertex(janusGraphDao, props, ResourceTypeEnum.VF);
272
273             props = propsForHighestVersion();
274             props.put(GraphPropertyEnum.IS_VSP_ARCHIVED, true);
275             props.put(GraphPropertyEnum.CSAR_UUID, CSAR_UUID2);
276             resourceVertexVspArchived = GraphTestUtils.createResourceVertex(janusGraphDao, props, ResourceTypeEnum.VF);
277
278             //Connect Service/Resource to Catalog Root
279             janusGraphDao.createEdge(catalogVertex, serviceVertex, EdgeLabelEnum.CATALOG_ELEMENT, null);
280             janusGraphDao.createEdge(catalogVertex, resourceVertex, EdgeLabelEnum.CATALOG_ELEMENT, null);
281         }
282
283         private Map<GraphPropertyEnum, Object> propsForHighestVersion(){
284             Map<GraphPropertyEnum, Object> props = new HashMap<>();
285             props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
286             return props;
287         }
288     }
289
290     public static final HttpServletRequest request = mock(HttpServletRequest.class);
291
292     /* Users */
293     private static final User adminUser = new User("admin", "admin", "admin", "admin@email.com", Role.ADMIN.name(), System.currentTimeMillis());
294     private static final User designerUser = new User("designer", "designer", "designer", "designer@email.com", Role.DESIGNER.name(), System
295                                                                                                                                               .currentTimeMillis());
296     private static final User otherUser = new User("other", "other", "other", "other@email.com", Role.TESTER.name(), System.currentTimeMillis());
297
298     @BeforeClass
299     public static void setup() {
300         //Needed for User Authorization
301         //========================================================================================================================
302         when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
303         when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
304         when(webApplicationContext.getBean(ServletUtils.class)).thenReturn(servletUtils);
305         when(servletUtils.getUserAdmin()).thenReturn(userAdmin);
306         when(servletUtils.getComponentsUtils()).thenReturn(componentUtils);
307         when(componentUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION)).thenReturn(responseFormat);
308         when(componentUtils.getResponseFormat(eq(ActionStatus.INVALID_SERVICE_STATE), any())).thenReturn(invalidServiceStateResponseFormat);
309         when(responseFormat.getStatus()).thenReturn(HttpStatus.UNAUTHORIZED.value());
310
311         ComponentException ce = new ByResponseFormatComponentException(responseFormat);
312         doThrow(ce).when(accessValidationsMock).userIsAdminOrDesigner(eq(otherUser.getUserId()), any());
313
314         //Needed for error configuration
315         when(notFoundResponseFormat.getStatus()).thenReturn(HttpStatus.NOT_FOUND.value());
316         when(invalidServiceStateResponseFormat.getStatus()).thenReturn(HttpStatus.CONFLICT.value());
317         when(badRequestResponseFormat.getStatus()).thenReturn(HttpStatus.BAD_REQUEST.value());
318         when(componentUtils.getResponseFormat(eq(ActionStatus.RESOURCE_NOT_FOUND), (String[]) any())).thenReturn(notFoundResponseFormat);
319         when(componentUtils.getResponseFormat(eq(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID), (String[]) any())).thenReturn(badRequestResponseFormat);
320
321         when(graphLockOperation.lockComponent(anyString(), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
322         when(userAdmin.getUser(adminUser.getUserId(), false)).thenReturn(adminUser);
323         when(userAdmin.getUser(designerUser.getUserId(), false)).thenReturn(designerUser);
324         when(userAdmin.getUser(otherUser.getUserId(), false)).thenReturn(otherUser);
325         //========================================================================================================================
326
327         String appConfigDir = "src/test/resources/config";
328         ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
329         ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
330
331         org.openecomp.sdc.be.config.Configuration configuration = new org.openecomp.sdc.be.config.Configuration();
332         configuration.setJanusGraphInMemoryGraph(true);
333
334         org.openecomp.sdc.be.config.Configuration.HeatDeploymentArtifactTimeout heatDeploymentArtifactTimeout = new org.openecomp.sdc.be.config.Configuration.HeatDeploymentArtifactTimeout();
335         heatDeploymentArtifactTimeout.setDefaultMinutes(30);;
336         configuration.setHeatArtifactDeploymentTimeout(heatDeploymentArtifactTimeout);
337         configurationManager.setConfiguration(configuration);
338
339         configurationManager.setConfiguration(configuration);
340         ExternalConfiguration.setAppName("catalog-be");
341     }
342
343     @Test
344     public void getArchivedComponents_Empty() {
345         assertOnGetArchivedComponents(null, 0);
346     }
347
348     @Test
349     public void archiveAndGetArchivedService_SingleService() {
350         Component serviceComponent = mock(Component.class);
351         final String serviceUniqueId = serviceVertex.getUniqueId();
352         when(toscaOperationFacade.getToscaElement(serviceUniqueId)).thenReturn(Either.left(serviceComponent));
353         when(catalogOperations.updateCatalog(ChangeTypeEnum.ARCHIVE, serviceComponent)).thenReturn(ActionStatus.OK);
354         archiveService(serviceUniqueId, HttpStatus.OK.value());
355         assertOnGetArchivedComponents(ComponentTypeEnum.SERVICE_PARAM_NAME, 1);
356         //restoreService(serviceUniqueId, 200);
357     }
358
359     @Test
360     public void archiveAndGetArchivedResource_SingleResource() {
361         Component component = mock(Component.class);
362         final String uniqueId = resourceVertex.getUniqueId();
363         when(toscaOperationFacade.getToscaElement(uniqueId)).thenReturn(Either.left(component));
364         when(catalogOperations.updateCatalog(ChangeTypeEnum.ARCHIVE, component)).thenReturn(ActionStatus.OK);
365         archiveResource(uniqueId, HttpStatus.OK.value());
366         assertOnGetArchivedComponents(ComponentTypeEnum.RESOURCE_PARAM_NAME, 1);
367         //restoreResource(uniqueId, 200);
368     }
369
370     @Test
371     public void attemptArchiveCheckedOutService() {
372         checkoutComponent(serviceVertex);
373         archiveService(serviceVertex.getUniqueId(), HttpStatus.CONFLICT.value());
374     }
375
376     @Test
377     public void testOnArchivedVsps(){
378         String path = "/v1/catalog/notif/vsp/archived";
379         List<String> csarIds = new LinkedList<>();
380         csarIds.add("123456");
381         csarIds.add(CSAR_UUID2);   //An archived CSAR ID
382         Response response = target()
383                                     .path(path)
384                                     .request(MediaType.APPLICATION_JSON)
385                                     .accept(MediaType.APPLICATION_JSON)
386                                     .header(Constants.USER_ID_HEADER, designerUser.getUserId())
387                                     .post(Entity.json(csarIds));
388
389         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
390         assertOnVertexProp(resourceVertexVspArchived.getUniqueId(), true);
391     }
392
393     @Test
394     public void testOnRestoredVsps(){
395         String path = "/v1/catalog/notif/vsp/restored";
396         List<String> csarIds = new LinkedList<>();
397         csarIds.add("123456");
398         csarIds.add(CSAR_UUID1);   //Non archived CSAR_ID
399         Response response = target()
400                                     .path(path)
401                                     .request(MediaType.APPLICATION_JSON)
402                                     .accept(MediaType.APPLICATION_JSON)
403                                     .header(Constants.USER_ID_HEADER, designerUser.getUserId())
404                                     .post(Entity.json(csarIds));
405
406         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
407         assertOnVertexProp(resourceVertex.getUniqueId(), false);
408     }
409
410     /*
411      *   Rainy Scenarios
412      */
413     @Test
414     public void archiveWithInvalidUid() {
415         archiveService("fakeUid", HttpStatus.NOT_FOUND.value());
416     }
417
418     @Test
419     public void restoreWithInvalidUid() {
420         restoreService("fakeUid", HttpStatus.NOT_FOUND.value());
421     }
422
423     @Test
424     public void archiveWithTester() {
425         String path = String.format("/v1/catalog/services/%s/%s", serviceVertex.getUniqueId(), "archive");
426         Response response = target()
427                                     .path(path)
428                                     .request()
429                                     .accept(MediaType.APPLICATION_JSON)
430                                     .header(Constants.USER_ID_HEADER, otherUser.getUserId())
431                                     .post(null);
432
433         assertThat(response.getStatus()).isEqualTo(HttpStatus.UNAUTHORIZED.value());
434     }
435
436     private void checkoutComponent(GraphVertex component) {
437         Either<GraphVertex, JanusGraphOperationStatus> vE = janusGraphDao.getVertexById(component.getUniqueId());
438         GraphVertex v = vE.left().value();
439         v.addMetadataProperty(GraphPropertyEnum.STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
440         v.setJsonMetadataField(JsonPresentationFields.LIFECYCLE_STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
441         janusGraphDao.updateVertex(v);
442         janusGraphDao.commit();
443     }
444
445     private void assertOnVertexProp(String componentId, Object expectedValue) {
446         Either<GraphVertex, JanusGraphOperationStatus> vE = janusGraphDao.getVertexById(componentId);
447         GraphVertex v = vE.left().value();
448         assertThat(v.getMetadataProperty(GraphPropertyEnum.IS_VSP_ARCHIVED)).isEqualTo(expectedValue);
449     }
450
451     private void archiveService(String id, int expectedStatus){ archiveOrRestoreService(id, ArchiveOperation.Action.ARCHIVE, expectedStatus); }
452     private void restoreService(String id, int expectedStatus){ archiveOrRestoreService(id, ArchiveOperation.Action.RESTORE, expectedStatus); }
453
454     private void archiveResource(String id, int expectedStatus){ archiveOrRestoreResource(id, ArchiveOperation.Action.ARCHIVE, expectedStatus); }
455     private void restoreResource(String id, int expectedStatus){ archiveOrRestoreResource(id, ArchiveOperation.Action.RESTORE, expectedStatus); }
456
457     private void archiveOrRestoreService(String compUid, ArchiveOperation.Action action, int expectedStatus) {
458         String path = String.format("/v1/catalog/services/%s/%s", compUid, action.name().toLowerCase());
459         Response response = target()
460                                     .path(path)
461                                     .request()
462                                     .accept(MediaType.APPLICATION_JSON)
463                                     .header(Constants.USER_ID_HEADER, designerUser.getUserId())
464                                     .post(null);
465
466         assertThat(response.getStatus()).isEqualTo(expectedStatus);
467     }
468
469     private void archiveOrRestoreResource(String compUid, ArchiveOperation.Action action, int expectedStatus) {
470         String path = String.format("/v1/catalog/resources/%s/%s", compUid, action.name().toLowerCase());
471         Response response = target()
472                 .path(path)
473                 .request()
474                 .accept(MediaType.APPLICATION_JSON)
475                 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
476                 .post(null);
477
478         assertThat(response.getStatus()).isEqualTo(expectedStatus);
479     }
480
481     private void assertOnGetArchivedComponents(String componentType, int expectedCount) {
482         String path = "/v1/catalog/archive";
483
484         Response response = target()
485                                     .path(path)
486                                     .request()
487                                     .accept(MediaType.APPLICATION_JSON)
488                                     .header(Constants.USER_ID_HEADER, designerUser.getUserId())
489                                     .get();
490
491         Map<String, List<CatalogComponent>> archivedComponents = response.readEntity(new GenericType<Map<String, List<CatalogComponent>>>() {  });
492         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
493
494         if (componentType == null) {
495             assertThat(archivedComponents).isEmpty();
496         } else {
497             assertThat(archivedComponents.get(componentType)).hasSize(expectedCount);
498         }
499
500     }
501
502     @Override
503     protected Application configure() {
504         ApplicationContext context = new AnnotationConfigApplicationContext(TestSpringConfig.class);
505         return new ResourceConfig(ArchiveEndpoint.class)
506                        .register(DefaultExceptionMapper.class)
507                        .register(ComponentExceptionMapper.class)
508                        .register(StorageExceptionMapper.class)
509                        .property("contextConfig", context);
510     }
511 }