Get manifest location from Meta file 23/81923/2
authorkooper <sergey.sachkov@est.tech>
Tue, 12 Mar 2019 09:47:48 +0000 (09:47 +0000)
committerkooper <sergey.sachkov@est.tech>
Tue, 12 Mar 2019 09:47:48 +0000 (09:47 +0000)
Change-Id: Ibdf3e3c0a5c045d19e207c7e48f3404ff099fb3c
Issue-ID: SDC-2152
Signed-off-by: kooper <sergey.sachkov@est.tech>
26 files changed:
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VspManagerFactoryImpl.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ImagesTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentDependencyModelTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerImplTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerImplTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImplTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImplTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImplTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerImplTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImplTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerImplTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/CandidateServiceImplTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImplTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/HeatTreeManagerTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/ValidNonManoTosca.mf [new file with mode: 0644]
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/metadata/ValidETSItosca.meta [new file with mode: 0644]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java

index 582bf47..91c1959 100644 (file)
@@ -354,7 +354,7 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
         byte[] orchestrationTemplateFile =
                 vendorSoftwareProductManager.getOrchestrationTemplateFile(vspId, new Version(versionId));
 
-        if (orchestrationTemplateFile == null) {
+        if (orchestrationTemplateFile == null || orchestrationTemplateFile.length == 0) {
             return Response.status(Response.Status.NOT_FOUND).build();
         }
         Response.ResponseBuilder response = Response.ok(orchestrationTemplateFile);
index ee498e6..65babbd 100644 (file)
             <artifactId>openecomp-tosca-lib</artifactId>
             <version>${project.version}</version>
         </dependency>
-        <dependency>
-            <groupId>org.testng</groupId>
-            <artifactId>testng</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-core</artifactId>
             <artifactId>openecomp-tosca-converter-core</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
-
     <properties>
         <useSystemClassLoader>false</useSystemClassLoader>
     </properties>
index 19d06ed..51a4bdd 100644 (file)
@@ -16,6 +16,9 @@
 
 package org.openecomp.sdc.vendorsoftwareproduct.impl;
 
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_MANIFEST;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.candidateDataNotProcessedOrAbortedErrorBuilder;
 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.invalidProcessedCandidate;
 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.vspMissingDeploymentFlavorErrorBuilder;
@@ -27,6 +30,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
@@ -64,6 +68,8 @@ import org.openecomp.sdc.common.errors.ValidationErrorBuilder;
 import org.openecomp.sdc.common.utils.CommonUtil;
 import org.openecomp.sdc.datatypes.error.ErrorLevel;
 import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata;
+import org.openecomp.sdc.tosca.csar.ToscaMetadata;
 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
 import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
 import org.openecomp.sdc.validation.util.ValidationManagerUtil;
@@ -136,75 +142,25 @@ import org.openecomp.sdc.versioning.dao.types.Version;
 
 public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductManager {
 
-  private final VspMergeDao vspMergeDao;
-  private final OrchestrationTemplateDao orchestrationTemplateDao;
-  private final OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager;
-  private final VendorSoftwareProductInfoDao vspInfoDao;
-  private final VendorLicenseFacade vendorLicenseFacade;
-  private final ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
-  private final EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao;
-  private final VendorLicenseArtifactsService licenseArtifactsService;
-  private final InformationArtifactGenerator informationArtifactGenerator;
-  private final PackageInfoDao packageInfoDao;
-  private final DeploymentFlavorDao deploymentFlavorDao;
-  private final ComponentDao componentDao;
-  private final ComponentDependencyModelDao componentDependencyModelDao;
-  private final NicDao nicDao;
-  private final ComputeDao computeDao;
-  private final ImageDao imageDao;
-  private final ManualVspToscaManager manualVspToscaManager;
-  private final UniqueValueUtil uniqueValueUtil;
-  private final CandidateService candidateService;
-
-  public VendorSoftwareProductManagerImpl(
-      VspMergeDao vspMergeDao,
-      OrchestrationTemplateDao orchestrationTemplateDataDao,
-      OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager,
-      VendorSoftwareProductInfoDao vspInfoDao,
-      VendorLicenseFacade vendorLicenseFacade,
-      ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao,
-      EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao,
-      VendorLicenseArtifactsService licenseArtifactsService,
-      InformationArtifactGenerator informationArtifactGenerator,
-      PackageInfoDao packageInfoDao,
-      DeploymentFlavorDao deploymentFlavorDao,
-      ComponentDao componentDao,
-      ComponentDependencyModelDao componentDependencyModelDao,
-      NicDao nicDao,
-      ComputeDao computeDao,
-      ImageDao imageDao,
-      ManualVspToscaManager manualVspToscaManager,
-      UniqueValueDao uniqueValueDao,
-      CandidateService candidateService) {
-    this.vspMergeDao = vspMergeDao;
-    this.orchestrationTemplateDao = orchestrationTemplateDataDao;
-    this.orchestrationTemplateCandidateManager = orchestrationTemplateCandidateManager;
-    this.vspInfoDao = vspInfoDao;
-    this.vendorLicenseFacade = vendorLicenseFacade;
-    this.serviceModelDao = serviceModelDao;
-    this.enrichedServiceModelDao = enrichedServiceModelDao;
-    this.licenseArtifactsService = licenseArtifactsService;
-    this.informationArtifactGenerator = informationArtifactGenerator;
-    this.packageInfoDao = packageInfoDao;
-    this.deploymentFlavorDao = deploymentFlavorDao;
-    this.componentDao = componentDao;
-    this.componentDependencyModelDao = componentDependencyModelDao;
-    this.nicDao = nicDao;
-    this.computeDao = computeDao;
-    this.imageDao = imageDao;
-    this.manualVspToscaManager = manualVspToscaManager;
-    this.uniqueValueUtil = new UniqueValueUtil(uniqueValueDao);
-    this.candidateService = candidateService;
-
-    registerToVersioning();
-  }
-
-  private void registerToVersioning() {
-    serviceModelDao.registerVersioning(
-        VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
-    enrichedServiceModelDao.registerVersioning(
-        VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
-  }
+  private VspMergeDao vspMergeDao;
+  private OrchestrationTemplateDao orchestrationTemplateDao;
+  private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager;
+  private VendorSoftwareProductInfoDao vspInfoDao;
+  private VendorLicenseFacade vendorLicenseFacade;
+  private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
+  private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao;
+  private VendorLicenseArtifactsService licenseArtifactsService;
+  private InformationArtifactGenerator informationArtifactGenerator;
+  private PackageInfoDao packageInfoDao;
+  private DeploymentFlavorDao deploymentFlavorDao;
+  private ComponentDao componentDao;
+  private ComponentDependencyModelDao componentDependencyModelDao;
+  private NicDao nicDao;
+  private ComputeDao computeDao;
+  private ImageDao imageDao;
+  private ManualVspToscaManager manualVspToscaManager;
+  private UniqueValueUtil uniqueValueUtil;
+  private CandidateService candidateService;
 
   @Override
   public ValidationResponse validate(VspDetails vspDetails) throws IOException {
@@ -218,10 +174,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
       if (!validationResponse.isValid()) {
         return validationResponse;
       }
-      if (vspDetails.getVlmVersion() != null || vspDetails.getLicenseAgreement() != null
-          || vspDetails.getFeatureGroups() != null) {
-        vspErrors.addAll(validateMandatoryLicenseFields(vspDetails));
-      }
+      validateLicense(vspDetails, vspErrors);
       OrchestrationTemplateEntity orchestrationTemplate =
           orchestrationTemplateDao.get(vspDetails.getId(), vspDetails.getVersion());
       ToscaServiceModel serviceModel =
@@ -261,6 +214,13 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
     return validationResponse;
   }
 
+  private void validateLicense(VspDetails vspDetails, List<ErrorCode> vspErrors) {
+    if (vspDetails.getVlmVersion() != null || vspDetails.getLicenseAgreement() != null
+            || vspDetails.getFeatureGroups() != null) {
+      vspErrors.addAll(validateMandatoryLicenseFields(vspDetails));
+    }
+  }
+
   private void validateOrchestrationTemplateCandidate(ValidationResponse validationResponse,
                                                       List<ErrorCode> vspErrors, String vspId,
                                                       Version version) {
@@ -352,36 +312,33 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
     List<ComponentComputeAssociation> componentComputeAssociations =
         deploymentlocalFlavor.getComponentComputeAssociations();
     if (CollectionUtils.isEmpty(componentComputeAssociations)) {
-      CompositionEntityValidationData compositionEntityValidationData = new
-          CompositionEntityValidationData(CompositionEntityType.deployment, deploymentFlavor
-          .getId());
-      compositionEntityValidationData.setEntityName(deployment
-          .getDeploymentFlavorCompositionData().getModel());
-      ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder
-          .getInvalidComponentComputeAssociationErrorBuilder(
-              deploymentlocalFlavor.getModel());
-
-      errorCodeList.add(deploymentFlavorErrorBuilder);
+        validateCompositionEntity(errorCodeList, deploymentFlavor, deployment, deploymentlocalFlavor);
     } else {
       componentComputeAssociations.forEach(componentComputeAssociation -> {
         if (componentComputeAssociation == null
             || !(componentComputeAssociation.getComponentId() != null
             && componentComputeAssociation.getComputeFlavorId() != null)) {
-          CompositionEntityValidationData compositionEntityValidationData = new
-              CompositionEntityValidationData(CompositionEntityType.deployment,
-              deploymentFlavor.getId());
-          compositionEntityValidationData.setEntityName(deployment
-              .getDeploymentFlavorCompositionData().getModel());
-          ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder
-              .getInvalidComponentComputeAssociationErrorBuilder(
-                  deploymentlocalFlavor.getModel());
-
-          errorCodeList.add(deploymentFlavorErrorBuilder);
+            validateCompositionEntity(errorCodeList, deploymentFlavor, deployment, deploymentlocalFlavor);
         }
       });
     }
   }
 
+  private void validateCompositionEntity(Collection<ErrorCode> errorCodeList,
+                                                                             DeploymentFlavorEntity deploymentFlavor,
+                                                                             DeploymentFlavorEntity deployment,
+                                                                             DeploymentFlavor deploymentlocalFlavor){
+    CompositionEntityValidationData compositionEntityValidationData = new
+            CompositionEntityValidationData(CompositionEntityType.deployment, deploymentFlavor
+            .getId());
+    compositionEntityValidationData.setEntityName(deployment
+            .getDeploymentFlavorCompositionData().getModel());
+    ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder
+            .getInvalidComponentComputeAssociationErrorBuilder(
+                    deploymentlocalFlavor.getModel());
+    errorCodeList.add(deploymentFlavorErrorBuilder);
+  }
+
   private Set<CompositionEntityValidationData> componentValidation(String vspId, Version version) {
     Set<CompositionEntityValidationData> validationData = new HashSet<>();
     Collection<ComponentEntity> components =
@@ -625,7 +582,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
     OrchestrationTemplateEntity uploadData = orchestrationTemplateDao.get(vspId, version);
     ByteBuffer contentData = uploadData.getContentData();
     if (contentData == null) {
-      return null;
+      return new byte[0];
     }
 
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -677,9 +634,10 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
     ETSIService etsiService = new ETSIServiceImpl();
     if(etsiService.isSol004WithToscaMetaDirectory(toscaServiceModel.getArtifactFiles())){
         FileContentHandler handler = toscaServiceModel.getArtifactFiles();
-        Manifest onboardingManifest = OnboardingManifest.parse(handler.getFileContent(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME));
-      etsiService.moveNonManoFileToArtifactFolder(handler, onboardingManifest);
-
+        try(InputStream manifestInputStream = getManifest(handler)) {
+          Manifest onboardingManifest = OnboardingManifest.parse(manifestInputStream);
+          etsiService.moveNonManoFileToArtifactFolder(handler, onboardingManifest);
+        }
     }
     packageInfo.setTranslatedFile(ByteBuffer.wrap(
         toscaServiceTemplateServiceCsar.createOutputFile(toscaServiceModel, licenseArtifacts)));
@@ -688,6 +646,38 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
     return packageInfo;
   }
 
+  private InputStream getManifest(FileContentHandler handler) throws IOException {
+    ToscaMetadata metadata = getMetadata(handler);
+    return getManifestInputStream(handler, metadata.getMetaEntries().get(TOSCA_META_ENTRY_MANIFEST));
+  }
+
+  private ToscaMetadata getMetadata(FileContentHandler handler) throws IOException {
+    ToscaMetadata metadata;
+    if(handler.containsFile(TOSCA_META_PATH_FILE_NAME)){
+      metadata = OnboardingToscaMetadata.parseToscaMetadataFile(handler.getFileContent(TOSCA_META_PATH_FILE_NAME));
+
+    }else if(handler.containsFile(TOSCA_META_ORIG_PATH_FILE_NAME)){
+      metadata = OnboardingToscaMetadata.parseToscaMetadataFile(handler.getFileContent(TOSCA_META_ORIG_PATH_FILE_NAME));
+    }else {
+      throw new IOException("TOSCA.meta file not found!");
+    }
+    return metadata;
+  }
+
+  private InputStream getManifestInputStream(FileContentHandler handler, String manifestLocation) throws IOException {
+    InputStream io;
+    if(manifestLocation == null || !handler.containsFile(manifestLocation)){
+      io = handler.getFileContent(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME);
+    }else {
+      io = handler.getFileContent(manifestLocation);
+    }
+
+    if(io == null){
+      throw new IOException("Manifest file not found!");
+    }
+    return io;
+  }
+
   void populateVersionsForVlm(String vlmId, Version vlmVersion) {
     VersioningManager versioningManager = VersioningManagerFactory.getInstance().createInterface();
     versioningManager.list(vlmId).stream()
@@ -878,4 +868,157 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
     return serviceModel == null || serviceModel.getEntryDefinitionServiceTemplate() == null;
   }
 
+  public static class Builder{
+    private VspMergeDao vspMergeDao;
+    private OrchestrationTemplateDao orchestrationTemplateDao;
+    private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager;
+    private VendorSoftwareProductInfoDao vspInfoDao;
+    private VendorLicenseFacade vendorLicenseFacade;
+    private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
+    private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao;
+    private VendorLicenseArtifactsService licenseArtifactsService;
+    private InformationArtifactGenerator informationArtifactGenerator;
+    private PackageInfoDao packageInfoDao;
+    private DeploymentFlavorDao deploymentFlavorDao;
+    private ComponentDao componentDao;
+    private ComponentDependencyModelDao componentDependencyModelDao;
+    private NicDao nicDao;
+    private ComputeDao computeDao;
+    private ImageDao imageDao;
+    private ManualVspToscaManager manualVspToscaManager;
+    private UniqueValueDao uniqueValueDao;
+    private CandidateService candidateService;
+
+    public Builder vspMerge(VspMergeDao vspMergeDao){
+      this.vspMergeDao = vspMergeDao;
+      return this;
+    }
+
+    public Builder orchestrationTemplate(OrchestrationTemplateDao orchestrationTemplateDao) {
+      this.orchestrationTemplateDao = orchestrationTemplateDao;
+      return this;
+    }
+
+    public Builder orchestrationTemplateCandidateManager(OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager) {
+      this.orchestrationTemplateCandidateManager = orchestrationTemplateCandidateManager;
+      return this;
+    }
+
+    public Builder vspInfo(VendorSoftwareProductInfoDao vspInfoDao) {
+      this.vspInfoDao = vspInfoDao;
+      return this;
+    }
+
+    public Builder vendorLicenseFacade(VendorLicenseFacade vendorLicenseFacade) {
+      this.vendorLicenseFacade = vendorLicenseFacade;
+      return this;
+    }
+
+    public Builder serviceModel(ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao) {
+      this.serviceModelDao = serviceModelDao;
+      return this;
+    }
+
+    public Builder enrichedServiceModel(EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao) {
+      this.enrichedServiceModelDao = enrichedServiceModelDao;
+      return this;
+    }
+
+    public Builder licenseArtifactsService(VendorLicenseArtifactsService licenseArtifactsService) {
+      this.licenseArtifactsService = licenseArtifactsService;
+      return this;
+    }
+
+    public Builder informationArtifactGenerator(InformationArtifactGenerator informationArtifactGenerator) {
+      this.informationArtifactGenerator = informationArtifactGenerator;
+      return this;
+    }
+
+    public Builder packageInfo(PackageInfoDao packageInfoDao) {
+      this.packageInfoDao = packageInfoDao;
+      return this;
+    }
+
+    public Builder deploymentFlavor(DeploymentFlavorDao deploymentFlavorDao) {
+      this.deploymentFlavorDao = deploymentFlavorDao;
+      return this;
+    }
+
+    public Builder component(ComponentDao componentDao) {
+      this.componentDao = componentDao;
+      return this;
+    }
+
+    public Builder componentDependencyModel(ComponentDependencyModelDao componentDependencyModelDao) {
+      this.componentDependencyModelDao = componentDependencyModelDao;
+      return this;
+    }
+
+    public Builder nic(NicDao nicDao) {
+      this.nicDao = nicDao;
+      return this;
+    }
+
+    public Builder compute(ComputeDao computeDao) {
+      this.computeDao = computeDao;
+      return this;
+    }
+
+    public Builder image(ImageDao imageDao) {
+      this.imageDao = imageDao;
+      return this;
+    }
+
+    public Builder manualVspToscaManager(ManualVspToscaManager manualVspToscaManager) {
+      this.manualVspToscaManager = manualVspToscaManager;
+      return this;
+    }
+
+    public Builder uniqueValue(UniqueValueDao uniqueValueDao) {
+      this.uniqueValueDao = uniqueValueDao;
+      return this;
+    }
+
+    public Builder candidateService(CandidateService candidateService) {
+      this.candidateService = candidateService;
+      return this;
+    }
+
+    private void registerToVersioning() {
+      if(serviceModelDao != null) {
+        serviceModelDao.registerVersioning(
+                VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
+      }
+      if(enrichedServiceModelDao != null) {
+        enrichedServiceModelDao.registerVersioning(
+                VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE);
+      }
+    }
+
+    public VendorSoftwareProductManager build(){
+      VendorSoftwareProductManagerImpl vendorSoftwareProductManager = new VendorSoftwareProductManagerImpl();
+      vendorSoftwareProductManager.vspMergeDao = this.vspMergeDao;
+      vendorSoftwareProductManager.orchestrationTemplateDao = this.orchestrationTemplateDao;
+      vendorSoftwareProductManager.orchestrationTemplateCandidateManager = this.orchestrationTemplateCandidateManager;
+      vendorSoftwareProductManager.vspInfoDao = this.vspInfoDao;
+      vendorSoftwareProductManager.vendorLicenseFacade = this.vendorLicenseFacade;
+      vendorSoftwareProductManager.serviceModelDao = this.serviceModelDao;
+      vendorSoftwareProductManager.enrichedServiceModelDao = this.enrichedServiceModelDao;
+      vendorSoftwareProductManager.licenseArtifactsService = this.licenseArtifactsService;
+      vendorSoftwareProductManager.informationArtifactGenerator = this.informationArtifactGenerator;
+      vendorSoftwareProductManager.packageInfoDao = this.packageInfoDao;
+      vendorSoftwareProductManager.deploymentFlavorDao = this.deploymentFlavorDao;
+      vendorSoftwareProductManager.componentDao = this.componentDao;
+      vendorSoftwareProductManager.componentDependencyModelDao = this.componentDependencyModelDao;
+      vendorSoftwareProductManager.nicDao = this.nicDao;
+      vendorSoftwareProductManager.computeDao = this.computeDao;
+      vendorSoftwareProductManager.imageDao = this.imageDao;
+      vendorSoftwareProductManager.manualVspToscaManager = this.manualVspToscaManager;
+      vendorSoftwareProductManager.uniqueValueUtil = new UniqueValueUtil(this.uniqueValueDao);
+      vendorSoftwareProductManager.candidateService = candidateService;
+      this.registerToVersioning();
+      return vendorSoftwareProductManager;
+    }
+  }
+
 }
index 75351e2..b0385a3 100644 (file)
@@ -24,32 +24,41 @@ import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory;
 import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManagerFactory;
 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
 import org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.*;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.VspMergeDaoFactory;
 import org.openecomp.sdc.vendorsoftwareproduct.factory.CandidateServiceFactory;
 import org.openecomp.sdc.vendorsoftwareproduct.factory.InformationArtifactGeneratorFactory;
 
 public class VspManagerFactoryImpl extends VspManagerFactory {
-  private static final VendorSoftwareProductManager INSTANCE =
-      new VendorSoftwareProductManagerImpl(
-          VspMergeDaoFactory.getInstance().createInterface(),
-          OrchestrationTemplateDaoFactory.getInstance().createInterface(),
-          OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface(),
-          VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(),
-          VendorLicenseFacadeFactory.getInstance().createInterface(),
-          ServiceModelDaoFactory.getInstance().createInterface(),
-          EnrichedServiceModelDaoFactory.getInstance().createInterface(),
-          VendorLicenseArtifactServiceFactory.getInstance().createInterface(),
-          InformationArtifactGeneratorFactory.getInstance().createInterface(),
-          PackageInfoDaoFactory.getInstance().createInterface(),
-          DeploymentFlavorDaoFactory.getInstance().createInterface(),
-          ComponentDaoFactory.getInstance().createInterface(),
-          ComponentDependencyModelDaoFactory.getInstance().createInterface(),
-          NicDaoFactory.getInstance().createInterface(),
-          ComputeDaoFactory.getInstance().createInterface(),
-          ImageDaoFactory.getInstance().createInterface(),
-          new ManualVspToscaManagerImpl(),
-          UniqueValueDaoFactory.getInstance().createInterface(), CandidateServiceFactory
-          .getInstance().createInterface());
+  private static final VendorSoftwareProductManager INSTANCE = new VendorSoftwareProductManagerImpl.Builder()
+          .vspMerge(VspMergeDaoFactory.getInstance().createInterface())
+          .orchestrationTemplate(OrchestrationTemplateDaoFactory.getInstance().createInterface())
+          .orchestrationTemplateCandidateManager(OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface())
+          .vspInfo(VendorSoftwareProductInfoDaoFactory.getInstance().createInterface())
+          .vendorLicenseFacade(VendorLicenseFacadeFactory.getInstance().createInterface())
+          .serviceModel(ServiceModelDaoFactory.getInstance().createInterface())
+          .enrichedServiceModel(EnrichedServiceModelDaoFactory.getInstance().createInterface())
+          .licenseArtifactsService(VendorLicenseArtifactServiceFactory.getInstance().createInterface())
+          .informationArtifactGenerator(InformationArtifactGeneratorFactory.getInstance().createInterface())
+          .packageInfo(PackageInfoDaoFactory.getInstance().createInterface())
+          .deploymentFlavor(DeploymentFlavorDaoFactory.getInstance().createInterface())
+          .component(ComponentDaoFactory.getInstance().createInterface())
+          .componentDependencyModel(ComponentDependencyModelDaoFactory.getInstance().createInterface())
+          .nic(NicDaoFactory.getInstance().createInterface())
+          .compute(ComputeDaoFactory.getInstance().createInterface())
+          .image(ImageDaoFactory.getInstance().createInterface())
+          .manualVspToscaManager(new ManualVspToscaManagerImpl())
+          .uniqueValue(UniqueValueDaoFactory.getInstance().createInterface())
+          .candidateService(CandidateServiceFactory.getInstance().createInterface())
+          .build();
 
   @Override
   public VendorSoftwareProductManager createInterface() {
index 52b1546..78cd45c 100644 (file)
@@ -1,5 +1,9 @@
 package org.openecomp.sdc.vendorsoftwareproduct;
 
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -10,12 +14,8 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity;
 import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes;
 import org.openecomp.sdc.vendorsoftwareproduct.impl.ImageManagerImpl;
 import org.openecomp.sdc.versioning.dao.types.Version;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
-import static org.mockito.Matchers.anyObject;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.verify;
 
@@ -36,12 +36,12 @@ public class ImagesTest {
   @Spy
   private ImageManagerImpl imageManager;
 
-  @BeforeMethod
+  @Before
   public void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
   }
 
-  @AfterMethod
+  @After
   public void tearDown(){
     imageManager = null;
   }
@@ -49,7 +49,7 @@ public class ImagesTest {
   @Test
   public void createImage() {
     ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID);
-    doReturn(true).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vendorSoftwareProductInfoDao).isManual(any(), any());
 
     imageManager.createImage(imageEntity);
     verify(compositionEntityDataManager).createImage(imageEntity);
@@ -58,7 +58,7 @@ public class ImagesTest {
   @Test
   public void createImageHeat() {
     ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID);
-    doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject());
+    doReturn(false).when(vendorSoftwareProductInfoDao).isManual(any(), any());
 
     try {
       imageManager.createImage(imageEntity);
index b86a1db..ee4b2fa 100644 (file)
@@ -22,7 +22,13 @@ package org.openecomp.sdc.vendorsoftwareproduct;
 
 
 import org.apache.commons.collections4.MapUtils;
-import org.mockito.*;
+import org.junit.Assert;
+import org.junit.Before;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
 import org.openecomp.core.model.dao.ServiceModelDao;
 import org.openecomp.core.model.types.ServiceElement;
 import org.openecomp.core.validation.util.MessageContainerUtil;
@@ -39,8 +45,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.tree.UploadFileTest;
 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire;
 import org.openecomp.sdc.versioning.dao.types.Version;
-import org.testng.Assert;
-import org.testng.annotations.BeforeMethod;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -74,7 +78,7 @@ public class QuestionnaireDataServiceTest {
   private static Version vspActiveVersion;
   private static final String USER1 = "vspTestUser1";
 
-  @BeforeMethod
+  @Before
   public void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
   }
index 2557da7..b7388b5 100644 (file)
@@ -1,21 +1,25 @@
 package org.openecomp.sdc.vendorsoftwareproduct.impl;
 
-import org.mockito.*;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
 import org.openecomp.sdc.common.errors.CoreException;
 import org.openecomp.sdc.vendorsoftwareproduct.ComponentManager;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
 import org.openecomp.sdc.vendorsoftwareproduct.errors.ComponentDependencyModelErrorBuilder;
 import org.openecomp.sdc.versioning.dao.types.Version;
-import org.testng.Assert;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
-import static org.mockito.Matchers.anyObject;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.when;
 
 public class ComponentDependencyModelTest {
@@ -37,8 +41,8 @@ public class ComponentDependencyModelTest {
   @Mock
   private ComponentDependencyModelDao componentDependencyModelDao;
 
-  @BeforeMethod
-  private void init() {
+  @Before
+  public void init() {
     MockitoAnnotations.initMocks(this);
   }
 
@@ -100,7 +104,7 @@ public class ComponentDependencyModelTest {
         createModelEntity(COMP_ID_1, COMP_ID_2);
     modelEntity.setId(COMP_DEP_ID);
 
-    when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity);
+    when(componentDependencyModelDao.get(any())).thenReturn(modelEntity);
 
     componentDependencyModelManager.update(modelEntity);
     Mockito.verify(componentDependencyModelDao, Mockito.times(1)).update(modelEntity);
@@ -112,7 +116,7 @@ public class ComponentDependencyModelTest {
     ComponentDependencyModelEntity modelEntity = createModelEntity(null, COMP_ID_1);
     modelEntity.setId(COMP_DEP_ID);
 
-    when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity);
+    when(componentDependencyModelDao.get(any())).thenReturn(modelEntity);
 
     testUpdateDependency_negative(modelEntity,
         ComponentDependencyModelErrorBuilder.getNoSourceComponentErrorBuilder().id(),
@@ -121,7 +125,7 @@ public class ComponentDependencyModelTest {
     ComponentDependencyModelEntity modelEntity1 = createModelEntity("", COMP_ID_1);
     modelEntity1.setId(COMP_DEP_ID);
 
-    when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity1);
+    when(componentDependencyModelDao.get(any())).thenReturn(modelEntity1);
 
     testUpdateDependency_negative(modelEntity1,
         ComponentDependencyModelErrorBuilder.getNoSourceComponentErrorBuilder().id(),
@@ -134,7 +138,7 @@ public class ComponentDependencyModelTest {
         createModelEntity(COMP_ID_1, COMP_ID_1);
     modelEntity.setId(COMP_DEP_ID);
 
-    when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity);
+    when(componentDependencyModelDao.get(any())).thenReturn(modelEntity);
     testUpdateDependency_negative(modelEntity,
         ComponentDependencyModelErrorBuilder.getSourceTargetComponentEqualErrorBuilder().id(),
         ComponentDependencyModelErrorBuilder.getSourceTargetComponentEqualErrorBuilder().message());
@@ -146,7 +150,7 @@ public class ComponentDependencyModelTest {
         createModelEntity(COMP_ID_1, COMP_ID_2);
     modelEntity.setId(COMP_DEP_ID);
 
-    when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity);
+    when(componentDependencyModelDao.get(any())).thenReturn(modelEntity);
 
     componentDependencyModelManager.delete(VSP_ID, VERSION, COMP_DEP_ID);
     Mockito.verify(componentDependencyModelDao, Mockito.times(1)).delete(modelEntity);
@@ -177,7 +181,7 @@ public class ComponentDependencyModelTest {
         createModelEntity(COMP_ID_1, COMP_ID_2);
     modelEntity.setId(COMP_DEP_ID);
 
-    when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity);
+    when(componentDependencyModelDao.get(any())).thenReturn(modelEntity);
 
     ComponentDependencyModelEntity retrieved =
         componentDependencyModelManager.get(VSP_ID, VERSION, COMP_DEP_ID);
index 7eb593b..0617464 100644 (file)
@@ -1,6 +1,14 @@
 package org.openecomp.sdc.vendorsoftwareproduct.impl;
 
-import org.mockito.*;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentMatchers;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
 import org.openecomp.sdc.common.errors.CoreException;
 import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager;
 import org.openecomp.sdc.vendorsoftwareproduct.NicManager;
@@ -17,17 +25,15 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEnti
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
 import org.openecomp.sdc.versioning.dao.types.Version;
 import org.openecomp.sdc.versioning.errors.VersioningErrorCodes;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
 
 public class ComponentManagerImplTest {
   private static final String VSP_ID = "VSP_ID";
@@ -50,12 +56,12 @@ public class ComponentManagerImplTest {
   @Spy
   private ComponentManagerImpl componentManager;
 
-  @BeforeMethod
+  @Before
   public void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
   }
 
-  @AfterMethod
+  @After
   public void tearDown() {
     componentManager = null;
   }
@@ -66,10 +72,9 @@ public class ComponentManagerImplTest {
     Assert.assertEquals(components.size(), 0);
   }
 
-  @Test(expectedExceptions = CoreException.class,
-      expectedExceptionsMessageRegExp = COMP_NOT_EXIST_MSG)
+  @Test(expected = CoreException.class)
   public void validateExceptionWhenTryingToRetriveNotExistingComponentEntity() {
-    doReturn(null).when(componentDaoMock).get(anyObject());
+    doReturn(null).when(componentDaoMock).get(any());
     componentManager.validateComponentExistence(VSP_ID, VERSION, COMP1_ID);
   }
 
@@ -78,7 +83,7 @@ public class ComponentManagerImplTest {
     doReturn(Arrays.asList(
         createComponent(VSP_ID, VERSION, COMP1_ID),
         createComponent(VSP_ID, VERSION, COMP2_ID)))
-        .when(componentDaoMock).list(anyObject());
+        .when(componentDaoMock).list(any());
 
     Collection<ComponentEntity> actual = componentManager.listComponents(VSP_ID, VERSION);
     Assert.assertEquals(actual.size(), 2);
@@ -98,10 +103,10 @@ public class ComponentManagerImplTest {
     compData.setDescription("comp1 desc");
     expected.setComponentCompositionData(compData);
 
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
     Collection<ComponentEntity> vspComponentList = new ArrayList<>();
-    doReturn(vspComponentList).when(componentDaoMock).list(anyObject());
-    doReturn(expected).when(compositionEntityDataManagerMock).createComponent(anyObject(), Matchers.anyBoolean());
+    doReturn(vspComponentList).when(componentDaoMock).list(any());
+    doReturn(expected).when(compositionEntityDataManagerMock).createComponent(any(), ArgumentMatchers.anyBoolean());
 
     ComponentEntity created = componentManager.createComponent(expected);
     Assert.assertNotNull(created);
@@ -122,10 +127,10 @@ public class ComponentManagerImplTest {
     compData.setDescription("comp1 desc");
     expected.setComponentCompositionData(compData);
 
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
     Collection<ComponentEntity> vspComponentList = new ArrayList<>();
     vspComponentList.add(expected);
-    doReturn(vspComponentList).when(componentDaoMock).list(anyObject());
+    doReturn(vspComponentList).when(componentDaoMock).list(any());
 
     try {
        componentManager.createComponent(expected);
@@ -144,13 +149,13 @@ public class ComponentManagerImplTest {
     compData.setDescription("comp1 desc");
     expected.setComponentCompositionData(compData);
 
-    doReturn(expected).when(componentDaoMock).get(anyObject());
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(expected).when(componentDaoMock).get(any());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
     Collection<ComponentEntity> vspComponentList = new ArrayList<>();
     vspComponentList.add(expected);
-    doReturn(vspComponentList).when(componentDaoMock).list(anyObject());
+    doReturn(vspComponentList).when(componentDaoMock).list(any());
     doReturn(new CompositionEntityValidationData(null, null)).when(compositionEntityDataManagerMock)
-        .validateEntity(anyObject(), anyObject(), anyObject());
+        .validateEntity(any(), any(), any());
 
     CompositionEntityValidationData created = componentManager.updateComponent(expected);
     Assert.assertNotNull(created);
@@ -165,16 +170,16 @@ public class ComponentManagerImplTest {
     compData.setDisplayName("comp1 displayname");
     expected.setComponentCompositionData(compData);
 
-    doReturn(expected).when(componentDaoMock).get(anyObject());
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(expected).when(componentDaoMock).get(any());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
     Collection<ComponentEntity> vspComponentList = new ArrayList<>();
     vspComponentList.add(expected);
     ComponentEntity expected2 = new ComponentEntity(VSP_ID + "2", null, COMP1_ID + "2");
     expected2.setComponentCompositionData(compData);
     vspComponentList.add(expected2);
-    doReturn(vspComponentList).when(componentDaoMock).list(anyObject());
+    doReturn(vspComponentList).when(componentDaoMock).list(any());
     doReturn(new CompositionEntityValidationData(null, null)).when(compositionEntityDataManagerMock)
-        .validateEntity(anyObject(), anyObject(), anyObject());
+        .validateEntity(any(), any(), any());
 
     try {
        componentManager.updateComponent(expected);
@@ -210,7 +215,7 @@ public class ComponentManagerImplTest {
   @Test
   public void testUpdateNonExistingComponentId_negative() {
     String componentId = "non existing component id";
-    doReturn(null).when(componentDaoMock).get(anyObject());
+    doReturn(null).when(componentDaoMock).get(any());
 
     testUpdate_negative(VSP_ID, VERSION, componentId,
         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
@@ -219,11 +224,11 @@ public class ComponentManagerImplTest {
   @Test
   public void testUpdateOnUploadVsp() {
     doReturn(createComponent(VSP_ID, VERSION, COMP1_ID)).when(componentDaoMock)
-        .get(anyObject());
+        .get(any());
 
     doReturn(new CompositionEntityValidationData(CompositionEntityType.component, COMP1_ID))
         .when(compositionEntityDataManagerMock)
-        .validateEntity(anyObject(), anyObject(), anyObject());
+        .validateEntity(any(), any(), any());
 
     ComponentEntity component = new ComponentEntity(VSP_ID, VERSION, COMP1_ID);
     ComponentData compData = new ComponentData();
@@ -242,14 +247,14 @@ public class ComponentManagerImplTest {
   @Test
   public void testIllegalUpdateOnUploadVsp() {
     doReturn(createComponent(VSP_ID, VERSION, COMP1_ID))
-        .when(componentDaoMock).get(anyObject());
+        .when(componentDaoMock).get(any());
 
     CompositionEntityValidationData toBeReturned =
         new CompositionEntityValidationData(CompositionEntityType.component, COMP1_ID);
     toBeReturned.setErrors(Arrays.asList("error1", "error2"));
     doReturn(toBeReturned)
         .when(compositionEntityDataManagerMock)
-        .validateEntity(anyObject(), anyObject(), anyObject());
+        .validateEntity(any(), any(), any());
 
     ComponentEntity component = new ComponentEntity(VSP_ID, VERSION, COMP1_ID);
     ComponentData compData = new ComponentData();
@@ -267,7 +272,7 @@ public class ComponentManagerImplTest {
   @Test
   public void testGetNonExistingComponentId_negative() {
     String componentId = "non existing component id";
-    doReturn(null).when(componentDaoMock).get(anyObject());
+    doReturn(null).when(componentDaoMock).get(any());
 
     testGet_negative(VSP_ID, VERSION, componentId,
         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
@@ -276,9 +281,9 @@ public class ComponentManagerImplTest {
   @Test
   public void testGet() {
     ComponentEntity expected = createComponent(VSP_ID, VERSION, COMP1_ID);
-    doReturn(expected).when(componentDaoMock).get(anyObject());
+    doReturn(expected).when(componentDaoMock).get(any());
 
-    doReturn("schema string").when(componentManager).getComponentCompositionSchema(anyObject());
+    doReturn("schema string").when(componentManager).getComponentCompositionSchema(any());
 
     testGet(VSP_ID, VERSION, COMP1_ID, expected);
   }
@@ -313,8 +318,7 @@ public class ComponentManagerImplTest {
         VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED);
   }
 
-  @Test(expectedExceptions = CoreException.class,
-      expectedExceptionsMessageRegExp = COMP_NOT_EXIST_MSG)
+  @Test(expected = CoreException.class)
   public void testGetNonExistingComponentQuestionnaire() throws Exception {
     componentManager.getQuestionnaire(VSP_ID, VERSION, COMP1_ID);
   }
@@ -324,7 +328,7 @@ public class ComponentManagerImplTest {
     doReturn(new ComponentEntity(VSP_ID, VERSION, COMP1_ID)).when(componentDaoMock)
         .getQuestionnaireData(VSP_ID, VERSION, COMP1_ID);
     String schema = "schema string";
-    doReturn(schema).when(componentManager).getComponentQuestionnaireSchema(anyObject());
+    doReturn(schema).when(componentManager).getComponentQuestionnaireSchema(any());
 
     QuestionnaireResponse questionnaire =
         componentManager.getQuestionnaire(VSP_ID, VERSION, COMP1_ID);
@@ -355,7 +359,7 @@ public class ComponentManagerImplTest {
         .when(nicManagerMock).listNics(VSP_ID, VERSION, COMP1_ID);
 
     String schema = "schema string";
-    doReturn(schema).when(componentManager).getComponentQuestionnaireSchema(anyObject());
+    doReturn(schema).when(componentManager).getComponentQuestionnaireSchema(any());
 
     QuestionnaireResponse questionnaire =
         componentManager.getQuestionnaire(VSP_ID, VERSION, COMP1_ID);
@@ -365,17 +369,16 @@ public class ComponentManagerImplTest {
     Assert.assertNull(questionnaire.getErrorMessage());
   }
 
-  @Test(expectedExceptions = CoreException.class,
-      expectedExceptionsMessageRegExp = COMP_NOT_EXIST_MSG)
+  @Test(expected = CoreException.class)
   public void testUpdateNonExistingComponentQuestionnaire() throws Exception {
-    doReturn(null).when(componentDaoMock).get(anyObject());
+    doReturn(null).when(componentDaoMock).get(any());
     componentManager.updateQuestionnaire(VSP_ID, VERSION, COMP1_ID, "questionnaire data");
   }
 
   @Test
   public void testUpdateQuestionnaire() throws Exception {
     ComponentEntity component = createComponent(VSP_ID, VERSION, COMP1_ID);
-    doReturn(component).when(componentDaoMock).get(anyObject());
+    doReturn(component).when(componentDaoMock).get(any());
 
     componentManager.updateQuestionnaire(VSP_ID, VERSION, COMP1_ID, "questionnaire data");
 
index 2713b4c..836767d 100644 (file)
@@ -21,6 +21,9 @@
 package org.openecomp.sdc.vendorsoftwareproduct.impl;
 
 import org.apache.commons.collections.CollectionUtils;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.MockitoAnnotations;
 import org.mockito.Spy;
@@ -38,9 +41,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network;
 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.NetworkCompositionSchemaInput;
 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext;
 import org.openecomp.sdc.versioning.dao.types.Version;
-import org.testng.Assert;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -94,12 +94,12 @@ public class CompositionEntityDataManagerImplTest {
   @Spy
   private CompositionEntityDataManagerImpl compositionEntityDataManager;
 
-  @BeforeMethod
+  @Before
   public void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
   }
 
-  @Test(expectedExceptions = CoreException.class)
+  @Test(expected = CoreException.class)
   public void testAddNullEntity_negative() {
     compositionEntityDataManager.addEntity(null, null);
   }
@@ -139,8 +139,9 @@ public class CompositionEntityDataManagerImplTest {
     Assert.assertTrue(errorsById.containsKey(nicId.getParentId()));
   }
 
-  @Test(dependsOnMethods = "testAddEntity")
+  @Test
   public void testBuildTrees() {
+    testAddEntity();
     compositionEntityDataManager.buildTrees();
   }
 
@@ -249,8 +250,10 @@ public class CompositionEntityDataManagerImplTest {
     Assert.assertEquals(errorsById.size(), 1);
   }
 
-  @Test(dependsOnMethods = "testNicAndComponentValidQuestionnaire")
+  @Test
   public void testComponentInvalidQuestionnaire() {
+    //JUnit doesn't have depend on logic available
+    testNicAndComponentValidQuestionnaire();
     ComponentEntity componentEntity = new ComponentEntity(VSP1, VERSION, COMPONENT1);
     componentEntity.setQuestionnaireData(loadFileToString("quesionnaire/invalidComponent.json"));
     compositionEntityDataManager.addEntity(componentEntity, null);
index 895c9cb..ca2c709 100644 (file)
@@ -1,5 +1,9 @@
 package org.openecomp.sdc.vendorsoftwareproduct.impl;
 
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -21,16 +25,17 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEnti
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComputeData;
 import org.openecomp.sdc.versioning.dao.types.Version;
 import org.openecomp.sdc.versioning.errors.VersioningErrorCodes;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
 import java.util.Arrays;
 import java.util.Collection;
 
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
 
 public class ComputeManagerImplTest {
 
@@ -56,12 +61,12 @@ public class ComputeManagerImplTest {
   @Spy
   private ComputeManagerImpl computeManager;
 
-  @BeforeMethod
+  @Before
   public void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
   }
 
-  @AfterMethod
+  @After
   public void tearDown() {
     computeManager = null;
   }
@@ -78,7 +83,7 @@ public class ComputeManagerImplTest {
     doReturn(Arrays.asList(
         createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID),
         createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE2_ID)))
-        .when(computeDao).list(anyObject());
+        .when(computeDao).list(any());
 
 
     Collection<ListComputeResponse> computes =
@@ -101,7 +106,7 @@ public class ComputeManagerImplTest {
   @Test
   public void testCreateManualCompute() {
     ComputeEntity expected = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID);
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
     doNothing().when(computeManager)
         .validateUniqueName(VSP_ID, VERSION, COMPONENT_ID,
             expected.getComputeCompositionData().getName());
@@ -109,16 +114,16 @@ public class ComputeManagerImplTest {
         .createUniqueName(VSP_ID, VERSION, COMPONENT_ID,
             expected.getComputeCompositionData().getName());
     String questionnaireSchema = "{}";
-    doReturn(questionnaireSchema).when(computeManager).getComputeQuestionnaireSchema(anyObject());
+    doReturn(questionnaireSchema).when(computeManager).getComputeQuestionnaireSchema(any());
 
     computeManager.createCompute(expected);
     verify(computeDao).create(expected);
   }
 
-  @Test(expectedExceptions = CoreException.class)
+  @Test(expected = CoreException.class)
   public void testCreateManualComputeWithDuplicateName() {
     ComputeEntity expected = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID);
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
 
     doThrow(new CoreException(
         new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build()))
@@ -137,11 +142,11 @@ public class ComputeManagerImplTest {
   @Test
   public void testUpdateCompute() {
     ComputeEntity retrieved = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID);
-    doReturn(retrieved).when(computeDao).get(anyObject());
+    doReturn(retrieved).when(computeDao).get(any());
 
     doReturn(new CompositionEntityValidationData(CompositionEntityType.compute, COMPUTE1_ID))
         .when(compositionEntityDataManagerMock)
-        .validateEntity(anyObject(), anyObject(), anyObject());
+        .validateEntity(any(), any(), any());
 
     ComputeEntity computeEntity = new ComputeEntity(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID);
     ComputeData computeData = new ComputeData();
@@ -162,16 +167,16 @@ public class ComputeManagerImplTest {
   @Test
   public void testIllegalComputeUpdate() {
     doReturn(createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID))
-        .when(computeDao).get(anyObject());
+        .when(computeDao).get(any());
 
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
 
     CompositionEntityValidationData toBeReturned =
         new CompositionEntityValidationData(CompositionEntityType.compute, COMPUTE1_ID);
     toBeReturned.setErrors(Arrays.asList("error1", "error2"));
     doReturn(toBeReturned)
         .when(compositionEntityDataManagerMock)
-        .validateEntity(anyObject(), anyObject(), anyObject());
+        .validateEntity(any(), any(), any());
 
     ComputeEntity computeEntity = new ComputeEntity(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID);
     ComputeData computeData = new ComputeData();
@@ -190,7 +195,7 @@ public class ComputeManagerImplTest {
   @Test
   public void testUpdateHEATComputeName() throws Exception {
     doReturn(createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID))
-        .when(computeDao).get(anyObject());
+        .when(computeDao).get(any());
 
     String updatedName = COMPUTE1_ID + " name updated";
     CompositionEntityValidationData toBeReturned =
@@ -198,7 +203,7 @@ public class ComputeManagerImplTest {
 
     toBeReturned.setErrors(Arrays.asList("#/name: "+updatedName+" is not a valid value."+
         COMPUTE1_ID+"is the only possible value for this field"));
-    doReturn(toBeReturned).when(compositionEntityDataManagerMock).validateEntity(anyObject(),anyObject(),anyObject());
+    doReturn(toBeReturned).when(compositionEntityDataManagerMock).validateEntity(any(),any(),any());
 
     ComputeEntity computeEntity = new ComputeEntity(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID);
     ComputeData computeData = new ComputeData();
@@ -214,8 +219,8 @@ public class ComputeManagerImplTest {
   @Test
   public void testUpdateManualComputeQuestionnaire() throws Exception {
     String json = "{\"md5\" :\"FFDSD33SS\"}";
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
-    doReturn(new ComputeEntity(null, null, null, null)).when(computeDao).get(anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
+    doReturn(new ComputeEntity(null, null, null, null)).when(computeDao).get(any());
 
     computeManager
         .updateComputeQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID, json);
@@ -231,9 +236,9 @@ public class ComputeManagerImplTest {
   @Test
   public void testGet() {
     ComputeEntity expected = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID);
-    doReturn(expected).when(computeDao).get(anyObject());
+    doReturn(expected).when(computeDao).get(any());
     String compositionSchema = "schema string";
-    doReturn(compositionSchema).when(computeManager).getComputeCompositionSchema(anyObject());
+    doReturn(compositionSchema).when(computeManager).getComputeCompositionSchema(any());
 
     CompositionEntityResponse<ComputeData> response =
         computeManager.getCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID);
@@ -254,7 +259,7 @@ public class ComputeManagerImplTest {
 
     String schema = "schema string";
 
-    doReturn(schema).when(computeManager).getComputeQuestionnaireSchema(anyObject());
+    doReturn(schema).when(computeManager).getComputeQuestionnaireSchema(any());
 
     QuestionnaireResponse questionnaire =
         computeManager.getComputeQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID);
@@ -268,7 +273,7 @@ public class ComputeManagerImplTest {
   @Test
   public void testDeleteOnNotManualCompute() {
     ComputeEntity expected = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID);
-    doReturn(expected).when(computeDao).get(anyObject());
+    doReturn(expected).when(computeDao).get(any());
     testDelete_negative(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID,
         VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED);
   }
@@ -276,13 +281,13 @@ public class ComputeManagerImplTest {
   @Test
   public void testDeleteOnManualCompute() {
     ComputeEntity expected = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID);
-    doReturn(expected).when(computeDao).get(anyObject());
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(expected).when(computeDao).get(any());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
     doNothing().when(computeManager).deleteUniqueValue(VSP_ID, VERSION, COMPONENT_ID,
         expected.getComputeCompositionData().getName());
 
     computeManager.deleteCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID);
-    verify(computeDao).delete(anyObject());
+    verify(computeDao).delete(any());
   }
 
   @Test
index f6c3928..4e4e1da 100644 (file)
@@ -1,6 +1,10 @@
 package org.openecomp.sdc.vendorsoftwareproduct.impl;
 
 
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -23,14 +27,14 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEnti
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor;
 import org.openecomp.sdc.versioning.dao.types.Version;
 import org.openecomp.sdc.versioning.errors.VersioningErrorCodes;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
 
-import static org.mockito.Matchers.anyObject;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.verify;
 
@@ -57,12 +61,12 @@ public class DeploymentFlavorManagerImplTest {
   @Spy
   private DeploymentFlavorManagerImpl deploymentFlavorManager;
 
-  @BeforeMethod
+  @Before
   public void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
   }
 
-  @AfterMethod
+  @After
   public void tearDown() {
     deploymentFlavorManager = null;
   }
@@ -84,11 +88,11 @@ public class DeploymentFlavorManagerImplTest {
   @Test
   public void testCreateManualDepFlavor() {
     DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID);
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
 
     VspDetails vspDetails = new VspDetails(VSP_ID, VERSION);
     vspDetails.setFeatureGroups(fgs);
-    doReturn(vspDetails).when(vspInfoDao).get(anyObject());
+    doReturn(vspDetails).when(vspInfoDao).get(any());
 
     deploymentFlavorManager.createDeploymentFlavor(expected);
     verify(compositionEntityDataManagerMock).createDeploymentFlavor(expected);
@@ -97,7 +101,7 @@ public class DeploymentFlavorManagerImplTest {
   @Test
   public void testCreateManualDepFlavorWithDuplicateName() {
     DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID);
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
 
     DeploymentFlavorEntity expectedDiffName = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID);
     DeploymentFlavor deploymentFlavor = expectedDiffName.getDeploymentFlavorCompositionData();
@@ -105,7 +109,7 @@ public class DeploymentFlavorManagerImplTest {
     expectedDiffName.setDeploymentFlavorCompositionData(deploymentFlavor);
     List<DeploymentFlavorEntity> list = new ArrayList<>();
     list.add(expectedDiffName);
-    doReturn(list).when(deploymentFlavorDaoMock).list(anyObject());
+    doReturn(list).when(deploymentFlavorDaoMock).list(any());
 
     try {
       deploymentFlavorManager.createDeploymentFlavor(expected);
@@ -125,7 +129,7 @@ public class DeploymentFlavorManagerImplTest {
     deploymentFlavor.setFeatureGroupId("fg3");
     expected.setCompositionData(JsonUtil.object2Json(deploymentFlavor));
 
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
 
     List<String> featureGrps = new ArrayList<>();
     featureGrps.add("fg1");
@@ -133,7 +137,7 @@ public class DeploymentFlavorManagerImplTest {
 
     VspDetails vspDetails = new VspDetails(VSP_ID, VERSION);
     vspDetails.setFeatureGroups(featureGrps);
-    doReturn(vspDetails).when(vspInfoDao).get(anyObject());
+    doReturn(vspDetails).when(vspInfoDao).get(any());
 
 
     try {
@@ -153,10 +157,10 @@ public class DeploymentFlavorManagerImplTest {
     deploymentFlavor.setFeatureGroupId(null);
     expected.setCompositionData(JsonUtil.object2Json(deploymentFlavor));
 
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
 
     VspDetails vspDetails = new VspDetails(VSP_ID, VERSION);
-    doReturn(vspDetails).when(vspInfoDao).get(anyObject());
+    doReturn(vspDetails).when(vspInfoDao).get(any());
     deploymentFlavorManager.createDeploymentFlavor(expected);
     verify(compositionEntityDataManagerMock).createDeploymentFlavor(expected);
   }
@@ -174,11 +178,11 @@ public class DeploymentFlavorManagerImplTest {
     deploymentFlavor.setComponentComputeAssociations(list);
     expected.setCompositionData(JsonUtil.object2Json(deploymentFlavor));
 
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
 
     VspDetails vspDetails = new VspDetails(VSP_ID, VERSION);
     vspDetails.setFeatureGroups(fgs);
-    doReturn(vspDetails).when(vspInfoDao).get(anyObject());
+    doReturn(vspDetails).when(vspInfoDao).get(any());
 
     try {
       deploymentFlavorManager.createDeploymentFlavor(expected);
@@ -204,16 +208,16 @@ public class DeploymentFlavorManagerImplTest {
     deploymentFlavor.setComponentComputeAssociations(list);
     expected.setCompositionData(JsonUtil.object2Json(deploymentFlavor));
 
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
 
     VspDetails vspDetails = new VspDetails(VSP_ID, VERSION);
     vspDetails.setFeatureGroups(fgs);
-    doReturn(vspDetails).when(vspInfoDao).get(anyObject());
+    doReturn(vspDetails).when(vspInfoDao).get(any());
 
     ComponentEntity component = new ComponentEntity(VSP_ID, VERSION, null);
-    doReturn(component).when(componentDaoMock).get(anyObject());
+    doReturn(component).when(componentDaoMock).get(any());
 
-    doReturn(null).when(computeDaoMock).get(anyObject());
+    doReturn(null).when(computeDaoMock).get(any());
 
     try {
       deploymentFlavorManager.createDeploymentFlavor(expected);
@@ -237,17 +241,17 @@ public class DeploymentFlavorManagerImplTest {
     deploymentFlavor.setComponentComputeAssociations(list);
     expected.setCompositionData(JsonUtil.object2Json(deploymentFlavor));
 
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
 
     VspDetails vspDetails = new VspDetails(VSP_ID, VERSION);
     vspDetails.setFeatureGroups(fgs);
-    doReturn(vspDetails).when(vspInfoDao).get(anyObject());
+    doReturn(vspDetails).when(vspInfoDao).get(any());
 
     ComponentEntity component = new ComponentEntity(VSP_ID, VERSION, null);
-    doReturn(component).when(componentDaoMock).get(anyObject());
+    doReturn(component).when(componentDaoMock).get(any());
 
     ComputeEntity computeEntity = new ComputeEntity(VSP_ID, VERSION, COMPONENT_ID, "CF1");
-    doReturn(computeEntity).when(computeDaoMock).get(anyObject());
+    doReturn(computeEntity).when(computeDaoMock).get(any());
 
     try {
       deploymentFlavorManager.createDeploymentFlavor(expected);
@@ -264,7 +268,7 @@ public class DeploymentFlavorManagerImplTest {
     doReturn(Arrays.asList(
         createDeploymentFlavor(VSP_ID, VERSION, DF1_ID),
         createDeploymentFlavor(VSP_ID, VERSION, DF2_ID)))
-        .when(deploymentFlavorDaoMock).list(anyObject());
+        .when(deploymentFlavorDaoMock).list(any());
 
 
     final Collection<DeploymentFlavorEntity> deploymentFlavorEntities =
@@ -284,24 +288,24 @@ public class DeploymentFlavorManagerImplTest {
 
   @Test
   public void testUpdateNonExistingManualDepFlavorId_negative() {
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
     testUpdate_negative(VSP_ID, VERSION, DF1_ID,
         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
   }
 
   @Test
   public void testManualUpdateDepFlavor() {
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
 
     doReturn(createDeploymentFlavor(VSP_ID, VERSION, DF1_ID))
-        .when(deploymentFlavorDaoMock).get(anyObject());
+        .when(deploymentFlavorDaoMock).get(any());
 
     doReturn(new CompositionEntityValidationData(CompositionEntityType.image, DF1_ID))
         .when(compositionEntityDataManagerMock)
-        .validateEntity(anyObject(), anyObject(), anyObject());
+        .validateEntity(any(), any(), any());
 
     VspDetails vspDetails = new VspDetails(VSP_ID, VERSION);
-    doReturn(vspDetails).when(vspInfoDao).get(anyObject());
+    doReturn(vspDetails).when(vspInfoDao).get(any());
 
     DeploymentFlavorEntity deploymentFlavorEntity =
         new DeploymentFlavorEntity(VSP_ID, VERSION, DF1_ID);
@@ -326,7 +330,7 @@ public class DeploymentFlavorManagerImplTest {
   @Test
   public void testDeleteDepFlavorOnHEAT() {
     DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID);
-    doReturn(expected).when(deploymentFlavorDaoMock).get(anyObject());
+    doReturn(expected).when(deploymentFlavorDaoMock).get(any());
     testDelete_negative(VSP_ID, VERSION, DF1_ID,
         VendorSoftwareProductErrorCodes.DELETE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING);
   }
@@ -340,10 +344,10 @@ public class DeploymentFlavorManagerImplTest {
   @Test
   public void testDeleteOnManualImage() {
     DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID);
-    doReturn(expected).when(deploymentFlavorDaoMock).get(anyObject());
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(expected).when(deploymentFlavorDaoMock).get(any());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
     deploymentFlavorManager.deleteDeploymentFlavor(VSP_ID, VERSION, DF1_ID);
-    verify(deploymentFlavorDaoMock).delete(anyObject());
+    verify(deploymentFlavorDaoMock).delete(any());
   }
 
   private void testCreate_negative(DeploymentFlavorEntity deploymentFlavorEntity,
index 6325f98..006094c 100644 (file)
@@ -1,6 +1,10 @@
 package org.openecomp.sdc.vendorsoftwareproduct.impl;
 
 
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -18,18 +22,16 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEnti
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Image;
 import org.openecomp.sdc.versioning.dao.types.Version;
 import org.openecomp.sdc.versioning.errors.VersioningErrorCodes;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
 
 public class ImageManagerImplTest {
 
@@ -63,12 +65,12 @@ public class ImageManagerImplTest {
     @Spy
     private ImageManagerImpl imageManager;
 
-    @BeforeMethod
+    @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
     }
 
-    @AfterMethod
+    @After
     public void tearDown() {
         imageManager = null;
     }
@@ -84,7 +86,7 @@ public class ImageManagerImplTest {
     public void testList() {
 
         doReturn(Arrays.asList(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID),
-                createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE2_ID))).when(imageDao).list(anyObject());
+                createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE2_ID))).when(imageDao).list(any());
 
 
         final Collection<ImageEntity> images = imageManager.listImages(VSP_ID, VERSION, COMPONENT_ID);
@@ -105,7 +107,7 @@ public class ImageManagerImplTest {
     @Test
     public void testCreateManualImage() {
         ImageEntity expected = createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID);
-        doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+        doReturn(true).when(vspInfoDao).isManual(any(), any());
         imageManager.createImage(expected);
         verify(compositionEntityDataManagerMock).createImage(expected);
         verify(compositionEntityDataManagerMock).createImage(expected);
@@ -119,10 +121,10 @@ public class ImageManagerImplTest {
 
     @Test
     public void testUpdateImage() {
-        doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)).when(imageDao).get(anyObject());
+        doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)).when(imageDao).get(any());
 
         doReturn(new CompositionEntityValidationData(CompositionEntityType.image, IMAGE1_ID))
-                .when(compositionEntityDataManagerMock).validateEntity(anyObject(), anyObject(), anyObject());
+                .when(compositionEntityDataManagerMock).validateEntity(any(), any(), any());
 
         ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID);
         Image imageData = new Image();
@@ -137,15 +139,15 @@ public class ImageManagerImplTest {
 
     @Test
     public void testIllegalImageUpdate() {
-        doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)).when(imageDao).get(anyObject());
+        doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)).when(imageDao).get(any());
 
-        doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+        doReturn(true).when(vspInfoDao).isManual(any(), any());
 
         CompositionEntityValidationData toBeReturned =
                 new CompositionEntityValidationData(CompositionEntityType.image, IMAGE1_ID);
         toBeReturned.setErrors(Arrays.asList("error1", "error2"));
         doReturn(toBeReturned).when(compositionEntityDataManagerMock)
-                              .validateEntity(anyObject(), anyObject(), anyObject());
+                              .validateEntity(any(), any(), any());
 
         ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID);
         Image imageData = new Image();
@@ -162,7 +164,7 @@ public class ImageManagerImplTest {
 
     @Test
     public void testUpdateHEATImageFileName() throws Exception {
-        doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)).when(imageDao).get(anyObject());
+        doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)).when(imageDao).get(any());
 
         String updatedName = IMAGE1_ID + " name updated";
         CompositionEntityValidationData toBeReturned =
@@ -171,7 +173,7 @@ public class ImageManagerImplTest {
         toBeReturned.setErrors(Arrays.asList("#/name: " + updatedName + " is not a valid value." + IMAGE1_ID
                                                      + "is the only possible value for this field"));
         doReturn(toBeReturned).when(compositionEntityDataManagerMock)
-                              .validateEntity(anyObject(), anyObject(), anyObject());
+                              .validateEntity(any(), any(), any());
 
         ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID);
         Image imageData = new Image();
@@ -193,9 +195,9 @@ public class ImageManagerImplTest {
     @Test
     public void testGet() {
         ImageEntity expected = createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID);
-        doReturn(expected).when(imageDao).get(anyObject());
+        doReturn(expected).when(imageDao).get(any());
         String compositionSchema = "schema string";
-        doReturn(compositionSchema).when(imageManager).getImageCompositionSchema(anyObject());
+        doReturn(compositionSchema).when(imageManager).getImageCompositionSchema(any());
 
         CompositionEntityResponse<Image> response = imageManager.getImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID);
         Assert.assertEquals(response.getId(), expected.getId());
@@ -208,7 +210,7 @@ public class ImageManagerImplTest {
     @Test
     public void testDeleteOnNotManualImage() {
         ImageEntity expected = createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID);
-        doReturn(expected).when(imageDao).get(anyObject());
+        doReturn(expected).when(imageDao).get(any());
         testDelete_negative(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID,
                 VendorSoftwareProductErrorCodes.DELETE_IMAGE_NOT_ALLOWED);
     }
@@ -222,10 +224,10 @@ public class ImageManagerImplTest {
     @Test
     public void testDeleteOnManualImage() {
         ImageEntity expected = createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID);
-        doReturn(expected).when(imageDao).get(anyObject());
-        doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+        doReturn(expected).when(imageDao).get(any());
+        doReturn(true).when(vspInfoDao).isManual(any(), any());
         imageManager.deleteImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID);
-        verify(imageDao).delete(anyObject());
+        verify(imageDao).delete(any());
     }
 
     @Test
@@ -235,7 +237,7 @@ public class ImageManagerImplTest {
         doReturn(image).when(imageDao).getQuestionnaireData(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID);
 
         String schema = "schema string";
-        doReturn(schema).when(imageManager).getImageQuestionnaireSchema(anyObject());
+        doReturn(schema).when(imageManager).getImageQuestionnaireSchema(any());
 
         QuestionnaireResponse questionnaire =
                 imageManager.getImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID);
@@ -248,8 +250,8 @@ public class ImageManagerImplTest {
     @Test
     public void testUpdateManualImageQuestionnaire() throws Exception {
         String json = "{\"md5\" :\"FFDSD33SS\"}";
-        doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
-        doReturn(new ImageEntity()).when(imageDao).get(anyObject());
+        doReturn(true).when(vspInfoDao).isManual(any(), any());
+        doReturn(new ImageEntity()).when(imageDao).get(any());
 
         imageManager.updateImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, json);
         verify(imageDao).updateQuestionnaireData(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, json);
@@ -267,13 +269,13 @@ public class ImageManagerImplTest {
                 add(imageEntity);
             }};
 
-            doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
-            doReturn(imageEntity).when(imageDao).get(anyObject());
-            doReturn(imageEntities).when(imageDao).list(anyObject());
+            doReturn(true).when(vspInfoDao).isManual(any(), any());
+            doReturn(imageEntity).when(imageDao).get(any());
+            doReturn(imageEntities).when(imageDao).list(any());
             doReturn(imageEntities.get(0)).when(imageDao)
-                                          .getQuestionnaireData(anyObject(), anyObject(), anyObject(), anyObject());
+                                          .getQuestionnaireData(any(), any(), any(), any());
 
-            doReturn(IMAGE_QUEST_SCHEMA).when(imageManager).getImageQuestionnaireSchema(anyObject());
+            doReturn(IMAGE_QUEST_SCHEMA).when(imageManager).getImageQuestionnaireSchema(any());
 
             imageManager.updateImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, json);
             Assert.fail();
@@ -289,10 +291,10 @@ public class ImageManagerImplTest {
         String json = "{\"format\" :\"qcow2\"}";
         ImageEntity image = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID);
         image.setQuestionnaireData(json);
-        doReturn(image).when(imageDao).get(anyObject());
+        doReturn(image).when(imageDao).get(any());
 
-        doReturn(false).when(vspInfoDao).isManual(anyObject(), anyObject());
-        doReturn(IMAGE_QUEST_SCHEMA).when(imageManager).getImageQuestionnaireSchema(anyObject());
+        doReturn(false).when(vspInfoDao).isManual(any(), any());
+        doReturn(IMAGE_QUEST_SCHEMA).when(imageManager).getImageQuestionnaireSchema(any());
         doReturn(image).when(imageDao).getQuestionnaireData(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID);
         String updJson = "{\"format\" :\"aki\"}";
         try {
@@ -308,7 +310,7 @@ public class ImageManagerImplTest {
         String json = "{\"format\" :\"qcow2\"}";
         ImageEntity image = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID);
         image.setQuestionnaireData(json);
-        doReturn(image).when(imageDao).get(anyObject());
+        doReturn(image).when(imageDao).get(any());
 
         String updJson = "{\"format\" :\"a22\"}";
         try {
index 817955e..4c4d4f7 100644 (file)
@@ -1,5 +1,9 @@
 package org.openecomp.sdc.vendorsoftwareproduct.impl;
 
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -9,10 +13,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity;
 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.MonitoringUploadStatus;
 import org.openecomp.sdc.versioning.dao.types.Version;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -21,9 +21,10 @@ import java.util.Arrays;
 import java.util.Optional;
 import java.util.function.Consumer;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
 
 public class MonitoringUploadsManagerImplTest {
 
@@ -44,17 +45,17 @@ public class MonitoringUploadsManagerImplTest {
   @InjectMocks
   private MonitoringUploadsManagerImpl monitoringUploadsManager;
 
-  @BeforeMethod
+  @Before
   public void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
   }
 
-  @AfterMethod
+  @After
   public void tearDown(){
     monitoringUploadsManager = null;
   }
 
-  @Test(expectedExceptions = CoreException.class)
+  @Test(expected = CoreException.class)
   public void testUploadEmptyZip() {
     processFile(ZIP_DIR + EMPTY_ZIP_FILE_NAME, inputStream ->
         monitoringUploadsManager
@@ -62,8 +63,7 @@ public class MonitoringUploadsManagerImplTest {
                 MonitoringUploadType.SNMP_TRAP));
   }
 
-  @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp =
-      "Invalid zip file")
+  @Test(expected = CoreException.class)
   public void testUploadInvalidZip() {
     processFile("/notZipFile", inputStream ->
         monitoringUploadsManager
@@ -118,7 +118,7 @@ public class MonitoringUploadsManagerImplTest {
     artifact3.setArtifactName(VES_FILE_NAME);
 
     doReturn(Arrays.asList(artifact1, artifact2, artifact3))
-        .when(componentArtifactDaoMock).list(anyObject());
+        .when(componentArtifactDaoMock).list(any());
 
     MonitoringUploadStatus monitoringUploadStatus =
         monitoringUploadsManager.listFilenames(VSP_ID, VERSION, COMPONENT_ID);
@@ -128,13 +128,13 @@ public class MonitoringUploadsManagerImplTest {
     Assert.assertEquals(monitoringUploadStatus.getVesEvent(), VES_FILE_NAME);
   }
 
-  @Test(expectedExceptions = CoreException.class)
+  @Test(expected = CoreException.class)
   public void testDeleteComponentMibWhenNone() {
     doReturn(Optional.empty()).when(componentArtifactDaoMock).getByType(any());
     monitoringUploadsManager
         .delete(VSP_ID, VERSION, COMPONENT_ID, MonitoringUploadType.SNMP_POLL);
 
-    verify(componentArtifactDaoMock, never()).delete(anyObject());
+    verify(componentArtifactDaoMock, never()).delete(any());
   }
 
   @Test
@@ -142,12 +142,12 @@ public class MonitoringUploadsManagerImplTest {
     doReturn(Optional
         .of(new ComponentMonitoringUploadEntity(VSP_ID, VERSION, COMPONENT_ID, "artifactId")))
         .when
-            (componentArtifactDaoMock).getByType(anyObject());
+            (componentArtifactDaoMock).getByType(any());
 
     monitoringUploadsManager
         .delete(VSP_ID, VERSION, COMPONENT_ID, MonitoringUploadType.SNMP_POLL);
 
-    verify(componentArtifactDaoMock).delete(anyObject());
+    verify(componentArtifactDaoMock).delete(any());
   }
 
 
index a12b121..8e7423c 100644 (file)
 package org.openecomp.sdc.vendorsoftwareproduct.impl;
 
 
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -34,16 +38,14 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEnti
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network;
 import org.openecomp.sdc.versioning.dao.types.Version;
 import org.openecomp.sdc.versioning.errors.VersioningErrorCodes;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
 import java.util.Arrays;
 import java.util.Collection;
 
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
 
 public class NetworkManagerImplTest {
 
@@ -74,13 +76,13 @@ public class NetworkManagerImplTest {
     return networkEntity;
   }
 
-  @BeforeMethod
+  @Before
   public void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
     SessionContextProviderFactory.getInstance().createInterface().create(USER_ID, tenant);
   }
 
-  @AfterMethod
+  @After
   public void tearDown() {
     networkManager = null;
     SessionContextProviderFactory.getInstance().createInterface().close();
@@ -98,7 +100,7 @@ public class NetworkManagerImplTest {
     doReturn(Arrays.asList(
         createNetwork(VSP_ID, VERSION, NETWORK1_ID),
         createNetwork(VSP_ID, VERSION, NETWORK2_ID)))
-        .when(networkDaoMock).list(anyObject());
+        .when(networkDaoMock).list(any());
 
     Collection<NetworkEntity> actual = networkManager.listNetworks(VSP_ID, VERSION);
     Assert.assertEquals(actual.size(), 2);
@@ -119,15 +121,15 @@ public class NetworkManagerImplTest {
   @Test
   public void testIllegalUpdateOnUploadVsp() {
     doReturn(createNetwork(VSP_ID, VERSION, NETWORK1_ID))
-        .when(networkDaoMock).get(anyObject());
+        .when(networkDaoMock).get(any());
 
     CompositionEntityValidationData toBeReturned =
         new CompositionEntityValidationData(CompositionEntityType.network, NETWORK1_ID);
     toBeReturned.setErrors(Arrays.asList("error1", "error2"));
     doReturn(toBeReturned)
         .when(compositionEntityDataManagerMock)
-        .validateEntity(anyObject(), anyObject(), anyObject());
-    doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(),anyObject());
+        .validateEntity(any(), any(), any());
+    doReturn(false).when(vendorSoftwareProductInfoDao).isManual(any(),any());
 
     NetworkEntity networkEntity = new NetworkEntity(VSP_ID, VERSION, NETWORK1_ID);
     Network networkData = new Network();
@@ -153,9 +155,9 @@ public class NetworkManagerImplTest {
   public void testGet() {
     NetworkEntity network = createNetwork(VSP_ID, VERSION, NETWORK1_ID);
     doReturn(network)
-        .when(networkDaoMock).get(anyObject());
-    doReturn("schema string").when(networkManager).getCompositionSchema(anyObject());
-    doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(),anyObject());
+        .when(networkDaoMock).get(any());
+    doReturn("schema string").when(networkManager).getCompositionSchema(any());
+    doReturn(false).when(vendorSoftwareProductInfoDao).isManual(any(),any());
 
     CompositionEntityResponse<Network> response =
         networkManager.getNetwork(VSP_ID, VERSION, NETWORK1_ID);
@@ -164,15 +166,16 @@ public class NetworkManagerImplTest {
     Assert.assertNotNull(response.getSchema());
   }
 
-  @Test(dependsOnMethods = "testList")
+  @Test
   public void testDeleteOnUploadVsp_negative() {
+    testList();
     testDelete_negative(VSP_ID, VERSION, NETWORK1_ID,
         VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED);
   }
 
   private void testCreate_negative(NetworkEntity network, String expectedErrorCode) {
     try {
-      doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(),anyObject());
+      doReturn(false).when(vendorSoftwareProductInfoDao).isManual(any(),any());
       networkManager.createNetwork(network);
       Assert.fail();
     } catch (CoreException exception) {
@@ -212,7 +215,7 @@ public class NetworkManagerImplTest {
   private void testDelete_negative(String vspId, Version version, String networkId,
                                    String expectedErrorCode) {
     try {
-      doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(),anyObject());
+      doReturn(false).when(vendorSoftwareProductInfoDao).isManual(any(),any());
       networkManager.deleteNetwork(vspId, version, networkId);
       Assert.fail();
     } catch (CoreException exception) {
index b095acf..4aca9ae 100644 (file)
 
 package org.openecomp.sdc.vendorsoftwareproduct.impl;
 
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -36,17 +40,15 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.NetworkType;
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
 import org.openecomp.sdc.versioning.dao.types.Version;
 import org.openecomp.sdc.versioning.errors.VersioningErrorCodes;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
 
 public class NicManagerImplTest {
 
@@ -74,12 +76,12 @@ public class NicManagerImplTest {
   @Spy
   private NicManagerImpl nicManager;
 
-  @BeforeMethod
+  @Before
   public void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
   }
 
-  @AfterMethod
+  @After
   public void tearDown() {
     nicManager = null;
   }
@@ -95,7 +97,7 @@ public class NicManagerImplTest {
     doReturn(Arrays.asList(
         createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID),
         createNic(VSP_ID, VERSION, COMPONENT_ID, NIC2_ID, NETWORK2_ID)))
-        .when(nicDao).list(anyObject());
+        .when(nicDao).list(any());
 
     NetworkEntity network1 = NetworkManagerImplTest.createNetwork(VSP_ID, VERSION, NETWORK1_ID);
     NetworkEntity network2 = NetworkManagerImplTest.createNetwork(VSP_ID, VERSION, NETWORK2_ID);
@@ -118,10 +120,10 @@ public class NicManagerImplTest {
     Nic nic = nicEntity.getNicCompositionData();
     nic.setNetworkType(NetworkType.Internal);
     nicEntity.setNicCompositionData(nic);
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
     Collection<NicEntity> nicEntities = new ArrayList<>();
-    doReturn(nicEntities).when(nicDao).list(anyObject());
-    doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(anyObject());
+    doReturn(nicEntities).when(nicDao).list(any());
+    doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(any());
 
     NicEntity created = nicManager.createNic(nicEntity);
     Assert.assertNotNull(created);
@@ -133,7 +135,7 @@ public class NicManagerImplTest {
     Nic nic = nicEntity.getNicCompositionData();
     nic.setNetworkType(NetworkType.Internal);
     nicEntity.setNicCompositionData(nic);
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
     Collection<NicEntity> nicEntities = new ArrayList<>();
 
     NicEntity nicEntityDiffName = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID);
@@ -141,8 +143,8 @@ public class NicManagerImplTest {
     newNameNic.setName(NIC1_ID + "_Name/*");
     nicEntityDiffName.setNicCompositionData(newNameNic);
     nicEntities.add(nicEntityDiffName);
-    doReturn(nicEntities).when(nicDao).list(anyObject());
-    doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(anyObject());
+    doReturn(nicEntities).when(nicDao).list(any());
+    doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(any());
 
     try {
       NicEntity created = nicManager.createNic(nicEntity);
@@ -158,7 +160,7 @@ public class NicManagerImplTest {
     Nic nic = nicEntity.getNicCompositionData();
     nic.setNetworkType(NetworkType.Internal);
     nicEntity.setNicCompositionData(nic);
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
     Collection<NicEntity> nicEntities = new ArrayList<>();
 
     NicEntity nicEntityDiffName = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID);
@@ -166,8 +168,8 @@ public class NicManagerImplTest {
     newNameNic.setName(NIC1_ID + "_Name");
     nicEntityDiffName.setNicCompositionData(newNameNic);
     nicEntities.add(nicEntityDiffName);
-    doReturn(nicEntities).when(nicDao).list(anyObject());
-    doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(anyObject());
+    doReturn(nicEntities).when(nicDao).list(any());
+    doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(any());
 
     try {
       NicEntity created = nicManager.createNic(nicEntity);
@@ -186,10 +188,10 @@ public class NicManagerImplTest {
     Nic nic = nicEntity.getNicCompositionData();
     nic.setNetworkType(NetworkType.External);
     nicEntity.setNicCompositionData(nic);
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
     Collection<NicEntity> nicEntities = new ArrayList<>();
-    doReturn(nicEntities).when(nicDao).list(anyObject());
-    doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(anyObject());
+    doReturn(nicEntities).when(nicDao).list(any());
+    doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(any());
 
     try {
       NicEntity created = nicManager.createNic(nicEntity);
@@ -209,10 +211,10 @@ public class NicManagerImplTest {
     nic.setNetworkType(NetworkType.Internal);
     nic.setNetworkDescription(NIC1_ID);
     nicEntity.setNicCompositionData(nic);
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
     Collection<NicEntity> nicEntities = new ArrayList<>();
-    doReturn(nicEntities).when(nicDao).list(anyObject());
-    doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(anyObject());
+    doReturn(nicEntities).when(nicDao).list(any());
+    doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(any());
 
     try {
       NicEntity created = nicManager.createNic(nicEntity);
@@ -227,8 +229,8 @@ public class NicManagerImplTest {
   @Test
   public void testDeleteNic() {
     NicEntity nicEntity = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID);
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
-    doReturn(nicEntity).when(nicDao).get(anyObject());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
+    doReturn(nicEntity).when(nicDao).get(any());
 
     nicManager.deleteNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID);
 
@@ -238,8 +240,8 @@ public class NicManagerImplTest {
   public void testUpdateNicQuestionnaire() {
     NicEntity nicEntity = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID);
 
-    doReturn(nicEntity).when(nicDao).get(anyObject());
-    doReturn("{}").when(nicManager).getNicCompositionSchema(anyObject());
+    doReturn(nicEntity).when(nicDao).get(any());
+    doReturn("{}").when(nicManager).getNicCompositionSchema(any());
 
     nicManager
         .updateNicQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, "Ques");
@@ -287,7 +289,7 @@ public class NicManagerImplTest {
 
   @Test
   public void testUpdateNonExistingNicId_negative() {
-    doReturn(null).when(nicDao).get(anyObject());
+    doReturn(null).when(nicDao).get(any());
 
     testUpdate_negative(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID,
         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
@@ -296,11 +298,11 @@ public class NicManagerImplTest {
   @Test
   public void testUpdateOnUploadVsp() {
     doReturn(createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID))
-        .when(nicDao).get(anyObject());
+        .when(nicDao).get(any());
 
     doReturn(new CompositionEntityValidationData(CompositionEntityType.nic, NIC1_ID))
         .when(compositionEntityDataManagerMock)
-        .validateEntity(anyObject(), anyObject(), anyObject());
+        .validateEntity(any(), any(), any());
 
     NicEntity nicEntity = new NicEntity(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID);
     Nic nicData = new Nic();
@@ -318,14 +320,14 @@ public class NicManagerImplTest {
   @Test
   public void testIllegalUpdateOnUploadVsp() {
     doReturn(createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID))
-        .when(nicDao).get(anyObject());
+        .when(nicDao).get(any());
 
     CompositionEntityValidationData toBeReturned =
         new CompositionEntityValidationData(CompositionEntityType.nic, NIC1_ID);
     toBeReturned.setErrors(Arrays.asList("error1", "error2"));
     doReturn(toBeReturned)
         .when(compositionEntityDataManagerMock)
-        .validateEntity(anyObject(), anyObject(), anyObject());
+        .validateEntity(any(), any(), any());
 
     NicEntity nicEntity = new NicEntity(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID);
     Nic nicData = new Nic();
@@ -344,15 +346,15 @@ public class NicManagerImplTest {
   @Test
   public void testUpdateIncorrectNameFormat() {
     doReturn(createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID))
-        .when(nicDao).get(anyObject());
+        .when(nicDao).get(any());
 
     CompositionEntityValidationData toBeReturned =
         new CompositionEntityValidationData(CompositionEntityType.nic, NIC1_ID);
     toBeReturned.setErrors(Arrays.asList("Field does not conform to predefined criteria:name : must match [a-zA-Z0-9_]*$"));
     doReturn(toBeReturned)
         .when(compositionEntityDataManagerMock)
-        .validateEntity(anyObject(), anyObject(), anyObject());
-    doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject());
+        .validateEntity(any(), any(), any());
+    doReturn(true).when(vspInfoDao).isManual(any(), any());
 
     NicEntity nicEntity = new NicEntity(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID);
     Nic nicData = new Nic();
@@ -377,9 +379,9 @@ public class NicManagerImplTest {
   @Test
   public void testGet() {
     NicEntity expected = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID);
-    doReturn(expected).when(nicDao).get(anyObject());
+    doReturn(expected).when(nicDao).get(any());
     String compositionSchema = "schema string";
-    doReturn(compositionSchema).when(nicManager).getNicCompositionSchema(anyObject());
+    doReturn(compositionSchema).when(nicManager).getNicCompositionSchema(any());
 
     CompositionEntityResponse<Nic> response =
         nicManager.getNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID);
@@ -418,8 +420,7 @@ public class NicManagerImplTest {
         VendorSoftwareProductErrorCodes.DELETE_NIC_NOT_ALLOWED);
   }
 
-  @Test(expectedExceptions = CoreException.class,
-      expectedExceptionsMessageRegExp = NIC_NOT_EXIST_MSG)
+  @Test(expected = CoreException.class)
   public void testGetNonExistingNicQuestionnaire() throws Exception {
     nicManager.getNicQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID);
   }
@@ -431,7 +432,7 @@ public class NicManagerImplTest {
     doReturn(nic).when(nicDao).getQuestionnaireData(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID);
 
     String schema = "schema string";
-    doReturn(schema).when(nicManager).getNicQuestionnaireSchema(anyObject());
+    doReturn(schema).when(nicManager).getNicQuestionnaireSchema(any());
 
     QuestionnaireResponse questionnaire =
         nicManager.getNicQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID);
@@ -441,10 +442,9 @@ public class NicManagerImplTest {
     Assert.assertNull(questionnaire.getErrorMessage());
   }
 
-  @Test(expectedExceptions = CoreException.class,
-      expectedExceptionsMessageRegExp = NIC_NOT_EXIST_MSG)
+  @Test(expected = CoreException.class)
   public void testUpdateNonExistingNicQuestionnaire() throws Exception {
-    doReturn(null).when(nicDao).get(anyObject());
+    doReturn(null).when(nicDao).get(any());
     nicManager
         .updateNicQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, "questionnaire data");
   }
index b56098f..8f33be1 100644 (file)
 
 package org.openecomp.sdc.vendorsoftwareproduct.impl;
 
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.Mockito;
@@ -38,20 +42,20 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStru
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
 import org.openecomp.sdc.vendorsoftwareproduct.utils.ZipFileUtils;
 import org.openecomp.sdc.versioning.dao.types.Version;
-import org.testng.Assert;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
 
 import java.nio.ByteBuffer;
-import java.util.*;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doReturn;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
 
 public class OrchestrationTemplateCandidateManagerImplTest {
   private static final String VSP_ID = "vspId";
@@ -89,22 +93,18 @@ public class OrchestrationTemplateCandidateManagerImplTest {
   @InjectMocks
   private OrchestrationUtil orchestrationUtil;
 
-  @BeforeClass
+  @Before
   public void setUp() {
     MockitoAnnotations.initMocks(this);
   }
 
-  @AfterMethod
-  private void resetMocks() {
+  @After
+  public void resetMocks() {
     Mockito.reset(vspInfoDaoMock);
     Mockito.reset(candidateServiceMock);
     Mockito.reset(orchestrationTemplateDaoMock);
     Mockito.reset(componentDependencyModelDaoMock);
     Mockito.reset(componentDaoMock);
-  }
-
-  @AfterClass
-  public void tearDown() {
     candidateManager = null;
     orchestrationUtil = null;
   }
@@ -203,7 +203,7 @@ public class OrchestrationTemplateCandidateManagerImplTest {
     doReturn(initialVspComponents).when(componentDaoMock).list(any());
     Map<String, String> vspComponentIdNameInfo =
         orchestrationUtil.getVspComponentIdNameInfo(VSP_ID, VERSION01);
-    Assert.assertEquals(vspComponentIdNameInfo.size(), 0);
+    assertEquals(vspComponentIdNameInfo.size(), 0);
   }
 
   @Test
@@ -240,7 +240,7 @@ public class OrchestrationTemplateCandidateManagerImplTest {
   public void testGetComponentDependenciesBeforeDeleteInvalid() {
     Collection<ComponentDependencyModelEntity> componentDependenciesBeforeDelete =
         orchestrationUtil.getComponentDependenciesBeforeDelete(null, null);
-    Assert.assertEquals(componentDependenciesBeforeDelete.size(), 0);
+    assertEquals(componentDependenciesBeforeDelete.size(), 0);
   }
 
   @Test
@@ -250,7 +250,7 @@ public class OrchestrationTemplateCandidateManagerImplTest {
     doReturn(existingComponentsDependencies).when(componentDependencyModelDaoMock).list(any());
     Collection<ComponentDependencyModelEntity> componentDependenciesBeforeDelete =
         orchestrationUtil.getComponentDependenciesBeforeDelete(VSP_ID, VERSION01);
-    Assert.assertEquals(componentDependenciesBeforeDelete.size(), 2);
+    assertEquals(componentDependenciesBeforeDelete.size(), 2);
   }
 
   @Test
index 17bc2a3..fdfa7d5 100644 (file)
 
 package org.openecomp.sdc.vendorsoftwareproduct.impl;
 
-import org.mockito.*;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
 import org.openecomp.sdc.common.errors.CoreException;
 import org.openecomp.sdc.common.errors.ErrorCategory;
@@ -26,10 +35,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessType;
 import org.openecomp.sdc.versioning.dao.types.Version;
 import org.openecomp.sdc.versioning.errors.VersioningErrorCodes;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -37,9 +42,13 @@ import java.nio.ByteBuffer;
 import java.util.Arrays;
 import java.util.Collection;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
 
 public class ProcessManagerImplTest {
 
@@ -60,12 +69,12 @@ public class ProcessManagerImplTest {
   @Captor
   private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
 
-  @BeforeMethod
+  @Before
   public void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
   }
 
-  @AfterMethod
+  @After
   public void tearDown() {
     processManager = null;
   }
@@ -133,7 +142,7 @@ public class ProcessManagerImplTest {
     Assert.assertEquals(process, processToCreate);
   }
 
-  @Test(expectedExceptions = CoreException.class)
+  @Test(expected = CoreException.class)
   public void testCreateWithExistingName_negative() {
     ProcessEntity process = createProcess(VSP_ID, VERSION, COMPONENT_ID, null);
     process.setName("p1 name");
@@ -153,7 +162,7 @@ public class ProcessManagerImplTest {
         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
   }
 
-  @Test(expectedExceptions = CoreException.class)
+  @Test(expected = CoreException.class)
   public void testUpdateWithExistingName_negative() {
     ProcessEntity existingProcess = createProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID);
     doReturn(existingProcess).when(processDaoMock).get(any(ProcessEntity.class));
@@ -210,7 +219,7 @@ public class ProcessManagerImplTest {
     Assert.assertEquals(actual.getArtifactName(), ARTIFACT_NAME);
   }
 
-  @Test(expectedExceptions = CoreException.class)
+  @Test(expected = CoreException.class)
   public void testDeleteNonExistingProcessId_negative() {
     processManager.deleteProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID);
   }
index 6e9d1ea..3900059 100644 (file)
 
 package org.openecomp.sdc.vendorsoftwareproduct.impl;
 
-import org.mockito.*;
+import org.apache.commons.io.IOUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
 import org.openecomp.core.enrichment.factory.EnrichmentManagerFactory;
 import org.openecomp.core.factory.impl.AbstractFactoryBase;
 import org.openecomp.core.model.dao.EnrichedServiceModelDao;
@@ -33,9 +43,21 @@ import org.openecomp.sdc.healing.api.HealingManager;
 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
 import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService;
-import org.openecomp.sdc.vendorsoftwareproduct.*;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.*;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.type.*;
+import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager;
+import org.openecomp.sdc.vendorsoftwareproduct.ManualVspToscaManager;
+import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager;
+import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
+import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
 import org.openecomp.sdc.vendorsoftwareproduct.impl.mock.EnrichmentManagerFactoryImpl;
 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator;
 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
@@ -46,10 +68,6 @@ import org.openecomp.sdc.versioning.dao.types.Version;
 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
 import org.openecomp.sdc.versioning.types.VersionInfo;
 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -57,13 +75,27 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.nio.ByteBuffer;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Optional;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyObject;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
+
 
 
 public class VendorSoftwareProductManagerImplTest {
@@ -116,16 +148,60 @@ public class VendorSoftwareProductManagerImplTest {
   @Captor
   private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
 
-  @BeforeMethod
+  @Before
   public void setUp() {
     MockitoAnnotations.initMocks(this);
   }
 
-  @AfterMethod
+  @After
   public void tearDown() {
     vendorSoftwareProductManager = null;
   }
 
+  @Test
+  public void testCreatePackageEtsi(){
+    try(InputStream metadataInput = getClass().getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta");
+        InputStream manifestInput = getClass().getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoTosca.mf")) {
+
+      FileContentHandler handler = new FileContentHandler();
+      handler.addFile(TOSCA_META_PATH_FILE_NAME, IOUtils.toByteArray(metadataInput));
+      handler.addFile(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, IOUtils.toByteArray(manifestInput));
+      ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
+      when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata );
+      VspDetails vsp =
+              createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
+                      "category", "subCategory", "123", null);
+      //want to avoid triggering populateVersionsForVlm method
+      vsp.setVlmVersion(null);
+
+      when(vspInfoDaoMock.get(any())).thenReturn(vsp);
+      when(licenseArtifactsServiceMock.createLicenseArtifacts(any(),any(), any(), any())).thenReturn(new FileContentHandler());
+      vendorSoftwareProductManager.createPackage("0", new Version());
+    } catch (IOException e) {
+      fail();
+    }
+  }
+
+  @Test(expected = IOException.class)
+  public void testCreatePackageEtsiNoManifest() throws IOException {
+    try(InputStream metadataInput = getClass().getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta"))
+    {
+      FileContentHandler handler = new FileContentHandler();
+      handler.addFile(TOSCA_META_PATH_FILE_NAME, IOUtils.toByteArray(metadataInput));
+      ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
+      when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata );
+      VspDetails vsp =
+              createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
+                      "category", "subCategory", "123", null);
+      //want to avoid triggering populateVersionsForVlm method
+      vsp.setVlmVersion(null);
+
+      when(vspInfoDaoMock.get(any())).thenReturn(vsp);
+      when(licenseArtifactsServiceMock.createLicenseArtifacts(any(),any(), any(), any())).thenReturn(new FileContentHandler());
+      vendorSoftwareProductManager.createPackage("0", new Version());
+      fail();
+    }
+  }
 
   @Test
   public void testCreate() {
@@ -145,7 +221,7 @@ public class VendorSoftwareProductManagerImplTest {
     assertVspsEquals(vsp, vspToCreate);
   }
 
-  @Test(expectedExceptions = CoreException.class)
+  @Test(expected = CoreException.class)
   public void testUpdateWithExistingName_negative() {
     VersionInfo versionInfo = new VersionInfo();
     versionInfo.setActiveVersion(VERSION01);
@@ -238,7 +314,7 @@ public class VendorSoftwareProductManagerImplTest {
 
   }
 
-  @Test(expectedExceptions = CoreException.class)
+  @Test(expected = CoreException.class)
   public void testGetNonExistingVersion_negative() {
     Version notExistversion = new Version("43, 8");
     doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
index ea2d068..c67c30c 100644 (file)
 
 package org.openecomp.sdc.vendorsoftwareproduct.services.impl;
 
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.doReturn;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
+
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
 import org.apache.commons.collections4.CollectionUtils;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -44,9 +48,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremo
 import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure;
 import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.Module;
 import org.openecomp.sdc.versioning.dao.types.Version;
-import org.testng.Assert;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
+
 
 /**
  * @author Avrahamg
@@ -58,7 +60,7 @@ public class CandidateServiceImplTest {
   @InjectMocks
   private CandidateServiceImpl candidateService;
 
-  @BeforeMethod
+  @Before
   public void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
   }
index 9aabef6..c6b4314 100644 (file)
@@ -26,6 +26,9 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 import org.apache.commons.io.FileUtils;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.MockitoAnnotations;
 import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
@@ -36,9 +39,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component;
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData;
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network;
 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
-import org.testng.Assert;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
 /**
  * @author shiria
@@ -50,7 +50,7 @@ public class CompositionDataExtractorImplTest {
   @InjectMocks
   private static CompositionDataExtractorImpl compositionDataExtractor;
 
-  @BeforeMethod
+  @Before
   public void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
   }
index 61c8f05..6b1493f 100644 (file)
@@ -16,6 +16,8 @@
 
 package org.openecomp.sdc.vendorsoftwareproduct.tree;
 
+import org.junit.Assert;
+import org.junit.Test;
 import org.openecomp.sdc.datatypes.error.ErrorLevel;
 import org.openecomp.sdc.datatypes.error.ErrorMessage;
 import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree;
@@ -23,10 +25,11 @@ import org.openecomp.sdc.heat.services.tree.HeatTreeManager;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
-import java.util.*;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 public class HeatTreeManagerTest extends TreeBaseTest {
 
index 10f0926..c213585 100644 (file)
@@ -21,9 +21,9 @@
 package org.openecomp.sdc.vendorsoftwareproduct.tree;
 
 
-import static org.mockito.Matchers.any;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
-import static org.testng.Assert.assertEquals;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -32,6 +32,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.zip.ZipOutputStream;
+
+import org.junit.Before;
+import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -52,8 +55,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremo
 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
 import org.openecomp.sdc.vendorsoftwareproduct.utils.VSPCommon;
 import org.openecomp.sdc.versioning.dao.types.Version;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
 public class UploadFileTest {
   private static final String USER1 = "vspTestUser1";
@@ -85,7 +86,7 @@ public class UploadFileTest {
   public static Version activeVersion002 = null;
 
 
-  @BeforeMethod
+  @Before
   public void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
   }
index 42b7dc3..b772c69 100644 (file)
 package org.openecomp.sdc.vendorsoftwareproduct.upload.csar;
 
 
-import static org.mockito.Matchers.any;
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -28,6 +28,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
 import java.util.function.Predicate;
+
+import org.junit.Before;
+import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -42,8 +45,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremo
 import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.ManifestCreatorNamingConventionImpl;
 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
 import org.openecomp.sdc.versioning.dao.types.Version;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
 public class UploadCSARFileTest {
 
@@ -68,7 +69,7 @@ public class UploadCSARFileTest {
   private static final String CSAR = "csar";
 
 
-  @BeforeMethod
+  @Before
   public void setUp() throws Exception {
     MockitoAnnotations.initMocks(this);
     candidateService = new CandidateServiceImpl(manifestCreator, orchestrationTemplateCandidateDao);
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/ValidNonManoTosca.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/ValidNonManoTosca.mf
new file mode 100644 (file)
index 0000000..43a3fd2
--- /dev/null
@@ -0,0 +1,7 @@
+metadata:
+    vnf_product_name: Mock
+    vnf_provider_id: ZTE
+    vnf_package_version: 1.0
+    vnf_release_data_time: 2017.01.01T10:00+03:00
+
+Source: MainServiceTemplate.yaml
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/metadata/ValidETSItosca.meta b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/metadata/ValidETSItosca.meta
new file mode 100644 (file)
index 0000000..0d74a15
--- /dev/null
@@ -0,0 +1,6 @@
+TOSCA-Meta-File-Version: 1.0
+CSAR-Version: 1.1
+Created-By: Sergey Sachkov
+Entry-Definitions: Definitions/MainServiceTemplate.yaml
+Entry-Manifest: MainServiceTemplate.mf
+Entry-Change-Log: change.log
index 7e5e203..2d4acdc 100644 (file)
 package org.openecomp.core.impl;
 
 import org.apache.commons.collections.MapUtils;
-import org.onap.sdc.tosca.datatypes.model.*;
+import org.onap.sdc.tosca.datatypes.model.ArtifactDefinition;
+import org.onap.sdc.tosca.datatypes.model.CapabilityAssignment;
+import org.onap.sdc.tosca.datatypes.model.Import;
+import org.onap.sdc.tosca.datatypes.model.NodeFilter;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
+import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
 import org.openecomp.core.converter.ServiceTemplateReaderService;
 import org.openecomp.core.converter.ToscaConverter;
 import org.openecomp.core.converter.datatypes.Constants;
@@ -36,19 +45,34 @@ import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypes
 import org.yaml.snakeyaml.error.YAMLException;
 
 import java.io.File;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
 import java.util.regex.Pattern;
 
-import static org.openecomp.core.converter.datatypes.Constants.*;
-import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.*;
+import static org.openecomp.core.converter.datatypes.Constants.ONAP_INDEX;
+import static org.openecomp.core.converter.datatypes.Constants.capabilities;
+import static org.openecomp.core.converter.datatypes.Constants.inputs;
+import static org.openecomp.core.converter.datatypes.Constants.nodeType;
+import static org.openecomp.core.converter.datatypes.Constants.definitionsDir;
+import static org.openecomp.core.converter.datatypes.Constants.globalStName;
+import static org.openecomp.core.converter.datatypes.Constants.globalSubstitution;
+import static org.openecomp.core.converter.datatypes.Constants.mainStName;
+import static org.openecomp.core.converter.datatypes.Constants.openecompHeatIndex;
+import static org.openecomp.core.converter.datatypes.Constants.outputs;
+import static org.openecomp.core.converter.datatypes.Constants.requirements;
+import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME;
+import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.HEAT_INDEX_IMPORT_FILE;
+import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.ONAP_INDEX_IMPORT_FILE;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
 
 public class ToscaConverterImpl implements ToscaConverter {
 
-    private static final String ORIGINAL = ".original";
-  public ToscaConverterImpl() {
-
-  }
-
   @Override
   public ToscaServiceModel convert(FileContentHandler fileContentHandler) {
     Map<String, byte[]> csarFiles = new HashMap<>(fileContentHandler.getFiles());
@@ -86,9 +110,9 @@ public class ToscaConverterImpl implements ToscaConverter {
     }
 
     private void handleMetadataFile(Map<String, byte[]> csarFiles) {
-        byte[] bytes = csarFiles.remove(metadataFile);
+        byte[] bytes = csarFiles.remove(TOSCA_META_PATH_FILE_NAME);
         if (bytes != null) {
-            csarFiles.put(metadataFile + ORIGINAL, bytes);
+            csarFiles.put(TOSCA_META_ORIG_PATH_FILE_NAME, bytes);
         }
     }
 
@@ -129,8 +153,8 @@ public class ToscaConverterImpl implements ToscaConverter {
         addGlobalServiceTemplates(globalServiceTemplates, serviceTemplates);
         toscaServiceModel.setEntryDefinitionServiceTemplate(mainStName);
         toscaServiceModel.setServiceTemplates(serviceTemplates);
-        externalFilesHandler.addFile(metadataFile + ORIGINAL,
-            csarFiles.get(metadataFile + ORIGINAL));
+        externalFilesHandler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME,
+            csarFiles.get(TOSCA_META_ORIG_PATH_FILE_NAME));
         toscaServiceModel.setArtifactFiles(externalFilesHandler);
 
         if(MapUtils.isNotEmpty(globalSubstitutionServiceTemplate.getNode_types())) {
@@ -437,7 +461,7 @@ public class ToscaConverterImpl implements ToscaConverter {
   }
 
   private boolean isMetadataFile(String fileName) {
-    return fileName.equals(metadataFile);
+    return fileName.equals(TOSCA_META_PATH_FILE_NAME);
   }
 
   private boolean isGlobalServiceTemplate(String fileName) {