1 package org.openecomp.sdc.vendorsoftwareproduct.impl;
3 import org.mockito.InjectMocks;
4 import org.mockito.Mock;
5 import org.mockito.MockitoAnnotations;
6 import org.openecomp.core.model.dao.ServiceModelDao;
7 import org.openecomp.core.model.types.ServiceElement;
8 import org.openecomp.core.utilities.file.FileUtils;
9 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
10 import org.openecomp.sdc.datatypes.error.ErrorLevel;
11 import org.openecomp.sdc.healing.api.HealingManager;
12 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
13 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
14 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
15 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateDataEntity;
16 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
17 import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor;
18 import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager;
19 import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
20 import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse;
21 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
22 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileStatus;
23 import org.openecomp.sdc.vendorsoftwareproduct.utils.ZipFileUtils;
24 import org.openecomp.sdc.versioning.dao.types.Version;
25 import org.testng.Assert;
26 import org.testng.annotations.BeforeMethod;
28 import java.io.IOException;
29 import java.nio.ByteBuffer;
30 import java.util.Optional;
32 import static org.mockito.Matchers.anyObject;
33 import static org.mockito.Mockito.doReturn;
37 * @since November 08, 2016
39 public class OrchestrationTemplateCandidateManagerImplTest {
40 private static final String USER1 = "vspTestUser1";
41 private static final String VSP_ID = "vspId";
42 private static final Version VERSION01 = new Version(0, 1);
45 private VendorSoftwareProductDao vendorSoftwareProductDaoMock;
47 private VendorSoftwareProductInfoDao vspInfoDaoMock;
49 private CandidateService candidateServiceMock;
51 private HealingManager healingManagerMock;
53 private CompositionDataExtractor compositionDataExtractorMock;
55 private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
57 private CompositionEntityDataManager compositionEntityDataManagerMock;
59 private OrchestrationTemplateCandidateManagerImpl candidateManager;
62 public void setUp() throws Exception {
63 MockitoAnnotations.initMocks(this);
66 // TODO: 3/15/2017 fix and enable
68 public void testProcessEmptyUpload() throws IOException {
69 /* testLegalUpload(VSP_ID, activeVersion002,
70 new ZipFileUtils().getZipInputStream("/vspmanager/zips/emptyComposition.zip"), USER1);*/
72 OrchestrationTemplateCandidateDataEntity orchTemplate =
73 new OrchestrationTemplateCandidateDataEntity(VSP_ID, VERSION01);
75 .setContentData(ByteBuffer.wrap(FileUtils.toByteArray(new ZipFileUtils().getZipInputStream
76 ("/vspmanager/zips/emptyComposition.zip"))));
77 orchTemplate.setFilesDataStructure("{\n" +
80 " \"isBase\": false,\n" +
81 " \"yaml\": \"ep-jsa_net.yaml\"\n" +
85 doReturn(orchTemplate)
86 .when(candidateServiceMock).getOrchestrationTemplateCandidate(VSP_ID, VERSION01);
88 doReturn(new VspDetails(VSP_ID, VERSION01))
89 .when(vspInfoDaoMock).get(anyObject());
91 doReturn("{}").when(candidateServiceMock).createManifest(anyObject(), anyObject());
92 doReturn(Optional.empty()).when(candidateServiceMock)
93 .fetchZipFileByteArrayInputStream(anyObject(), anyObject(), anyObject(), OnboardingTypesEnum.ZIP, anyObject());
96 OrchestrationTemplateActionResponse response =
97 candidateManager.process(VSP_ID, VERSION01, USER1);
99 Assert.assertNotNull(response);
102 @Test(dependsOnMethods = {"testUploadFile"})
103 public void testUploadNotExistingFile() throws IOException {
104 URL url = this.getClass().getResource("notExist.zip");
105 testLegalUpload(VSP_ID, activeVersion002, url == null ? null : url.openStream(), USER1);
108 private void testLegalUpload(String vspId, Version version, InputStream upload, String user) {
109 candidateManager.upload(vspId, VERSION01, upload, USER1);
110 candidateManager.process(vspId, VERSION01, user);
114 vendorSoftwareProductDaoMock.getUploadData(new UploadDataEntity(vspId, version));
115 Assert.assertNotNull(uploadData);
118 // TODO: 3/15/2017 fix and enable
120 public void testUploadWith2VolsIn1HeatInManifest() {
121 doReturn(Optional.empty()).when(candidateServiceMock).validateNonEmptyFileToUpload(anyObject());
122 doReturn(Optional.empty()).when(candidateServiceMock).validateRawZipData(anyObject());
124 UploadFileResponse uploadFileResponse = candidateManager
125 .upload(VSP_ID, VERSION01, new ZipFileUtils().getZipInputStream("/legalUploadWithWarning"),
126 USER1, "zip", "legalUploadWithWarning");
127 Assert.assertTrue(uploadFileResponse.getStatus() == UploadFileStatus.Success);
129 uploadFileResponse.getErrors().get("uploadFile").get(0).getLevel() == ErrorLevel.WARNING);
130 Assert.assertTrue(uploadFileResponse.getErrors().get("uploadFile").get(0).getMessage()
131 .equals("heat contains more then one vol. selecting only first vol"));
134 // TODO: 3/15/2017 fix and enable
136 public void testUploadWithManifest() {
137 UploadFileResponse uploadFileResponse = candidateManager
138 .upload(VSP_ID, VERSION01, new ZipFileUtils().getZipInputStream("/legalUploadWithWarning"),
139 USER1, "zip", "legalUploadWithWarning");
140 Assert.assertTrue(uploadFileResponse.getStatus() == UploadFileStatus.Success);
142 uploadFileResponse.getErrors().get("uploadFile").get(0).getLevel() == ErrorLevel.WARNING);
143 Assert.assertTrue(uploadFileResponse.getErrors().get("uploadFile").get(0).getMessage()
144 .equals("heat contains more then one vol. selecting only first vol"));