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