aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java
blob: 284cc3fb47228875eb4a710d1d82ae073f9c7604 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 * Modifications copyright (c) 2019 Nokia
 * ================================================================================
 */

package org.openecomp.sdc.be.servlets;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import fj.data.Either;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.text.StrSubstitutor;
import org.apache.http.HttpStatus;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
import org.json.JSONException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
import org.openecomp.sdc.be.config.SpringConfig;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.UploadResourceInfo;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.util.GeneralUtility;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.when;

public class ResourceServletTest extends JerseyTest {
    public static final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    public static final ResourceImportManager resourceImportManager = Mockito.mock(ResourceImportManager.class);
    private static final HttpSession session = Mockito.mock(HttpSession.class);
    private static final ServletContext servletContext = Mockito.mock(ServletContext.class);
    private static final WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
    private static final WebApplicationContext webApplicationContext = Mockito.mock(WebApplicationContext.class);
    public static final ServletUtils servletUtils = Mockito.mock(ServletUtils.class);
    public static final ComponentsUtils componentUtils = Mockito.mock(ComponentsUtils.class);
    private static final UserBusinessLogic userAdmin = Mockito.mock(UserBusinessLogic.class);
    private static final UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class);
    private static final GroupBusinessLogic groupBL = Mockito.mock(GroupBusinessLogic.class);
    private static final ComponentInstanceBusinessLogic componentInstanceBL = Mockito.mock(ComponentInstanceBusinessLogic.class);
    private static final ResourceBusinessLogic resourceBusinessLogic = Mockito.mock(ResourceBusinessLogic.class);
    private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
    private static final ResponseFormat okResponseFormat = new ResponseFormat(HttpStatus.SC_OK);
    private static final ResponseFormat conflictResponseFormat = new ResponseFormat(HttpStatus.SC_CONFLICT);
    private static final ResponseFormat generalErrorResponseFormat = new ResponseFormat(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    private static final ResponseFormat createdResponseFormat = new ResponseFormat(HttpStatus.SC_CREATED);
    private static final ResponseFormat noContentResponseFormat = new ResponseFormat(HttpStatus.SC_NO_CONTENT);
    private static final ResponseFormat notFoundResponseFormat = new ResponseFormat(HttpStatus.SC_NOT_FOUND);
    private static final ResponseFormat badRequestResponseFormat = new ResponseFormat(HttpStatus.SC_BAD_REQUEST);
    private static final String RESOURCE_NAME = "resourceName";
    private static final String VERSION = "version";
    private static final String RESOURCE_ID = "resourceId";
    private static final String RESOURCE_VERSION = "resourceVersion";
    private static final String SUBTYPE = "subtype";
    private static final String CSAR_UUID = "csaruuid";
    private static final String EMPTY_JSON = "{}";
    private static final String NON_UI_IMPORT_JSON = "{\n" +
            "  \"node1\": \"value1\",\n" +
            "  \"node2\": {\n" +
            "    \"level21\": \"value21\",\n" +
            "    \"level22\": \"value22\"\n" +
            "  }\n" +
            "}";
    private static User user;

    @BeforeClass
    public static void setup() {
        ExternalConfiguration.setAppName("catalog-be");
        when(request.getSession()).thenReturn(session);
        when(session.getServletContext()).thenReturn(servletContext);
        when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
        when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
        when(webApplicationContext.getBean(ResourceImportManager.class)).thenReturn(resourceImportManager);
        when(webApplicationContext.getBean(ServletUtils.class)).thenReturn(servletUtils);
        when(servletUtils.getComponentsUtils()).thenReturn(componentUtils);
        when(servletUtils.getUserAdmin()).thenReturn(userAdmin);
        String userId = "jh0003";
        user = new User();
        user.setUserId(userId);
        user.setRole(Role.ADMIN.name());
        when(userAdmin.getUser(userId)).thenReturn(user);
        when(request.getHeader(Constants.USER_ID_HEADER)).thenReturn(userId);

        ImmutablePair<Resource, ActionStatus> pair = new ImmutablePair<>(new Resource(), ActionStatus.OK);
        when(resourceImportManager.importUserDefinedResource(Mockito.anyString(), Mockito.any(UploadResourceInfo.class), Mockito.any(User.class), Mockito.anyBoolean())).thenReturn(pair);
        when(webApplicationContext.getBean(ResourceBusinessLogic.class)).thenReturn(resourceBusinessLogic);

    }

    @Before
    public void beforeTest() {
        Mockito.reset(componentUtils);
        Mockito.reset(resourceBusinessLogic);

        when(componentUtils.getResponseFormat(ActionStatus.OK)) .thenReturn(okResponseFormat);
        when(componentUtils.getResponseFormat(ActionStatus.CREATED)).thenReturn(createdResponseFormat);
        when(componentUtils.getResponseFormat(ActionStatus.NO_CONTENT)).thenReturn(noContentResponseFormat);
        when(componentUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)).thenReturn(badRequestResponseFormat);
        when(componentUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)) .thenReturn(generalErrorResponseFormat);
        when(componentUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND)) .thenReturn(notFoundResponseFormat);
    }

    @Test
    public void testHappyScenarioTest() {
        when(componentUtils.getResponseFormat(ActionStatus.OK)) .thenReturn(createdResponseFormat);

        UploadResourceInfo validJson = buildValidJson();
        setMD5OnRequest(true, validJson);
        Response response = target().path("/v1/catalog/resources").request(MediaType.APPLICATION_JSON).post(Entity.json(gson.toJson(validJson)), Response.class);
        Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(Mockito.any(ActionStatus.class));
        Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(ActionStatus.OK);
        assertEquals(HttpStatus.SC_CREATED, response.getStatus());

    }

    @Test
    public void testNonValidMd5Fail() {
        UploadResourceInfo validJson = buildValidJson();

        setMD5OnRequest(false, validJson);

        Response response = target().path("/v1/catalog/resources").request(MediaType.APPLICATION_JSON).post(Entity.json(gson.toJson(validJson)), Response.class);
        Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(Mockito.any(ActionStatus.class));
        Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(ActionStatus.INVALID_RESOURCE_CHECKSUM);
        assertEquals(response.getStatus(), HttpStatus.SC_INTERNAL_SERVER_ERROR);

    }

    @Test
    public void testNonValidPayloadNameFail() {
        UploadResourceInfo mdJson = buildValidJson();
        mdJson.setPayloadName("myCompute.xml");

        runAndVerifyActionStatusError(mdJson, ActionStatus.INVALID_TOSCA_FILE_EXTENSION);

    }

    @Test
    public void testNullPayloadFail() {
        UploadResourceInfo mdJson = buildValidJson();
        mdJson.setPayloadData(null);
        runAndVerifyActionStatusError(mdJson, ActionStatus.INVALID_RESOURCE_PAYLOAD);

    }

    @Test
    public void testNonYmlPayloadFail() {
        UploadResourceInfo mdJson = buildValidJson();
        String payload = "{ json : { isNot : yaml } ";
        encodeAndSetPayload(mdJson, payload);
        runAndVerifyActionStatusError(mdJson, ActionStatus.INVALID_YAML_FILE);

    }

    @Test
    public void testNonToscaPayloadFail() {
        UploadResourceInfo mdJson = buildValidJson();

        String payload = "node_types: \r\n" + "  org.openecomp.resource.importResource4test:\r\n" + "    derived_from: tosca.nodes.Root\r\n" + "    description: update update";
        encodeAndSetPayload(mdJson, payload);
        runAndVerifyActionStatusError(mdJson, ActionStatus.INVALID_TOSCA_TEMPLATE);

    }

    @Test
    public void testServiceToscaPayloadFail() {
        UploadResourceInfo mdJson = buildValidJson();

        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"
                + "    description: update update";

        encodeAndSetPayload(mdJson, payload);
        runAndVerifyActionStatusError(mdJson, ActionStatus.NOT_RESOURCE_TOSCA_TEMPLATE);

    }

    @Test
    public void testMultipleResourcesInPayloadFail() {
        UploadResourceInfo mdJson = buildValidJson();

        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"
                + "    derived_from: tosca.nodes.Root\r\n" + "    description: update update";

        encodeAndSetPayload(mdJson, payload);
        runAndVerifyActionStatusError(mdJson, ActionStatus.NOT_SINGLE_RESOURCE);

    }

    @Test
    public void testNonValidNameSpaceInPayloadFail() {
        UploadResourceInfo mdJson = buildValidJson();

        String payload = "tosca_definitions_version: tosca_simple_yaml_1_0_0\r\n" + "node_types: \r\n" + "  org.openecomp.resourceX.importResource4test:\r\n" + "    derived_from: tosca.nodes.Root\r\n" + "    description: update update";

        encodeAndSetPayload(mdJson, payload);
        runAndVerifyActionStatusError(mdJson, ActionStatus.INVALID_RESOURCE_NAMESPACE);

    }

    @Test
    public void deleteResourceTryDeleteNonExistingResourceTest() {
        String resourceId = "resourceId";
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put("resourceId", resourceId);

        String formatEndpoint = "/v1/catalog/resources/{resourceId}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        when(resourceBusinessLogic.deleteResource(any(), any(User.class)))
                .thenReturn(notFoundResponseFormat);

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .delete();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
    }

    @Test
    public void deleteResourceExceptionDuringDeletingTest() {
        String resourceId = RESOURCE_ID;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_ID, resourceId);

        String formatEndpoint = "/v1/catalog/resources/{resourceId}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        when(resourceBusinessLogic.deleteResource(any(), any(User.class)))
                .thenThrow(new JSONException("Test exception: deleteResource"));

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .delete();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }

    @Test
    public void deleteResourceCategoryTest() {
        String resourceId = "resourceId";
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put("resourceId", resourceId);

        String formatEndpoint = "/v1/catalog/resources/{resourceId}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        when(resourceBusinessLogic.deleteResource(eq(resourceId.toLowerCase()), any(User.class)))
                .thenReturn(noContentResponseFormat);

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .delete();

        assertThat(response.getStatus()).isEqualTo(org.apache.http.HttpStatus.SC_NO_CONTENT);
    }

    @Test
    public void deleteResourceByNameAndVersionTryDeleteNonExistingResourceTest() {
        String resourceName = RESOURCE_NAME;
        String version = VERSION;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_NAME, resourceName);
        parametersMap.put(VERSION, version);

        String formatEndpoint = "/v1/catalog/resources/{resourceName}/{version}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        when(resourceBusinessLogic.deleteResourceByNameAndVersion(eq(resourceName), eq(version), any(User.class)))
                .thenReturn(notFoundResponseFormat);

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .delete();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
    }

    @Test
    public void deleteResourceByNameAndVersionExceptionDuringDeletingTest() {
        String resourceName = RESOURCE_NAME;
        String version = VERSION;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_NAME, resourceName);
        parametersMap.put(VERSION, version);

        String formatEndpoint = "/v1/catalog/resources/{resourceName}/{version}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        when(resourceBusinessLogic.deleteResourceByNameAndVersion(eq(resourceName), eq(version), any(User.class)))
                .thenThrow(new JSONException("Test exception: deleteResourceByNameAndVersion"));

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .delete();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }

    @Test
    public void deleteResourceByNameAndVersionCategoryTest() {
        String resourceName = RESOURCE_NAME;
        String version = VERSION;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_NAME, resourceName);
        parametersMap.put(VERSION, version);

        String formatEndpoint = "/v1/catalog/resources/{resourceName}/{version}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        when(resourceBusinessLogic.deleteResourceByNameAndVersion(eq(resourceName), eq(version), any(User.class)))
                .thenReturn(noContentResponseFormat);

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .delete();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
    }

    @Test
    public void getResourceByIdTryGetNonExistingResourceTest() {
        String resourceId = RESOURCE_ID;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_ID, resourceId);

        String formatEndpoint = "/v1/catalog/resources/{resourceId}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        Either<Resource, ResponseFormat> getResourceByIdEither = Either.right(notFoundResponseFormat);
        when(resourceBusinessLogic.getResource(eq(resourceId.toLowerCase()), any(User.class)))
                .thenReturn(getResourceByIdEither);

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .get();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
    }

    @Test
    public void getResourceByIdExceptionDuringSearchingTest() {
        String resourceId = RESOURCE_ID;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_ID, resourceId);

        String formatEndpoint = "/v1/catalog/resources/{resourceId}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        given(resourceBusinessLogic.getResource(eq(resourceId.toLowerCase()), any(User.class)))
                .willAnswer( invocation -> { throw new IOException("Test exception: getResourceById"); });

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .get();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }

    @Test
    public void getResourceByIdTest() {
        String resourceId = RESOURCE_ID;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_ID, resourceId);

        String formatEndpoint = "/v1/catalog/resources/{resourceId}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        Either<Resource, ResponseFormat> getResourceByIdEither = Either.left(new Resource());
        when(resourceBusinessLogic.getResource(eq(resourceId.toLowerCase()), any(User.class)))
                .thenReturn(getResourceByIdEither);

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .get();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
    }

    @Test
    public void getResourceByNameAndVersionTryGetNonExistingResourceTest() {
        String resourceName = RESOURCE_NAME;
        String resourceVersion = RESOURCE_VERSION;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_NAME, resourceName);
        parametersMap.put(RESOURCE_VERSION, resourceVersion);

        String formatEndpoint = "/v1/catalog/resources/resourceName/{resourceName}/resourceVersion/{resourceVersion}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        Either<Resource, ResponseFormat> getResourceByNameAndVersionEither = Either.right(notFoundResponseFormat);
        when(resourceBusinessLogic.getResourceByNameAndVersion(eq(resourceName), eq(resourceVersion), eq(user.getUserId())))
                .thenReturn(getResourceByNameAndVersionEither);

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .get();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
    }

    @Test
    public void getResourceByNameAndVersionExceptionDuringSearchingTest() {
        String resourceName = RESOURCE_NAME;
        String resourceVersion = RESOURCE_VERSION;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_NAME, resourceName);
        parametersMap.put(RESOURCE_VERSION, resourceVersion);

        String formatEndpoint = "/v1/catalog/resources/resourceName/{resourceName}/resourceVersion/{resourceVersion}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        given(resourceBusinessLogic.getResourceByNameAndVersion(eq(resourceName), eq(resourceVersion), eq(user.getUserId())))
                .willAnswer( invocation -> { throw new IOException("Test exception: getResourceByNameAndVersion"); });

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .get();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }

    @Test
    public void getResourceByNameAndVersionTest() {
        String resourceName = RESOURCE_NAME;
        String resourceVersion = RESOURCE_VERSION;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_NAME, resourceName);
        parametersMap.put(RESOURCE_VERSION, resourceVersion);

        String formatEndpoint = "/v1/catalog/resources/resourceName/{resourceName}/resourceVersion/{resourceVersion}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        Either<Resource, ResponseFormat> getResourceByNameAndVersionEither = Either.left(new Resource());
        when(resourceBusinessLogic.getResourceByNameAndVersion(eq(resourceName), eq(resourceVersion), eq(user.getUserId())))
                .thenReturn(getResourceByNameAndVersionEither);

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .get();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
    }

    @Test
    public void validateResourceNameTryValidateNonExistingResourceTest() {
        String resourceName = RESOURCE_NAME;
        String resourceType = "VFC";
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_NAME, resourceName);

        String formatEndpoint = "/v1/catalog/resources/validate-name/{resourceName}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        Either<Map<String, Boolean>, ResponseFormat> validateResourceNameEither =
                Either.right(notFoundResponseFormat);
        ResourceTypeEnum resourceTypeEnum = ResourceTypeEnum.valueOf(resourceType);
        when(resourceBusinessLogic.validateResourceNameExists(eq(resourceName), eq(resourceTypeEnum), eq(user.getUserId())))
                .thenReturn(validateResourceNameEither);

        Response response = target()
                .path(path)
                .queryParam(SUBTYPE, resourceType)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .get();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
    }

    @Test
    public void validateResourceNameInvalidContentTest() {
        String resourceName = RESOURCE_NAME;
        String resourceType = "ThisIsInvalid";
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_NAME, resourceName);

        String formatEndpoint = "/v1/catalog/resources/validate-name/{resourceName}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        Response response = target()
                .path(path)
                .queryParam(SUBTYPE, resourceType)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .get();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
    }

    @Test
    public void validateResourceNameTest() {
        String resourceName = RESOURCE_NAME;
        String resourceType = "VFC";
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_NAME, resourceName);

        String formatEndpoint = "/v1/catalog/resources/validate-name/{resourceName}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        Either<Map<String, Boolean>, ResponseFormat> validateResourceNameEither =
                Either.left(new HashMap<>());
        ResourceTypeEnum resourceTypeEnum = ResourceTypeEnum.valueOf(resourceType);
        when(resourceBusinessLogic.validateResourceNameExists(eq(resourceName), eq(resourceTypeEnum), eq(user.getUserId())))
                .thenReturn(validateResourceNameEither);

        Response response = target()
                .path(path)
                .queryParam(SUBTYPE, resourceType)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .get();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
    }

    @Test
    public void getCertifiedAbstractResourcesExceptionDuringSearchingTest() {
        String path = "/v1/catalog/resources/certified/abstract";
        given(resourceBusinessLogic.getAllCertifiedResources(eq(true), eq(HighestFilterEnum.HIGHEST_ONLY),
                eq(user.getUserId())))
                .willAnswer( invocation -> { throw new IOException("Test exception: getCertifiedAbstractResources"); });

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .get();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }

    @Test
    public void getCertifiedAbstractResourcesTest() {
        String path = "/v1/catalog/resources/certified/abstract";

        List<Resource> resources = Arrays.asList(new Resource(), new Resource());
        when(resourceBusinessLogic.getAllCertifiedResources(eq(true), eq(HighestFilterEnum.HIGHEST_ONLY),
                eq(user.getUserId())))
                .thenReturn(resources);

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .get();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
    }

    @Test
    public void getCertifiedNotAbstractResourcesExceptionDuringSearchingTest() {
        String path = "/v1/catalog/resources/certified/notabstract";
        given(resourceBusinessLogic.getAllCertifiedResources(eq(false), eq(HighestFilterEnum.ALL),
                eq(user.getUserId())))
                .willAnswer( invocation -> { throw new IOException("Test exception: getCertifiedNotAbstractResources"); });

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .get();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }

    @Test
    public void getCertifiedNotAbstractResourcesTest() {
        String path = "/v1/catalog/resources/certified/notabstract";

        List<Resource> resources = Arrays.asList(new Resource(), new Resource());
        when(resourceBusinessLogic.getAllCertifiedResources(eq(true), eq(HighestFilterEnum.ALL),
                eq(user.getUserId())))
                .thenReturn(resources);

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .get();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
    }

    @Test
    public void updateResourceMetadataTryUpdateNonExistingResourceTest() {
        String resourceId = RESOURCE_ID;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_ID, resourceId);

        String formatEndpoint = "/v1/catalog/resources/{resourceId}/metadata";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        Either<Resource, ResponseFormat> updateResourceMetadataEither = Either.right(badRequestResponseFormat);

        when(componentUtils.convertJsonToObjectUsingObjectMapper(any(), any(), eq(Resource.class),
                eq(AuditingActionEnum.UPDATE_RESOURCE_METADATA), eq(ComponentTypeEnum.RESOURCE)))
                .thenReturn(updateResourceMetadataEither);

        when(resourceBusinessLogic.updateResourceMetadata(eq(resourceId.toLowerCase()), any(), any(), any(User.class),
                eq(false)))
                .thenReturn(new Resource());

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .put(Entity.json(EMPTY_JSON));

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
    }

    @Test
    public void updateResourceMetadataExceptionDuringUpdateTest() {
        String resourceId = RESOURCE_ID;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_ID, resourceId);

        String formatEndpoint = "/v1/catalog/resources/{resourceId}/metadata";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        given(componentUtils.convertJsonToObjectUsingObjectMapper(any(), any(), eq(Resource.class),
                eq(AuditingActionEnum.UPDATE_RESOURCE_METADATA), eq(ComponentTypeEnum.RESOURCE)))
                .willAnswer( invocation -> { throw new IOException("Test exception: updateResourceMetadata"); });

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .put(Entity.json(EMPTY_JSON));

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }

    @Test
    public void updateResourceMetadataCategoryTest() {
        String resourceId = RESOURCE_ID;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_ID, resourceId);

        String formatEndpoint = "/v1/catalog/resources/{resourceId}/metadata";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        Resource initialResource = new Resource();
        Either<Resource, ResponseFormat> updateResourceMetadataEither = Either.left(initialResource);

        when(componentUtils.convertJsonToObjectUsingObjectMapper(any(), any(), eq(Resource.class),
                eq(AuditingActionEnum.UPDATE_RESOURCE_METADATA), eq(ComponentTypeEnum.RESOURCE)))
                .thenReturn(updateResourceMetadataEither);

        when(resourceBusinessLogic.updateResourceMetadata(eq(resourceId.toLowerCase()), eq(initialResource), any(),
                any(User.class), eq(false)))
                .thenReturn(new Resource());

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .put(Entity.json(EMPTY_JSON));

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
    }

    @Test
    public void updateResourceParsingUncussessfulTest() {
        String resourceId = RESOURCE_ID;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_ID, resourceId);

        String formatEndpoint = "/v1/catalog/resources/{resourceId}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        Either<Resource, ResponseFormat> updateResourceEither = Either.right(badRequestResponseFormat);

        when(componentUtils.convertJsonToObjectUsingObjectMapper(eq(NON_UI_IMPORT_JSON), any(User.class),
                eq(Resource.class), eq(AuditingActionEnum.UPDATE_RESOURCE_METADATA), eq(ComponentTypeEnum.RESOURCE)))
                .thenReturn(updateResourceEither);

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .put(Entity.json(NON_UI_IMPORT_JSON));

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
    }

    @Test
    public void updateResourceExceptionDuringUpdateTest() {
        String resourceId = RESOURCE_ID;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_ID, resourceId);

        String formatEndpoint = "/v1/catalog/resources/{resourceId}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        given(componentUtils.convertJsonToObjectUsingObjectMapper(eq(NON_UI_IMPORT_JSON), any(User.class),
                eq(Resource.class), eq(AuditingActionEnum.UPDATE_RESOURCE_METADATA), eq(ComponentTypeEnum.RESOURCE)))
                .willAnswer( invocation -> { throw new IOException("Test exception: updateResource"); });

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .put(Entity.json(NON_UI_IMPORT_JSON));

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }

    @Test
    public void updateResourceNonUiImportTest() {
        String resourceId = RESOURCE_ID;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(RESOURCE_ID, resourceId);

        String formatEndpoint = "/v1/catalog/resources/{resourceId}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        Either<Resource, ResponseFormat> updateResourceEither = Either.left(new Resource());

        when(componentUtils.convertJsonToObjectUsingObjectMapper(eq(NON_UI_IMPORT_JSON), any(User.class), eq(Resource.class),
                eq(AuditingActionEnum.UPDATE_RESOURCE_METADATA), eq(ComponentTypeEnum.RESOURCE)))
                .thenReturn(updateResourceEither);

        when(resourceBusinessLogic.validateAndUpdateResourceFromCsar(any(), any(), any(), any(), eq(resourceId)))
                .thenReturn(new Resource());

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .put(Entity.json(NON_UI_IMPORT_JSON));

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
    }

    @Test
    public void getResourceFromCsarTryGetNonExistingResourceTest() {
        String csarUuid = CSAR_UUID;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(CSAR_UUID, csarUuid);

        String formatEndpoint = "/v1/catalog/resources/csar/{csaruuid}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");
        
        Either<Resource, ResponseFormat> getResourceFromCsarEither = Either.right(notFoundResponseFormat);
        when(resourceBusinessLogic.getLatestResourceFromCsarUuid(eq(csarUuid), any(User.class)))
                .thenReturn(getResourceFromCsarEither);

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .get();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
    }

    @Test
    public void getResourceFromCsarExceptionDuringGettingTest() {
        String csarUuid = CSAR_UUID;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(CSAR_UUID, csarUuid);

        String formatEndpoint = "/v1/catalog/resources/csar/{csaruuid}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        given(resourceBusinessLogic.getLatestResourceFromCsarUuid(eq(csarUuid), any(User.class)))
                .willAnswer( invocation -> { throw new IOException("Test exception: getResourceFromCsar"); });

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .get();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }

    @Test
    public void getResourceFromCsarTest() {
        String csarUuid = CSAR_UUID;
        Map<String,String> parametersMap = new HashMap<>();
        parametersMap.put(CSAR_UUID, csarUuid);

        String formatEndpoint = "/v1/catalog/resources/csar/{csaruuid}";
        String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");

        Either<Resource, ResponseFormat> getResourceFromCsarEither = Either.left(new Resource());
        when(resourceBusinessLogic.getLatestResourceFromCsarUuid(eq(csarUuid), any(User.class)))
                .thenReturn(getResourceFromCsarEither);

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .get();

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
    }

    @Test
    public void createResourceExceptionDuringCreateTest() {
        String path = "/v1/catalog/resources";

        given(componentUtils.convertJsonToObjectUsingObjectMapper(eq(NON_UI_IMPORT_JSON), any(User.class),
                eq(Resource.class), eq(AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.RESOURCE)))
                .willAnswer( invocation -> { throw new IOException("Test exception: createResource"); });

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .post(Entity.json(NON_UI_IMPORT_JSON));

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }

    @Test
    public void createResourceNonUiImportProcessingFailedTest() {
        String path = "/v1/catalog/resources";

        Either<Resource, ResponseFormat> createResourceEither = Either.right(badRequestResponseFormat);

        when(componentUtils.convertJsonToObjectUsingObjectMapper(eq(NON_UI_IMPORT_JSON), any(User.class),
                eq(Resource.class), eq(AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.RESOURCE)))
                .thenReturn(createResourceEither);

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .post(Entity.json(NON_UI_IMPORT_JSON));

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
    }

    @Test
    public void createResourceNonUiImportTest() {
        String path = "/v1/catalog/resources";

        Either<Resource, ResponseFormat> createResourceEither = Either.left(new Resource());

        when(componentUtils.convertJsonToObjectUsingObjectMapper(eq(NON_UI_IMPORT_JSON), any(User.class),
                eq(Resource.class), eq(AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.RESOURCE)))
                .thenReturn(createResourceEither);

        when(resourceBusinessLogic.createResource(eq(createResourceEither.left().value()), eq(AuditingActionEnum.CREATE_RESOURCE),
                any(User.class), any(), any()))
                .thenReturn(new Resource());

        Response response = target()
                .path(path)
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .header(Constants.USER_ID_HEADER, user.getUserId())
                .post(Entity.json(NON_UI_IMPORT_JSON));

        assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CREATED);
    }

    private void encodeAndSetPayload(UploadResourceInfo mdJson, String payload) {
        byte[] encodedBase64Payload = Base64.encodeBase64(payload.getBytes());
        mdJson.setPayloadData(new String(encodedBase64Payload));
    }

    private void runAndVerifyActionStatusError(UploadResourceInfo mdJson, ActionStatus invalidResourcePayload) {
        setMD5OnRequest(true, mdJson);
        Response response = target().path("/v1/catalog/resources").request(MediaType.APPLICATION_JSON).post(Entity.json(gson.toJson(mdJson)), Response.class);
        Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(Mockito.any(ActionStatus.class));
        Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(invalidResourcePayload);
        assertEquals(response.getStatus(), HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }

    private void setMD5OnRequest(boolean isValid, UploadResourceInfo json) {
        String md5 = (isValid) ? GeneralUtility.calculateMD5Base64EncodedByString(gson.toJson(json)) : "stam=";
        when(request.getHeader(Constants.MD5_HEADER)).thenReturn(md5);

    }

    private UploadResourceInfo buildValidJson() {
        UploadResourceInfo ret = new UploadResourceInfo();
        ret.setName("ciMyCompute");
        ret.setPayloadName("ciMyCompute.yml");
        ret.addSubCategory("Application Layer 4+", "Application Servers");
        ret.setDescription("ResourceDescription");
        ret.setVendorName("VendorName");
        ret.setVendorRelease("VendorRelease");
        ret.setContactId("AT1234");
        ret.setIcon("router");
        ret.setTags(Collections.singletonList("ciMyCompute"));
        ret.setPayloadData(
                "dG9zY2FfZGVmaW5pdGlvbnNfdmVyc2lvbjogdG9zY2Ffc2ltcGxlX3lhbWxfMV8wXzANCm5vZGVfdHlwZXM6IA0KICBvcmcub3BlbmVjb21wLnJlc291cmNlLk15Q29tcHV0ZToNCiAgICBkZXJpdmVkX2Zyb206IHRvc2NhLm5vZGVzLlJvb3QNCiAgICBhdHRyaWJ1dGVzOg0KICAgICAgcHJpdmF0ZV9hZGRyZXNzOg0KICAgICAgICB0eXBlOiBzdHJpbmcNCiAgICAgIHB1YmxpY19hZGRyZXNzOg0KICAgICAgICB0eXBlOiBzdHJpbmcNCiAgICAgIG5ldHdvcmtzOg0KICAgICAgICB0eXBlOiBtYXANCiAgICAgICAgZW50cnlfc2NoZW1hOg0KICAgICAgICAgIHR5cGU6IHRvc2NhLmRhdGF0eXBlcy5uZXR3b3JrLk5ldHdvcmtJbmZvDQogICAgICBwb3J0czoNCiAgICAgICAgdHlwZTogbWFwDQogICAgICAgIGVudHJ5X3NjaGVtYToNCiAgICAgICAgICB0eXBlOiB0b3NjYS5kYXRhdHlwZXMubmV0d29yay5Qb3J0SW5mbw0KICAgIHJlcXVpcmVtZW50czoNCiAgICAgIC0gbG9jYWxfc3RvcmFnZTogDQogICAgICAgICAgY2FwYWJpbGl0eTogdG9zY2EuY2FwYWJpbGl0aWVzLkF0dGFjaG1lbnQNCiAgICAgICAgICBub2RlOiB0b3NjYS5ub2Rlcy5CbG9ja1N0b3JhZ2UNCiAgICAgICAgICByZWxhdGlvbnNoaXA6IHRvc2NhLnJlbGF0aW9uc2hpcHMuQXR0YWNoZXNUbw0KICAgICAgICAgIG9jY3VycmVuY2VzOiBbMCwgVU5CT1VOREVEXSAgDQogICAgY2FwYWJpbGl0aWVzOg0KICAgICAgaG9zdDogDQogICAgICAgIHR5cGU6IHRvc2NhLmNhcGFiaWxpdGllcy5Db250YWluZXINCiAgICAgICAgdmFsaWRfc291cmNlX3R5cGVzOiBbdG9zY2Eubm9kZXMuU29mdHdhcmVDb21wb25lbnRdIA0KICAgICAgZW5kcG9pbnQgOg0KICAgICAgICB0eXBlOiB0b3NjYS5jYXBhYmlsaXRpZXMuRW5kcG9pbnQuQWRtaW4gDQogICAgICBvczogDQogICAgICAgIHR5cGU6IHRvc2NhLmNhcGFiaWxpdGllcy5PcGVyYXRpbmdTeXN0ZW0NCiAgICAgIHNjYWxhYmxlOg0KICAgICAgICB0eXBlOiB0b3NjYS5jYXBhYmlsaXRpZXMuU2NhbGFibGUNCiAgICAgIGJpbmRpbmc6DQogICAgICAgIHR5cGU6IHRvc2NhLmNhcGFiaWxpdGllcy5uZXR3b3JrLkJpbmRhYmxl");
        return ret;
    }

    @Override
    protected Application configure() {
        ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        forceSet(TestProperties.CONTAINER_PORT, "0");
        return new ResourceConfig(ResourcesServlet.class)
            .register(new AbstractBinder() {
                @Override
                protected void configure() {
                    bind(request).to(HttpServletRequest.class);
                    bind(servletUtils).to(ServletUtils.class);
                    bind(componentUtils).to(ComponentsUtils.class);
                    bind(userBusinessLogic).to(UserBusinessLogic.class);
                    bind(resourceBusinessLogic).to(ResourceBusinessLogic.class);
                    bind(groupBL).to(GroupBusinessLogic.class);
                    bind(componentInstanceBL).to(ComponentInstanceBusinessLogic.class);
                    bind(resourceImportManager).to(ResourceImportManager.class);
                }
            })
            .property("contextConfig", context);
    }
}