1 package org.openecomp.sdc.vendorlicense;
3 import org.mockito.InjectMocks;
4 import org.mockito.Mock;
5 import org.mockito.MockitoAnnotations;
6 import org.mockito.Spy;
7 import org.openecomp.sdc.vendorlicense.dao.*;
8 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
9 import org.openecomp.sdc.vendorlicense.facade.impl.VendorLicenseFacadeImpl;
10 import org.openecomp.sdc.versioning.VersioningManager;
11 import org.openecomp.sdc.versioning.dao.types.Version;
12 import org.testng.annotations.BeforeMethod;
13 import org.testng.annotations.Test;
15 import java.util.HashSet;
18 import static org.mockito.Matchers.anyObject;
19 import static org.mockito.Mockito.doReturn;
20 import static org.mockito.Mockito.never;
21 import static org.mockito.Mockito.verify;
24 * Created by diveshm on 7/3/2017.
26 public class VendorLicenseFacadeImplTest {
27 //JUnit Test Cases using Mockito
28 private static final Version VERSION01 = new Version(0, 1);
29 private final String FG1_NAME = "FG1 name";
32 private VendorLicenseModelDao vendorLicenseModelDao;
35 private LicenseAgreementDao licenseAgreementDao;
38 private FeatureGroupDao featureGroupDao;
41 private EntitlementPoolDao entitlementPoolDao;
44 private LicenseKeyGroupDao licenseKeyGroupDao;
47 private VersioningManager versioningManager;
51 private VendorLicenseFacadeImpl vendorLicenseFacadeImpl;
53 public FeatureGroupEntity createFeatureGroup(String vlmId, Version version, String id, String name, String desc,
54 String partNumber, String manufacturerReferenceNumber, Set<String>
55 licenseKeyGroupIds, Set<String> entitlementPoolIds, Set<String>
56 referencingLicenseAgreements){
57 FeatureGroupEntity featureGroup = new FeatureGroupEntity(vlmId, version, id);
58 featureGroup.setVendorLicenseModelId(vlmId);
59 featureGroup.setVersion(version);
60 featureGroup.setId(id);
61 featureGroup.setName(name);
62 featureGroup.setDescription(desc);
63 featureGroup.setPartNumber(partNumber);
64 //featureGroup.setManufacturerReferenceNumber(manufacturerReferenceNumber);
65 featureGroup.setLicenseKeyGroupIds(licenseKeyGroupIds);
66 featureGroup.setEntitlementPoolIds(entitlementPoolIds);
67 featureGroup.setReferencingLicenseAgreements(referencingLicenseAgreements);
73 public void setUp() throws Exception{
74 MockitoAnnotations.initMocks(this);
78 public void testCreate(){
79 Set<String> licenseKeyGroupIds;
80 licenseKeyGroupIds = new HashSet<>();
81 licenseKeyGroupIds.add("lkg1");
83 Set<String> entitlementPoolIds;
84 entitlementPoolIds = new HashSet<>();
85 entitlementPoolIds.add("ep1");
87 Set<String> referencingLicenseAgreements;
88 referencingLicenseAgreements = new HashSet<>();
89 referencingLicenseAgreements.add("la1");
91 FeatureGroupEntity featureGroupEntity = createFeatureGroup("vlmId", VERSION01, "fgId", FG1_NAME, "fg1 desc",
92 "partNumber", "MRN", licenseKeyGroupIds, entitlementPoolIds,
93 referencingLicenseAgreements);
95 doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject());
97 /*if(featureGroupEntity.getManufacturerReferenceNumber() != null)
98 featureGroupDao.create(featureGroupEntity);
99 verify(featureGroupDao).create(anyObject());*/
103 public void testCreateWithoutManufacturerReferenceNumber(){
104 Set<String> licenseKeyGroupIds;
105 licenseKeyGroupIds = new HashSet<>();
106 licenseKeyGroupIds.add("lkg1");
108 Set<String> entitlementPoolIds;
109 entitlementPoolIds = new HashSet<>();
110 entitlementPoolIds.add("ep1");
112 Set<String> referencingLicenseAgreements;
113 referencingLicenseAgreements = new HashSet<>();
114 referencingLicenseAgreements.add("la1");
116 FeatureGroupEntity featureGroupEntity = createFeatureGroup("vlmId", VERSION01, "fgId", FG1_NAME, "fg1 desc",
117 "partNumber", null, licenseKeyGroupIds, entitlementPoolIds,
118 referencingLicenseAgreements);
119 doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject());
121 /*if(featureGroupEntity.getManufacturerReferenceNumber() != null)
122 featureGroupDao.create(featureGroupEntity);
124 verify(featureGroupDao, never()).create(anyObject());*/