Create new VSP, onboard from TOSCA file - UI
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / impl / OrchestrationTemplateCandidateManagerImplTest.java
1 package org.openecomp.sdc.vendorsoftwareproduct.impl;
2
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;
27
28 import java.io.IOException;
29 import java.nio.ByteBuffer;
30 import java.util.Optional;
31
32 import static org.mockito.Matchers.anyObject;
33 import static org.mockito.Mockito.doReturn;
34
35 /**
36  * @author Avrahamg
37  * @since November 08, 2016
38  */
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);
43
44   @Mock
45   private VendorSoftwareProductDao vendorSoftwareProductDaoMock;
46   @Mock
47   private VendorSoftwareProductInfoDao vspInfoDaoMock;
48   @Mock
49   private CandidateService candidateServiceMock;
50   @Mock
51   private HealingManager healingManagerMock;
52   @Mock
53   private CompositionDataExtractor compositionDataExtractorMock;
54   @Mock
55   private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
56   @Mock
57   private CompositionEntityDataManager compositionEntityDataManagerMock;
58   @InjectMocks
59   private OrchestrationTemplateCandidateManagerImpl candidateManager;
60
61   @BeforeMethod
62   public void setUp() throws Exception {
63     MockitoAnnotations.initMocks(this);
64   }
65
66   // TODO: 3/15/2017 fix and enable
67   //@Test
68   public void testProcessEmptyUpload() throws IOException {
69 /*    testLegalUpload(VSP_ID, activeVersion002,
70         new ZipFileUtils().getZipInputStream("/vspmanager/zips/emptyComposition.zip"), USER1);*/
71
72     OrchestrationTemplateCandidateDataEntity orchTemplate =
73         new OrchestrationTemplateCandidateDataEntity(VSP_ID, VERSION01);
74     orchTemplate
75         .setContentData(ByteBuffer.wrap(FileUtils.toByteArray(new ZipFileUtils().getZipInputStream
76             ("/vspmanager/zips/emptyComposition.zip"))));
77     orchTemplate.setFilesDataStructure("{\n" +
78         "  \"modules\": [\n" +
79         "    {\n" +
80         "      \"isBase\": false,\n" +
81         "      \"yaml\": \"ep-jsa_net.yaml\"\n" +
82         "    }\n" +
83         "  ]\n" +
84         "}");
85     doReturn(orchTemplate)
86         .when(candidateServiceMock).getOrchestrationTemplateCandidate(VSP_ID, VERSION01);
87
88     doReturn(new VspDetails(VSP_ID, VERSION01))
89         .when(vspInfoDaoMock).get(anyObject());
90
91     doReturn("{}").when(candidateServiceMock).createManifest(anyObject(), anyObject());
92     doReturn(Optional.empty()).when(candidateServiceMock)
93         .fetchZipFileByteArrayInputStream(anyObject(), anyObject(), anyObject(), OnboardingTypesEnum.ZIP, anyObject());
94
95
96     OrchestrationTemplateActionResponse response =
97         candidateManager.process(VSP_ID, VERSION01, USER1);
98
99     Assert.assertNotNull(response);
100   }
101   /*
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);
106   }
107
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);
111
112     UploadDataEntity
113         uploadData =
114         vendorSoftwareProductDaoMock.getUploadData(new UploadDataEntity(vspId, version));
115     Assert.assertNotNull(uploadData);
116   }*/
117
118   // TODO: 3/15/2017 fix and enable
119   //@Test
120   public void testUploadWith2VolsIn1HeatInManifest() {
121     doReturn(Optional.empty()).when(candidateServiceMock).validateNonEmptyFileToUpload(anyObject());
122     doReturn(Optional.empty()).when(candidateServiceMock).validateRawZipData(anyObject());
123
124     UploadFileResponse uploadFileResponse = candidateManager
125         .upload(VSP_ID, VERSION01, new ZipFileUtils().getZipInputStream("/legalUploadWithWarning"),
126             USER1, "zip", "legalUploadWithWarning");
127     Assert.assertTrue(uploadFileResponse.getStatus() == UploadFileStatus.Success);
128     Assert.assertTrue(
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"));
132   }
133
134   // TODO: 3/15/2017 fix and enable
135   //@Test
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);
141     Assert.assertTrue(
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"));
145   }
146
147
148 }