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.junit.Assert.assertEquals;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.Mockito.doReturn;
28 import java.io.ByteArrayInputStream;
29 import java.io.ByteArrayOutputStream;
31 import java.io.IOException;
32 import java.io.InputStream;
34 import java.util.zip.ZipOutputStream;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.mockito.InjectMocks;
39 import org.mockito.Mock;
40 import org.mockito.MockitoAnnotations;
41 import org.mockito.Spy;
42 import org.openecomp.core.model.dao.ServiceModelDao;
43 import org.openecomp.core.model.types.ServiceElement;
44 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
45 import org.openecomp.sdc.healing.api.HealingManager;
46 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
47 import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager;
48 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
49 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
50 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity;
51 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
52 import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl;
53 import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor;
54 import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.CandidateServiceImpl;
55 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
56 import org.openecomp.sdc.vendorsoftwareproduct.utils.VSPCommon;
57 import org.openecomp.sdc.versioning.dao.types.Version;
59 public class UploadFileTest {
60 private static final String USER1 = "vspTestUser1";
62 public static final Version VERSION01 = new Version(0, 1);
65 private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
67 private CandidateServiceImpl candidateService;
69 private HealingManager healingManagerMock;
71 private CompositionDataExtractor compositionDataExtractorMock;
73 private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
75 private CompositionEntityDataManager compositionEntityDataManagerMock;
77 private VendorSoftwareProductInfoDao vspInfoDaoMock;
80 private OrchestrationTemplateCandidateManagerImpl candidateManager;
82 private static String vlm1Id;
83 public static String id001 = null;
84 public static String id002 = null;
86 public static Version activeVersion002 = null;
90 public void setUp() throws Exception {
91 MockitoAnnotations.initMocks(this);
95 public void testUploadFile() {
96 VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0));
97 doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class));
98 candidateManager.upload(id001, activeVersion002, getZipInputStream("/legalUpload"),
99 OnboardingTypesEnum.ZIP.toString(), "legalUpload");
103 private void testLegalUpload(String vspId, Version version, InputStream upload, String user) {
104 UploadFileResponse uploadFileResponse = candidateManager.upload(vspId, activeVersion002,
105 upload, OnboardingTypesEnum.ZIP.toString(), "file");
106 assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.ZIP);
107 OrchestrationTemplateEntity uploadData = orchestrationTemplateDataDaoMock.get(vspId, version);
111 public InputStream getZipInputStream(String name) {
112 URL url = this.getClass().getResource(name);
113 File templateDir = new File(url.getFile());
115 ByteArrayOutputStream baos = new ByteArrayOutputStream();
116 try (ZipOutputStream zos = new ZipOutputStream(baos)) {
117 VSPCommon.zipDir(templateDir, "", zos, true);
118 } catch (IOException e) {
121 return new ByteArrayInputStream(baos.toByteArray());