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 org.mockito.ArgumentCaptor;
20 import org.mockito.Captor;
21 import org.mockito.InjectMocks;
22 import org.mockito.Mock;
23 import org.mockito.MockitoAnnotations;
24 import org.mockito.Spy;
25 import org.openecomp.core.enrichment.factory.EnrichmentManagerFactory;
26 import org.openecomp.core.factory.impl.AbstractFactoryBase;
27 import org.openecomp.core.model.dao.EnrichedServiceModelDao;
28 import org.openecomp.core.model.dao.ServiceModelDao;
29 import org.openecomp.core.model.types.ServiceElement;
30 import org.openecomp.core.utilities.file.FileContentHandler;
31 import org.openecomp.core.utilities.file.FileUtils;
32 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
33 import org.openecomp.sdc.common.errors.CoreException;
34 import org.openecomp.sdc.common.errors.ErrorCategory;
35 import org.openecomp.sdc.common.errors.ErrorCode;
36 import org.openecomp.sdc.common.errors.Messages;
37 import org.openecomp.sdc.healing.api.HealingManager;
38 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
39 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
40 import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService;
41 import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager;
42 import org.openecomp.sdc.vendorsoftwareproduct.ManualVspToscaManager;
43 import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager;
44 import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
45 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
46 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao;
47 import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao;
48 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
49 import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao;
50 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
51 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
52 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
53 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity;
54 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
55 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
56 import org.openecomp.sdc.vendorsoftwareproduct.impl.mock.EnrichmentManagerFactoryImpl;
57 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator;
58 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
59 import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
60 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor;
61 import org.openecomp.sdc.versioning.ActionVersioningManager;
62 import org.openecomp.sdc.versioning.dao.types.Version;
63 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
64 import org.openecomp.sdc.versioning.types.VersionInfo;
65 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
66 import org.testng.Assert;
67 import org.testng.annotations.AfterMethod;
68 import org.testng.annotations.BeforeMethod;
69 import org.testng.annotations.Test;
72 import java.io.FileInputStream;
73 import java.io.IOException;
74 import java.io.InputStream;
76 import java.nio.ByteBuffer;
77 import java.util.ArrayList;
78 import java.util.Arrays;
79 import java.util.Collections;
80 import java.util.HashMap;
81 import java.util.List;
82 import java.util.Optional;
83 import java.util.zip.ZipEntry;
84 import java.util.zip.ZipInputStream;
86 import static org.mockito.Matchers.any;
87 import static org.mockito.Matchers.anyObject;
88 import static org.mockito.Mockito.doNothing;
89 import static org.mockito.Mockito.doReturn;
90 import static org.mockito.Mockito.doThrow;
91 import static org.mockito.Mockito.never;
92 import static org.mockito.Mockito.verify;
95 public class VendorSoftwareProductManagerImplTest {
97 private static final String VSP_ID = "vspId";
98 private static final Version VERSION01 = new Version("0, 1");
99 private static final Version VERSION10 = new Version("1, 0");
100 private static final String USER1 = "vspTestUser1";
101 private static final String USER2 = "vspTestUser2";
104 private ActionVersioningManager versioningManagerMock;
106 private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
108 private VendorLicenseFacade vendorLicenseFacadeMock;
110 private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
112 private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDaoMock;
114 private HealingManager healingManagerMock;
116 private VendorLicenseArtifactsService licenseArtifactsServiceMock;
118 private CompositionEntityDataManager compositionEntityDataManagerMock;
120 private InformationArtifactGenerator informationArtifactGeneratorMock;
122 private PackageInfoDao packageInfoDao;
124 private VendorSoftwareProductInfoDao vspInfoDaoMock;
126 private ManualVspToscaManager manualVspToscaManager;
128 private DeploymentFlavorDao deploymentFlavorDaoMock;
133 private VendorSoftwareProductManagerImpl vendorSoftwareProductManager;
136 private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManagerMock;
138 private ComponentDependencyModelDao componentDependencyModelDao;
139 private OrchestrationTemplateCandidateManager candidateManager;
140 private MonitoringUploadsManager monitoringUploadsManager;
143 private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
146 public void setUp() {
147 MockitoAnnotations.initMocks(this);
151 public void tearDown() {
152 vendorSoftwareProductManager = null;
157 public void testCreate() {
158 //doReturn(VERSION01).when(versioningManagerMock).create(anyObject(), anyObject(), anyObject());
160 .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject());
162 VspDetails vspToCreate =
163 createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
164 "category", "subCategory", "123", null);
166 VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate);
168 Assert.assertNotNull(vsp);
169 vspToCreate.setId(vsp.getId());
170 vspToCreate.setVersion(VERSION01);
171 assertVspsEquals(vsp, vspToCreate);
174 @Test(expectedExceptions = CoreException.class)
175 public void testUpdateWithExistingName_negative() {
176 VersionInfo versionInfo = new VersionInfo();
177 versionInfo.setActiveVersion(VERSION01);
178 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
179 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
180 VersionableEntityAction.Write);
182 VspDetails existingVsp =
183 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-existingVsp", "vendorName", "vlm1Id",
184 "icon", "category", "subCategory", "123", null);
185 VspDetails updatedVsp =
186 createVspDetails(VSP_ID, VERSION01, "Vsp1_updated", "Test-existingVsp", "vendorName",
187 "vlm1Id", "icon", "category", "subCategory", "123", null);
188 doReturn(existingVsp).when(vspInfoDaoMock)
189 .get(any(VspDetails.class));
190 doThrow(new CoreException(
191 new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build()))
192 .when(vendorSoftwareProductManager)
193 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
195 vendorSoftwareProductManager.updateVsp(updatedVsp);
199 public void testUpdate() {
200 VersionInfo versionInfo = new VersionInfo();
201 versionInfo.setActiveVersion(VERSION01);
202 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
203 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
204 VersionableEntityAction.Write);
205 VspDetails existingVsp =
206 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
208 "subCategory", "456", null);
209 VspDetails updatedVsp =
210 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
212 "subCategory", "456", null);
213 doReturn(existingVsp).when(vspInfoDaoMock)
214 .get(any(VspDetails.class));
215 doNothing().when(vendorSoftwareProductManager)
216 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
218 vendorSoftwareProductManager.updateVsp(updatedVsp);
220 verify(vspInfoDaoMock).update(updatedVsp);
224 public void testUpdateRemoveFG() {
225 VersionInfo versionInfo = new VersionInfo();
226 versionInfo.setActiveVersion(VERSION01);
227 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
228 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
229 VersionableEntityAction.Write);
230 List<String> fgs = new ArrayList<>();
233 VspDetails existingVsp =
234 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
236 "subCategory", "456", fgs);
238 List<String> updFgs = new ArrayList<>();
240 VspDetails updatedVsp =
241 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
243 "subCategory", "456", updFgs);
244 doReturn(existingVsp).when(vspInfoDaoMock)
245 .get(any(VspDetails.class));
246 doNothing().when(vendorSoftwareProductManager)
247 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
249 DeploymentFlavorEntity dfEntity = new DeploymentFlavorEntity(VSP_ID, VERSION01, "DF_ID");
250 DeploymentFlavor flavor = new DeploymentFlavor();
251 flavor.setFeatureGroupId("fg1");
252 dfEntity.setDeploymentFlavorCompositionData(flavor);
254 List<DeploymentFlavorEntity> dfList = new ArrayList<>();
255 dfList.add(dfEntity);
257 doReturn(dfList).when(deploymentFlavorDaoMock).list(anyObject());
259 vendorSoftwareProductManager.updateVsp(updatedVsp);
261 verify(deploymentFlavorDaoMock).update(dfEntity);
263 Assert.assertNull(dfEntity.getDeploymentFlavorCompositionData().getFeatureGroupId());
267 @Test(expectedExceptions = CoreException.class)
268 public void testGetNonExistingVersion_negative() {
269 Version notExistversion = new Version("43, 8");
270 doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
271 vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion);
275 public void testGetCheckedOutVersion() {
276 VersionInfo versionInfo = new VersionInfo();
277 versionInfo.setActiveVersion(VERSION01);
278 versionInfo.setStatus(VersionStatus.Locked);
279 versionInfo.setLockingUser(USER1);
280 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
281 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
282 VersionableEntityAction.Read);
284 VspDetails existingVsp =
285 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
287 "subCategory", "456", null);
288 doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class));
290 VspDetails actualVsp =
291 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
293 assertVspsEquals(actualVsp, existingVsp);
297 public void testGetOldVersion() {
298 VersionInfo versionInfo = new VersionInfo();
299 versionInfo.setActiveVersion(new Version("0, 2"));
300 versionInfo.setViewableVersions(Arrays.asList(VERSION01, new Version("0, 2")));
301 versionInfo.setStatus(VersionStatus.Locked);
302 versionInfo.setLockingUser(USER2);
303 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
304 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
305 VersionableEntityAction.Read);
307 VspDetails existingVsp =
308 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
310 "subCategory", "456", null);
311 doReturn(existingVsp)
312 .when(vspInfoDaoMock).get(any(VspDetails.class));
314 VspDetails actualVsp =
315 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
317 VspDetails expectedVsp =
319 .get(new VspDetails(VSP_ID, VERSION01));
320 assertVspsEquals(actualVsp, expectedVsp);
325 public void testSubmitWithMissingData() throws IOException {
326 VersionInfo versionInfo = new VersionInfo();
327 versionInfo.setActiveVersion(VERSION01);
329 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
330 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
331 VSP_ID, USER1, VersionableEntityAction.Read);
333 VspDetails vsp = new VspDetails(VSP_ID, VERSION01);
334 vsp.setOnboardingMethod("Manual");
335 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
337 VspQuestionnaireEntity vspQuestionnaire = new VspQuestionnaireEntity(VSP_ID, VERSION01);
338 vspQuestionnaire.setQuestionnaireData("{}");
339 doReturn(vspQuestionnaire).when(vspInfoDaoMock).getQuestionnaire(VSP_ID, VERSION01);
341 ComponentEntity comp1 = new ComponentEntity(VSP_ID, VERSION01, "comp1");
342 comp1.setQuestionnaireData("{}");
343 doReturn(Collections.singleton(comp1)).when(vendorSoftwareProductDaoMock)
344 .listComponentsCompositionAndQuestionnaire(VSP_ID, VERSION01);
346 NicEntity nic1 = new NicEntity(VSP_ID, VERSION01, "comp1", "nic1");
347 nic1.setQuestionnaireData("{}");
348 doReturn(Collections.singleton(nic1))
349 .when(vendorSoftwareProductDaoMock).listNicsByVsp(VSP_ID, VERSION01);
351 ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1);
352 Assert.assertNotNull(validationResponse);
353 Assert.assertFalse(validationResponse.isValid());
354 List<String> errorIds = validationResponse.getVspErrors().stream().map(ErrorCode::id).distinct()
355 .collect(Collectors.toList());
356 Assert.assertTrue(errorIds.contains(ValidationErrorBuilder.FIELD_VALIDATION_ERROR_ERR_ID));
357 Assert.assertTrue(errorIds.contains(VendorSoftwareProductErrorCodes.VSP_INVALID));
359 verify(versioningManagerMock, never())
360 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
362 verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
367 // TODO: 3/15/2017 fix and enable
369 public void testSubmitWithInvalidLicensingData() throws IOException {
370 VersionInfo versionInfo = new VersionInfo();
371 versionInfo.setActiveVersion(VERSION01);
372 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
373 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
374 VSP_ID, USER1, VersionableEntityAction.Read);
377 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
378 "category", "subCategory", "licenseAgreementId",
379 Collections.singletonList("featureGroupId"));
380 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
381 OrchestrationTemplateEntity uploadData = new OrchestrationTemplateEntity(VSP_ID, VERSION01);
382 uploadData.setContentData(
383 ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition"))));
384 doReturn(uploadData).when(orchestrationTemplateDataDaoMock)
385 .get(anyObject(), anyObject());
386 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(),
387 "MainServiceTemplate.yaml"))
388 .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01);
390 ValidationResponse validationResponse =
391 vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
392 Assert.assertNotNull(validationResponse);
393 Assert.assertFalse(validationResponse.isValid());
394 Assert.assertNull(validationResponse.getVspErrors());
395 Assert.assertEquals(validationResponse.getLicensingDataErrors().size(), 1);
397 verify(versioningManagerMock, never())
398 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
402 // TODO: 3/15/2017 fix and enable
404 public void testSubmit() throws IOException {
405 mockVersioning(VersionableEntityAction.Read);
407 EnrichmentManagerFactory.getInstance();
409 .registerFactory(EnrichmentManagerFactory.class, EnrichmentManagerFactoryImpl.class);
412 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
413 "category", "subCategory", "123", Collections.singletonList("fg1"));
414 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
415 OrchestrationTemplateEntity uploadData = new OrchestrationTemplateEntity(VSP_ID, VERSION01);
416 uploadData.setContentData(
417 ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition"))));
418 doReturn(uploadData).when(orchestrationTemplateDataDaoMock)
419 .get(anyObject(), anyObject());
420 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(),
421 "MainServiceTemplate.yaml"))
422 .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01);
424 ValidationResponse validationResponse =
425 vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
426 Assert.assertTrue(validationResponse.isValid());
428 /* Assert.assertEquals(vsp2.getVersionInfo().getVersion(), VERSION10);
429 Assert.assertEquals(vsp2.getVersionInfo().getStatus(), VersionStatus.Certified);
430 Assert.assertNull(vsp2.getVersionInfo().getLockingUser());*/
432 verify(versioningManagerMock)
433 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
438 public void testCreatePackage() {
439 /*VspDetails vspDetailsMock = new VspDetails("vspId", new Version(1, 0));
440 doReturn(vspDetailsMock).when(vspInfoDaoMock).get(anyObject());*/
441 VersionInfo versionInfo = new VersionInfo();
442 versionInfo.setActiveVersion(VERSION10);
443 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
444 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
445 VersionableEntityAction.Read);
447 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), "")).when
448 (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10);
449 doNothing().when(vendorSoftwareProductManager).populateVersionsForVlm(anyObject(), anyObject());
450 VspDetails vsp = new VspDetails(VSP_ID, VERSION10);
451 vsp.setVendorId("vendorId");
452 vsp.setVlmVersion(VERSION10);
453 vsp.setFeatureGroups(Arrays.asList("fg1", "fg2"));
454 doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class));
456 doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock)
457 .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups()
460 PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10);
461 Assert.assertNotNull(packageInfo.getVspId());
464 // TODO: 3/15/2017 fix and enable
465 //@Test(dependsOnMethods = {"testListFinals"})
466 public void testUploadFileMissingFile() throws IOException {
467 try (InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip")) {
469 UploadFileResponse uploadFileResponse =
470 candidateManager.upload(VSP_ID, VERSION01, zis, "zip", "file");
472 Assert.assertEquals(uploadFileResponse.getErrors().size(), 0);
476 // TODO: 3/15/2017 fix and enable
477 //@Test(dependsOnMethods = {"testUploadFileMissingFile"})
478 public void testUploadNotZipFile() {
479 URL url = this.getClass().getResource("/notZipFile");
482 candidateManager.upload(VSP_ID, VERSION01, url.openStream(), "zip", "file");
483 candidateManager.process(VSP_ID, VERSION01);
484 } catch (Exception ce) {
485 Assert.assertEquals(ce.getMessage(), Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage());
489 private List<String> getWantedFileNamesFromCsar(String pathInCsar)
491 File translatedFile = vendorSoftwareProductManager.getTranslatedFile(VSP_ID, VERSION10);
493 return getFileNamesFromFolderInCsar(translatedFile,
497 private List<String> getFileNamesFromFolderInCsar(File csar, String folderName)
499 List<String> fileNames = new ArrayList<>();
501 try (ZipInputStream zip = new ZipInputStream(new FileInputStream(csar))) {
504 while ((ze = zip.getNextEntry()) != null) {
505 String name = ze.getName();
506 if (name.contains(folderName)) {
515 //Disabled for sonar null pointer issue for componentEntities
516 private Pair<String, String> uploadMib(String vspId, String user, String filePath,
518 List<ComponentEntity> componentEntities = null;
519 //(List<ComponentEntity>) vendorSoftwareProductManager.listComponents(vspId, null, user);
520 monitoringUploadsManager.upload(getFileInputStream(filePath),
523 VERSION01, componentEntities.get(0).getId(), ArtifactType.SNMP_POLL);
524 //TODO: add validate of logActivity() func call
526 VERSION01, componentEntities.get(0).getId(), MonitoringUploadType.SNMP_POLL, user);
527 //TODO: add validate of addActionLog() func call
528 >>>>>>> feature/Amdocs-ASDC-1710
530 return new ImmutablePair<>(componentEntities.get(0).getId(),
531 componentEntities.get(0).getComponentCompositionData()
535 // TODO: 3/15/2017 fix and enable
538 public void testUpdatedVSPShouldBeInBeginningOfList() {
539 vendorSoftwareProductManager.updateVsp(new VspDetails(), USER3);
540 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
542 InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
543 candidateManager.upload(id007, VERSION01, zis, USER3);
544 candidateManager.process(id007, VERSION01, USER3);
545 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
548 @Test(dependsOnMethods = {"testUpdatedVSPShouldBeInBeginningOfList"})
549 public void testVSPInBeginningOfListAfterCheckin() {
550 vendorSoftwareProductManager.checkin(id006, USER3);
551 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
553 vendorSoftwareProductManager.checkin(id007, USER3);
554 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
557 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckin"})
558 public void testVSPInBeginningOfListAfterCheckout() {
559 vendorSoftwareProductManager.checkout(id006, USER3);
560 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
563 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckout"})
564 public void testVSPInBeginningOfListAfterUndoCheckout() {
565 vendorSoftwareProductManager.checkout(id007, USER3);
566 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
568 vendorSoftwareProductManager.undoCheckout(id006, USER3);
569 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
572 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterUndoCheckout"})
573 public void testVSPInBeginningOfListAfterSubmit() throws IOException {
574 vendorSoftwareProductManager.checkin(id007, USER3);
575 vendorSoftwareProductManager.submit(id007, USER3);
577 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
581 public void testValidateWithCandidateDataNotProcessed() throws IOException {
583 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
584 "category", "subCategory", "licenseAgreementId",
585 Collections.singletonList("featureGroupId"));
586 vsp.setOnboardingMethod("NetworkPackage");
587 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
589 OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
590 OrchestrationTemplateCandidateData();
591 orchestrationTemplateCandidateData.setFileSuffix("zip");
592 orchestrationTemplateCandidateData.setFilesDataStructure("testdata");
593 orchestrationTemplateCandidateData.setValidationData("");
594 doReturn(Optional.of(orchestrationTemplateCandidateData))
595 .when(orchestrationTemplateCandidateManagerMock)
596 .getInfo(VSP_ID, VERSION01);
597 ValidationResponse validationResponse =
598 vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
599 Assert.assertNotNull(validationResponse);
600 Assert.assertFalse(validationResponse.isValid());
601 Assert.assertNotNull(validationResponse.getVspErrors());
602 Assert.assertEquals(validationResponse.getVspErrors().size(), 1);
607 public void testValidateWithCandidateProcessedIsInvalid() throws IOException {
608 VspDetails vsp = createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-VSP", "vendorName",
609 "vl1Id", "icond", "category", "subcategory", "licenseAgreementId", Collections
610 .singletonList("featureGroupId"));
611 vsp.setOnboardingMethod("NetworkPackage");
612 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
614 OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
615 OrchestrationTemplateCandidateData();
616 orchestrationTemplateCandidateData.setFileSuffix("zip");
617 orchestrationTemplateCandidateData.setValidationData("Invalid processed data");
618 doReturn(Optional.of(orchestrationTemplateCandidateData))
619 .when(orchestrationTemplateCandidateManagerMock)
620 .getInfo(VSP_ID, VERSION01);
621 ValidationResponse validationResponse =
622 vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
623 Assert.assertNotNull(validationResponse);
624 Assert.assertFalse(validationResponse.isValid());
625 Assert.assertNotNull(validationResponse.getVspErrors());
626 Assert.assertEquals(validationResponse.getVspErrors().size(), 1);
629 private void testLegalUpload(String vspId, Version version, InputStream upload, String user) {
630 candidateManager.upload(vspId, VERSION01, upload, "zip", "file");
631 candidateManager.process(vspId, VERSION01);
633 OrchestrationTemplateEntity uploadData =
634 orchestrationTemplateDataDaoMock.get(vspId, version);
635 Assert.assertNotNull(uploadData);
639 private InputStream getFileInputStream(String fileName) {
640 URL url = this.getClass().getResource(fileName);
642 return url.openStream();
643 } catch (IOException exception) {
644 exception.printStackTrace();
649 private static VspDetails createVspDetails(String id, Version version, String name, String desc,
650 String vendorName, String vlm, String icon,
651 String category, String subCategory,
652 String licenseAgreement, List<String> featureGroups) {
653 VspDetails vspDetails = new VspDetails(id, version);
654 vspDetails.setName(name);
655 vspDetails.setDescription(desc);
656 vspDetails.setIcon(icon);
657 vspDetails.setCategory(category);
658 vspDetails.setSubCategory(subCategory);
659 vspDetails.setVendorName(vendorName);
660 vspDetails.setVendorId(vlm);
661 vspDetails.setVlmVersion(new Version("1, 0"));
662 vspDetails.setLicenseAgreement(licenseAgreement);
663 vspDetails.setFeatureGroups(featureGroups);
664 vspDetails.setOnboardingMethod("HEAT");
668 private static void assertVspsEquals(VspDetails actual, VspDetails expected) {
669 Assert.assertEquals(actual.getId(), expected.getId());
670 Assert.assertEquals(actual.getVersion(), expected.getVersion());
671 Assert.assertEquals(actual.getName(), expected.getName());
672 Assert.assertEquals(actual.getDescription(), expected.getDescription());
673 Assert.assertEquals(actual.getIcon(), expected.getIcon());
674 Assert.assertEquals(actual.getCategory(), expected.getCategory());
675 Assert.assertEquals(actual.getSubCategory(), expected.getSubCategory());
676 Assert.assertEquals(actual.getVendorName(), expected.getVendorName());
677 Assert.assertEquals(actual.getVendorId(), expected.getVendorId());
678 Assert.assertEquals(actual.getLicenseAgreement(), expected.getLicenseAgreement());
679 Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups());
683 // todo ********************** move to common **************************************
685 private void mockVersioning(VersionableEntityAction action) {
686 VersionInfo versionInfo = new VersionInfo();
687 versionInfo.setActiveVersion(VERSION01);
688 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
689 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,