summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseFacadeImplTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseFacadeImplTest.java')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseFacadeImplTest.java144
1 files changed, 90 insertions, 54 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseFacadeImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseFacadeImplTest.java
index 58db488d86..40bbc77faa 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseFacadeImplTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseFacadeImplTest.java
@@ -1,18 +1,27 @@
package org.openecomp.sdc.vendorlicense;
+import org.junit.Assert;
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.EntitlementPoolEntity;
import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
import org.openecomp.sdc.vendorlicense.facade.impl.VendorLicenseFacadeImpl;
+import org.openecomp.sdc.vendorlicense.impl.VendorLicenseManagerImpl;
import org.openecomp.sdc.versioning.VersioningManager;
import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.types.VersionInfo;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import static org.mockito.Matchers.anyObject;
@@ -21,12 +30,16 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
/**
- * Created by diveshm on 7/3/2017.
+ * This test just verifies Feature Group Get and List APIs.
*/
public class VendorLicenseFacadeImplTest {
//JUnit Test Cases using Mockito
private static final Version VERSION01 = new Version(0, 1);
- private final String FG1_NAME = "FG1 name";
+ public static final String EP1 = "ep1";
+ public static final String MRN = "mrn";
+ public static final String VLM_ID = "VLM_ID";
+ public static final String USER = "USER1";
+
@Mock
private VendorLicenseModelDao vendorLicenseModelDao;
@@ -50,78 +63,101 @@ public class VendorLicenseFacadeImplTest {
@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");
+ public void testGetFeatureGroupWhenMRNNull () {
+ resetFieldModifiers();
+
+ FeatureGroupEntity featureGroup = createFeatureGroup();
+
+ VersionInfo info = new VersionInfo();
+ info.getViewableVersions().add(VERSION01);
+ info.setActiveVersion(VERSION01);
Set<String> entitlementPoolIds;
entitlementPoolIds = new HashSet<>();
- entitlementPoolIds.add("ep1");
-
- Set<String> referencingLicenseAgreements;
- referencingLicenseAgreements = new HashSet<>();
- referencingLicenseAgreements.add("la1");
+ entitlementPoolIds.add(EP1);
- FeatureGroupEntity featureGroupEntity = createFeatureGroup("vlmId", VERSION01, "fgId", FG1_NAME, "fg1 desc",
- "partNumber", "MRN", licenseKeyGroupIds, entitlementPoolIds,
- referencingLicenseAgreements);
+ EntitlementPoolEntity ep = createEP();
- doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject());
+ featureGroup.setEntitlementPoolIds(entitlementPoolIds);
- /*if(featureGroupEntity.getManufacturerReferenceNumber() != null)
- featureGroupDao.create(featureGroupEntity);
- verify(featureGroupDao).create(anyObject());*/
+ doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject());
+ doReturn(featureGroup).when(featureGroupDao).get(featureGroup);
+ doReturn(ep).when(entitlementPoolDao).get(anyObject());
+ doReturn(MRN).when(entitlementPoolDao).getManufacturerReferenceNumber(anyObject());
+ FeatureGroupEntity retrieved = vendorLicenseFacadeImpl.getFeatureGroup(featureGroup, USER);
+ Assert.assertEquals(MRN, retrieved.getManufacturerReferenceNumber());
}
@Test
- public void testCreateWithoutManufacturerReferenceNumber(){
- Set<String> licenseKeyGroupIds;
- licenseKeyGroupIds = new HashSet<>();
- licenseKeyGroupIds.add("lkg1");
+ public void testListFeatureGroups () {
+ resetFieldModifiers();
- Set<String> entitlementPoolIds;
- entitlementPoolIds = new HashSet<>();
- entitlementPoolIds.add("ep1");
+ FeatureGroupEntity featureGroup = createFeatureGroup();
- Set<String> referencingLicenseAgreements;
- referencingLicenseAgreements = new HashSet<>();
- referencingLicenseAgreements.add("la1");
+ Collection<FeatureGroupEntity> featureGroups = new ArrayList<FeatureGroupEntity>();
+ featureGroups.add(featureGroup);
- FeatureGroupEntity featureGroupEntity = createFeatureGroup("vlmId", VERSION01, "fgId", FG1_NAME, "fg1 desc",
- "partNumber", null, licenseKeyGroupIds, entitlementPoolIds,
- referencingLicenseAgreements);
- doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject());
+ VersionInfo info = new VersionInfo();
+ info.getViewableVersions().add(VERSION01);
+ info.setActiveVersion(VERSION01);
- /*if(featureGroupEntity.getManufacturerReferenceNumber() != null)
- featureGroupDao.create(featureGroupEntity);
+ EntitlementPoolEntity ep = createEP();
- verify(featureGroupDao, never()).create(anyObject());*/
+ doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject());
+ doReturn(featureGroup).when(featureGroupDao).get(featureGroup);
+ doReturn(ep).when(entitlementPoolDao).get(anyObject());
+ doReturn(MRN).when(entitlementPoolDao).getManufacturerReferenceNumber(anyObject());
+ Collection<FeatureGroupEntity> retrieved = vendorLicenseFacadeImpl.listFeatureGroups(VLM_ID,
+ VERSION01, USER);
+ retrieved.stream().forEach(fg -> Assert.assertEquals(MRN,fg.getManufacturerReferenceNumber()));
+ }
+
+ private void resetFieldModifiers() {
+ try {
+ Field fgField = VendorLicenseFacadeImpl.class.getDeclaredField("featureGroupDao");
+ fgField.setAccessible(true);
+ Field modifiersField = Field.class.getDeclaredField("modifiers");
+ modifiersField.setAccessible(true);
+ modifiersField.setInt(fgField, fgField.getModifiers() & ~Modifier.FINAL);
+ fgField.set(null, featureGroupDao);
+
+ Field epField = VendorLicenseFacadeImpl.class.getDeclaredField("entitlementPoolDao");
+ epField.setAccessible(true);
+ modifiersField = Field.class.getDeclaredField("modifiers");
+ modifiersField.setAccessible(true);
+ modifiersField.setInt(epField, epField.getModifiers() & ~Modifier.FINAL);
+ epField.set(null, entitlementPoolDao);
+ } catch(NoSuchFieldException | IllegalAccessException e)
+ {
+ org.testng.Assert.fail();
+ }
+ }
+
+ private FeatureGroupEntity createFeatureGroup() {
+ FeatureGroupEntity featureGroup = new FeatureGroupEntity(VLM_ID, VERSION01, USER);
+ featureGroup.setManufacturerReferenceNumber(null);
+ VersionInfo info = new VersionInfo();
+ info.getViewableVersions().add(VERSION01);
+ info.setActiveVersion(VERSION01);
+
+ Set<String> entitlementPoolIds;
+ entitlementPoolIds = new HashSet<>();
+ entitlementPoolIds.add(EP1);
+
+ featureGroup.setEntitlementPoolIds(entitlementPoolIds);
+ return featureGroup;
+ }
+ private EntitlementPoolEntity createEP() {
+ EntitlementPoolEntity ep = new EntitlementPoolEntity(VLM_ID,VERSION01, EP1);
+ ep.setManufacturerReferenceNumber(MRN);
+ return ep;
}
+
}