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;
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;
55 import java.io.FileInputStream;
56 import java.io.IOException;
57 import java.io.InputStream;
59 import java.nio.ByteBuffer;
61 import java.util.zip.ZipEntry;
62 import java.util.zip.ZipInputStream;
64 import static org.mockito.Matchers.any;
65 import static org.mockito.Matchers.anyObject;
66 import static org.mockito.Mockito.*;
69 public class VendorSoftwareProductManagerImplTest {
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";
78 private ActionVersioningManager versioningManagerMock;
80 private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
82 private VendorLicenseFacade vendorLicenseFacadeMock;
84 private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
86 private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDaoMock;
88 private HealingManager healingManagerMock;
90 private VendorLicenseArtifactsService licenseArtifactsServiceMock;
92 private CompositionEntityDataManager compositionEntityDataManagerMock;
94 private InformationArtifactGenerator informationArtifactGeneratorMock;
96 private PackageInfoDao packageInfoDao;
98 private VendorSoftwareProductInfoDao vspInfoDaoMock;
100 private ManualVspToscaManager manualVspToscaManager;
102 private DeploymentFlavorDao deploymentFlavorDaoMock;
107 private VendorSoftwareProductManagerImpl vendorSoftwareProductManager;
110 private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManagerMock;
112 private ComponentDependencyModelDao componentDependencyModelDao;
113 private OrchestrationTemplateCandidateManager candidateManager;
114 private MonitoringUploadsManager monitoringUploadsManager;
117 private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
120 public void setUp() {
121 MockitoAnnotations.initMocks(this);
125 public void tearDown() {
126 vendorSoftwareProductManager = null;
131 public void testCreate() {
132 //doReturn(VERSION01).when(versioningManagerMock).create(anyObject(), anyObject(), anyObject());
134 .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject());
136 VspDetails vspToCreate =
137 createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
138 "category", "subCategory", "123", null);
140 VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate);
142 Assert.assertNotNull(vsp);
143 vspToCreate.setId(vsp.getId());
144 vspToCreate.setVersion(VERSION01);
145 assertVspsEquals(vsp, vspToCreate);
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);
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());
169 vendorSoftwareProductManager.updateVsp(updatedVsp);
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",
182 "subCategory", "456", null);
183 VspDetails updatedVsp =
184 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
186 "subCategory", "456", null);
187 doReturn(existingVsp).when(vspInfoDaoMock)
188 .get(any(VspDetails.class));
189 doNothing().when(vendorSoftwareProductManager)
190 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
192 vendorSoftwareProductManager.updateVsp(updatedVsp);
194 verify(vspInfoDaoMock).update(updatedVsp);
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<>();
207 VspDetails existingVsp =
208 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
210 "subCategory", "456", fgs);
212 List<String> updFgs = new ArrayList<>();
214 VspDetails updatedVsp =
215 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
217 "subCategory", "456", updFgs);
218 doReturn(existingVsp).when(vspInfoDaoMock)
219 .get(any(VspDetails.class));
220 doNothing().when(vendorSoftwareProductManager)
221 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
223 DeploymentFlavorEntity dfEntity = new DeploymentFlavorEntity(VSP_ID, VERSION01, "DF_ID");
224 DeploymentFlavor flavor = new DeploymentFlavor();
225 flavor.setFeatureGroupId("fg1");
226 dfEntity.setDeploymentFlavorCompositionData(flavor);
228 List<DeploymentFlavorEntity> dfList = new ArrayList<>();
229 dfList.add(dfEntity);
231 doReturn(dfList).when(deploymentFlavorDaoMock).list(anyObject());
233 vendorSoftwareProductManager.updateVsp(updatedVsp);
235 verify(deploymentFlavorDaoMock).update(dfEntity);
237 Assert.assertNull(dfEntity.getDeploymentFlavorCompositionData().getFeatureGroupId());
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);
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);
258 VspDetails existingVsp =
259 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
261 "subCategory", "456", null);
262 doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class));
264 VspDetails actualVsp =
265 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
267 assertVspsEquals(actualVsp, existingVsp);
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);
281 VspDetails existingVsp =
282 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
284 "subCategory", "456", null);
285 doReturn(existingVsp)
286 .when(vspInfoDaoMock).get(any(VspDetails.class));
288 VspDetails actualVsp =
289 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
291 VspDetails expectedVsp =
293 .get(new VspDetails(VSP_ID, VERSION01));
294 assertVspsEquals(actualVsp, expectedVsp);
299 public void testSubmitWithMissingData() throws IOException {
300 VersionInfo versionInfo = new VersionInfo();
301 versionInfo.setActiveVersion(VERSION01);
303 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
304 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
305 VSP_ID, USER1, VersionableEntityAction.Read);
307 VspDetails vsp = new VspDetails(VSP_ID, VERSION01);
308 vsp.setOnboardingMethod("Manual");
309 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
311 VspQuestionnaireEntity vspQuestionnaire = new VspQuestionnaireEntity(VSP_ID, VERSION01);
312 vspQuestionnaire.setQuestionnaireData("{}");
313 doReturn(vspQuestionnaire).when(vspInfoDaoMock).getQuestionnaire(VSP_ID, VERSION01);
315 ComponentEntity comp1 = new ComponentEntity(VSP_ID, VERSION01, "comp1");
316 comp1.setQuestionnaireData("{}");
317 doReturn(Collections.singleton(comp1)).when(vendorSoftwareProductDaoMock)
318 .listComponentsCompositionAndQuestionnaire(VSP_ID, VERSION01);
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);
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));
333 verify(versioningManagerMock, never())
334 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
336 verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
341 // TODO: 3/15/2017 fix and enable
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);
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);
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);
371 verify(versioningManagerMock, never())
372 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
376 // TODO: 3/15/2017 fix and enable
378 public void testSubmit() throws IOException {
379 mockVersioning(VersionableEntityAction.Read);
381 EnrichmentManagerFactory.getInstance();
383 .registerFactory(EnrichmentManagerFactory.class, EnrichmentManagerFactoryImpl.class);
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);
398 ValidationResponse validationResponse =
399 vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
400 Assert.assertTrue(validationResponse.isValid());
402 /* Assert.assertEquals(vsp2.getVersionInfo().getVersion(), VERSION10);
403 Assert.assertEquals(vsp2.getVersionInfo().getStatus(), VersionStatus.Certified);
404 Assert.assertNull(vsp2.getVersionInfo().getLockingUser());*/
406 verify(versioningManagerMock)
407 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
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);
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));
430 doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock)
431 .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups()
434 PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10);
435 Assert.assertNotNull(packageInfo.getVspId());
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")) {
443 UploadFileResponse uploadFileResponse =
444 candidateManager.upload(VSP_ID, VERSION01, zis, "zip", "file");
446 Assert.assertEquals(uploadFileResponse.getErrors().size(), 0);
450 // TODO: 3/15/2017 fix and enable
451 //@Test(dependsOnMethods = {"testUploadFileMissingFile"})
452 public void testUploadNotZipFile() {
453 URL url = this.getClass().getResource("/notZipFile");
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());
463 private List<String> getWantedFileNamesFromCsar(String pathInCsar)
465 File translatedFile = vendorSoftwareProductManager.getTranslatedFile(VSP_ID, VERSION10);
467 return getFileNamesFromFolderInCsar(translatedFile,
471 private List<String> getFileNamesFromFolderInCsar(File csar, String folderName)
473 List<String> fileNames = new ArrayList<>();
475 try (ZipInputStream zip = new ZipInputStream(new FileInputStream(csar))) {
478 while ((ze = zip.getNextEntry()) != null) {
479 String name = ze.getName();
480 if (name.contains(folderName)) {
489 //Disabled for sonar null pointer issue for componentEntities
490 private Pair<String, String> uploadMib(String vspId, String user, String filePath,
492 List<ComponentEntity> componentEntities = null;
493 //(List<ComponentEntity>) vendorSoftwareProductManager.listComponents(vspId, null, user);
494 monitoringUploadsManager.upload(getFileInputStream(filePath),
497 VERSION01, componentEntities.get(0).getId(), ArtifactType.SNMP_POLL);
498 //TODO: add validate of logActivity() func call
500 VERSION01, componentEntities.get(0).getId(), MonitoringUploadType.SNMP_POLL, user);
501 //TODO: add validate of addActionLog() func call
502 >>>>>>> feature/Amdocs-ASDC-1710
504 return new ImmutablePair<>(componentEntities.get(0).getId(),
505 componentEntities.get(0).getComponentCompositionData()
509 // TODO: 3/15/2017 fix and enable
512 public void testUpdatedVSPShouldBeInBeginningOfList() {
513 vendorSoftwareProductManager.updateVsp(new VspDetails(), USER3);
514 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
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);
522 @Test(dependsOnMethods = {"testUpdatedVSPShouldBeInBeginningOfList"})
523 public void testVSPInBeginningOfListAfterCheckin() {
524 vendorSoftwareProductManager.checkin(id006, USER3);
525 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
527 vendorSoftwareProductManager.checkin(id007, USER3);
528 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
531 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckin"})
532 public void testVSPInBeginningOfListAfterCheckout() {
533 vendorSoftwareProductManager.checkout(id006, USER3);
534 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
537 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckout"})
538 public void testVSPInBeginningOfListAfterUndoCheckout() {
539 vendorSoftwareProductManager.checkout(id007, USER3);
540 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
542 vendorSoftwareProductManager.undoCheckout(id006, USER3);
543 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
546 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterUndoCheckout"})
547 public void testVSPInBeginningOfListAfterSubmit() throws IOException {
548 vendorSoftwareProductManager.checkin(id007, USER3);
549 vendorSoftwareProductManager.submit(id007, USER3);
551 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
555 public void testValidateWithCandidateDataNotProcessed() throws IOException {
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());
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);
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());
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);
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);
607 OrchestrationTemplateEntity uploadData =
608 orchestrationTemplateDataDaoMock.get(vspId, version);
609 Assert.assertNotNull(uploadData);
613 private InputStream getFileInputStream(String fileName) {
614 URL url = this.getClass().getResource(fileName);
616 return url.openStream();
617 } catch (IOException exception) {
618 exception.printStackTrace();
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");
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());
657 // todo ********************** move to common **************************************
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,