From 15d1f8344d4584aa71d3fc58e6add3ad08bf71e1 Mon Sep 17 00:00:00 2001 From: nitram509 Date: Fri, 9 Oct 2020 21:48:27 +0200 Subject: [PATCH 1/4] throw RuntimeException instead of log.error() to make test fail --- .../library/mgt/FunctionLibraryManagementServiceTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/test/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceTest.java b/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/test/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceTest.java index abef076c5288..8cdc33f18f50 100644 --- a/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/test/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceTest.java +++ b/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/test/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceTest.java @@ -120,7 +120,7 @@ public void createFunctionLibrary(Object functionLibrary, String tenantDomain) { functionLibraryManagementService.deleteFunctionLibrary( ((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain); } catch (Exception e) { - log.error("Error test Create script library " + e); + throw new RuntimeException("Error test Create script library ", e); } } @@ -404,7 +404,7 @@ public void testIsRegexValidated(Object functionLibrary, String tenantDomain) { assertEquals(e.getMessage(), "The script library name is not valid! It is not adhering to the regex " + FunctionLibraryMgtUtil.FUNCTION_LIBRARY_NAME_VALIDATING_REGEX + "."); } catch (Exception e) { - log.error("Exception" + e); + throw new RuntimeException(e); } } @@ -452,7 +452,7 @@ public void testAlreadyExistFunctionLibrary(Object functionLibrary, String tenan assertEquals(e.getMessage(), "Already a script library available with the name: " + ((FunctionLibrary) functionLibrary).getFunctionLibraryName() + "."); } catch (Exception e) { - log.error("Exception" + e); + throw new RuntimeException(e); } } @@ -486,7 +486,7 @@ public void testFunctionLibraryNameRequired(Object functionLibrary, String tenan } catch (FunctionLibraryManagementException e) { assertEquals(e.getMessage(), "Script library name is required"); } catch (Exception e) { - log.error("Exception" + e); + throw new RuntimeException(e); } } From c4ece01ed84b5fda081bf6a5cf2715f0513e30e3 Mon Sep 17 00:00:00 2001 From: nitram509 Date: Fri, 9 Oct 2020 21:53:35 +0200 Subject: [PATCH 2/4] add exception parameter to the log...() method calls replace string concatenation with throwable parameter see https://github.com/wso2/carbon-identity-framework/issues/1974 --- .../common/model/IdentityProvider.java | 2 +- .../framework/util/FrameworkUtils.java | 2 +- .../ThriftAuthenticationServiceComponent.java | 32 +++++++++---------- .../identity/entitlement/EntitlementUtil.java | 2 +- .../pip/CarbonAttributeFinder.java | 8 ++--- ...FunctionLibraryManagementAdminService.java | 2 +- .../FunctionLibraryManagementServiceImpl.java | 2 +- .../identity/base/IdentityException.java | 6 ++-- .../base/IdentityRuntimeException.java | 8 ++--- .../identity/core/util/IdentityUtil.java | 8 ++--- .../mgt/store/ArtifactDeleteThread.java | 4 +-- .../mgt/WorkflowManagementAdminService.java | 2 +- .../AbstractWorkflowRequestHandler.java | 2 +- .../mgt/template/AbstractTemplate.java | 2 +- .../mgt/util/WorkflowManagementUtil.java | 2 +- .../mgt/workflow/AbstractWorkflow.java | 10 +++--- 16 files changed, 47 insertions(+), 47 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/IdentityProvider.java b/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/IdentityProvider.java index 920065eef7b2..7dcae80848ea 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/IdentityProvider.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/IdentityProvider.java @@ -252,7 +252,7 @@ public static IdentityProvider build(OMElement identityProviderOM) { } catch (IdentityApplicationManagementException e) { log.error("Error while building provisioningConnectorConfig for IDP " + identityProvider .getIdentityProviderName() + ". Cause : " + e.getMessage() + ". Building rest of the " + - "IDP configs"); + "IDP configs", e); } if (proConConfig != null) { provisioningConnectorConfigsArrList.add(proConConfig); diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java index b839c0a4706a..8400d46a3f44 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java @@ -1865,7 +1865,7 @@ public static String getMultiAttributeSeparator() { } catch (UserStoreException e) { log.warn("Error while retrieving MultiAttributeSeparator from UserRealm."); if (log.isDebugEnabled()) { - log.debug("Error while retrieving MultiAttributeSeparator from UserRealm." + e); + log.debug("Error while retrieving MultiAttributeSeparator from UserRealm.", e); } } diff --git a/components/carbon-authenticators/thrift-authenticator/org.wso2.carbon.identity.authenticator.thrift/src/main/java/org/wso2/carbon/identity/thrift/authentication/internal/ThriftAuthenticationServiceComponent.java b/components/carbon-authenticators/thrift-authenticator/org.wso2.carbon.identity.authenticator.thrift/src/main/java/org/wso2/carbon/identity/thrift/authentication/internal/ThriftAuthenticationServiceComponent.java index a7062f709b4c..9d3165cc94d4 100644 --- a/components/carbon-authenticators/thrift-authenticator/org.wso2.carbon.identity.authenticator.thrift/src/main/java/org/wso2/carbon/identity/thrift/authentication/internal/ThriftAuthenticationServiceComponent.java +++ b/components/carbon-authenticators/thrift-authenticator/org.wso2.carbon.identity.authenticator.thrift/src/main/java/org/wso2/carbon/identity/thrift/authentication/internal/ThriftAuthenticationServiceComponent.java @@ -50,7 +50,7 @@ import org.osgi.service.component.annotations.ReferencePolicy; @Component( - name = "org.wso2.carbon.identity.thrift.authentication.internal.ThriftAuthenticationServiceComponent", + name = "org.wso2.carbon.identity.thrift.authentication.internal.ThriftAuthenticationServiceComponent", immediate = true) public class ThriftAuthenticationServiceComponent { @@ -130,10 +130,10 @@ public static void setRealmServiceInstance(RealmService realmServiceInstance) { } @Reference( - name = "http.service", - service = org.osgi.service.http.HttpService.class, - cardinality = ReferenceCardinality.MANDATORY, - policy = ReferencePolicy.DYNAMIC, + name = "http.service", + service = org.osgi.service.http.HttpService.class, + cardinality = ReferenceCardinality.MANDATORY, + policy = ReferencePolicy.DYNAMIC, unbind = "unsetHttpService") protected void setHttpService(HttpService httpService) { setHttpServiceInstance(httpService); @@ -144,10 +144,10 @@ protected void unsetHttpService(HttpService httpService) { } @Reference( - name = "org.wso2.carbon.user.core", - service = org.wso2.carbon.user.core.service.RealmService.class, - cardinality = ReferenceCardinality.MANDATORY, - policy = ReferencePolicy.DYNAMIC, + name = "org.wso2.carbon.user.core", + service = org.wso2.carbon.user.core.service.RealmService.class, + cardinality = ReferenceCardinality.MANDATORY, + policy = ReferencePolicy.DYNAMIC, unbind = "unsetRealmService") protected void setRealmService(RealmService realmService) { setRealmServiceInstance(realmService); @@ -158,10 +158,10 @@ protected void unsetRealmService(RealmService realmService) { } @Reference( - name = "configuration.context", - service = org.wso2.carbon.utils.ConfigurationContextService.class, - cardinality = ReferenceCardinality.MANDATORY, - policy = ReferencePolicy.DYNAMIC, + name = "configuration.context", + service = org.wso2.carbon.utils.ConfigurationContextService.class, + cardinality = ReferenceCardinality.MANDATORY, + policy = ReferencePolicy.DYNAMIC, unbind = "unsetConfigurationContext") protected void setConfigurationContext(ConfigurationContextService configurationContext) { this.configurationContext = configurationContext; @@ -184,9 +184,9 @@ private void startThriftHttpAuthenticatorService(ThriftAuthenticatorService thri TCompactProtocol.Factory outProtFactory = new TCompactProtocol.Factory(); getHttpServiceInstance().registerServlet("/thriftAuthenticator", new AuthenticatorServlet(authServiceProcessor, inProtFactory, outProtFactory), new Hashtable(), getHttpServiceInstance().createDefaultHttpContext()); } catch (ServletException e) { - log.error("Unable to start Thrift Authenticator Service." + e); + log.error("Unable to start Thrift Authenticator Service.", e); } catch (NamespaceException e) { - log.error("Unable to start Thrift Authenticator Service" + e); + log.error("Unable to start Thrift Authenticator Service", e); } } @@ -237,7 +237,7 @@ private void startThriftTcpAuthenticatorService(ThriftAuthenticatorService thrif clientTimeout = Integer.parseInt(clientTimeoutElement.getText()); } catch (Throwable e) { String msg = "Error, in Thrift Auth Client Timeout, hence using the default timeout: " + ThriftAuthenticationConstants.DEFAULT_CLIENT_TIMEOUT + "ms"; - log.error(msg + e); + log.error(msg, e); clientTimeout = ThriftAuthenticationConstants.DEFAULT_CLIENT_TIMEOUT; } } else { diff --git a/components/entitlement/org.wso2.carbon.identity.entitlement/src/main/java/org/wso2/carbon/identity/entitlement/EntitlementUtil.java b/components/entitlement/org.wso2.carbon.identity.entitlement/src/main/java/org/wso2/carbon/identity/entitlement/EntitlementUtil.java index a2b3dac7184b..d46393367e22 100644 --- a/components/entitlement/org.wso2.carbon.identity.entitlement/src/main/java/org/wso2/carbon/identity/entitlement/EntitlementUtil.java +++ b/components/entitlement/org.wso2.carbon.identity.entitlement/src/main/java/org/wso2/carbon/identity/entitlement/EntitlementUtil.java @@ -248,7 +248,7 @@ public static boolean validatePolicy(PolicyDTO policy) { log.error("Invalid Namespace in policy"); } } catch (SAXException e) { - log.error("XACML policy is not valid according to the schema :" + e.getMessage()); + log.error("XACML policy is not valid according to the schema :" + e.getMessage(), e); } catch (IOException e) { //ignore } catch (ParserConfigurationException e) { diff --git a/components/entitlement/org.wso2.carbon.identity.entitlement/src/main/java/org/wso2/carbon/identity/entitlement/pip/CarbonAttributeFinder.java b/components/entitlement/org.wso2.carbon.identity.entitlement/src/main/java/org/wso2/carbon/identity/entitlement/pip/CarbonAttributeFinder.java index 0701d4bb706a..6b946b5f7d27 100644 --- a/components/entitlement/org.wso2.carbon.identity.entitlement/src/main/java/org/wso2/carbon/identity/entitlement/pip/CarbonAttributeFinder.java +++ b/components/entitlement/org.wso2.carbon.identity.entitlement/src/main/java/org/wso2/carbon/identity/entitlement/pip/CarbonAttributeFinder.java @@ -212,7 +212,7 @@ public EvaluationResult findAttribute(URI attributeType, URI attributeId, String } } } catch (ParsingException e) { - log.error("Error while parsing attribute values from EvaluationCtx : " + e); + log.error("Error while parsing attribute values from EvaluationCtx : ", e); ArrayList code = new ArrayList(); code.add(Status.STATUS_MISSING_ATTRIBUTE); Status status = new Status(code, @@ -220,21 +220,21 @@ public EvaluationResult findAttribute(URI attributeType, URI attributeId, String return new EvaluationResult(status); } catch (ParseException e) { e.printStackTrace(); - log.error("Error while parsing attribute values from EvaluationCtx : " + e); + log.error("Error while parsing attribute values from EvaluationCtx : ", e); ArrayList code = new ArrayList(); code.add(Status.STATUS_MISSING_ATTRIBUTE); Status status = new Status(code, "Error while parsing attribute values from EvaluationCtx : " + e.getMessage()); return new EvaluationResult(status); } catch (URISyntaxException e) { - log.error("Error while parsing attribute values from EvaluationCtx : " + e); + log.error("Error while parsing attribute values from EvaluationCtx : ", e); ArrayList code = new ArrayList(); code.add(Status.STATUS_MISSING_ATTRIBUTE); Status status = new Status(code, "Error while parsing attribute values from EvaluationCtx :" + e.getMessage()); return new EvaluationResult(status); } catch (Exception e) { - log.error("Error while retrieving attribute values from PIP attribute finder : " + e); + log.error("Error while retrieving attribute values from PIP attribute finder : ", e); ArrayList code = new ArrayList(); code.add(Status.STATUS_MISSING_ATTRIBUTE); Status status = new Status(code, "Error while retrieving attribute values from PIP" diff --git a/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/main/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementAdminService.java b/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/main/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementAdminService.java index fffa16a3e7f9..403faed67a92 100644 --- a/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/main/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementAdminService.java +++ b/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/main/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementAdminService.java @@ -175,7 +175,7 @@ private void evaluateScript(FunctionLibrary functionLibrary) throws FunctionLibr engine.eval(code); } catch (ScriptException e) { log.error("Script library script of " + functionLibrary.getFunctionLibraryName() + - " contains errors." + e); + " contains errors.", e); throw FunctionLibraryExceptionManagementUtil.handleClientException( FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_VALIDATE_SCRIPT_LIBRARY_SCRIPT, functionLibrary.getFunctionLibraryName(), e); diff --git a/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/main/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceImpl.java b/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/main/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceImpl.java index ebaa85602630..e7bf89235a98 100644 --- a/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/main/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceImpl.java +++ b/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/main/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceImpl.java @@ -176,7 +176,7 @@ private void evaluateScript(FunctionLibrary functionLibrary) throws FunctionLibr engine.eval(code); } catch (ScriptException e) { log.error("Script library script of " + functionLibrary.getFunctionLibraryName() + - " contains errors." + e); + " contains errors.", e); throw FunctionLibraryExceptionManagementUtil.handleClientException( FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_VALIDATE_SCRIPT_LIBRARY_SCRIPT, functionLibrary.getFunctionLibraryName(), e); diff --git a/components/identity-core/org.wso2.carbon.identity.base/src/main/java/org/wso2/carbon/identity/base/IdentityException.java b/components/identity-core/org.wso2.carbon.identity.base/src/main/java/org/wso2/carbon/identity/base/IdentityException.java index 53e64a69c527..9ed9147cda8a 100644 --- a/components/identity-core/org.wso2.carbon.identity.base/src/main/java/org/wso2/carbon/identity/base/IdentityException.java +++ b/components/identity-core/org.wso2.carbon.identity.base/src/main/java/org/wso2/carbon/identity/base/IdentityException.java @@ -77,7 +77,7 @@ public static T error(Class exceptionClass, Str try { exception = exceptionClass.getConstructor(String.class, String.class).newInstance(errorCode, message); } catch (Exception e) { - throw new IdentityRuntimeException("Invalid Exception Type, " + e.getMessage()); + throw new IdentityRuntimeException("Invalid Exception Type, " + e.getMessage(), e); } return exception; } @@ -87,7 +87,7 @@ public static T error(Class exceptionClass, Str try { exception = exceptionClass.getConstructor(String.class, Throwable.class).newInstance(message, cause); } catch (Exception e) { - throw new IdentityRuntimeException("Invalid Exception Type, " + e.getMessage()); + throw new IdentityRuntimeException("Invalid Exception Type, " + e.getMessage(), e); } return exception; } @@ -99,7 +99,7 @@ public static T error(Class exceptionClass, Str exception = exceptionClass.getConstructor(String.class, String.class, Throwable.class). newInstance(errorCode, message, cause); } catch (Exception e) { - throw new IdentityRuntimeException("Invalid Exception Type, " + e.getMessage()); + throw new IdentityRuntimeException("Invalid Exception Type, " + e.getMessage(), e); } return exception; } diff --git a/components/identity-core/org.wso2.carbon.identity.base/src/main/java/org/wso2/carbon/identity/base/IdentityRuntimeException.java b/components/identity-core/org.wso2.carbon.identity.base/src/main/java/org/wso2/carbon/identity/base/IdentityRuntimeException.java index 2e147d18c4b7..fe1096cf1917 100644 --- a/components/identity-core/org.wso2.carbon.identity.base/src/main/java/org/wso2/carbon/identity/base/IdentityRuntimeException.java +++ b/components/identity-core/org.wso2.carbon.identity.base/src/main/java/org/wso2/carbon/identity/base/IdentityRuntimeException.java @@ -73,7 +73,7 @@ public static T error(Class exceptionCla try { exception = exceptionClass.getConstructor(String.class).newInstance(message); } catch (Exception e) { - throw new IdentityRuntimeException("Invalid Exception Type, " + e.getMessage()); + throw new IdentityRuntimeException("Invalid Exception Type, " + e.getMessage(), e); } return exception; } @@ -83,7 +83,7 @@ public static T error(Class exceptionCla try { exception = exceptionClass.getConstructor(String.class, String.class).newInstance(errorCode, message); } catch (Exception e) { - throw new IdentityRuntimeException("Invalid Exception Type, " + e.getMessage()); + throw new IdentityRuntimeException("Invalid Exception Type, " + e.getMessage(), e); } return exception; } @@ -93,7 +93,7 @@ public static T error(Class exceptionCla try { exception = exceptionClass.getConstructor(String.class, Throwable.class).newInstance(message, cause); } catch (Exception e) { - throw new IdentityRuntimeException("Invalid Exception Type, " + e.getMessage()); + throw new IdentityRuntimeException("Invalid Exception Type, " + e.getMessage(), e); } return exception; } @@ -105,7 +105,7 @@ public static T error(Class exceptionCla exception = exceptionClass.getConstructor(String.class, String.class, Throwable.class). newInstance(errorCode, message, cause); } catch (Exception e) { - throw new IdentityRuntimeException("Invalid Exception Type, " + e.getMessage()); + throw new IdentityRuntimeException("Invalid Exception Type, " + e.getMessage(), e); } return exception; } diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/util/IdentityUtil.java b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/util/IdentityUtil.java index d94c95d2b7b9..d0f6aabcd9f2 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/util/IdentityUtil.java +++ b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/util/IdentityUtil.java @@ -1,13 +1,13 @@ /* * Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * + * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -332,7 +332,7 @@ public static String getHMAC(String secretKey, String baseString) throws Signatu byte[] rawHmac = mac.doFinal(baseString.getBytes()); return Base64.getEncoder().encodeToString(rawHmac); } catch (Exception e) { - throw new SignatureException("Failed to generate HMAC : " + e.getMessage()); + throw new SignatureException("Failed to generate HMAC : " + e.getMessage(), e); } } diff --git a/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/store/ArtifactDeleteThread.java b/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/store/ArtifactDeleteThread.java index cc155c1d4a3c..5ca1d2c06745 100644 --- a/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/store/ArtifactDeleteThread.java +++ b/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/store/ArtifactDeleteThread.java @@ -71,7 +71,7 @@ private void deleteOldResourcesIfFound() { collection = (Collection) registry.get(secretKeyPath.toLowerCase()); } catch (RegistryException e) { log.error( - "Error while deleting the old confirmation code. Unable to find data collection in registry." + e); + "Error while deleting the old confirmation code. Unable to find data collection in registry.", e); } //Introduced property to fix resource not being introduced deleted when special characters are present. @@ -129,7 +129,7 @@ public int compare(Resource r1, Resource r2) { } } } catch (RegistryException e) { - log.error("Error while deleting the old confirmation code \n" + e); + log.error("Error while deleting the old confirmation code", e); } finally { PrivilegedCarbonContext.endTenantFlow(); } diff --git a/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/WorkflowManagementAdminService.java b/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/WorkflowManagementAdminService.java index c7d99812325b..585db5dc6786 100644 --- a/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/WorkflowManagementAdminService.java +++ b/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/WorkflowManagementAdminService.java @@ -111,7 +111,7 @@ private WorkflowWizard getWorkflow(org.wso2.carbon.identity.workflow.mgt.bean.Wo } catch (InternalWorkflowException e) { String errorMsg = "Error occurred while reading workflow object details for given workflow id, " + e.getMessage(); - log.error(errorMsg); + log.error(errorMsg, e); throw new WorkflowException(errorMsg, e); } diff --git a/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/extension/AbstractWorkflowRequestHandler.java b/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/extension/AbstractWorkflowRequestHandler.java index 8f281120605f..cec809a7017c 100644 --- a/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/extension/AbstractWorkflowRequestHandler.java +++ b/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/extension/AbstractWorkflowRequestHandler.java @@ -252,7 +252,7 @@ public boolean isAssociated() throws WorkflowException{ eventEngaged = WorkflowServiceDataHolder.getInstance().getWorkflowService().isEventAssociated(getEventId()); } catch (InternalWorkflowException e) { String errorMsg = "Error occurred while checking any association for this event, " + e.getMessage() ; - log.error(errorMsg); + log.error(errorMsg, e); throw new WorkflowException(errorMsg,e); } return eventEngaged ; diff --git a/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/template/AbstractTemplate.java b/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/template/AbstractTemplate.java index 07cf1cd33564..2d1b66fd240a 100644 --- a/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/template/AbstractTemplate.java +++ b/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/template/AbstractTemplate.java @@ -57,7 +57,7 @@ public AbstractTemplate(String metaDataXML) throws WorkflowRuntimeException { this.parametersMetaData = this.metaData.getTemplate().getParametersMetaData(); } catch (JAXBException e) { String errorMsg = "Error occured while converting template parameter data to object : " + e.getMessage(); - log.error(errorMsg); + log.error(errorMsg, e); throw new WorkflowRuntimeException(errorMsg, e); } } diff --git a/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/util/WorkflowManagementUtil.java b/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/util/WorkflowManagementUtil.java index f23552bf9db8..217ae61c1f81 100644 --- a/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/util/WorkflowManagementUtil.java +++ b/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/util/WorkflowManagementUtil.java @@ -157,7 +157,7 @@ public static String readFileFromResource(InputStream resourceAsStream) throws U } catch (IOException e) { String errorMsg = "Error occurred while reading file from class path, " + e.getMessage(); - log.error(errorMsg); + log.error(errorMsg, e); throw new WorkflowRuntimeException(errorMsg, e); } return content; diff --git a/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/workflow/AbstractWorkflow.java b/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/workflow/AbstractWorkflow.java index 6e63a0121c8b..1c8c51c608ea 100644 --- a/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/workflow/AbstractWorkflow.java +++ b/components/workflow-mgt/org.wso2.carbon.identity.workflow.mgt/src/main/java/org/wso2/carbon/identity/workflow/mgt/workflow/AbstractWorkflow.java @@ -69,7 +69,7 @@ public AbstractWorkflow(Class templateInitializer this.parametersMetaData = this.metaData.getWorkflowImpl().getParametersMetaData(); } catch (JAXBException e) { String errorMsg = "Error occurred while converting workflow parameter data to object : " + e.getMessage(); - log.error(errorMsg); + log.error(errorMsg, e); throw new WorkflowRuntimeException(errorMsg, e); } } @@ -166,11 +166,11 @@ public WorkFlowExecutor getWorkFlowExecutor() { workFlowExecutor = workFlowExecutorClass.newInstance(); } catch (InstantiationException e) { String errorMsg = "Error occurred while initializing WorkFlowExecutor : " + e.getMessage(); - log.error(errorMsg); + log.error(errorMsg, e); throw new WorkflowRuntimeException(errorMsg, e); } catch (IllegalAccessException e) { String errorMsg = "Error occurred while initializing WorkFlowExecutor : " + e.getMessage(); - log.error(errorMsg); + log.error(errorMsg, e); throw new WorkflowRuntimeException(errorMsg, e); } return workFlowExecutor; @@ -184,11 +184,11 @@ public TemplateInitializer getTemplateInitializer() throws WorkflowRuntimeExcept templateInitializer = templateInitializerClass.newInstance(); } catch (InstantiationException e) { String errorMsg = "Error occurred while initializing TemplateInitializer : " + e.getMessage(); - log.error(errorMsg); + log.error(errorMsg, e); throw new WorkflowRuntimeException(errorMsg, e); } catch (IllegalAccessException e) { String errorMsg = "Error occurred while initializing TemplateInitializer : " + e.getMessage(); - log.error(errorMsg); + log.error(errorMsg, e); throw new WorkflowRuntimeException(errorMsg, e); } return templateInitializer; From 7e058dd263b3b02bbbf1b5a8a6abd89350353a8a Mon Sep 17 00:00:00 2001 From: nitram509 Date: Sat, 10 Oct 2020 10:20:27 +0200 Subject: [PATCH 3/4] fixed test-setup for sampleFunction3 replace log.error() with Assert.fail() in order to detect test failures Logging in a test might be overseen --- .../FunctionLibraryManagementServiceTest.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/test/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceTest.java b/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/test/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceTest.java index 8cdc33f18f50..5ccc52afcceb 100644 --- a/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/test/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceTest.java +++ b/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/test/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceTest.java @@ -18,8 +18,6 @@ package org.wso2.carbon.identity.functions.library.mgt; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.testng.annotations.DataProvider; @@ -34,9 +32,7 @@ import java.util.List; import static org.powermock.api.mockito.PowerMockito.when; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import static org.testng.Assert.*; import static org.wso2.carbon.identity.functions.library.mgt.FunctionLibraryMgtUtil.isRegexValidated; @PrepareForTest({FunctionLibraryManagementServiceImpl.class}) @@ -44,7 +40,6 @@ public class FunctionLibraryManagementServiceTest extends PowerMockIdentityBaseT private static final String SAMPLE_TENANT_DOMAIN = "carbon.super"; private static final String SAMPLE_TENANT_DOMAIN2 = "abc.com"; - private static final Log log = LogFactory.getLog(FunctionLibraryManagementServiceTest.class); @DataProvider(name = "createFunctionLibraryDataProvider") public Object[][] createFunctionLibraryData() { @@ -62,7 +57,7 @@ public Object[][] createFunctionLibraryData() { FunctionLibrary functionLibrary3 = new FunctionLibrary(); functionLibrary3.setFunctionLibraryName("sample3"); functionLibrary3.setDescription("sample3"); - functionLibrary3.setFunctionLibraryScript("samplefunction3"); + functionLibrary3.setFunctionLibraryScript("function samplefunction3(){}"); FunctionLibrary functionLibrary4 = new FunctionLibrary(); functionLibrary4.setFunctionLibraryName("sample4"); @@ -120,7 +115,7 @@ public void createFunctionLibrary(Object functionLibrary, String tenantDomain) { functionLibraryManagementService.deleteFunctionLibrary( ((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain); } catch (Exception e) { - throw new RuntimeException("Error test Create script library ", e); + fail("Error test Create script library ", e); } } @@ -174,7 +169,7 @@ public void getFunctionLibrary(Object functionLibrary, String tenantDomain) { deleteFunctionLibraries(functionLibraryManagementService, Collections.singletonList(functionLibrary), tenantDomain); } catch (Exception e) { - log.error("Exception"); + fail("Exception", e); } } @@ -326,7 +321,7 @@ public void updateFunctionLibrary(Object functionLibrary, String tenantDomain) t FunctionLibraryMgtUtil.FUNCTION_LIBRARY_NAME_VALIDATING_REGEX + "."); } } catch (Exception e) { - log.error("Exception"); + fail("Exception", e); } } @@ -404,7 +399,7 @@ public void testIsRegexValidated(Object functionLibrary, String tenantDomain) { assertEquals(e.getMessage(), "The script library name is not valid! It is not adhering to the regex " + FunctionLibraryMgtUtil.FUNCTION_LIBRARY_NAME_VALIDATING_REGEX + "."); } catch (Exception e) { - throw new RuntimeException(e); + fail("Exception", e); } } @@ -452,7 +447,7 @@ public void testAlreadyExistFunctionLibrary(Object functionLibrary, String tenan assertEquals(e.getMessage(), "Already a script library available with the name: " + ((FunctionLibrary) functionLibrary).getFunctionLibraryName() + "."); } catch (Exception e) { - throw new RuntimeException(e); + fail("Exception", e); } } @@ -486,7 +481,7 @@ public void testFunctionLibraryNameRequired(Object functionLibrary, String tenan } catch (FunctionLibraryManagementException e) { assertEquals(e.getMessage(), "Script library name is required"); } catch (Exception e) { - throw new RuntimeException(e); + fail("Exception", e); } } From d9b2a55274c008eb042073fab107e47f2154748d Mon Sep 17 00:00:00 2001 From: nitram509 Date: Sat, 10 Oct 2020 11:46:12 +0200 Subject: [PATCH 4/4] make explicit import statements, as per convention for this project. --- .../library/mgt/FunctionLibraryManagementServiceTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/test/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceTest.java b/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/test/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceTest.java index 5ccc52afcceb..438be1c2ff09 100644 --- a/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/test/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceTest.java +++ b/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/test/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceTest.java @@ -32,7 +32,10 @@ import java.util.List; import static org.powermock.api.mockito.PowerMockito.when; -import static org.testng.Assert.*; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; import static org.wso2.carbon.identity.functions.library.mgt.FunctionLibraryMgtUtil.isRegexValidated; @PrepareForTest({FunctionLibraryManagementServiceImpl.class})