From 193fc178482e684c2838b070f7ad8e73c159b071 Mon Sep 17 00:00:00 2001 From: Tal Gitelman Date: Wed, 16 May 2018 19:27:27 +0300 Subject: new unit tests for sdc-be Change-Id: I0e2ee2950898668b9ce1e3ef5acf85c1b68cf5d8 Issue-ID: SDC-1333 Signed-off-by: Tal Gitelman --- .../be/components/validation/UserValidations.java | 167 ++++++++++----------- .../ecomp/converters/AssetMetadataConverter.java | 2 +- 2 files changed, 80 insertions(+), 89 deletions(-) (limited to 'catalog-be/src/main/java/org') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java index a0c8d9fcf7..ba96a9ef41 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java @@ -19,93 +19,84 @@ import fj.data.Either; @org.springframework.stereotype.Component public class UserValidations { - private static final Logger log = LoggerFactory.getLogger(UserValidations.class); - private final IUserBusinessLogic userAdmin; - private final ComponentsUtils componentsUtils; - - public UserValidations(IUserBusinessLogic userAdmin, ComponentsUtils componentsUtils) { - this.userAdmin = userAdmin; - this.componentsUtils = componentsUtils; - } - - public Either validateUserExists(String userId, String ecompErrorContext, boolean inTransaction) { - Either eitherCreator = userAdmin.getUser(userId, inTransaction); - if (eitherCreator.isRight() || eitherCreator.left().value() == null) { - ResponseFormat responseFormat; - if (eitherCreator.right().value().equals(ActionStatus.USER_NOT_FOUND)) { - if (log.isDebugEnabled()) { - log.debug("validateUserExists - not authorized user, userId {}", userId); - } - responseFormat = componentsUtils.getResponseFormat(ActionStatus.AUTH_FAILED); - } else { - if (log.isDebugEnabled()) { - log.debug("validateUserExists - failed to authorize user, userId {}", userId); - } - responseFormat = componentsUtils.getResponseFormat(eitherCreator.right().value()); - } - if (log.isDebugEnabled()) { - log.debug("User is not listed. userId {}", userId); - } - BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, userId); - return Either.right(responseFormat); - } - return Either.left(eitherCreator.left().value()); - } - - public Either validateUserRole(User user, List roles) { - Role userRole = Role.valueOf(user.getRole()); - if (roles != null) { - if (!roles.contains(userRole)) { - if (log.isDebugEnabled()) { - log.debug("user is not in appropriate role to perform action"); - } - ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION); - return Either.right(responseFormat); - } - return Either.left(Boolean.TRUE); - } - return Either.left(Boolean.FALSE); - } - - public Either validateUserExistsActionStatus(String userId, String ecompErrorContext) { - Either eitherCreator = userAdmin.getUser(userId, false); - if (eitherCreator.isRight() || eitherCreator.left().value() == null) { - if (eitherCreator.right().value().equals(ActionStatus.USER_NOT_FOUND)) { - log.debug("validateUserExists - not authorized user, userId {}", userId); - Either.right(ActionStatus.RESTRICTED_OPERATION); - } else { - log.debug("validateUserExists - failed to authorize user, userId {}", userId); - } - log.debug("User is not listed. userId {}", userId); - BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, userId); - return Either.right(eitherCreator.right().value()); - } - return Either.left(eitherCreator.left().value()); - } - - public Either validateUserNotEmpty(User user, String ecompErrorContext) { - String userId = user.getUserId(); - - if (StringUtils.isEmpty(userId)) { - log.debug("User header is missing "); - BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, user.getUserId()); - ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION); - return Either.right(responseFormat); - } - return Either.left(user); - } - - public Either validateUserExists(User user, String ecompErrorContext, boolean inTransaction) { - return validateUserExists(user.getUserId(), ecompErrorContext, inTransaction); - } - - public void validateUserExist(String userId, String ecompErrorContext, Wrapper errorWrapper) { - Either resp = validateUserExists(userId, ecompErrorContext, false); - if (resp.isRight()) { - errorWrapper.setInnerElement(resp.right().value()); - } - } - - + private static final Logger log = LoggerFactory.getLogger(UserValidations.class); + private final IUserBusinessLogic userAdmin; + private final ComponentsUtils componentsUtils; + + public UserValidations(IUserBusinessLogic userAdmin, ComponentsUtils componentsUtils) { + this.userAdmin = userAdmin; + this.componentsUtils = componentsUtils; + } + + public Either validateUserExists(String userId, String ecompErrorContext, + boolean inTransaction) { + Either eitherCreator = userAdmin.getUser(userId, inTransaction); + if (eitherCreator.isRight() || eitherCreator.left().value() == null) { + ResponseFormat responseFormat; + if (eitherCreator.right().value().equals(ActionStatus.USER_NOT_FOUND)) { + log.debug("validateUserExists - not authorized user, userId {}", userId); + responseFormat = componentsUtils.getResponseFormat(ActionStatus.AUTH_FAILED); + } else { + log.debug("validateUserExists - failed to authorize user, userId {}", userId); + responseFormat = componentsUtils.getResponseFormat(eitherCreator.right().value()); + } + log.debug("User is not listed. userId {}", userId); + BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, userId); + return Either.right(responseFormat); + } + return Either.left(eitherCreator.left().value()); + } + + public Either validateUserRole(User user, List roles) { + Role userRole = Role.valueOf(user.getRole()); + if (roles != null) { + if (!roles.contains(userRole)) { + log.debug("user is not in appropriate role to perform action"); + ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION); + return Either.right(responseFormat); + } + return Either.left(Boolean.TRUE); + } + return Either.left(Boolean.FALSE); + } + + public Either validateUserExistsActionStatus(String userId, String ecompErrorContext) { + Either eitherCreator = userAdmin.getUser(userId, false); + if (eitherCreator.isRight() || eitherCreator.left().value() == null) { + if (eitherCreator.right().value().equals(ActionStatus.USER_NOT_FOUND)) { + log.debug("validateUserExists - not authorized user, userId {}", userId); + Either.right(ActionStatus.RESTRICTED_OPERATION); + } else { + log.debug("validateUserExists - failed to authorize user, userId {}", userId); + } + log.debug("User is not listed. userId {}", userId); + BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, userId); + return Either.right(eitherCreator.right().value()); + } + return Either.left(eitherCreator.left().value()); + } + + public Either validateUserNotEmpty(User user, String ecompErrorContext) { + String userId = user.getUserId(); + + if (StringUtils.isEmpty(userId)) { + log.debug("User header is missing "); + BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, user.getUserId()); + ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION); + return Either.right(responseFormat); + } + return Either.left(user); + } + + public Either validateUserExists(User user, String ecompErrorContext, boolean inTransaction) { + return validateUserExists(user.getUserId(), ecompErrorContext, inTransaction); + } + + public void validateUserExist(String userId, String ecompErrorContext, Wrapper errorWrapper) { + Either resp = validateUserExists(userId, ecompErrorContext, false); + if (resp.isRight()) { + errorWrapper.setInnerElement(resp.right().value()); + } + } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverter.java index eb227a5d06..5d27723c09 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverter.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverter.java @@ -316,7 +316,7 @@ public class AssetMetadataConverter { } metadata.setArtifactDescription(artifact.getDescription()); - metadata.setArtifactTimeout(artifact.getTimeout() > 0 ? artifact.getTimeout() : null); + metadata.setArtifactTimeout(artifact.getTimeout() != null && artifact.getTimeout() > 0 ? artifact.getTimeout() : null); metadata.setArtifactChecksum(artifact.getArtifactChecksum()); metadata.setArtifactUUID(artifact.getArtifactUUID()); metadata.setArtifactVersion(artifact.getArtifactVersion()); -- cgit 1.2.3-korg