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.VersioningManager;
70 import org.openecomp.sdc.versioning.dao.types.Version;
71 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
72 import org.openecomp.sdc.versioning.types.VersionInfo;
73 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
74 import org.testng.Assert;
75 import org.testng.annotations.AfterMethod;
76 import org.testng.annotations.BeforeMethod;
77 import org.testng.annotations.Test;
80 import java.io.FileInputStream;
81 import java.io.IOException;
82 import java.io.InputStream;
84 import java.nio.ByteBuffer;
85 import java.util.ArrayList;
86 import java.util.Arrays;
87 import java.util.Collections;
88 import java.util.HashMap;
89 import java.util.List;
90 import java.util.zip.ZipEntry;
91 import java.util.zip.ZipInputStream;
94 public class VendorSoftwareProductManagerImplTest {
95 private static final String INVALID_VERSION_MSG = "Invalid requested version.";
97 private static String VSP_ID = "vspId";
98 private static String VERSION_ID = "versionId";
99 public static final Version VERSION01 = new Version(0, 1);
100 private static final Version VERSION10 = new Version(1, 0);
101 private static final String USER1 = "vspTestUser1";
102 private static final String USER2 = "vspTestUser2";
103 private static final String USER3 = "vspTestUser3";
104 private static String id006 = null;
105 private static String id007 = null;
108 private VersioningManager versioningManagerMock;
110 private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
112 private VendorLicenseFacade vendorLicenseFacadeMock;
114 private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
116 private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDaoMock;
118 private HealingManager healingManagerMock;
120 private VendorLicenseArtifactsService licenseArtifactsServiceMock;
122 private CompositionEntityDataManager compositionEntityDataManagerMock;
124 private InformationArtifactGenerator informationArtifactGeneratorMock;
126 private PackageInfoDao packageInfoDao;
128 private VendorSoftwareProductInfoDao vspInfoDaoMock;
130 private ManualVspToscaManager manualVspToscaManager;
132 private DeploymentFlavorDao deploymentFlavorDaoMock;
137 private VendorSoftwareProductManagerImpl vendorSoftwareProductManager;
140 private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManagerMock;
142 private ComponentDependencyModelDao componentDependencyModelDao;
143 private OrchestrationTemplateCandidateManager candidateManager;
144 private MonitoringUploadsManager monitoringUploadsManager;
147 private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
150 public void setUp() throws Exception {
151 MockitoAnnotations.initMocks(this);
155 public void tearDown(){
156 vendorSoftwareProductManager = null;
161 public void testCreate() {
162 //doReturn(VERSION01).when(versioningManagerMock).create(anyObject(), anyObject(), anyObject());
164 .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject());
166 VspDetails vspToCreate =
167 createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
168 "category", "subCategory", "123", null);
170 VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate);
172 Assert.assertNotNull(vsp);
173 vspToCreate.setId(vsp.getId());
174 vspToCreate.setVersion(VERSION01);
175 assertVspsEquals(vsp, vspToCreate);
178 @Test(expectedExceptions = CoreException.class)
179 public void testUpdateWithExistingName_negative() {
180 VersionInfo versionInfo = new VersionInfo();
181 versionInfo.setActiveVersion(VERSION01);
182 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
183 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
184 VersionableEntityAction.Write);
186 VspDetails existingVsp =
187 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-existingVsp", "vendorName", "vlm1Id",
188 "icon", "category", "subCategory", "123", null);
189 VspDetails updatedVsp =
190 createVspDetails(VSP_ID, VERSION01, "Vsp1_updated", "Test-existingVsp", "vendorName",
191 "vlm1Id", "icon", "category", "subCategory", "123", null);
192 doReturn(existingVsp).when(vspInfoDaoMock)
193 .get(any(VspDetails.class));
194 doThrow(new CoreException(
195 new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build()))
196 .when(vendorSoftwareProductManager)
197 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
199 vendorSoftwareProductManager.updateVsp(updatedVsp);
203 public void testUpdate() {
204 VersionInfo versionInfo = new VersionInfo();
205 versionInfo.setActiveVersion(VERSION01);
206 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
207 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
208 VersionableEntityAction.Write);
209 VspDetails existingVsp =
210 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
212 "subCategory", "456", null);
213 VspDetails updatedVsp =
214 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
216 "subCategory", "456", null);
217 existingVsp.setWritetimeMicroSeconds(8L);
218 doReturn(existingVsp).when(vspInfoDaoMock)
219 .get(any(VspDetails.class));
220 doNothing().when(vendorSoftwareProductManager)
221 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
223 vendorSoftwareProductManager.updateVsp(updatedVsp);
225 verify(vspInfoDaoMock).update(updatedVsp);
229 public void testUpdateRemoveFG() {
230 VersionInfo versionInfo = new VersionInfo();
231 versionInfo.setActiveVersion(VERSION01);
232 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
233 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
234 VersionableEntityAction.Write);
235 List<String> fgs = new ArrayList<String>();
238 VspDetails existingVsp =
239 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
241 "subCategory", "456", fgs);
243 List<String> updFgs = new ArrayList<String>();
245 VspDetails updatedVsp =
246 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
248 "subCategory", "456", updFgs);
249 existingVsp.setWritetimeMicroSeconds(8L);
250 doReturn(existingVsp).when(vspInfoDaoMock)
251 .get(any(VspDetails.class));
252 doNothing().when(vendorSoftwareProductManager)
253 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
255 DeploymentFlavorEntity dfEntity = new DeploymentFlavorEntity(VSP_ID, VERSION01, "DF_ID");
256 DeploymentFlavor flavor = new DeploymentFlavor();
257 flavor.setFeatureGroupId("fg1");
258 dfEntity.setDeploymentFlavorCompositionData(flavor);
260 List<DeploymentFlavorEntity> dfList = new ArrayList<DeploymentFlavorEntity>();
261 dfList.add(dfEntity);
263 doReturn(dfList).when(deploymentFlavorDaoMock).list(anyObject());
265 vendorSoftwareProductManager.updateVsp(updatedVsp);
267 verify(deploymentFlavorDaoMock).update(dfEntity);
269 Assert.assertNull(dfEntity.getDeploymentFlavorCompositionData().getFeatureGroupId());
273 @Test(expectedExceptions = CoreException.class)
274 public void testGetNonExistingVersion_negative() {
275 Version notExistversion = new Version(43, 8);
276 doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
277 vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion);
281 public void testGetCheckedOutVersion() {
282 VersionInfo versionInfo = new VersionInfo();
283 versionInfo.setActiveVersion(VERSION01);
284 versionInfo.setStatus(VersionStatus.Locked);
285 versionInfo.setLockingUser(USER1);
286 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
287 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
288 VersionableEntityAction.Read);
290 VspDetails existingVsp =
291 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
293 "subCategory", "456", null);
294 existingVsp.setWritetimeMicroSeconds(8L);
295 doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class));
297 VspDetails actualVsp =
298 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
300 assertVspsEquals(actualVsp, existingVsp);
304 public void testGetOldVersion() {
305 VersionInfo versionInfo = new VersionInfo();
306 versionInfo.setActiveVersion(new Version(0, 2));
307 versionInfo.setViewableVersions(Arrays.asList(VERSION01, new Version(0, 2)));
308 versionInfo.setStatus(VersionStatus.Locked);
309 versionInfo.setLockingUser(USER2);
310 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
311 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
312 VersionableEntityAction.Read);
314 VspDetails existingVsp =
315 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
317 "subCategory", "456", null);
318 existingVsp.setWritetimeMicroSeconds(8L);
319 doReturn(existingVsp)
320 .when(vspInfoDaoMock).get(any(VspDetails.class));
322 VspDetails actualVsp =
323 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
325 VspDetails expectedVsp =
327 .get(new VspDetails(VSP_ID, VERSION01));
328 assertVspsEquals(actualVsp, expectedVsp);
333 public void testSubmitWithMissingData() throws IOException {
334 VersionInfo versionInfo = new VersionInfo();
335 versionInfo.setActiveVersion(VERSION01);
337 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
338 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
339 VSP_ID, USER1, VersionableEntityAction.Read);
341 VspDetails vsp = new VspDetails(VSP_ID, VERSION01);
342 vsp.setOnboardingMethod("Manual");
343 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
345 VspQuestionnaireEntity vspQuestionnaire = new VspQuestionnaireEntity(VSP_ID, VERSION01);
346 vspQuestionnaire.setQuestionnaireData("{}");
347 doReturn(vspQuestionnaire).when(vspInfoDaoMock).getQuestionnaire(VSP_ID, VERSION01);
349 ComponentEntity comp1 = new ComponentEntity(VSP_ID, VERSION01, "comp1");
350 comp1.setQuestionnaireData("{}");
351 doReturn(Collections.singleton(comp1)).when(vendorSoftwareProductDaoMock)
352 .listComponentsCompositionAndQuestionnaire(VSP_ID, VERSION01);
354 NicEntity nic1 = new NicEntity(VSP_ID, VERSION01, "comp1", "nic1");
355 nic1.setQuestionnaireData("{}");
356 doReturn(Collections.singleton(nic1))
357 .when(vendorSoftwareProductDaoMock).listNicsByVsp(VSP_ID, VERSION01);
359 ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1);
360 Assert.assertNotNull(validationResponse);
361 Assert.assertFalse(validationResponse.isValid());
362 List<String> errorIds = validationResponse.getVspErrors().stream().map(ErrorCode::id).distinct()
363 .collect(Collectors.toList());
364 Assert.assertTrue(errorIds.contains(ValidationErrorBuilder.FIELD_VALIDATION_ERROR_ERR_ID));
365 Assert.assertTrue(errorIds.contains(VendorSoftwareProductErrorCodes.VSP_INVALID));
367 verify(versioningManagerMock, never())
368 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
370 verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
375 // TODO: 3/15/2017 fix and enable
377 public void testSubmitWithInvalidLicensingData() throws IOException {
378 VersionInfo versionInfo = new VersionInfo();
379 versionInfo.setActiveVersion(VERSION01);
380 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
381 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
382 VSP_ID, USER1, VersionableEntityAction.Read);
385 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
386 "category", "subCategory", "licenseAgreementId",
387 Collections.singletonList("featureGroupId"));
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.assertNotNull(validationResponse);
401 Assert.assertFalse(validationResponse.isValid());
402 Assert.assertNull(validationResponse.getVspErrors());
403 Assert.assertEquals(validationResponse.getLicensingDataErrors().size(), 1);
405 verify(versioningManagerMock, never())
406 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
410 // TODO: 3/15/2017 fix and enable
412 public void testSubmit() throws IOException {
413 mockVersioning(VersionableEntityAction.Read);
415 EnrichmentManagerFactory.getInstance();
417 .registerFactory(EnrichmentManagerFactory.class, EnrichmentManagerFactoryImpl.class);
420 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
421 "category", "subCategory", "123", Collections.singletonList("fg1"));
422 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
423 OrchestrationTemplateEntity uploadData = new OrchestrationTemplateEntity(VSP_ID, VERSION01);
424 uploadData.setContentData(
425 ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition"))));
426 doReturn(uploadData).when(orchestrationTemplateDataDaoMock)
427 .get(anyObject(), anyObject());
428 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(),
429 "MainServiceTemplate.yaml"))
430 .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01);
432 ValidationResponse validationResponse =
433 vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
434 Assert.assertTrue(validationResponse.isValid());
436 /* Assert.assertEquals(vsp2.getVersionInfo().getVersion(), VERSION10);
437 Assert.assertEquals(vsp2.getVersionInfo().getStatus(), VersionStatus.Certified);
438 Assert.assertNull(vsp2.getVersionInfo().getLockingUser());*/
440 verify(versioningManagerMock)
441 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
446 public void testCreatePackage() throws IOException {
447 /*VspDetails vspDetailsMock = new VspDetails("vspId", new Version(1, 0));
448 doReturn(vspDetailsMock).when(vspInfoDaoMock).get(anyObject());*/
449 VersionInfo versionInfo = new VersionInfo();
450 versionInfo.setActiveVersion(VERSION10);
451 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
452 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
453 VersionableEntityAction.Read);
455 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), "")).when
456 (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10);
457 doNothing().when(vendorSoftwareProductManager).populateVersionsForVlm(anyObject(), anyObject());
458 VspDetails vsp = new VspDetails(VSP_ID, VERSION10);
459 vsp.setVendorId("vendorId");
460 vsp.setVlmVersion(VERSION10);
461 vsp.setFeatureGroups(Arrays.asList("fg1", "fg2"));
462 doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class));
464 doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock)
465 .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups()
468 PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10);
469 Assert.assertNotNull(packageInfo.getVspId());
472 // TODO: 3/15/2017 fix and enable
473 //@Test(dependsOnMethods = {"testListFinals"})
474 public void testUploadFileMissingFile() throws IOException {
475 try (InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip")) {
477 UploadFileResponse uploadFileResponse =
478 candidateManager.upload(VSP_ID, VERSION01, zis, "zip", "file");
480 Assert.assertEquals(uploadFileResponse.getErrors().size(), 0);
484 // TODO: 3/15/2017 fix and enable
485 //@Test(dependsOnMethods = {"testUploadFileMissingFile"})
486 public void testUploadNotZipFile() throws IOException {
487 URL url = this.getClass().getResource("/notZipFile");
490 candidateManager.upload(VSP_ID, VERSION01, url.openStream(), "zip", "file");
491 candidateManager.process(VSP_ID, VERSION01);
492 } catch (Exception ce) {
493 Assert.assertEquals(ce.getMessage(), Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage());
497 private List<String> getWantedFileNamesFromCsar(String pathInCsar)
499 File translatedFile = vendorSoftwareProductManager.getTranslatedFile(VSP_ID, VERSION10);
501 return getFileNamesFromFolderInCsar(translatedFile,
505 private List<String> getFileNamesFromFolderInCsar(File csar, String folderName)
507 List<String> fileNames = new ArrayList<>();
509 try (ZipInputStream zip = new ZipInputStream(new FileInputStream(csar))) {
512 while ((ze = zip.getNextEntry()) != null) {
513 String name = ze.getName();
514 if (name.contains(folderName)) {
523 //Disabled for sonar null pointer issue for componentEntities
524 private Pair<String, String> uploadMib(String vspId, String user, String filePath,
526 List<ComponentEntity> componentEntities = null;
527 //(List<ComponentEntity>) vendorSoftwareProductManager.listComponents(vspId, null, user);
528 monitoringUploadsManager.upload(getFileInputStream(filePath),
531 VERSION01, componentEntities.get(0).getId(), ArtifactType.SNMP_POLL);
532 //TODO: add validate of logActivity() func call
534 VERSION01, componentEntities.get(0).getId(), MonitoringUploadType.SNMP_POLL, user);
535 //TODO: add validate of addActionLog() func call
536 >>>>>>> feature/Amdocs-ASDC-1710
538 return new ImmutablePair<>(componentEntities.get(0).getId(),
539 componentEntities.get(0).getComponentCompositionData()
543 // TODO: 3/15/2017 fix and enable
546 public void testUpdatedVSPShouldBeInBeginningOfList() {
547 vendorSoftwareProductManager.updateVsp(new VspDetails(), USER3);
548 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
550 InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
551 candidateManager.upload(id007, VERSION01, zis, USER3);
552 candidateManager.process(id007, VERSION01, USER3);
553 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
556 @Test(dependsOnMethods = {"testUpdatedVSPShouldBeInBeginningOfList"})
557 public void testVSPInBeginningOfListAfterCheckin() {
558 vendorSoftwareProductManager.checkin(id006, USER3);
559 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
561 vendorSoftwareProductManager.checkin(id007, USER3);
562 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
565 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckin"})
566 public void testVSPInBeginningOfListAfterCheckout() {
567 vendorSoftwareProductManager.checkout(id006, USER3);
568 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
571 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckout"})
572 public void testVSPInBeginningOfListAfterUndoCheckout() {
573 vendorSoftwareProductManager.checkout(id007, USER3);
574 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
576 vendorSoftwareProductManager.undoCheckout(id006, USER3);
577 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
580 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterUndoCheckout"})
581 public void testVSPInBeginningOfListAfterSubmit() throws IOException {
582 vendorSoftwareProductManager.checkin(id007, USER3);
583 vendorSoftwareProductManager.submit(id007, USER3);
585 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
589 public void testValidateWithCandidateDataNotProcessed() throws IOException {
591 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
592 "category", "subCategory", "licenseAgreementId",
593 Collections.singletonList("featureGroupId"));
594 vsp.setOnboardingMethod("NetworkPackage");
595 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
597 OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
598 OrchestrationTemplateCandidateData();
599 orchestrationTemplateCandidateData.setFileSuffix("zip");
600 orchestrationTemplateCandidateData.setFilesDataStructure("testdata");
601 orchestrationTemplateCandidateData.setValidationData("");
602 doReturn(orchestrationTemplateCandidateData).when(orchestrationTemplateCandidateManagerMock)
603 .getInfo(VSP_ID, VERSION01);
604 ValidationResponse validationResponse =
605 vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
606 Assert.assertNotNull(validationResponse);
607 Assert.assertFalse(validationResponse.isValid());
608 Assert.assertNotNull(validationResponse.getVspErrors());
609 Assert.assertEquals(validationResponse.getVspErrors().size(), 1);
614 public void testValidateWithCandidateProcessedIsInvalid() throws IOException {
615 VspDetails vsp = createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-VSP", "vendorName",
616 "vl1Id", "icond", "category", "subcategory", "licenseAgreementId", Collections
617 .singletonList("featureGroupId"));
618 vsp.setOnboardingMethod("NetworkPackage");
619 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
621 OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
622 OrchestrationTemplateCandidateData();
623 orchestrationTemplateCandidateData.setFileSuffix("zip");
624 orchestrationTemplateCandidateData.setValidationData("Invalid processed data");
625 doReturn(orchestrationTemplateCandidateData).when(orchestrationTemplateCandidateManagerMock)
626 .getInfo(VSP_ID, VERSION01);
627 ValidationResponse validationResponse =
628 vendorSoftwareProductManager.validate(VSP_ID, VERSION01);
629 Assert.assertNotNull(validationResponse);
630 Assert.assertFalse(validationResponse.isValid());
631 Assert.assertNotNull(validationResponse.getVspErrors());
632 Assert.assertEquals(validationResponse.getVspErrors().size(), 1);
635 private void testLegalUpload(String vspId, Version version, InputStream upload, String user) {
636 candidateManager.upload(vspId, VERSION01, upload, "zip", "file");
637 candidateManager.process(vspId, VERSION01);
639 OrchestrationTemplateEntity uploadData =
640 orchestrationTemplateDataDaoMock.get(vspId, version);
641 Assert.assertNotNull(uploadData);
645 public InputStream getFileInputStream(String fileName) {
646 URL url = this.getClass().getResource(fileName);
648 return url.openStream();
649 } catch (IOException exception) {
650 exception.printStackTrace();
655 static VspDetails createVspDetails(String id, Version version, String name, String desc,
656 String vendorName, String vlm, String icon,
657 String category, String subCategory,
658 String licenseAgreement, List<String> featureGroups) {
659 VspDetails vspDetails = new VspDetails(id, version);
660 vspDetails.setName(name);
661 vspDetails.setDescription(desc);
662 vspDetails.setIcon(icon);
663 vspDetails.setCategory(category);
664 vspDetails.setSubCategory(subCategory);
665 vspDetails.setVendorName(vendorName);
666 vspDetails.setVendorId(vlm);
667 vspDetails.setVlmVersion(new Version(1, 0));
668 vspDetails.setLicenseAgreement(licenseAgreement);
669 vspDetails.setFeatureGroups(featureGroups);
670 vspDetails.setOnboardingMethod("HEAT");
674 static void assertVspsEquals(VspDetails actual, VspDetails expected) {
675 Assert.assertEquals(actual.getId(), expected.getId());
676 Assert.assertEquals(actual.getVersion(), expected.getVersion());
677 Assert.assertEquals(actual.getName(), expected.getName());
678 Assert.assertEquals(actual.getDescription(), expected.getDescription());
679 Assert.assertEquals(actual.getIcon(), expected.getIcon());
680 Assert.assertEquals(actual.getCategory(), expected.getCategory());
681 Assert.assertEquals(actual.getSubCategory(), expected.getSubCategory());
682 Assert.assertEquals(actual.getVendorName(), expected.getVendorName());
683 Assert.assertEquals(actual.getVendorId(), expected.getVendorId());
684 Assert.assertEquals(actual.getLicenseAgreement(), expected.getLicenseAgreement());
685 Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups());
689 // todo ********************** move to common **************************************
691 private void mockVersioning(VersionableEntityAction action) {
692 VersionInfo versionInfo = new VersionInfo();
693 versionInfo.setActiveVersion(VERSION01);
694 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
695 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,