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 existingVsp.setWritetimeMicroSeconds(8L);
219 doReturn(existingVsp).when(vspInfoDaoMock)
220 .get(any(VspDetails.class));
221 doNothing().when(vendorSoftwareProductManager)
222 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
224 vendorSoftwareProductManager.updateVsp(updatedVsp);
226 verify(vspInfoDaoMock).update(updatedVsp);
230 public void testUpdateRemoveFG() {
231 VersionInfo versionInfo = new VersionInfo();
232 versionInfo.setActiveVersion(VERSION01);
233 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
234 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
235 VersionableEntityAction.Write);
236 List<String> fgs = new ArrayList<String>();
239 VspDetails existingVsp =
240 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
242 "subCategory", "456", fgs);
244 List<String> updFgs = new ArrayList<String>();
246 VspDetails updatedVsp =
247 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
249 "subCategory", "456", updFgs);
250 existingVsp.setWritetimeMicroSeconds(8L);
251 doReturn(existingVsp).when(vspInfoDaoMock)
252 .get(any(VspDetails.class));
253 doNothing().when(vendorSoftwareProductManager)
254 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
256 DeploymentFlavorEntity dfEntity = new DeploymentFlavorEntity(VSP_ID, VERSION01, "DF_ID");
257 DeploymentFlavor flavor = new DeploymentFlavor();
258 flavor.setFeatureGroupId("fg1");
259 dfEntity.setDeploymentFlavorCompositionData(flavor);
261 List<DeploymentFlavorEntity> dfList = new ArrayList<DeploymentFlavorEntity>();
262 dfList.add(dfEntity);
264 doReturn(dfList).when(deploymentFlavorDaoMock).list(anyObject());
266 vendorSoftwareProductManager.updateVsp(updatedVsp);
268 verify(deploymentFlavorDaoMock).update(dfEntity);
270 Assert.assertNull(dfEntity.getDeploymentFlavorCompositionData().getFeatureGroupId());
274 @Test(expectedExceptions = CoreException.class)
275 public void testGetNonExistingVersion_negative() {
276 Version notExistversion = new Version(43, 8);
277 doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
278 vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion);
282 public void testGetCheckedOutVersion() {
283 VersionInfo versionInfo = new VersionInfo();
284 versionInfo.setActiveVersion(VERSION01);
285 versionInfo.setStatus(VersionStatus.Locked);
286 versionInfo.setLockingUser(USER1);
287 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
288 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
289 VersionableEntityAction.Read);
291 VspDetails existingVsp =
292 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
294 "subCategory", "456", null);
295 existingVsp.setWritetimeMicroSeconds(8L);
296 doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class));
298 VspDetails actualVsp =
299 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
301 assertVspsEquals(actualVsp, existingVsp);
305 public void testGetOldVersion() {
306 VersionInfo versionInfo = new VersionInfo();
307 versionInfo.setActiveVersion(new Version(0, 2));
308 versionInfo.setViewableVersions(Arrays.asList(VERSION01, new Version(0, 2)));
309 versionInfo.setStatus(VersionStatus.Locked);
310 versionInfo.setLockingUser(USER2);
311 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
312 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
313 VersionableEntityAction.Read);
315 VspDetails existingVsp =
316 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
318 "subCategory", "456", null);
319 existingVsp.setWritetimeMicroSeconds(8L);
320 doReturn(existingVsp)
321 .when(vspInfoDaoMock).get(any(VspDetails.class));
323 VspDetails actualVsp =
324 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
326 VspDetails expectedVsp =
328 .get(new VspDetails(VSP_ID, VERSION01));
329 assertVspsEquals(actualVsp, expectedVsp);
334 public void testSubmitWithMissingData() throws IOException {
335 VersionInfo versionInfo = new VersionInfo();
336 versionInfo.setActiveVersion(VERSION01);
338 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
339 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
340 VSP_ID, USER1, VersionableEntityAction.Read);
342 VspDetails vsp = new VspDetails(VSP_ID, VERSION01);
343 vsp.setOnboardingMethod("Manual");
344 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
346 VspQuestionnaireEntity vspQuestionnaire = new VspQuestionnaireEntity(VSP_ID, VERSION01);
347 vspQuestionnaire.setQuestionnaireData("{}");
348 doReturn(vspQuestionnaire).when(vspInfoDaoMock).getQuestionnaire(VSP_ID, VERSION01);
350 ComponentEntity comp1 = new ComponentEntity(VSP_ID, VERSION01, "comp1");
351 comp1.setQuestionnaireData("{}");
352 doReturn(Collections.singleton(comp1)).when(vendorSoftwareProductDaoMock)
353 .listComponentsCompositionAndQuestionnaire(VSP_ID, VERSION01);
355 NicEntity nic1 = new NicEntity(VSP_ID, VERSION01, "comp1", "nic1");
356 nic1.setQuestionnaireData("{}");
357 doReturn(Collections.singleton(nic1))
358 .when(vendorSoftwareProductDaoMock).listNicsByVsp(VSP_ID, VERSION01);
360 ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1);
361 Assert.assertNotNull(validationResponse);
362 Assert.assertFalse(validationResponse.isValid());
363 List<String> errorIds = validationResponse.getVspErrors().stream().map(ErrorCode::id).distinct()
364 .collect(Collectors.toList());
365 Assert.assertTrue(errorIds.contains(ValidationErrorBuilder.FIELD_VALIDATION_ERROR_ERR_ID));
366 Assert.assertTrue(errorIds.contains(VendorSoftwareProductErrorCodes.VSP_INVALID));
368 verify(versioningManagerMock, never())
369 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
371 verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
376 // TODO: 3/15/2017 fix and enable
378 public void testSubmitWithInvalidLicensingData() throws IOException {
379 VersionInfo versionInfo = new VersionInfo();
380 versionInfo.setActiveVersion(VERSION01);
381 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
382 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
383 VSP_ID, USER1, VersionableEntityAction.Read);
386 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
387 "category", "subCategory", "licenseAgreementId",
388 Collections.singletonList("featureGroupId"));
389 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
390 OrchestrationTemplateEntity uploadData = new OrchestrationTemplateEntity(VSP_ID, VERSION01);
391 uploadData.setContentData(
392 ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition"))));
393 doReturn(uploadData).when(orchestrationTemplateDataDaoMock)
394 .get(anyObject(), anyObject());
395 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(),
396 "MainServiceTemplate.yaml"))
397 .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01);
399 ValidationResponse validationResponse =
400 vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
401 Assert.assertNotNull(validationResponse);
402 Assert.assertFalse(validationResponse.isValid());
403 Assert.assertNull(validationResponse.getVspErrors());
404 Assert.assertEquals(validationResponse.getLicensingDataErrors().size(), 1);
406 verify(versioningManagerMock, never())
407 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
411 // TODO: 3/15/2017 fix and enable
413 public void testSubmit() throws IOException {
414 mockVersioning(VersionableEntityAction.Read);
416 EnrichmentManagerFactory.getInstance();
418 .registerFactory(EnrichmentManagerFactory.class, EnrichmentManagerFactoryImpl.class);
421 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
422 "category", "subCategory", "123", Collections.singletonList("fg1"));
423 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
424 OrchestrationTemplateEntity uploadData = new OrchestrationTemplateEntity(VSP_ID, VERSION01);
425 uploadData.setContentData(
426 ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition"))));
427 doReturn(uploadData).when(orchestrationTemplateDataDaoMock)
428 .get(anyObject(), anyObject());
429 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(),
430 "MainServiceTemplate.yaml"))
431 .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01);
433 ValidationResponse validationResponse =
434 vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
435 Assert.assertTrue(validationResponse.isValid());
437 /* Assert.assertEquals(vsp2.getVersionInfo().getVersion(), VERSION10);
438 Assert.assertEquals(vsp2.getVersionInfo().getStatus(), VersionStatus.Certified);
439 Assert.assertNull(vsp2.getVersionInfo().getLockingUser());*/
441 verify(versioningManagerMock)
442 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
447 public void testCreatePackage() throws IOException {
448 /*VspDetails vspDetailsMock = new VspDetails("vspId", new Version(1, 0));
449 doReturn(vspDetailsMock).when(vspInfoDaoMock).get(anyObject());*/
450 VersionInfo versionInfo = new VersionInfo();
451 versionInfo.setActiveVersion(VERSION10);
452 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
453 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
454 VersionableEntityAction.Read);
456 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), "")).when
457 (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10);
458 doNothing().when(vendorSoftwareProductManager).populateVersionsForVlm(anyObject(), anyObject());
459 VspDetails vsp = new VspDetails(VSP_ID, VERSION10);
460 vsp.setVendorId("vendorId");
461 vsp.setVlmVersion(VERSION10);
462 vsp.setFeatureGroups(Arrays.asList("fg1", "fg2"));
463 doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class));
465 doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock)
466 .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups()
469 PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10);
470 Assert.assertNotNull(packageInfo.getVspId());
473 // TODO: 3/15/2017 fix and enable
474 //@Test(dependsOnMethods = {"testListFinals"})
475 public void testUploadFileMissingFile() throws IOException {
476 try (InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip")) {
478 UploadFileResponse uploadFileResponse =
479 candidateManager.upload(VSP_ID, VERSION01, zis, "zip", "file");
481 Assert.assertEquals(uploadFileResponse.getErrors().size(), 0);
485 // TODO: 3/15/2017 fix and enable
486 //@Test(dependsOnMethods = {"testUploadFileMissingFile"})
487 public void testUploadNotZipFile() throws IOException {
488 URL url = this.getClass().getResource("/notZipFile");
491 candidateManager.upload(VSP_ID, VERSION01, url.openStream(), "zip", "file");
492 candidateManager.process(VSP_ID, VERSION01);
493 } catch (Exception ce) {
494 Assert.assertEquals(ce.getMessage(), Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage());
498 private List<String> getWantedFileNamesFromCsar(String pathInCsar)
500 File translatedFile = vendorSoftwareProductManager.getTranslatedFile(VSP_ID, VERSION10);
502 return getFileNamesFromFolderInCsar(translatedFile,
506 private List<String> getFileNamesFromFolderInCsar(File csar, String folderName)
508 List<String> fileNames = new ArrayList<>();
510 try (ZipInputStream zip = new ZipInputStream(new FileInputStream(csar))) {
513 while ((ze = zip.getNextEntry()) != null) {
514 String name = ze.getName();
515 if (name.contains(folderName)) {
524 //Disabled for sonar null pointer issue for componentEntities
525 private Pair<String, String> uploadMib(String vspId, String user, String filePath,
527 List<ComponentEntity> componentEntities = null;
528 //(List<ComponentEntity>) vendorSoftwareProductManager.listComponents(vspId, null, user);
529 monitoringUploadsManager.upload(getFileInputStream(filePath),
532 VERSION01, componentEntities.get(0).getId(), ArtifactType.SNMP_POLL);
533 //TODO: add validate of logActivity() func call
535 VERSION01, componentEntities.get(0).getId(), MonitoringUploadType.SNMP_POLL, user);
536 //TODO: add validate of addActionLog() func call
537 >>>>>>> feature/Amdocs-ASDC-1710
539 return new ImmutablePair<>(componentEntities.get(0).getId(),
540 componentEntities.get(0).getComponentCompositionData()
544 // TODO: 3/15/2017 fix and enable
547 public void testUpdatedVSPShouldBeInBeginningOfList() {
548 vendorSoftwareProductManager.updateVsp(new VspDetails(), USER3);
549 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
551 InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
552 candidateManager.upload(id007, VERSION01, zis, USER3);
553 candidateManager.process(id007, VERSION01, USER3);
554 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
557 @Test(dependsOnMethods = {"testUpdatedVSPShouldBeInBeginningOfList"})
558 public void testVSPInBeginningOfListAfterCheckin() {
559 vendorSoftwareProductManager.checkin(id006, USER3);
560 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
562 vendorSoftwareProductManager.checkin(id007, USER3);
563 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
566 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckin"})
567 public void testVSPInBeginningOfListAfterCheckout() {
568 vendorSoftwareProductManager.checkout(id006, USER3);
569 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
572 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckout"})
573 public void testVSPInBeginningOfListAfterUndoCheckout() {
574 vendorSoftwareProductManager.checkout(id007, USER3);
575 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
577 vendorSoftwareProductManager.undoCheckout(id006, USER3);
578 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
581 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterUndoCheckout"})
582 public void testVSPInBeginningOfListAfterSubmit() throws IOException {
583 vendorSoftwareProductManager.checkin(id007, USER3);
584 vendorSoftwareProductManager.submit(id007, USER3);
586 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
590 public void testValidateWithCandidateDataNotProcessed() throws IOException {
592 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
593 "category", "subCategory", "licenseAgreementId",
594 Collections.singletonList("featureGroupId"));
595 vsp.setOnboardingMethod("NetworkPackage");
596 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
598 OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
599 OrchestrationTemplateCandidateData();
600 orchestrationTemplateCandidateData.setFileSuffix("zip");
601 orchestrationTemplateCandidateData.setFilesDataStructure("testdata");
602 orchestrationTemplateCandidateData.setValidationData("");
603 doReturn(orchestrationTemplateCandidateData).when(orchestrationTemplateCandidateManagerMock)
604 .getInfo(VSP_ID, VERSION01);
605 ValidationResponse validationResponse =
606 vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
607 Assert.assertNotNull(validationResponse);
608 Assert.assertFalse(validationResponse.isValid());
609 Assert.assertNotNull(validationResponse.getVspErrors());
610 Assert.assertEquals(validationResponse.getVspErrors().size(), 1);
615 public void testValidateWithCandidateProcessedIsInvalid() throws IOException {
616 VspDetails vsp = createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-VSP", "vendorName",
617 "vl1Id", "icond", "category", "subcategory", "licenseAgreementId", Collections
618 .singletonList("featureGroupId"));
619 vsp.setOnboardingMethod("NetworkPackage");
620 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
622 OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
623 OrchestrationTemplateCandidateData();
624 orchestrationTemplateCandidateData.setFileSuffix("zip");
625 orchestrationTemplateCandidateData.setValidationData("Invalid processed data");
626 doReturn(orchestrationTemplateCandidateData).when(orchestrationTemplateCandidateManagerMock)
627 .getInfo(VSP_ID, VERSION01);
628 ValidationResponse validationResponse =
629 vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
630 Assert.assertNotNull(validationResponse);
631 Assert.assertFalse(validationResponse.isValid());
632 Assert.assertNotNull(validationResponse.getVspErrors());
633 Assert.assertEquals(validationResponse.getVspErrors().size(), 1);
636 private void testLegalUpload(String vspId, Version version, InputStream upload, String user) {
637 candidateManager.upload(vspId, VERSION01, upload, "zip", "file");
638 candidateManager.process(vspId, VERSION01);
640 OrchestrationTemplateEntity uploadData =
641 orchestrationTemplateDataDaoMock.get(vspId, version);
642 Assert.assertNotNull(uploadData);
646 public InputStream getFileInputStream(String fileName) {
647 URL url = this.getClass().getResource(fileName);
649 return url.openStream();
650 } catch (IOException exception) {
651 exception.printStackTrace();
656 static VspDetails createVspDetails(String id, Version version, String name, String desc,
657 String vendorName, String vlm, String icon,
658 String category, String subCategory,
659 String licenseAgreement, List<String> featureGroups) {
660 VspDetails vspDetails = new VspDetails(id, version);
661 vspDetails.setName(name);
662 vspDetails.setDescription(desc);
663 vspDetails.setIcon(icon);
664 vspDetails.setCategory(category);
665 vspDetails.setSubCategory(subCategory);
666 vspDetails.setVendorName(vendorName);
667 vspDetails.setVendorId(vlm);
668 vspDetails.setVlmVersion(new Version(1, 0));
669 vspDetails.setLicenseAgreement(licenseAgreement);
670 vspDetails.setFeatureGroups(featureGroups);
671 vspDetails.setOnboardingMethod("HEAT");
675 static void assertVspsEquals(VspDetails actual, VspDetails expected) {
676 Assert.assertEquals(actual.getId(), expected.getId());
677 Assert.assertEquals(actual.getVersion(), expected.getVersion());
678 Assert.assertEquals(actual.getName(), expected.getName());
679 Assert.assertEquals(actual.getDescription(), expected.getDescription());
680 Assert.assertEquals(actual.getIcon(), expected.getIcon());
681 Assert.assertEquals(actual.getCategory(), expected.getCategory());
682 Assert.assertEquals(actual.getSubCategory(), expected.getSubCategory());
683 Assert.assertEquals(actual.getVendorName(), expected.getVendorName());
684 Assert.assertEquals(actual.getVendorId(), expected.getVendorId());
685 Assert.assertEquals(actual.getLicenseAgreement(), expected.getLicenseAgreement());
686 Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups());
690 // todo ********************** move to common **************************************
692 private void mockVersioning(VersionableEntityAction action) {
693 VersionInfo versionInfo = new VersionInfo();
694 versionInfo.setActiveVersion(VERSION01);
695 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
696 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,