2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.vendorsoftwareproduct.tree;
24 import static org.mockito.Matchers.any;
25 import static org.mockito.Mockito.doReturn;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.MockitoAnnotations;
30 import org.mockito.Spy;
31 import org.openecomp.core.model.dao.ServiceModelDao;
32 import org.openecomp.core.model.types.ServiceElement;
33 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
34 import org.openecomp.sdc.healing.api.HealingManager;
35 import org.openecomp.sdc.logging.api.Logger;
36 import org.openecomp.sdc.logging.api.LoggerFactory;
37 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
38 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
39 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
40 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
41 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity;
42 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
43 import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl;
44 import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor;
45 import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager;
46 import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.CandidateServiceImpl;
47 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
48 import org.openecomp.sdc.vendorsoftwareproduct.utils.VSPCommon;
49 import org.openecomp.sdc.versioning.dao.types.Version;
50 import org.testng.annotations.BeforeMethod;
51 import org.testng.annotations.Test;
55 import java.util.zip.ZipOutputStream;
57 import static org.mockito.Matchers.any;
58 import static org.mockito.Mockito.doReturn;
59 import static org.testng.Assert.assertEquals;
61 public class UploadFileTest {
62 private static final String USER1 = "vspTestUser1";
64 public static final Version VERSION01 = new Version(0, 1);
66 private VendorSoftwareProductDao vendorSoftwareProductDaoMock;
68 private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
70 private CandidateServiceImpl candidateService;
72 private HealingManager healingManagerMock;
74 private CompositionDataExtractor compositionDataExtractorMock;
76 private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
78 private CompositionEntityDataManager compositionEntityDataManagerMock;
80 private VendorSoftwareProductInfoDao vspInfoDaoMock;
83 private OrchestrationTemplateCandidateManagerImpl candidateManager;
85 private static String vlm1Id;
86 public static String id001 = null;
87 public static String id002 = null;
89 public static Version activeVersion002 = null;
93 public void setUp() throws Exception {
94 MockitoAnnotations.initMocks(this);
98 public void testUploadFile() {
99 VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0));
100 doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class));
101 candidateManager.upload(id001, activeVersion002, getZipInputStream("/legalUpload"), USER1, OnboardingTypesEnum.ZIP.toString(), "legalUpload");
105 private void testLegalUpload(String vspId, Version version, InputStream upload, String user) {
106 UploadFileResponse uploadFileResponse = candidateManager.upload(vspId, activeVersion002,
107 upload, user, OnboardingTypesEnum.ZIP.toString(),"file" );
108 assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.ZIP);
109 UploadDataEntity uploadData =
110 orchestrationTemplateDataDaoMock.getOrchestrationTemplate(vspId, version);
114 public InputStream getZipInputStream(String name) {
115 URL url = this.getClass().getResource(name);
116 File templateDir = new File(url.getFile());
118 ByteArrayOutputStream baos = new ByteArrayOutputStream();
119 try (ZipOutputStream zos = new ZipOutputStream(baos)) {
120 VSPCommon.zipDir(templateDir, "", zos, true);
121 } catch (IOException e) {
124 return new ByteArrayInputStream(baos.toByteArray());