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 org.mockito.InjectMocks;
25 import org.mockito.Mock;
26 import org.mockito.MockitoAnnotations;
27 import org.mockito.Spy;
28 import org.openecomp.core.model.dao.ServiceModelDao;
29 import org.openecomp.core.model.types.ServiceElement;
30 import org.openecomp.sdc.healing.api.HealingManager;
31 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
32 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
33 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
34 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
35 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity;
36 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
37 import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl;
38 import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor;
39 import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager;
40 import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
41 import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.CandidateServiceImpl;
42 import org.openecomp.sdc.vendorsoftwareproduct.utils.VSPCommon;
43 import org.openecomp.sdc.versioning.dao.types.Version;
44 import org.testng.annotations.BeforeMethod;
45 import org.testng.annotations.Test;
47 import java.io.ByteArrayInputStream;
48 import java.io.ByteArrayOutputStream;
50 import java.io.IOException;
51 import java.io.InputStream;
53 import java.util.zip.ZipOutputStream;
55 import static org.mockito.Matchers.any;
56 import static org.mockito.Matchers.eq;
57 import static org.mockito.Mockito.doReturn;
59 public class UploadFileTest {
60 private static final String USER1 = "vspTestUser1";
62 public static final Version VERSION01 = new Version(0, 1);
64 private VendorSoftwareProductDao vendorSoftwareProductDaoMock;
66 private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
68 private CandidateServiceImpl candidateService;
70 private HealingManager healingManagerMock;
72 private CompositionDataExtractor compositionDataExtractorMock;
74 private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
76 private CompositionEntityDataManager compositionEntityDataManagerMock;
78 private VendorSoftwareProductInfoDao vspInfoDaoMock;
81 private OrchestrationTemplateCandidateManagerImpl candidateManager;
83 private static String vlm1Id;
84 public static String id001 = null;
85 public static String id002 = null;
87 public static Version activeVersion002 = null;
91 public void setUp() throws Exception {
92 MockitoAnnotations.initMocks(this);
96 public void testUploadFile() {
97 VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0));
98 doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class));
99 candidateManager.upload(id001, activeVersion002, getZipInputStream("/legalUpload"), USER1);
103 private void testLegalUpload(String vspId, Version version, InputStream upload, String user) {
104 candidateManager.upload(vspId, activeVersion002, upload, user);
106 UploadDataEntity uploadData =
107 orchestrationTemplateDataDaoMock.getOrchestrationTemplate(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 ZipOutputStream zos = new ZipOutputStream(baos);
118 VSPCommon.zipDir(templateDir, "", zos, true);
121 } catch (IOException e) {
124 return new ByteArrayInputStream(baos.toByteArray());