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