a9223db285d6ec5ca16554bbbcd2b97450ea19f1
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.vendorsoftwareproduct.impl;
18
19 import static org.mockito.Matchers.any;
20 import static org.mockito.Matchers.anyObject;
21 import static org.mockito.Mockito.doNothing;
22 import static org.mockito.Mockito.doReturn;
23 import static org.mockito.Mockito.doThrow;
24 import static org.mockito.Mockito.never;
25 import static org.mockito.Mockito.verify;
26
27 import org.mockito.ArgumentCaptor;
28 import org.mockito.Captor;
29 import org.mockito.InjectMocks;
30 import org.mockito.Mock;
31 import org.mockito.MockitoAnnotations;
32 import org.mockito.Spy;
33 import org.openecomp.core.enrichment.factory.EnrichmentManagerFactory;
34 import org.openecomp.core.factory.impl.AbstractFactoryBase;
35 import org.openecomp.core.model.dao.EnrichedServiceModelDao;
36 import org.openecomp.core.model.dao.ServiceModelDao;
37 import org.openecomp.core.model.types.ServiceElement;
38 import org.openecomp.core.utilities.file.FileContentHandler;
39 import org.openecomp.core.utilities.file.FileUtils;
40 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
41 import org.openecomp.sdc.common.errors.CoreException;
42 import org.openecomp.sdc.common.errors.ErrorCategory;
43 import org.openecomp.sdc.common.errors.ErrorCode;
44 import org.openecomp.sdc.common.errors.Messages;
45 import org.openecomp.sdc.healing.api.HealingManager;
46 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
47 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
48 import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService;
49 import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager;
50 import org.openecomp.sdc.vendorsoftwareproduct.ManualVspToscaManager;
51 import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager;
52 import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
53 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
54 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao;
55 import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao;
56 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
57 import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao;
58 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
59 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
60 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
61 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity;
62 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
63 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
64 import org.openecomp.sdc.vendorsoftwareproduct.impl.mock.EnrichmentManagerFactoryImpl;
65 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator;
66 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
67 import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
68 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor;
69 import org.openecomp.sdc.versioning.VersioningManager;
70 import org.openecomp.sdc.versioning.dao.types.Version;
71 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
72 import org.openecomp.sdc.versioning.types.VersionInfo;
73 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
74 import org.testng.Assert;
75 import org.testng.annotations.AfterMethod;
76 import org.testng.annotations.BeforeMethod;
77 import org.testng.annotations.Test;
78
79 import java.io.File;
80 import java.io.FileInputStream;
81 import java.io.IOException;
82 import java.io.InputStream;
83 import java.net.URL;
84 import java.nio.ByteBuffer;
85 import java.util.ArrayList;
86 import java.util.Arrays;
87 import java.util.Collections;
88 import java.util.HashMap;
89 import java.util.List;
90 import java.util.zip.ZipEntry;
91 import java.util.zip.ZipInputStream;
92
93
94 public class VendorSoftwareProductManagerImplTest {
95   private static final String INVALID_VERSION_MSG = "Invalid requested version.";
96
97   private static String VSP_ID = "vspId";
98   private static String VERSION_ID = "versionId";
99   public static final Version VERSION01 = new Version(0, 1);
100   private static final Version VERSION10 = new Version(1, 0);
101   private static final String USER1 = "vspTestUser1";
102   private static final String USER2 = "vspTestUser2";
103   private static final String USER3 = "vspTestUser3";
104   private static String id006 = null;
105   private static String id007 = null;
106
107   @Mock
108   private VersioningManager versioningManagerMock;
109   @Mock
110   private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
111   @Mock
112   private VendorLicenseFacade vendorLicenseFacadeMock;
113   @Mock
114   private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
115   @Mock
116   private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDaoMock;
117   @Mock
118   private HealingManager healingManagerMock;
119   @Mock
120   private VendorLicenseArtifactsService licenseArtifactsServiceMock;
121   @Mock
122   private CompositionEntityDataManager compositionEntityDataManagerMock;
123   @Mock
124   private InformationArtifactGenerator informationArtifactGeneratorMock;
125   @Mock
126   private PackageInfoDao packageInfoDao;
127   @Mock
128   private VendorSoftwareProductInfoDao vspInfoDaoMock;
129   @Mock
130   private ManualVspToscaManager manualVspToscaManager;
131   @Mock
132   private DeploymentFlavorDao deploymentFlavorDaoMock;
133
134
135   @Spy
136   @InjectMocks
137   private VendorSoftwareProductManagerImpl vendorSoftwareProductManager;
138
139   @Mock
140   private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManagerMock;
141   @Mock
142   private ComponentDependencyModelDao componentDependencyModelDao;
143   private OrchestrationTemplateCandidateManager candidateManager;
144   private MonitoringUploadsManager monitoringUploadsManager;
145
146   @Captor
147   private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
148
149   @BeforeMethod
150   public void setUp() throws Exception {
151     MockitoAnnotations.initMocks(this);
152   }
153
154   @AfterMethod
155   public void tearDown(){
156     vendorSoftwareProductManager = null;
157   }
158
159
160   @Test
161   public void testCreate() {
162     //doReturn(VERSION01).when(versioningManagerMock).create(anyObject(), anyObject(), anyObject());
163     doReturn("{}")
164         .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject());
165
166     VspDetails vspToCreate =
167         createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
168             "category", "subCategory", "123", null);
169
170     VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate);
171
172     Assert.assertNotNull(vsp);
173     vspToCreate.setId(vsp.getId());
174     vspToCreate.setVersion(VERSION01);
175     assertVspsEquals(vsp, vspToCreate);
176   }
177
178   @Test(expectedExceptions = CoreException.class)
179   public void testUpdateWithExistingName_negative() {
180     VersionInfo versionInfo = new VersionInfo();
181     versionInfo.setActiveVersion(VERSION01);
182     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
183         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
184         VersionableEntityAction.Write);
185
186     VspDetails existingVsp =
187         createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-existingVsp", "vendorName", "vlm1Id",
188             "icon", "category", "subCategory", "123", null);
189     VspDetails updatedVsp =
190         createVspDetails(VSP_ID, VERSION01, "Vsp1_updated", "Test-existingVsp", "vendorName",
191             "vlm1Id", "icon", "category", "subCategory", "123", null);
192     doReturn(existingVsp).when(vspInfoDaoMock)
193         .get(any(VspDetails.class));
194     doThrow(new CoreException(
195         new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build()))
196         .when(vendorSoftwareProductManager)
197         .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
198
199     vendorSoftwareProductManager.updateVsp(updatedVsp);
200   }
201
202   @Test
203   public void testUpdate() {
204     VersionInfo versionInfo = new VersionInfo();
205     versionInfo.setActiveVersion(VERSION01);
206     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
207         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
208         VersionableEntityAction.Write);
209     VspDetails existingVsp =
210         createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
211             "category",
212             "subCategory", "456", null);
213     VspDetails updatedVsp =
214         createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
215             "category_updated",
216             "subCategory", "456", null);
217     existingVsp.setWritetimeMicroSeconds(8L);
218     doReturn(existingVsp).when(vspInfoDaoMock)
219         .get(any(VspDetails.class));
220     doNothing().when(vendorSoftwareProductManager)
221         .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
222
223     vendorSoftwareProductManager.updateVsp(updatedVsp);
224
225     verify(vspInfoDaoMock).update(updatedVsp);
226   }
227
228   @Test
229   public void testUpdateRemoveFG() {
230     VersionInfo versionInfo = new VersionInfo();
231     versionInfo.setActiveVersion(VERSION01);
232     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
233         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
234         VersionableEntityAction.Write);
235     List<String> fgs = new ArrayList<String>();
236     fgs.add("fg1");
237     fgs.add("fg2");
238     VspDetails existingVsp =
239         createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
240             "category",
241             "subCategory", "456", fgs);
242
243     List<String> updFgs = new ArrayList<String>();
244     //updFgs.add("fg2");
245     VspDetails updatedVsp =
246         createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
247             "category_updated",
248             "subCategory", "456", updFgs);
249     existingVsp.setWritetimeMicroSeconds(8L);
250     doReturn(existingVsp).when(vspInfoDaoMock)
251         .get(any(VspDetails.class));
252     doNothing().when(vendorSoftwareProductManager)
253         .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
254
255     DeploymentFlavorEntity dfEntity = new DeploymentFlavorEntity(VSP_ID, VERSION01, "DF_ID");
256     DeploymentFlavor flavor = new DeploymentFlavor();
257     flavor.setFeatureGroupId("fg1");
258     dfEntity.setDeploymentFlavorCompositionData(flavor);
259
260     List<DeploymentFlavorEntity> dfList = new ArrayList<DeploymentFlavorEntity>();
261     dfList.add(dfEntity);
262
263     doReturn(dfList).when(deploymentFlavorDaoMock).list(anyObject());
264
265     vendorSoftwareProductManager.updateVsp(updatedVsp);
266
267     verify(deploymentFlavorDaoMock).update(dfEntity);
268
269     Assert.assertNull(dfEntity.getDeploymentFlavorCompositionData().getFeatureGroupId());
270
271   }
272
273   @Test(expectedExceptions = CoreException.class)
274   public void testGetNonExistingVersion_negative() {
275     Version notExistversion = new Version(43, 8);
276     doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
277     vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion);
278   }
279
280   @Test
281   public void testGetCheckedOutVersion() {
282     VersionInfo versionInfo = new VersionInfo();
283     versionInfo.setActiveVersion(VERSION01);
284     versionInfo.setStatus(VersionStatus.Locked);
285     versionInfo.setLockingUser(USER1);
286     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
287         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
288         VersionableEntityAction.Read);
289
290     VspDetails existingVsp =
291         createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
292             "category",
293             "subCategory", "456", null);
294     existingVsp.setWritetimeMicroSeconds(8L);
295     doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class));
296
297     VspDetails actualVsp =
298         vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
299
300     assertVspsEquals(actualVsp, existingVsp);
301   }
302
303   @Test
304   public void testGetOldVersion() {
305     VersionInfo versionInfo = new VersionInfo();
306     versionInfo.setActiveVersion(new Version(0, 2));
307     versionInfo.setViewableVersions(Arrays.asList(VERSION01, new Version(0, 2)));
308     versionInfo.setStatus(VersionStatus.Locked);
309     versionInfo.setLockingUser(USER2);
310     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
311         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
312         VersionableEntityAction.Read);
313
314     VspDetails existingVsp =
315         createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
316             "category",
317             "subCategory", "456", null);
318     existingVsp.setWritetimeMicroSeconds(8L);
319     doReturn(existingVsp)
320         .when(vspInfoDaoMock).get(any(VspDetails.class));
321
322     VspDetails actualVsp =
323         vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
324
325     VspDetails expectedVsp =
326         vspInfoDaoMock
327             .get(new VspDetails(VSP_ID, VERSION01));
328     assertVspsEquals(actualVsp, expectedVsp);
329   }
330
331 /*
332   @Test
333   public void testSubmitWithMissingData() throws IOException {
334     VersionInfo versionInfo = new VersionInfo();
335     versionInfo.setActiveVersion(VERSION01);
336
337     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
338         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
339         VSP_ID, USER1, VersionableEntityAction.Read);
340
341     VspDetails vsp = new VspDetails(VSP_ID, VERSION01);
342     vsp.setOnboardingMethod("Manual");
343     doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
344
345     VspQuestionnaireEntity vspQuestionnaire = new VspQuestionnaireEntity(VSP_ID, VERSION01);
346     vspQuestionnaire.setQuestionnaireData("{}");
347     doReturn(vspQuestionnaire).when(vspInfoDaoMock).getQuestionnaire(VSP_ID, VERSION01);
348
349     ComponentEntity comp1 = new ComponentEntity(VSP_ID, VERSION01, "comp1");
350     comp1.setQuestionnaireData("{}");
351     doReturn(Collections.singleton(comp1)).when(vendorSoftwareProductDaoMock)
352         .listComponentsCompositionAndQuestionnaire(VSP_ID, VERSION01);
353
354     NicEntity nic1 = new NicEntity(VSP_ID, VERSION01, "comp1", "nic1");
355     nic1.setQuestionnaireData("{}");
356     doReturn(Collections.singleton(nic1))
357         .when(vendorSoftwareProductDaoMock).listNicsByVsp(VSP_ID, VERSION01);
358
359     ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1);
360     Assert.assertNotNull(validationResponse);
361     Assert.assertFalse(validationResponse.isValid());
362     List<String> errorIds = validationResponse.getVspErrors().stream().map(ErrorCode::id).distinct()
363         .collect(Collectors.toList());
364     Assert.assertTrue(errorIds.contains(ValidationErrorBuilder.FIELD_VALIDATION_ERROR_ERR_ID));
365     Assert.assertTrue(errorIds.contains(VendorSoftwareProductErrorCodes.VSP_INVALID));
366
367     verify(versioningManagerMock, never())
368         .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
369             USER1, null);
370     verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
371   }
372
373   */
374
375   // TODO: 3/15/2017 fix and enable
376   //@Test
377   public void testSubmitWithInvalidLicensingData() throws IOException {
378     VersionInfo versionInfo = new VersionInfo();
379     versionInfo.setActiveVersion(VERSION01);
380     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
381         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
382         VSP_ID, USER1, VersionableEntityAction.Read);
383
384     VspDetails vsp =
385         createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
386             "category", "subCategory", "licenseAgreementId",
387             Collections.singletonList("featureGroupId"));
388     doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
389     OrchestrationTemplateEntity uploadData = new OrchestrationTemplateEntity(VSP_ID, VERSION01);
390     uploadData.setContentData(
391         ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition"))));
392     doReturn(uploadData).when(orchestrationTemplateDataDaoMock)
393         .get(anyObject(), anyObject());
394     doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(),
395         "MainServiceTemplate.yaml"))
396         .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01);
397
398     ValidationResponse validationResponse =
399         vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
400     Assert.assertNotNull(validationResponse);
401     Assert.assertFalse(validationResponse.isValid());
402     Assert.assertNull(validationResponse.getVspErrors());
403     Assert.assertEquals(validationResponse.getLicensingDataErrors().size(), 1);
404
405     verify(versioningManagerMock, never())
406         .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
407             USER1, null);
408   }
409
410   // TODO: 3/15/2017 fix and enable
411   //@Test
412   public void testSubmit() throws IOException {
413     mockVersioning(VersionableEntityAction.Read);
414
415     EnrichmentManagerFactory.getInstance();
416     AbstractFactoryBase
417         .registerFactory(EnrichmentManagerFactory.class, EnrichmentManagerFactoryImpl.class);
418
419     VspDetails vsp =
420         createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
421             "category", "subCategory", "123", Collections.singletonList("fg1"));
422     doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
423     OrchestrationTemplateEntity uploadData = new OrchestrationTemplateEntity(VSP_ID, VERSION01);
424     uploadData.setContentData(
425         ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition"))));
426     doReturn(uploadData).when(orchestrationTemplateDataDaoMock)
427         .get(anyObject(), anyObject());
428     doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(),
429         "MainServiceTemplate.yaml"))
430         .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01);
431
432     ValidationResponse validationResponse =
433         vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
434     Assert.assertTrue(validationResponse.isValid());
435
436 /*    Assert.assertEquals(vsp2.getVersionInfo().getVersion(), VERSION10);
437     Assert.assertEquals(vsp2.getVersionInfo().getStatus(), VersionStatus.Certified);
438     Assert.assertNull(vsp2.getVersionInfo().getLockingUser());*/
439
440     verify(versioningManagerMock)
441         .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
442             USER1, null);
443   }
444
445   @Test
446   public void testCreatePackage() throws IOException {
447     /*VspDetails vspDetailsMock = new VspDetails("vspId", new Version(1, 0));
448     doReturn(vspDetailsMock).when(vspInfoDaoMock).get(anyObject());*/
449     VersionInfo versionInfo = new VersionInfo();
450     versionInfo.setActiveVersion(VERSION10);
451     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
452         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
453         VersionableEntityAction.Read);
454
455     doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), "")).when
456         (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10);
457     doNothing().when(vendorSoftwareProductManager).populateVersionsForVlm(anyObject(), anyObject());
458     VspDetails vsp = new VspDetails(VSP_ID, VERSION10);
459     vsp.setVendorId("vendorId");
460     vsp.setVlmVersion(VERSION10);
461     vsp.setFeatureGroups(Arrays.asList("fg1", "fg2"));
462     doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class));
463
464     doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock)
465         .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups()
466         );
467
468     PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10);
469     Assert.assertNotNull(packageInfo.getVspId());
470   }
471
472   // TODO: 3/15/2017 fix and enable
473   //@Test(dependsOnMethods = {"testListFinals"})
474   public void testUploadFileMissingFile() throws IOException {
475     try (InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip")) {
476
477       UploadFileResponse uploadFileResponse =
478               candidateManager.upload(VSP_ID, VERSION01, zis, "zip", "file");
479
480       Assert.assertEquals(uploadFileResponse.getErrors().size(), 0);
481     }
482   }
483
484   // TODO: 3/15/2017 fix and enable
485   //@Test(dependsOnMethods = {"testUploadFileMissingFile"})
486   public void testUploadNotZipFile() throws IOException {
487     URL url = this.getClass().getResource("/notZipFile");
488
489     try {
490       candidateManager.upload(VSP_ID, VERSION01, url.openStream(), "zip", "file");
491       candidateManager.process(VSP_ID, VERSION01);
492     } catch (Exception ce) {
493       Assert.assertEquals(ce.getMessage(), Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage());
494     }
495   }
496
497   private List<String> getWantedFileNamesFromCsar(String pathInCsar)
498       throws IOException {
499     File translatedFile = vendorSoftwareProductManager.getTranslatedFile(VSP_ID, VERSION10);
500
501     return getFileNamesFromFolderInCsar(translatedFile,
502         pathInCsar);
503   }
504
505   private List<String> getFileNamesFromFolderInCsar(File csar, String folderName)
506       throws IOException {
507     List<String> fileNames = new ArrayList<>();
508
509     try (ZipInputStream zip = new ZipInputStream(new FileInputStream(csar))) {
510       ZipEntry ze;
511
512       while ((ze = zip.getNextEntry()) != null) {
513         String name = ze.getName();
514         if (name.contains(folderName)) {
515           fileNames.add(name);
516         }
517       }
518     }
519
520     return fileNames;
521   }
522   /*
523   //Disabled for sonar null pointer issue for componentEntities
524   private Pair<String, String> uploadMib(String vspId, String user, String filePath,
525                                          String fileName) {
526     List<ComponentEntity> componentEntities = null;
527     //(List<ComponentEntity>) vendorSoftwareProductManager.listComponents(vspId, null, user);
528     monitoringUploadsManager.upload(getFileInputStream(filePath),
529         fileName, vspId,
530 <<<<<<< HEAD
531         VERSION01, componentEntities.get(0).getId(), ArtifactType.SNMP_POLL);
532     //TODO: add validate of logActivity() func call
533 =======
534         VERSION01, componentEntities.get(0).getId(), MonitoringUploadType.SNMP_POLL, user);
535     //TODO: add validate of addActionLog() func call
536 >>>>>>> feature/Amdocs-ASDC-1710
537
538     return new ImmutablePair<>(componentEntities.get(0).getId(),
539         componentEntities.get(0).getComponentCompositionData()
540             .getDisplayName());
541   }*/
542
543   // TODO: 3/15/2017 fix and enable
544 /*
545
546   public void testUpdatedVSPShouldBeInBeginningOfList() {
547     vendorSoftwareProductManager.updateVsp(new VspDetails(), USER3);
548     assertVSPInWantedLocationInVSPList(id006, 0, USER3);
549
550     InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
551     candidateManager.upload(id007, VERSION01, zis, USER3);
552     candidateManager.process(id007, VERSION01, USER3);
553     assertVSPInWantedLocationInVSPList(id007, 0, USER3);
554   }
555
556   @Test(dependsOnMethods = {"testUpdatedVSPShouldBeInBeginningOfList"})
557   public void testVSPInBeginningOfListAfterCheckin() {
558     vendorSoftwareProductManager.checkin(id006, USER3);
559     assertVSPInWantedLocationInVSPList(id006, 0, USER3);
560
561     vendorSoftwareProductManager.checkin(id007, USER3);
562     assertVSPInWantedLocationInVSPList(id007, 0, USER3);
563   }
564
565   @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckin"})
566   public void testVSPInBeginningOfListAfterCheckout() {
567     vendorSoftwareProductManager.checkout(id006, USER3);
568     assertVSPInWantedLocationInVSPList(id006, 0, USER3);
569   }
570
571   @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckout"})
572   public void testVSPInBeginningOfListAfterUndoCheckout() {
573     vendorSoftwareProductManager.checkout(id007, USER3);
574     assertVSPInWantedLocationInVSPList(id007, 0, USER3);
575
576     vendorSoftwareProductManager.undoCheckout(id006, USER3);
577     assertVSPInWantedLocationInVSPList(id006, 0, USER3);
578   }
579
580   @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterUndoCheckout"})
581   public void testVSPInBeginningOfListAfterSubmit() throws IOException {
582     vendorSoftwareProductManager.checkin(id007, USER3);
583     vendorSoftwareProductManager.submit(id007, USER3);
584
585     assertVSPInWantedLocationInVSPList(id007, 0, USER3);
586   }
587 */
588   @Test
589   public void testValidateWithCandidateDataNotProcessed() throws IOException {
590     VspDetails vsp =
591         createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
592             "category", "subCategory", "licenseAgreementId",
593             Collections.singletonList("featureGroupId"));
594     vsp.setOnboardingMethod("NetworkPackage");
595     doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
596
597     OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
598         OrchestrationTemplateCandidateData();
599     orchestrationTemplateCandidateData.setFileSuffix("zip");
600     orchestrationTemplateCandidateData.setFilesDataStructure("testdata");
601     orchestrationTemplateCandidateData.setValidationData("");
602     doReturn(orchestrationTemplateCandidateData).when(orchestrationTemplateCandidateManagerMock)
603         .getInfo(VSP_ID, VERSION01);
604     ValidationResponse validationResponse =
605         vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
606     Assert.assertNotNull(validationResponse);
607     Assert.assertFalse(validationResponse.isValid());
608     Assert.assertNotNull(validationResponse.getVspErrors());
609     Assert.assertEquals(validationResponse.getVspErrors().size(), 1);
610
611   }
612
613   @Test
614   public void testValidateWithCandidateProcessedIsInvalid() throws IOException {
615     VspDetails vsp = createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-VSP", "vendorName",
616         "vl1Id", "icond", "category", "subcategory", "licenseAgreementId", Collections
617             .singletonList("featureGroupId"));
618     vsp.setOnboardingMethod("NetworkPackage");
619     doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
620
621     OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
622         OrchestrationTemplateCandidateData();
623     orchestrationTemplateCandidateData.setFileSuffix("zip");
624     orchestrationTemplateCandidateData.setValidationData("Invalid processed data");
625     doReturn(orchestrationTemplateCandidateData).when(orchestrationTemplateCandidateManagerMock)
626         .getInfo(VSP_ID, VERSION01);
627     ValidationResponse validationResponse =
628         vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
629     Assert.assertNotNull(validationResponse);
630     Assert.assertFalse(validationResponse.isValid());
631     Assert.assertNotNull(validationResponse.getVspErrors());
632     Assert.assertEquals(validationResponse.getVspErrors().size(), 1);
633   }
634
635   private void testLegalUpload(String vspId, Version version, InputStream upload, String user) {
636     candidateManager.upload(vspId, VERSION01, upload, "zip", "file");
637     candidateManager.process(vspId, VERSION01);
638
639     OrchestrationTemplateEntity uploadData =
640         orchestrationTemplateDataDaoMock.get(vspId, version);
641     Assert.assertNotNull(uploadData);
642   }
643
644
645   public InputStream getFileInputStream(String fileName) {
646     URL url = this.getClass().getResource(fileName);
647     try {
648       return url.openStream();
649     } catch (IOException exception) {
650       exception.printStackTrace();
651       return null;
652     }
653   }
654
655   static VspDetails createVspDetails(String id, Version version, String name, String desc,
656                                      String vendorName, String vlm, String icon,
657                                      String category, String subCategory,
658                                      String licenseAgreement, List<String> featureGroups) {
659     VspDetails vspDetails = new VspDetails(id, version);
660     vspDetails.setName(name);
661     vspDetails.setDescription(desc);
662     vspDetails.setIcon(icon);
663     vspDetails.setCategory(category);
664     vspDetails.setSubCategory(subCategory);
665     vspDetails.setVendorName(vendorName);
666     vspDetails.setVendorId(vlm);
667     vspDetails.setVlmVersion(new Version(1, 0));
668     vspDetails.setLicenseAgreement(licenseAgreement);
669     vspDetails.setFeatureGroups(featureGroups);
670     vspDetails.setOnboardingMethod("HEAT");
671     return vspDetails;
672   }
673
674   static void assertVspsEquals(VspDetails actual, VspDetails expected) {
675     Assert.assertEquals(actual.getId(), expected.getId());
676     Assert.assertEquals(actual.getVersion(), expected.getVersion());
677     Assert.assertEquals(actual.getName(), expected.getName());
678     Assert.assertEquals(actual.getDescription(), expected.getDescription());
679     Assert.assertEquals(actual.getIcon(), expected.getIcon());
680     Assert.assertEquals(actual.getCategory(), expected.getCategory());
681     Assert.assertEquals(actual.getSubCategory(), expected.getSubCategory());
682     Assert.assertEquals(actual.getVendorName(), expected.getVendorName());
683     Assert.assertEquals(actual.getVendorId(), expected.getVendorId());
684     Assert.assertEquals(actual.getLicenseAgreement(), expected.getLicenseAgreement());
685     Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups());
686   }
687
688
689   // todo ********************** move to common **************************************
690
691   private void mockVersioning(VersionableEntityAction action) {
692     VersionInfo versionInfo = new VersionInfo();
693     versionInfo.setActiveVersion(VERSION01);
694     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
695         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
696         action);
697   }
698
699 }