Onboarding upload control
[sdc.git] / openecomp-be / api / openecomp-sdc-rest-webapp / vendor-software-products-rest / vendor-software-products-rest-services / src / test / java / org / openecomp / sdcrests / vsp / rest / controllers / OrchestrationTemplateCandidateUploadManagerControllerImplTest.java
1 /*
2  * -
3  *  ============LICENSE_START=======================================================
4  *  Copyright (C) 2022 Nordix Foundation.
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *       http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.sdcrests.vsp.rest.controllers;
23
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertTrue;
26 import static org.mockito.Mockito.when;
27
28 import java.util.Date;
29 import java.util.Optional;
30 import java.util.UUID;
31 import javax.ws.rs.core.Response;
32 import org.apache.http.HttpStatus;
33 import org.junit.jupiter.api.BeforeEach;
34 import org.junit.jupiter.api.Test;
35 import org.mockito.InjectMocks;
36 import org.mockito.Mock;
37 import org.mockito.MockitoAnnotations;
38 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspUploadStatus;
39 import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspUploadStatusDto;
40 import org.openecomp.sdcrests.vsp.rest.services.OrchestrationTemplateCandidateUploadManager;
41
42 class OrchestrationTemplateCandidateUploadManagerControllerImplTest {
43
44     @Mock
45     private OrchestrationTemplateCandidateUploadManager orchestrationTemplateCandidateUploadManager;
46
47     @InjectMocks
48     private OrchestrationTemplateCandidateUploadManagerControllerImpl packageUploadManagerControllerImpl;
49
50     @BeforeEach
51     void setUp() {
52         MockitoAnnotations.openMocks(this);
53     }
54
55     @Test
56     void getLatestSuccessTest() {
57         //given
58         final String vspId = "vspId";
59         final String vspVersionId = "vspVersionId";
60         final String username = "username";
61         final VspUploadStatusDto vspUploadStatusDto = buildDefaultVspUploadStatus(vspId, vspVersionId);
62         //when
63         when(orchestrationTemplateCandidateUploadManager.findLatestStatus(vspId, vspVersionId, username)).thenReturn(Optional.of(vspUploadStatusDto));
64
65         final Response response = packageUploadManagerControllerImpl.getLatestStatus(vspId, vspVersionId, username);
66         //then
67         assertEquals(HttpStatus.SC_OK, response.getStatus());
68         final Object actualEntity = response.getEntity();
69         assertTrue(actualEntity instanceof VspUploadStatusDto);
70         assertEquals(vspUploadStatusDto, actualEntity);
71     }
72
73     private VspUploadStatusDto buildDefaultVspUploadStatus(final String vspId, final String vspVersionId) {
74         final var vspUploadStatusDto = new VspUploadStatusDto();
75         vspUploadStatusDto.setStatus(VspUploadStatus.UPLOADING);
76         vspUploadStatusDto.setLockId(UUID.randomUUID());
77         vspUploadStatusDto.setVspId(vspId);
78         vspUploadStatusDto.setVspVersionId(vspVersionId);
79         vspUploadStatusDto.setCreated(new Date());
80         vspUploadStatusDto.setComplete(false);
81         return vspUploadStatusDto;
82     }
83
84     @Test
85     void buildGetUrlSuccessTest() {
86         final String vspId = "vspId";
87         final String vspVersionId = "vspVersionId";
88         final String actualGetUrl = OrchestrationTemplateCandidateUploadManagerControllerImpl.buildGetUrl(vspId, vspVersionId);
89         assertEquals("/v1.0/vendor-software-products/vspId/versions/vspVersionId/orchestration-template-candidate/upload", actualGetUrl);
90     }
91
92 }