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.hamcrest.CoreMatchers.containsString;
20 import static org.hamcrest.MatcherAssert.assertThat;
21 import static org.hamcrest.Matchers.equalTo;
22 import static org.hamcrest.Matchers.hasItem;
23 import static org.hamcrest.Matchers.not;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.fail;
26 import static org.mockito.ArgumentMatchers.any;
27 import static org.mockito.ArgumentMatchers.anyString;
28 import static org.mockito.ArgumentMatchers.nullable;
29 import static org.mockito.Mockito.doNothing;
30 import static org.mockito.Mockito.doReturn;
31 import static org.mockito.Mockito.doThrow;
32 import static org.mockito.Mockito.verify;
33 import static org.mockito.Mockito.when;
34 import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME;
35 import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME;
36 import static org.openecomp.sdc.tosca.csar.ToscaMetadataFileInfo.TOSCA_META_PATH_FILE_NAME;
38 import java.io.IOException;
39 import java.io.InputStream;
40 import java.util.ArrayList;
41 import java.util.Arrays;
42 import java.util.Collections;
43 import java.util.HashMap;
44 import java.util.List;
45 import java.util.Optional;
46 import org.apache.commons.io.IOUtils;
47 import org.junit.After;
48 import org.junit.Assert;
49 import org.junit.Before;
50 import org.junit.Test;
51 import org.mockito.ArgumentCaptor;
52 import org.mockito.Captor;
53 import org.mockito.InjectMocks;
54 import org.mockito.Mock;
55 import org.mockito.MockitoAnnotations;
56 import org.mockito.Spy;
57 import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
58 import org.onap.sdc.tosca.services.YamlUtil;
59 import org.openecomp.core.model.dao.EnrichedServiceModelDao;
60 import org.openecomp.core.model.dao.ServiceModelDao;
61 import org.openecomp.core.utilities.file.FileContentHandler;
62 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
63 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
64 import org.openecomp.sdc.common.errors.CoreException;
65 import org.openecomp.sdc.common.errors.ErrorCategory;
66 import org.openecomp.sdc.common.errors.ErrorCode;
67 import org.openecomp.sdc.healing.api.HealingManager;
68 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
69 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
70 import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService;
71 import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager;
72 import org.openecomp.sdc.vendorsoftwareproduct.ManualVspToscaManager;
73 import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager;
74 import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
75 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
76 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao;
77 import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao;
78 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
79 import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao;
80 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
81 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
82 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
83 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
84 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
85 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator;
86 import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
87 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor;
88 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateInput;
89 import org.openecomp.sdc.versioning.ActionVersioningManager;
90 import org.openecomp.sdc.versioning.dao.types.Version;
91 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
92 import org.openecomp.sdc.versioning.types.VersionInfo;
93 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
95 public class VendorSoftwareProductManagerImplTest {
97 private static final String VSP_ID = "vspId";
98 private static final Version VERSION01 = new Version("0, 1");
99 private static final Version VERSION10 = new Version("1, 0");
100 private static final String USER1 = "vspTestUser1";
101 private static final String USER2 = "vspTestUser2";
104 private ActionVersioningManager versioningManagerMock;
106 private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
108 private VendorLicenseFacade vendorLicenseFacadeMock;
110 private ServiceModelDao<ToscaServiceModel> serviceModelDaoMock;
112 private EnrichedServiceModelDao<ToscaServiceModel> enrichedServiceModelDaoMock;
114 private HealingManager healingManagerMock;
116 private VendorLicenseArtifactsService licenseArtifactsServiceMock;
118 private CompositionEntityDataManager compositionEntityDataManagerMock;
120 private InformationArtifactGenerator informationArtifactGeneratorMock;
122 private PackageInfoDao packageInfoDao;
124 private VendorSoftwareProductInfoDao vspInfoDaoMock;
126 private ManualVspToscaManager manualVspToscaManager;
128 private DeploymentFlavorDao deploymentFlavorDaoMock;
131 private VendorSoftwareProductManagerImpl vendorSoftwareProductManager;
133 private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManagerMock;
135 private ComponentDependencyModelDao componentDependencyModelDao;
136 private OrchestrationTemplateCandidateManager candidateManager;
137 private MonitoringUploadsManager monitoringUploadsManager;
140 private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
143 public void setUp() {
144 MockitoAnnotations.initMocks(this);
148 public void tearDown() {
149 vendorSoftwareProductManager = null;
153 public void testCreatePackageEtsiVNF() throws IOException {
155 final InputStream metadataInput = getClass()
156 .getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta");
157 final InputStream manifestInput = getClass()
158 .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoTosca.mf")) {
160 final FileContentHandler handler = new FileContentHandler();
161 final byte[] metadataInputBytes = IOUtils.toByteArray(metadataInput);
162 handler.addFile(TOSCA_META_PATH_FILE_NAME, metadataInputBytes);
163 handler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME, metadataInputBytes);
164 handler.addFile(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, IOUtils.toByteArray(manifestInput));
165 final ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
166 when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata);
167 final VspDetails vsp =
168 createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
169 "category", "subCategory", "123", null);
170 //want to avoid triggering populateVersionsForVlm method
171 vsp.setVlmVersion(null);
173 when(vspInfoDaoMock.get(any())).thenReturn(vsp);
174 when(licenseArtifactsServiceMock.createLicenseArtifacts(any(), any(), any(), any()))
175 .thenReturn(new FileContentHandler());
176 final PackageInfo packageInfo = vendorSoftwareProductManager.createPackage("0", new Version());
177 assertEquals(packageInfo.getResourceType(), ResourceTypeEnum.VF.name());
181 @Test(expected = IOException.class)
182 public void testCreatePackageEtsiNoManifest() throws IOException {
183 try(InputStream metadataInput = getClass().getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta"))
185 FileContentHandler handler = new FileContentHandler();
186 handler.addFile(TOSCA_META_PATH_FILE_NAME, IOUtils.toByteArray(metadataInput));
187 ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
188 when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata );
190 createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
191 "category", "subCategory", "123", null);
192 //want to avoid triggering populateVersionsForVlm method
193 vsp.setVlmVersion(null);
195 when(vspInfoDaoMock.get(any())).thenReturn(vsp);
196 when(licenseArtifactsServiceMock.createLicenseArtifacts(any(),any(), any(), any())).thenReturn(new FileContentHandler());
197 vendorSoftwareProductManager.createPackage("0", new Version());
203 public void testCreatePackageEtsiPnfWithoutNonMano() throws IOException {
205 final InputStream metadataInput = getClass()
206 .getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta");
207 final InputStream manifestInput = getClass()
208 .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoToscaPnfWithoutNonMano.mf")) {
210 final FileContentHandler handler = new FileContentHandler();
211 final byte[] metadataInputBytes = IOUtils.toByteArray(metadataInput);
212 handler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME, metadataInputBytes);
213 handler.addFile(TOSCA_META_PATH_FILE_NAME, metadataInputBytes);
214 handler.addFile(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, IOUtils.toByteArray(manifestInput));
215 final ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
216 when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata);
217 final VspDetails vsp =
218 createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
219 "category", "subCategory", "123", null);
220 //want to avoid triggering populateVersionsForVlm method
221 vsp.setVlmVersion(null);
223 when(vspInfoDaoMock.get(any())).thenReturn(vsp);
224 when(licenseArtifactsServiceMock.createLicenseArtifacts(any(), any(), any(), any()))
225 .thenReturn(new FileContentHandler());
226 final PackageInfo packageInfo = vendorSoftwareProductManager.createPackage("0", new Version());
227 assertEquals(packageInfo.getResourceType(), ResourceTypeEnum.PNF.name());
232 public void testCreatePackageEtsiPnfWithNonManoArtifacts() throws IOException {
234 final InputStream metadataInput = getClass()
235 .getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta");
236 final InputStream manifestInput = getClass()
237 .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoToscaPNFWithNonMano.mf");
238 final InputStream mainServiceTemplateYamlFile = getClass()
239 .getResourceAsStream("/vspmanager.csar/descriptor/MainServiceTemplate.yaml")) {
241 final FileContentHandler handler = new FileContentHandler();
242 handler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME, IOUtils.toByteArray(metadataInput));
243 handler.addFile(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, IOUtils.toByteArray(manifestInput));
244 handler.addFile("Deployment/ANOTHER/authorized_keys", "".getBytes());
246 final ServiceTemplate mainServiceTemplate = new YamlUtil()
247 .yamlToObject(mainServiceTemplateYamlFile, ServiceTemplate.class);
248 final String mainServiceTemplateName = "MainServiceTemplate.yaml";
249 final HashMap<String, ServiceTemplate> serviceTemplateMap = new HashMap<>();
250 serviceTemplateMap.put(mainServiceTemplateName, mainServiceTemplate);
252 final ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, serviceTemplateMap,
253 mainServiceTemplateName);
254 when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata);
255 final VspDetails vsp =
256 createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
257 "category", "subCategory", "123", null);
258 //want to avoid triggering populateVersionsForVlm method
259 vsp.setVlmVersion(null);
261 when(vspInfoDaoMock.get(any())).thenReturn(vsp);
262 when(licenseArtifactsServiceMock.createLicenseArtifacts(any(), any(), any(), any()))
263 .thenReturn(new FileContentHandler());
264 final PackageInfo packageInfo = vendorSoftwareProductManager.createPackage("0", new Version());
265 assertThat("PackageInfo vendor release should be based on the manifest compatible_specification_versions highest version",
266 packageInfo.getVendorRelease(), equalTo("3.3.1"));
267 System.out.println(packageInfo.getVendorRelease());
268 assertThat("Package Info should contain resource type", packageInfo.getResourceType(),
269 equalTo(ResourceTypeEnum.PNF.name()));
270 assertThat("Should not contain moved artifact", toscaMetadata.getArtifactFiles().getFileList(),
271 not(hasItem("Deployment/ANOTHER/authorized_keys")));
272 assertThat("Should contain moved artifact", toscaMetadata.getArtifactFiles().getFileList(),
273 hasItem("Informational/OTHER/authorized_keys"));
274 final String serviceTemplateAsYaml = new YamlUtil().objectToYaml(toscaMetadata.getServiceTemplates());
275 assertThat("Descriptor should not contain reference to file", serviceTemplateAsYaml,
276 not(containsString("Artifacts/Deployment/ANOTHER/authorized_keys")));
277 assertThat("Descriptor should contain reference to file", serviceTemplateAsYaml,
278 containsString("Artifacts/Informational/OTHER/authorized_keys"));
283 public void testCreate() {
285 .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(nullable(SchemaTemplateInput.class));
287 VspDetails vspToCreate =
288 createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
289 "category", "subCategory", "123", null);
291 VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate);
293 Assert.assertNotNull(vsp);
294 vspToCreate.setId(vsp.getId());
295 vspToCreate.setVersion(VERSION01);
296 assertVspsEquals(vsp, vspToCreate);
299 @Test(expected = CoreException.class)
300 public void testUpdateWithExistingName_negative() {
301 VersionInfo versionInfo = new VersionInfo();
302 versionInfo.setActiveVersion(VERSION01);
303 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
304 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
305 VersionableEntityAction.Write);
307 VspDetails existingVsp =
308 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-existingVsp", "vendorName", "vlm1Id",
309 "icon", "category", "subCategory", "123", null);
310 VspDetails updatedVsp =
311 createVspDetails(VSP_ID, VERSION01, "Vsp1_updated", "Test-existingVsp", "vendorName",
312 "vlm1Id", "icon", "category", "subCategory", "123", null);
313 doReturn(existingVsp).when(vspInfoDaoMock)
314 .get(any(VspDetails.class));
315 doThrow(new CoreException(
316 new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build()))
317 .when(vendorSoftwareProductManager)
318 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
320 vendorSoftwareProductManager.updateVsp(updatedVsp);
324 public void testUpdate() {
325 VersionInfo versionInfo = new VersionInfo();
326 versionInfo.setActiveVersion(VERSION01);
327 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
328 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
329 VersionableEntityAction.Write);
330 VspDetails existingVsp =
331 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
333 "subCategory", "456", null);
334 VspDetails updatedVsp =
335 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
337 "subCategory", "456", null);
338 doReturn(existingVsp).when(vspInfoDaoMock)
339 .get(any(VspDetails.class));
340 doNothing().when(vendorSoftwareProductManager)
341 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
343 vendorSoftwareProductManager.updateVsp(updatedVsp);
345 verify(vspInfoDaoMock).update(updatedVsp);
349 public void testUpdateRemoveFG() {
350 VersionInfo versionInfo = new VersionInfo();
351 versionInfo.setActiveVersion(VERSION01);
352 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
353 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
354 VersionableEntityAction.Write);
355 List<String> fgs = new ArrayList<>();
358 VspDetails existingVsp =
359 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
361 "subCategory", "456", fgs);
363 List<String> updFgs = new ArrayList<>();
364 VspDetails updatedVsp =
365 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
367 "subCategory", "456", updFgs);
368 doReturn(existingVsp).when(vspInfoDaoMock)
369 .get(any(VspDetails.class));
370 doNothing().when(vendorSoftwareProductManager)
371 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
373 DeploymentFlavorEntity dfEntity = new DeploymentFlavorEntity(VSP_ID, VERSION01, "DF_ID");
374 DeploymentFlavor flavor = new DeploymentFlavor();
375 flavor.setFeatureGroupId("fg1");
376 dfEntity.setDeploymentFlavorCompositionData(flavor);
378 List<DeploymentFlavorEntity> dfList = new ArrayList<>();
379 dfList.add(dfEntity);
381 doReturn(dfList).when(deploymentFlavorDaoMock).list(any(DeploymentFlavorEntity.class));
383 vendorSoftwareProductManager.updateVsp(updatedVsp);
385 verify(deploymentFlavorDaoMock).update(dfEntity);
387 Assert.assertNull(dfEntity.getDeploymentFlavorCompositionData().getFeatureGroupId());
391 @Test(expected = CoreException.class)
392 public void testGetNonExistingVersion_negative() {
393 Version notExistversion = new Version("43, 8");
394 doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
395 vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion);
399 public void testGetCheckedOutVersion() {
400 VersionInfo versionInfo = new VersionInfo();
401 versionInfo.setActiveVersion(VERSION01);
402 versionInfo.setStatus(VersionStatus.Locked);
403 versionInfo.setLockingUser(USER1);
404 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
405 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
406 VersionableEntityAction.Read);
408 VspDetails existingVsp =
409 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
411 "subCategory", "456", null);
412 doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class));
414 VspDetails actualVsp =
415 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
417 assertVspsEquals(actualVsp, existingVsp);
421 public void testGetOldVersion() {
422 VersionInfo versionInfo = new VersionInfo();
423 versionInfo.setActiveVersion(new Version("0, 2"));
424 versionInfo.setViewableVersions(Arrays.asList(VERSION01, new Version("0, 2")));
425 versionInfo.setStatus(VersionStatus.Locked);
426 versionInfo.setLockingUser(USER2);
427 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
428 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
429 VersionableEntityAction.Read);
431 VspDetails existingVsp =
432 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
434 "subCategory", "456", null);
435 doReturn(existingVsp)
436 .when(vspInfoDaoMock).get(any(VspDetails.class));
438 VspDetails actualVsp =
439 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
441 VspDetails expectedVsp =
443 .get(new VspDetails(VSP_ID, VERSION01));
444 assertVspsEquals(actualVsp, expectedVsp);
448 public void testCreatePackage() throws IOException {
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(anyString(), any(Version.class));
458 VspDetails vsp = new VspDetails(VSP_ID, VERSION10);
459 vsp.setVendorId("vendorId");
460 vsp.setVlmVersion(VERSION10);
461 vsp.setFeatureGroups(Arrays.asList("fg1", "fg2"));
462 vsp.setModelIdList(List.of("aModel"));
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());
471 assertEquals("1.0", packageInfo.getVendorRelease());
475 public void testValidateWithCandidateDataNotProcessed() throws IOException {
477 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
478 "category", "subCategory", "licenseAgreementId",
479 Collections.singletonList("featureGroupId"));
480 vsp.setOnboardingMethod("NetworkPackage");
481 doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class));
483 OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
484 OrchestrationTemplateCandidateData();
485 orchestrationTemplateCandidateData.setFileSuffix("zip");
486 orchestrationTemplateCandidateData.setFilesDataStructure("testdata");
487 orchestrationTemplateCandidateData.setValidationData("");
488 doReturn(Optional.of(orchestrationTemplateCandidateData))
489 .when(orchestrationTemplateCandidateManagerMock)
490 .getInfo(VSP_ID, VERSION01);
491 ValidationResponse validationResponse =
492 vendorSoftwareProductManager.validate(vsp);
493 Assert.assertNotNull(validationResponse);
494 Assert.assertFalse(validationResponse.isValid());
495 Assert.assertNotNull(validationResponse.getVspErrors());
496 Assert.assertEquals(1, validationResponse.getVspErrors().size());
501 public void testValidateWithCandidateProcessedIsInvalid() throws IOException {
502 VspDetails vsp = createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-VSP", "vendorName",
503 "vl1Id", "icond", "category", "subcategory", "licenseAgreementId", Collections
504 .singletonList("featureGroupId"));
505 vsp.setOnboardingMethod("NetworkPackage");
506 doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class));
508 OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
509 OrchestrationTemplateCandidateData();
510 orchestrationTemplateCandidateData.setFileSuffix("zip");
511 orchestrationTemplateCandidateData.setValidationData("Invalid processed data");
512 doReturn(Optional.of(orchestrationTemplateCandidateData))
513 .when(orchestrationTemplateCandidateManagerMock)
514 .getInfo(VSP_ID, VERSION01);
515 ValidationResponse validationResponse =
516 vendorSoftwareProductManager.validate(vsp);
517 Assert.assertNotNull(validationResponse);
518 Assert.assertFalse(validationResponse.isValid());
519 Assert.assertNotNull(validationResponse.getVspErrors());
520 Assert.assertEquals(1, validationResponse.getVspErrors().size());
523 private static VspDetails createVspDetails(String id, Version version, String name, String desc,
524 String vendorName, String vlm, String icon,
525 String category, String subCategory,
526 String licenseAgreement, List<String> featureGroups) {
527 VspDetails vspDetails = new VspDetails(id, version);
528 vspDetails.setName(name);
529 vspDetails.setDescription(desc);
530 vspDetails.setIcon(icon);
531 vspDetails.setCategory(category);
532 vspDetails.setSubCategory(subCategory);
533 vspDetails.setVendorName(vendorName);
534 vspDetails.setVendorId(vlm);
535 vspDetails.setVlmVersion(new Version("1, 0"));
536 vspDetails.setLicenseAgreement(licenseAgreement);
537 vspDetails.setFeatureGroups(featureGroups);
538 vspDetails.setOnboardingMethod("HEAT");
542 private static void assertVspsEquals(VspDetails actual, VspDetails expected) {
543 Assert.assertEquals(actual.getId(), expected.getId());
544 Assert.assertEquals(actual.getVersion(), expected.getVersion());
545 Assert.assertEquals(actual.getName(), expected.getName());
546 Assert.assertEquals(actual.getDescription(), expected.getDescription());
547 Assert.assertEquals(actual.getIcon(), expected.getIcon());
548 Assert.assertEquals(actual.getCategory(), expected.getCategory());
549 Assert.assertEquals(actual.getSubCategory(), expected.getSubCategory());
550 Assert.assertEquals(actual.getVendorName(), expected.getVendorName());
551 Assert.assertEquals(actual.getVendorId(), expected.getVendorId());
552 Assert.assertEquals(actual.getLicenseAgreement(), expected.getLicenseAgreement());
553 Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups());