2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.openecomp.sdc.vendorsoftwareproduct.impl;
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;
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;
81 import java.io.FileInputStream;
82 import java.io.IOException;
83 import java.io.InputStream;
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;
95 public class VendorSoftwareProductManagerImplTest {
96 private static final String INVALID_VERSION_MSG = "Invalid requested version.";
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;
109 private ActionVersioningManager versioningManagerMock;
111 private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
113 private VendorLicenseFacade vendorLicenseFacadeMock;
115 private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
117 private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDaoMock;
119 private HealingManager healingManagerMock;
121 private VendorLicenseArtifactsService licenseArtifactsServiceMock;
123 private CompositionEntityDataManager compositionEntityDataManagerMock;
125 private InformationArtifactGenerator informationArtifactGeneratorMock;
127 private PackageInfoDao packageInfoDao;
129 private VendorSoftwareProductInfoDao vspInfoDaoMock;
131 private ManualVspToscaManager manualVspToscaManager;
133 private DeploymentFlavorDao deploymentFlavorDaoMock;
138 private VendorSoftwareProductManagerImpl vendorSoftwareProductManager;
141 private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManagerMock;
143 private ComponentDependencyModelDao componentDependencyModelDao;
144 private OrchestrationTemplateCandidateManager candidateManager;
145 private MonitoringUploadsManager monitoringUploadsManager;
148 private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
151 public void setUp() throws Exception {
152 MockitoAnnotations.initMocks(this);
156 public void tearDown(){
157 vendorSoftwareProductManager = null;
162 public void testCreate() {
163 //doReturn(VERSION01).when(versioningManagerMock).create(anyObject(), anyObject(), anyObject());
165 .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject());
167 VspDetails vspToCreate =
168 createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
169 "category", "subCategory", "123", null);
171 VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate);
173 Assert.assertNotNull(vsp);
174 vspToCreate.setId(vsp.getId());
175 vspToCreate.setVersion(VERSION01);
176 assertVspsEquals(vsp, vspToCreate);
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);
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());
200 vendorSoftwareProductManager.updateVsp(updatedVsp);
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",
213 "subCategory", "456", null);
214 VspDetails updatedVsp =
215 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
217 "subCategory", "456", null);
218 doReturn(existingVsp).when(vspInfoDaoMock)
219 .get(any(VspDetails.class));
220 doNothing().when(vendorSoftwareProductManager)
221 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
223 vendorSoftwareProductManager.updateVsp(updatedVsp);
225 verify(vspInfoDaoMock).update(updatedVsp);
229 public void testUpdateRemoveFG() {
230 VersionInfo versionInfo = new VersionInfo();
231 versionInfo.setActiveVersion(VERSION01);
232 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
233 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
234 VersionableEntityAction.Write);
235 List<String> fgs = new ArrayList<String>();
238 VspDetails existingVsp =
239 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
241 "subCategory", "456", fgs);
243 List<String> updFgs = new ArrayList<String>();
245 VspDetails updatedVsp =
246 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
248 "subCategory", "456", updFgs);
249 doReturn(existingVsp).when(vspInfoDaoMock)
250 .get(any(VspDetails.class));
251 doNothing().when(vendorSoftwareProductManager)
252 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
254 DeploymentFlavorEntity dfEntity = new DeploymentFlavorEntity(VSP_ID, VERSION01, "DF_ID");
255 DeploymentFlavor flavor = new DeploymentFlavor();
256 flavor.setFeatureGroupId("fg1");
257 dfEntity.setDeploymentFlavorCompositionData(flavor);
259 List<DeploymentFlavorEntity> dfList = new ArrayList<DeploymentFlavorEntity>();
260 dfList.add(dfEntity);
262 doReturn(dfList).when(deploymentFlavorDaoMock).list(anyObject());
264 vendorSoftwareProductManager.updateVsp(updatedVsp);
266 verify(deploymentFlavorDaoMock).update(dfEntity);
268 Assert.assertNull(dfEntity.getDeploymentFlavorCompositionData().getFeatureGroupId());
272 @Test(expectedExceptions = CoreException.class)
273 public void testGetNonExistingVersion_negative() {
274 Version notExistversion = new Version(43, 8);
275 doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
276 vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion);
280 public void testGetCheckedOutVersion() {
281 VersionInfo versionInfo = new VersionInfo();
282 versionInfo.setActiveVersion(VERSION01);
283 versionInfo.setStatus(VersionStatus.Locked);
284 versionInfo.setLockingUser(USER1);
285 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
286 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
287 VersionableEntityAction.Read);
289 VspDetails existingVsp =
290 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
292 "subCategory", "456", null);
293 doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class));
295 VspDetails actualVsp =
296 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
298 assertVspsEquals(actualVsp, existingVsp);
302 public void testGetOldVersion() {
303 VersionInfo versionInfo = new VersionInfo();
304 versionInfo.setActiveVersion(new Version(0, 2));
305 versionInfo.setViewableVersions(Arrays.asList(VERSION01, new Version(0, 2)));
306 versionInfo.setStatus(VersionStatus.Locked);
307 versionInfo.setLockingUser(USER2);
308 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
309 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
310 VersionableEntityAction.Read);
312 VspDetails existingVsp =
313 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
315 "subCategory", "456", null);
316 doReturn(existingVsp)
317 .when(vspInfoDaoMock).get(any(VspDetails.class));
319 VspDetails actualVsp =
320 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
322 VspDetails expectedVsp =
324 .get(new VspDetails(VSP_ID, VERSION01));
325 assertVspsEquals(actualVsp, expectedVsp);
330 public void testSubmitWithMissingData() throws IOException {
331 VersionInfo versionInfo = new VersionInfo();
332 versionInfo.setActiveVersion(VERSION01);
334 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
335 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
336 VSP_ID, USER1, VersionableEntityAction.Read);
338 VspDetails vsp = new VspDetails(VSP_ID, VERSION01);
339 vsp.setOnboardingMethod("Manual");
340 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
342 VspQuestionnaireEntity vspQuestionnaire = new VspQuestionnaireEntity(VSP_ID, VERSION01);
343 vspQuestionnaire.setQuestionnaireData("{}");
344 doReturn(vspQuestionnaire).when(vspInfoDaoMock).getQuestionnaire(VSP_ID, VERSION01);
346 ComponentEntity comp1 = new ComponentEntity(VSP_ID, VERSION01, "comp1");
347 comp1.setQuestionnaireData("{}");
348 doReturn(Collections.singleton(comp1)).when(vendorSoftwareProductDaoMock)
349 .listComponentsCompositionAndQuestionnaire(VSP_ID, VERSION01);
351 NicEntity nic1 = new NicEntity(VSP_ID, VERSION01, "comp1", "nic1");
352 nic1.setQuestionnaireData("{}");
353 doReturn(Collections.singleton(nic1))
354 .when(vendorSoftwareProductDaoMock).listNicsByVsp(VSP_ID, VERSION01);
356 ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1);
357 Assert.assertNotNull(validationResponse);
358 Assert.assertFalse(validationResponse.isValid());
359 List<String> errorIds = validationResponse.getVspErrors().stream().map(ErrorCode::id).distinct()
360 .collect(Collectors.toList());
361 Assert.assertTrue(errorIds.contains(ValidationErrorBuilder.FIELD_VALIDATION_ERROR_ERR_ID));
362 Assert.assertTrue(errorIds.contains(VendorSoftwareProductErrorCodes.VSP_INVALID));
364 verify(versioningManagerMock, never())
365 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
367 verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
372 // TODO: 3/15/2017 fix and enable
374 public void testSubmitWithInvalidLicensingData() throws IOException {
375 VersionInfo versionInfo = new VersionInfo();
376 versionInfo.setActiveVersion(VERSION01);
377 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
378 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
379 VSP_ID, USER1, VersionableEntityAction.Read);
382 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
383 "category", "subCategory", "licenseAgreementId",
384 Collections.singletonList("featureGroupId"));
385 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
386 OrchestrationTemplateEntity uploadData = new OrchestrationTemplateEntity(VSP_ID, VERSION01);
387 uploadData.setContentData(
388 ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition"))));
389 doReturn(uploadData).when(orchestrationTemplateDataDaoMock)
390 .get(anyObject(), anyObject());
391 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(),
392 "MainServiceTemplate.yaml"))
393 .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01);
395 ValidationResponse validationResponse =
396 vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
397 Assert.assertNotNull(validationResponse);
398 Assert.assertFalse(validationResponse.isValid());
399 Assert.assertNull(validationResponse.getVspErrors());
400 Assert.assertEquals(validationResponse.getLicensingDataErrors().size(), 1);
402 verify(versioningManagerMock, never())
403 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
407 // TODO: 3/15/2017 fix and enable
409 public void testSubmit() throws IOException {
410 mockVersioning(VersionableEntityAction.Read);
412 EnrichmentManagerFactory.getInstance();
414 .registerFactory(EnrichmentManagerFactory.class, EnrichmentManagerFactoryImpl.class);
417 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
418 "category", "subCategory", "123", Collections.singletonList("fg1"));
419 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
420 OrchestrationTemplateEntity uploadData = new OrchestrationTemplateEntity(VSP_ID, VERSION01);
421 uploadData.setContentData(
422 ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition"))));
423 doReturn(uploadData).when(orchestrationTemplateDataDaoMock)
424 .get(anyObject(), anyObject());
425 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(),
426 "MainServiceTemplate.yaml"))
427 .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01);
429 ValidationResponse validationResponse =
430 vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
431 Assert.assertTrue(validationResponse.isValid());
433 /* Assert.assertEquals(vsp2.getVersionInfo().getVersion(), VERSION10);
434 Assert.assertEquals(vsp2.getVersionInfo().getStatus(), VersionStatus.Certified);
435 Assert.assertNull(vsp2.getVersionInfo().getLockingUser());*/
437 verify(versioningManagerMock)
438 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
443 public void testCreatePackage() throws IOException {
444 /*VspDetails vspDetailsMock = new VspDetails("vspId", new Version(1, 0));
445 doReturn(vspDetailsMock).when(vspInfoDaoMock).get(anyObject());*/
446 VersionInfo versionInfo = new VersionInfo();
447 versionInfo.setActiveVersion(VERSION10);
448 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
449 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
450 VersionableEntityAction.Read);
452 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), "")).when
453 (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10);
454 doNothing().when(vendorSoftwareProductManager).populateVersionsForVlm(anyObject(), anyObject());
455 VspDetails vsp = new VspDetails(VSP_ID, VERSION10);
456 vsp.setVendorId("vendorId");
457 vsp.setVlmVersion(VERSION10);
458 vsp.setFeatureGroups(Arrays.asList("fg1", "fg2"));
459 doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class));
461 doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock)
462 .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups()
465 PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10);
466 Assert.assertNotNull(packageInfo.getVspId());
469 // TODO: 3/15/2017 fix and enable
470 //@Test(dependsOnMethods = {"testListFinals"})
471 public void testUploadFileMissingFile() throws IOException {
472 try (InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip")) {
474 UploadFileResponse uploadFileResponse =
475 candidateManager.upload(VSP_ID, VERSION01, zis, "zip", "file");
477 Assert.assertEquals(uploadFileResponse.getErrors().size(), 0);
481 // TODO: 3/15/2017 fix and enable
482 //@Test(dependsOnMethods = {"testUploadFileMissingFile"})
483 public void testUploadNotZipFile() throws IOException {
484 URL url = this.getClass().getResource("/notZipFile");
487 candidateManager.upload(VSP_ID, VERSION01, url.openStream(), "zip", "file");
488 candidateManager.process(VSP_ID, VERSION01);
489 } catch (Exception ce) {
490 Assert.assertEquals(ce.getMessage(), Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage());
494 private List<String> getWantedFileNamesFromCsar(String pathInCsar)
496 File translatedFile = vendorSoftwareProductManager.getTranslatedFile(VSP_ID, VERSION10);
498 return getFileNamesFromFolderInCsar(translatedFile,
502 private List<String> getFileNamesFromFolderInCsar(File csar, String folderName)
504 List<String> fileNames = new ArrayList<>();
506 try (ZipInputStream zip = new ZipInputStream(new FileInputStream(csar))) {
509 while ((ze = zip.getNextEntry()) != null) {
510 String name = ze.getName();
511 if (name.contains(folderName)) {
520 //Disabled for sonar null pointer issue for componentEntities
521 private Pair<String, String> uploadMib(String vspId, String user, String filePath,
523 List<ComponentEntity> componentEntities = null;
524 //(List<ComponentEntity>) vendorSoftwareProductManager.listComponents(vspId, null, user);
525 monitoringUploadsManager.upload(getFileInputStream(filePath),
528 VERSION01, componentEntities.get(0).getId(), ArtifactType.SNMP_POLL);
529 //TODO: add validate of logActivity() func call
531 VERSION01, componentEntities.get(0).getId(), MonitoringUploadType.SNMP_POLL, user);
532 //TODO: add validate of addActionLog() func call
533 >>>>>>> feature/Amdocs-ASDC-1710
535 return new ImmutablePair<>(componentEntities.get(0).getId(),
536 componentEntities.get(0).getComponentCompositionData()
540 // TODO: 3/15/2017 fix and enable
543 public void testUpdatedVSPShouldBeInBeginningOfList() {
544 vendorSoftwareProductManager.updateVsp(new VspDetails(), USER3);
545 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
547 InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
548 candidateManager.upload(id007, VERSION01, zis, USER3);
549 candidateManager.process(id007, VERSION01, USER3);
550 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
553 @Test(dependsOnMethods = {"testUpdatedVSPShouldBeInBeginningOfList"})
554 public void testVSPInBeginningOfListAfterCheckin() {
555 vendorSoftwareProductManager.checkin(id006, USER3);
556 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
558 vendorSoftwareProductManager.checkin(id007, USER3);
559 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
562 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckin"})
563 public void testVSPInBeginningOfListAfterCheckout() {
564 vendorSoftwareProductManager.checkout(id006, USER3);
565 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
568 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckout"})
569 public void testVSPInBeginningOfListAfterUndoCheckout() {
570 vendorSoftwareProductManager.checkout(id007, USER3);
571 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
573 vendorSoftwareProductManager.undoCheckout(id006, USER3);
574 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
577 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterUndoCheckout"})
578 public void testVSPInBeginningOfListAfterSubmit() throws IOException {
579 vendorSoftwareProductManager.checkin(id007, USER3);
580 vendorSoftwareProductManager.submit(id007, USER3);
582 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
586 public void testValidateWithCandidateDataNotProcessed() throws IOException {
588 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
589 "category", "subCategory", "licenseAgreementId",
590 Collections.singletonList("featureGroupId"));
591 vsp.setOnboardingMethod("NetworkPackage");
592 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
594 OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
595 OrchestrationTemplateCandidateData();
596 orchestrationTemplateCandidateData.setFileSuffix("zip");
597 orchestrationTemplateCandidateData.setFilesDataStructure("testdata");
598 orchestrationTemplateCandidateData.setValidationData("");
599 doReturn(orchestrationTemplateCandidateData).when(orchestrationTemplateCandidateManagerMock)
600 .getInfo(VSP_ID, VERSION01);
601 ValidationResponse validationResponse =
602 vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
603 Assert.assertNotNull(validationResponse);
604 Assert.assertFalse(validationResponse.isValid());
605 Assert.assertNotNull(validationResponse.getVspErrors());
606 Assert.assertEquals(validationResponse.getVspErrors().size(), 1);
611 public void testValidateWithCandidateProcessedIsInvalid() throws IOException {
612 VspDetails vsp = createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-VSP", "vendorName",
613 "vl1Id", "icond", "category", "subcategory", "licenseAgreementId", Collections
614 .singletonList("featureGroupId"));
615 vsp.setOnboardingMethod("NetworkPackage");
616 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
618 OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
619 OrchestrationTemplateCandidateData();
620 orchestrationTemplateCandidateData.setFileSuffix("zip");
621 orchestrationTemplateCandidateData.setValidationData("Invalid processed data");
622 doReturn(orchestrationTemplateCandidateData).when(orchestrationTemplateCandidateManagerMock)
623 .getInfo(VSP_ID, VERSION01);
624 ValidationResponse validationResponse =
625 vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
626 Assert.assertNotNull(validationResponse);
627 Assert.assertFalse(validationResponse.isValid());
628 Assert.assertNotNull(validationResponse.getVspErrors());
629 Assert.assertEquals(validationResponse.getVspErrors().size(), 1);
632 private void testLegalUpload(String vspId, Version version, InputStream upload, String user) {
633 candidateManager.upload(vspId, VERSION01, upload, "zip", "file");
634 candidateManager.process(vspId, VERSION01);
636 OrchestrationTemplateEntity uploadData =
637 orchestrationTemplateDataDaoMock.get(vspId, version);
638 Assert.assertNotNull(uploadData);
642 public InputStream getFileInputStream(String fileName) {
643 URL url = this.getClass().getResource(fileName);
645 return url.openStream();
646 } catch (IOException exception) {
647 exception.printStackTrace();
652 static VspDetails createVspDetails(String id, Version version, String name, String desc,
653 String vendorName, String vlm, String icon,
654 String category, String subCategory,
655 String licenseAgreement, List<String> featureGroups) {
656 VspDetails vspDetails = new VspDetails(id, version);
657 vspDetails.setName(name);
658 vspDetails.setDescription(desc);
659 vspDetails.setIcon(icon);
660 vspDetails.setCategory(category);
661 vspDetails.setSubCategory(subCategory);
662 vspDetails.setVendorName(vendorName);
663 vspDetails.setVendorId(vlm);
664 vspDetails.setVlmVersion(new Version(1, 0));
665 vspDetails.setLicenseAgreement(licenseAgreement);
666 vspDetails.setFeatureGroups(featureGroups);
667 vspDetails.setOnboardingMethod("HEAT");
671 static void assertVspsEquals(VspDetails actual, VspDetails expected) {
672 Assert.assertEquals(actual.getId(), expected.getId());
673 Assert.assertEquals(actual.getVersion(), expected.getVersion());
674 Assert.assertEquals(actual.getName(), expected.getName());
675 Assert.assertEquals(actual.getDescription(), expected.getDescription());
676 Assert.assertEquals(actual.getIcon(), expected.getIcon());
677 Assert.assertEquals(actual.getCategory(), expected.getCategory());
678 Assert.assertEquals(actual.getSubCategory(), expected.getSubCategory());
679 Assert.assertEquals(actual.getVendorName(), expected.getVendorName());
680 Assert.assertEquals(actual.getVendorId(), expected.getVendorId());
681 Assert.assertEquals(actual.getLicenseAgreement(), expected.getLicenseAgreement());
682 Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups());
686 // todo ********************** move to common **************************************
688 private void mockVersioning(VersionableEntityAction action) {
689 VersionInfo versionInfo = new VersionInfo();
690 versionInfo.setActiveVersion(VERSION01);
691 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
692 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,