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