diff options
author | 2018-09-20 10:00:37 +0300 | |
---|---|---|
committer | 2018-09-25 18:07:44 +0300 | |
commit | 2b7766dd6ecf6fc011c917a3e99cf538f8cfd6eb (patch) | |
tree | 3d44b5ef8598cbf479640f0822a0219467e9ff18 /openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main | |
parent | b8f536584bd539e232f6b22a2d80430055b59e42 (diff) |
Test coverage-Corrections
Increase test coverage
Change-Id: I8268d31486b3410fbe8791c6d8c4eed4b237462c
Issue-ID: SDC-1673
Signed-off-by: siddharth0905 <siddharth.singh4@amdocs.com>
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main')
6 files changed, 136 insertions, 127 deletions
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoFactoryImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoFactoryImpl.java index 87c0338c25..d2430a6166 100644 --- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoFactoryImpl.java +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoFactoryImpl.java @@ -1,6 +1,5 @@ package org.openecomp.sdc.itempermissions.dao.impl; - import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDao; import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDaoFactory; @@ -10,10 +9,10 @@ import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDaoFactory; */ public class ItemPermissionsDaoFactoryImpl extends ItemPermissionsDaoFactory { - private static ItemPermissionsDao INSTANCE =new ItemPermissionsDaoImpl(); + private static ItemPermissionsDao INSTANCE = new ItemPermissionsDaoImpl(); - @Override - public ItemPermissionsDao createInterface() { - return INSTANCE; - } + @Override + public ItemPermissionsDao createInterface() { + return INSTANCE; + } } diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java index 6421c283f3..c9c4198081 100644 --- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java @@ -13,75 +13,79 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.openecomp.sdc.itempermissions.dao.impl; import com.datastax.driver.core.ResultSet; import com.datastax.driver.mapping.Result; import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Query; -import org.openecomp.core.nosqldb.api.NoSqlDb; -import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; -import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDao; -import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity; import java.util.Collection; import java.util.Optional; import java.util.Set; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDao; +import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity; + /** * Created by ayalaben on 6/20/2017. */ public class ItemPermissionsDaoImpl implements ItemPermissionsDao { - private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static ItemPermissionsAccessor accessor = - noSqlDb.getMappingManager().createAccessor(ItemPermissionsAccessor.class); - - @Override - public Collection<ItemPermissionsEntity> listItemPermissions(String itemId) { - return accessor.getItemPermissions(itemId).all(); - } - - @Override - public void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds, - Set<String> removedUsersIds) { - addedUsersIds.forEach(userId -> accessor.addPermission(itemId, userId, permission)); - removedUsersIds.stream() - .filter(userId -> getUserItemPermission(itemId, userId) - .map(userPermissionOnItem -> userPermissionOnItem.equals(permission)) - .orElse(false)) - .forEach(userId -> accessor.deletePermission(itemId, userId)); - } - - @Override - public Optional<String> getUserItemPermission(String itemId, String userId) { - ResultSet result = accessor.getUserItemPermission(itemId, userId); - return result.getAvailableWithoutFetching() < 1 - ? Optional.empty() - : Optional.of(result.one().getString(0)); - } - - @Override - public void deleteItemPermissions(String itemId) { - accessor.deleteItemPermissions(itemId); - } - - - @Accessor - interface ItemPermissionsAccessor { - @Query("select * from dox.item_permissions WHERE item_id = ?") - Result<ItemPermissionsEntity> getItemPermissions(String itemId); - - @Query("select permission from dox.item_permissions WHERE item_id = ? AND user_id=?") - ResultSet getUserItemPermission(String itemId, String userId); - - @Query("delete from dox.item_permissions where item_id = ? and user_id = ?") - void deletePermission(String itemId, String userId); - - @Query("insert into dox.item_permissions (item_id,user_id,permission) values (?,?,?)") - void addPermission(String itemId, String userId, String permission); - - @Query("delete from dox.item_permissions where item_id=?") - void deleteItemPermissions(String itemId); - - } + + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static ItemPermissionsAccessor accessor = + noSqlDb.getMappingManager().createAccessor(ItemPermissionsAccessor.class); + + @Override + public Collection<ItemPermissionsEntity> listItemPermissions(String itemId) { + return accessor.getItemPermissions(itemId).all(); + } + + @Override + public void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds, + Set<String> removedUsersIds) { + addedUsersIds.forEach(userId -> accessor.addPermission(itemId, userId, permission)); + removedUsersIds.stream() + .filter(userId -> getUserItemPermission(itemId, userId) + .map(userPermissionOnItem -> userPermissionOnItem.equals(permission)) + .orElse(false)) + .forEach(userId -> accessor.deletePermission(itemId, userId)); + } + + @Override + public Optional<String> getUserItemPermission(String itemId, String userId) { + ResultSet result = accessor.getUserItemPermission(itemId, userId); + return result.getAvailableWithoutFetching() < 1 + ? Optional.empty() + : Optional.of(result.one().getString(0)); + } + + @Override + public void deleteItemPermissions(String itemId) { + accessor.deleteItemPermissions(itemId); + } + + + @Accessor + interface ItemPermissionsAccessor { + + @Query("select * from dox.item_permissions WHERE item_id = ?") + Result<ItemPermissionsEntity> getItemPermissions(String itemId); + + @Query("select permission from dox.item_permissions WHERE item_id = ? AND user_id=?") + ResultSet getUserItemPermission(String itemId, String userId); + + @Query("delete from dox.item_permissions where item_id = ? and user_id = ?") + void deletePermission(String itemId, String userId); + + @Query("insert into dox.item_permissions (item_id,user_id,permission) values (?,?,?)") + void addPermission(String itemId, String userId, String permission); + + @Query("delete from dox.item_permissions where item_id=?") + void deleteItemPermissions(String itemId); + + } } diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java index ec914b1530..d0e41d8c91 100644 --- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java @@ -13,8 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.openecomp.sdc.itempermissions.dao.impl; +import java.util.Collection; +import java.util.Optional; +import java.util.Set; + import org.openecomp.sdc.common.session.SessionContextProviderFactory; import org.openecomp.sdc.itempermissions.PermissionsRules; import org.openecomp.sdc.itempermissions.PermissionsServices; @@ -22,83 +27,79 @@ import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDao; import org.openecomp.sdc.itempermissions.dao.UserPermissionsDao; import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity; -import java.util.Collection; -import java.util.Optional; -import java.util.Set; - /** * Created by ayalaben on 6/22/2017. */ public class PermissionsServicesImpl implements PermissionsServices { - private ItemPermissionsDao itemPermissionsDao; + private ItemPermissionsDao itemPermissionsDao; - private UserPermissionsDao userPermissionsDao; + private UserPermissionsDao userPermissionsDao; - private PermissionsRules permissionsRules; + private PermissionsRules permissionsRules; - private static final String CHANGE_PERMISSIONS = "Change_Item_Permissions"; + private static final String CHANGE_PERMISSIONS = "Change_Item_Permissions"; - public PermissionsServicesImpl(PermissionsRules permissionsRules, - ItemPermissionsDao itemPermissionsDao, - UserPermissionsDao userPermissionsDao) { - this.itemPermissionsDao = itemPermissionsDao; - this.permissionsRules = permissionsRules; - this.userPermissionsDao = userPermissionsDao; - } + public PermissionsServicesImpl(PermissionsRules permissionsRules, + ItemPermissionsDao itemPermissionsDao, + UserPermissionsDao userPermissionsDao) { + this.itemPermissionsDao = itemPermissionsDao; + this.permissionsRules = permissionsRules; + this.userPermissionsDao = userPermissionsDao; + } - @Override - public Collection<ItemPermissionsEntity> listItemPermissions(String itemId) { - return itemPermissionsDao.listItemPermissions(itemId); - } + @Override + public Collection<ItemPermissionsEntity> listItemPermissions(String itemId) { + return itemPermissionsDao.listItemPermissions(itemId); + } - @Override - public Set<String> listUserPermittedItems(String userId, String permission) { - return userPermissionsDao.listUserPermittedItems(userId, permission); - } + @Override + public Set<String> listUserPermittedItems(String userId, String permission) { + return userPermissionsDao.listUserPermittedItems(userId, permission); + } - @Override - public void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds, - Set<String> removedUsersIds) { + @Override + public void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds, + Set<String> removedUsersIds) { - String currentUserId = SessionContextProviderFactory.getInstance() - .createInterface().get().getUser().getUserId(); + String currentUserId = SessionContextProviderFactory.getInstance() + .createInterface().get().getUser().getUserId(); - permissionsRules.executeAction(itemId, currentUserId, CHANGE_PERMISSIONS); + permissionsRules.executeAction(itemId, currentUserId, CHANGE_PERMISSIONS); - permissionsRules.updatePermission(itemId, currentUserId, permission, addedUsersIds, - removedUsersIds); + permissionsRules.updatePermission(itemId, currentUserId, permission, addedUsersIds, + removedUsersIds); - itemPermissionsDao.updateItemPermissions(itemId, permission, - addedUsersIds, removedUsersIds); + itemPermissionsDao.updateItemPermissions(itemId, permission, + addedUsersIds, removedUsersIds); - userPermissionsDao.updatePermissions(itemId, permission, - addedUsersIds, removedUsersIds); + userPermissionsDao.updatePermissions(itemId, permission, + addedUsersIds, removedUsersIds); - } + } - @Override - public boolean isAllowed(String itemId, String userId, String action) { - return itemPermissionsDao.getUserItemPermission(itemId, userId) - .map(permission -> permissionsRules.isAllowed(permission, action)) - .orElse(false); - } + @Override + public boolean isAllowed(String itemId, String userId, String action) { + return itemPermissionsDao.getUserItemPermission(itemId, userId) + .map(permission -> permissionsRules.isAllowed(permission, action)) + .orElse(false); + } - @Override - public void execute(String itemId, String userId, String action) { - permissionsRules.executeAction(itemId, userId, action); - } + @Override + public void execute(String itemId, String userId, String action) { + permissionsRules.executeAction(itemId, userId, action); + } - @Override - public Optional<String> getUserItemPermission(String itemId, String userId) { - return itemPermissionsDao.getUserItemPermission(itemId, userId); - } + @Override + public Optional<String> getUserItemPermission(String itemId, String userId) { + return itemPermissionsDao.getUserItemPermission(itemId, userId); + } - @Override - public void deleteItemPermissions(String itemId) { - itemPermissionsDao.deleteItemPermissions(itemId); - } + @Override + public void deleteItemPermissions(String itemId) { + itemPermissionsDao.deleteItemPermissions(itemId); + } } diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoFactoryImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoFactoryImpl.java index 86a64ddf1d..4c23743ea5 100644 --- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoFactoryImpl.java +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoFactoryImpl.java @@ -21,7 +21,7 @@ import org.openecomp.sdc.itempermissions.dao.UserPermissionsDaoFactory; public class UserPermissionsDaoFactoryImpl extends UserPermissionsDaoFactory { - private static UserPermissionsDao INSTANCE =new UserPermissionsDaoImpl(); + private static UserPermissionsDao INSTANCE = new UserPermissionsDaoImpl(); @Override public UserPermissionsDao createInterface() { diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoImpl.java index dad8f25535..8609f2f4a8 100644 --- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoImpl.java +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoImpl.java @@ -19,14 +19,15 @@ package org.openecomp.sdc.itempermissions.dao.impl; import com.datastax.driver.core.ResultSet; import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Query; -import org.openecomp.core.nosqldb.api.NoSqlDb; -import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; -import org.openecomp.sdc.itempermissions.dao.UserPermissionsDao; import java.util.Collections; import java.util.HashSet; import java.util.Set; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.itempermissions.dao.UserPermissionsDao; + public class UserPermissionsDaoImpl implements UserPermissionsDao { private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); @@ -36,23 +37,23 @@ public class UserPermissionsDaoImpl implements UserPermissionsDao { @Override public Set<String> listUserPermittedItems(String userId, String permission) { - ResultSet resultSet = accessor.getUserPermissionItems(userId,permission); - if(resultSet.isExhausted()){ + ResultSet resultSet = accessor.getUserPermissionItems(userId, permission); + if (resultSet.isExhausted()) { return new HashSet<>(); } else { - return resultSet.one().getSet(0,String.class); + return resultSet.one().getSet(0, String.class); } } @Override public void updatePermissions(String itemId, String permission, Set<String> addedUsersIds, - Set<String> removedUsersIds) { + Set<String> removedUsersIds) { Set<String> itemSet = Collections.singleton(itemId); addedUsersIds.forEach(userId -> - accessor.addItem(itemSet, userId,permission)); + accessor.addItem(itemSet, userId, permission)); removedUsersIds.forEach(userId -> - accessor.removeItem(itemSet,userId,permission)); + accessor.removeItem(itemSet, userId, permission)); } @Accessor diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java index 30472d6e80..9fe045f25d 100644 --- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java @@ -48,7 +48,11 @@ public class PermissionsFilter implements Filter { private static final String EDIT_ITEM = "Edit_Item"; public PermissionsFilter() { - this.permissionsServices = PermissionsServicesFactory.getInstance().createInterface(); + this(PermissionsServicesFactory.getInstance().createInterface()); + } + + PermissionsFilter(PermissionsServices permissionsServices) { + this.permissionsServices = permissionsServices; } @Override |