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