1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
package org.openecomp.sdc.vendorlicense;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.openecomp.sdc.vendorlicense.dao.*;
import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
import org.openecomp.sdc.vendorlicense.facade.impl.VendorLicenseFacadeImpl;
import org.openecomp.sdc.versioning.VersioningManager;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.HashSet;
import java.util.Set;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
/**
* Created by diveshm on 7/3/2017.
*/
public class VendorLicenseFacadeImplTest {
//JUnit Test Cases using Mockito
private static final Version VERSION01 = new Version(0, 1);
private final String FG1_NAME = "FG1 name";
@Mock
private VendorLicenseModelDao vendorLicenseModelDao;
@Mock
private LicenseAgreementDao licenseAgreementDao;
@Mock
private FeatureGroupDao featureGroupDao;
@Mock
private EntitlementPoolDao entitlementPoolDao;
@Mock
private LicenseKeyGroupDao licenseKeyGroupDao;
@Mock
private VersioningManager versioningManager;
@InjectMocks
@Spy
private VendorLicenseFacadeImpl vendorLicenseFacadeImpl;
public FeatureGroupEntity createFeatureGroup(String vlmId, Version version, String id, String name, String desc,
String partNumber, String manufacturerReferenceNumber, Set<String>
licenseKeyGroupIds, Set<String> entitlementPoolIds, Set<String>
referencingLicenseAgreements){
FeatureGroupEntity featureGroup = new FeatureGroupEntity(vlmId, version, id);
featureGroup.setVendorLicenseModelId(vlmId);
featureGroup.setVersion(version);
featureGroup.setId(id);
featureGroup.setName(name);
featureGroup.setDescription(desc);
featureGroup.setPartNumber(partNumber);
//featureGroup.setManufacturerReferenceNumber(manufacturerReferenceNumber);
featureGroup.setLicenseKeyGroupIds(licenseKeyGroupIds);
featureGroup.setEntitlementPoolIds(entitlementPoolIds);
featureGroup.setReferencingLicenseAgreements(referencingLicenseAgreements);
return featureGroup;
}
@BeforeMethod
public void setUp() throws Exception{
MockitoAnnotations.initMocks(this);
}
@Test
public void testCreate(){
Set<String> licenseKeyGroupIds;
licenseKeyGroupIds = new HashSet<>();
licenseKeyGroupIds.add("lkg1");
Set<String> entitlementPoolIds;
entitlementPoolIds = new HashSet<>();
entitlementPoolIds.add("ep1");
Set<String> referencingLicenseAgreements;
referencingLicenseAgreements = new HashSet<>();
referencingLicenseAgreements.add("la1");
FeatureGroupEntity featureGroupEntity = createFeatureGroup("vlmId", VERSION01, "fgId", FG1_NAME, "fg1 desc",
"partNumber", "MRN", licenseKeyGroupIds, entitlementPoolIds,
referencingLicenseAgreements);
doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject());
/*if(featureGroupEntity.getManufacturerReferenceNumber() != null)
featureGroupDao.create(featureGroupEntity);
verify(featureGroupDao).create(anyObject());*/
}
@Test
public void testCreateWithoutManufacturerReferenceNumber(){
Set<String> licenseKeyGroupIds;
licenseKeyGroupIds = new HashSet<>();
licenseKeyGroupIds.add("lkg1");
Set<String> entitlementPoolIds;
entitlementPoolIds = new HashSet<>();
entitlementPoolIds.add("ep1");
Set<String> referencingLicenseAgreements;
referencingLicenseAgreements = new HashSet<>();
referencingLicenseAgreements.add("la1");
FeatureGroupEntity featureGroupEntity = createFeatureGroup("vlmId", VERSION01, "fgId", FG1_NAME, "fg1 desc",
"partNumber", null, licenseKeyGroupIds, entitlementPoolIds,
referencingLicenseAgreements);
doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject());
/*if(featureGroupEntity.getManufacturerReferenceNumber() != null)
featureGroupDao.create(featureGroupEntity);
verify(featureGroupDao, never()).create(anyObject());*/
}
}
|