summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-license-manager
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-license-manager')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseModelTest.java103
1 files changed, 102 insertions, 1 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseModelTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseModelTest.java
index 89b555c449..30c1c03322 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseModelTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseModelTest.java
@@ -21,20 +21,28 @@
package org.openecomp.sdc.vendorlicense.impl;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.*;
import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
+import org.openecomp.sdc.datatypes.model.ItemType;
import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
import org.openecomp.sdc.vendorlicense.dao.*;
import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
import org.openecomp.sdc.versioning.VersioningManager;
import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.types.Item;
+import org.openecomp.sdc.versioning.types.ItemStatus;
+import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.HashSet;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
-
+import static org.hamcrest.MatcherAssert.assertThat;
/**
* Created by ayalaben on 7/19/2017
@@ -53,6 +61,10 @@ public class VendorLicenseModelTest {
public static final Version VERSION01 = new Version(0, 1);
private static final Version VERSION10 = new Version(1, 0);
+ private static final boolean MULTITENANCY_ENABLED = true;
+
+ private static final String TEST_TENANT = "test_tenant";
+
@Mock
private VersioningManager versioningManagerMcok;
@Mock
@@ -154,4 +166,93 @@ public class VendorLicenseModelTest {
// vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion);
// }
+
+ @Test
+ public void testCreate_withMultitenancyValidTenant_Success() {
+ Assert.assertEquals(MULTITENANCY_ENABLED,true);
+ VendorLicenseModelEntity vlmEntity = new VendorLicenseModelEntity();
+ vlmEntity.setId(vlm1_id);
+ vlmEntity.setVersion(VERSION01);
+ vlmEntity.setTenant(TEST_TENANT);
+ assertThat("Unauthorized Tenant", getTestRoles().contains(vlmEntity.getTenant()));
+ vendorLicenseManager.createVendorLicenseModel(vlmEntity);
+ verify(vendorLicenseModelDaoMcok).create(vlmEntity);
+ }
+
+ @Test
+ public void testCreate_withMultitenancyInvalidTenant_Failure() {
+ String invalidTenant="invalid_tenant";
+ Assert.assertEquals(MULTITENANCY_ENABLED,true);
+ VendorLicenseModelEntity vlmEntity = new VendorLicenseModelEntity();
+ vlmEntity.setId(vlm1_id);
+ vlmEntity.setVersion(VERSION01);
+ vlmEntity.setTenant(invalidTenant);
+ Assert.assertFalse(getTestRoles().contains(invalidTenant));
+ Assert.assertNotNull(vlmEntity.getTenant());
+ vendorLicenseManager.createVendorLicenseModel(vlmEntity);
+ assertThat("Unauthorized Tenant", !getTestRoles().contains(vlmEntity.getTenant()));
+ }
+
+ @Test
+ public void testListVLM_multitenancyWithTenant_FilterList() {
+ Assert.assertEquals(MULTITENANCY_ENABLED,true);
+ Assert.assertNotNull(getTestRoles());
+ assertThat("Unauthorized Tenant", getTestRoles().contains(TEST_TENANT));
+ String tenant = TEST_TENANT;
+ Assert.assertNotNull(tenant);
+ List<Item> expectedItems=new ArrayList<>();
+ getTestRoles().stream().forEach(role -> getLicenseModelItems().stream()
+ .filter(item -> item.getTenant().contains(role))
+ .forEach(item -> expectedItems.add(item)));
+ Assert.assertEquals(expectedItems.size(), 1);
+ }
+
+ @Test
+ public void testListVLM_multitenancyWithInvalidTenant_ReturnEmptylist() {
+ Assert.assertEquals(MULTITENANCY_ENABLED,true);
+ Assert.assertNotNull(getTestRoles());
+ String tenant= "invalid_tenant";
+ List<Item> expectedItems=new ArrayList<>();
+ List<Item> actualItems=getLicenseModelItems();
+ Assert.assertNotNull(tenant);
+ getTestRoles().stream().forEach(role -> getLicenseModelItems().stream()
+ .filter(item -> item.getTenant()!=null)
+ .filter(item -> item.getTenant().contains(tenant))
+ .forEach(item -> expectedItems.add(item)));
+
+ Assert.assertEquals(expectedItems.size(), 0);
+ Assert.assertNotEquals(expectedItems.containsAll(actualItems), actualItems.containsAll(expectedItems));
+ }
+
+ private Set<String> getTestRoles(){
+ Set<String> roles = new HashSet<>();
+ roles.add("test_admin");
+ roles.add("test_tenant");
+ return roles;
+ }
+
+ private List<Item> getLicenseModelItems(){
+ List<Item> items=new ArrayList<>();
+
+ Item itemOne = new Item();
+ itemOne.setType(ItemType.vlm.name());
+ itemOne.setOwner(USER1);
+ itemOne.setStatus(ItemStatus.ACTIVE);
+ itemOne.setName("TEST_VENDOR_ONE");
+ itemOne.setDescription("TEST_DESCRIPTION");
+ itemOne.setTenant(TEST_TENANT);
+
+ Item itemTwo = new Item();
+ itemTwo.setType(ItemType.vlm.name());
+ itemTwo.setOwner(USER1);
+ itemTwo.setStatus(ItemStatus.ACTIVE);
+ itemTwo.setName("TEST_VENDOR_TWO");
+ itemTwo.setDescription("TEST_DESCRIPTION");
+ itemTwo.setTenant("admin_tenant");
+
+ items.add(itemOne);
+ items.add(itemTwo);
+ return items;
+ }
+
}