From e804bbb6c7bd6a956667068c1b29e5ae2884c1d4 Mon Sep 17 00:00:00 2001 From: Shenali Date: Thu, 5 Sep 2024 12:46:02 +0530 Subject: [PATCH 1/3] Refactor the actionRestClient invoke implementation --- .../integration/test/actions/ActionsBaseTestCase.java | 8 ++++---- ...PreIssueAccessTokenClientCredentialsGrantTestCase.java | 3 --- .../actions/PreIssueAccessTokenPasswordGrantTestCase.java | 3 --- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/ActionsBaseTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/ActionsBaseTestCase.java index 0b9e5b6bae3..c4262363553 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/ActionsBaseTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/ActionsBaseTestCase.java @@ -32,7 +32,7 @@ */ public class ActionsBaseTestCase extends OAuth2ServiceAbstractIntegrationTest { - protected ActionsRestClient restClient; + protected ActionsRestClient actionsRestClient; /** * Initialize the test case. @@ -44,7 +44,7 @@ protected void init(TestUserMode userMode) throws Exception { super.init(userMode); - restClient = new ActionsRestClient(serverURL, tenantInfo); + actionsRestClient = new ActionsRestClient(serverURL, tenantInfo); setSystemproperties(); } @@ -59,7 +59,7 @@ protected void init(TestUserMode userMode) throws Exception { */ public String createAction(String actionType, ActionModel actionModel) throws IOException { - return restClient.createActionType(actionModel, actionType); + return actionsRestClient.createActionType(actionModel, actionType); } /** @@ -72,6 +72,6 @@ public String createAction(String actionType, ActionModel actionModel) throws IO */ public int deleteAction(String actionType, String actionId) throws IOException { - return restClient.deleteActionType(actionType, actionId); + return actionsRestClient.deleteActionType(actionType, actionId); } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenClientCredentialsGrantTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenClientCredentialsGrantTestCase.java index 65ba06140ed..9945e12160b 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenClientCredentialsGrantTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenClientCredentialsGrantTestCase.java @@ -171,8 +171,6 @@ protected boolean isRedirectable(String method) { }).build(); scim2RestClient = new SCIM2RestClient(serverURL, tenantInfo); - restClient = new ActionsRestClient(serverURL, tenantInfo); - // TODO: Review if ActionsRestClient should be instantiated, or if the superclass initialization is sufficient customScopes = Arrays.asList(CUSTOM_SCOPE_1, CUSTOM_SCOPE_2, CUSTOM_SCOPE_3); @@ -198,7 +196,6 @@ protected boolean isRedirectable(String method) { public void atEnd() throws Exception { deleteAction(PRE_ISSUE_ACCESS_TOKEN_API_PATH, actionId); - restClient = null; deleteRole(roleId); deleteApp(applicationId); deleteDomainAPI(domainAPIId); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenPasswordGrantTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenPasswordGrantTestCase.java index c1cd53f0995..3956fca5a1f 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenPasswordGrantTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenPasswordGrantTestCase.java @@ -127,8 +127,6 @@ public void testInit() throws Exception { super.init(TestUserMode.TENANT_USER); scim2RestClient = new SCIM2RestClient(serverURL, tenantInfo); - restClient = new ActionsRestClient(serverURL, tenantInfo); - // TODO: Review if ActionsRestClient should be instantiated, or if the superclass initialization is sufficient List customScopes = Arrays.asList(CUSTOM_SCOPE_1, CUSTOM_SCOPE_2, CUSTOM_SCOPE_3); @@ -154,7 +152,6 @@ public void testInit() throws Exception { public void atEnd() throws Exception { deleteAction(PRE_ISSUE_ACCESS_TOKEN_API_PATH, actionId); - restClient = null; deleteRole(roleId); deleteApp(applicationId); deleteDomainAPI(domainAPIId); From 982cf94acc2e4400b2a380586e8ff160a0384006 Mon Sep 17 00:00:00 2001 From: Shenali Date: Thu, 5 Sep 2024 13:08:28 +0530 Subject: [PATCH 2/3] Remove unused imports --- .../PreIssueAccessTokenClientCredentialsGrantTestCase.java | 1 - .../test/actions/PreIssueAccessTokenPasswordGrantTestCase.java | 1 - 2 files changed, 2 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenClientCredentialsGrantTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenClientCredentialsGrantTestCase.java index 9945e12160b..acc0a03ae3c 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenClientCredentialsGrantTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenClientCredentialsGrantTestCase.java @@ -58,7 +58,6 @@ import org.wso2.identity.integration.test.rest.api.user.common.model.PatchOperationRequestObject; import org.wso2.identity.integration.test.rest.api.user.common.model.RoleItemAddGroupobj; import org.wso2.identity.integration.test.rest.api.user.common.model.UserObject; -import org.wso2.identity.integration.test.restclients.ActionsRestClient; import org.wso2.identity.integration.test.restclients.SCIM2RestClient; import org.wso2.identity.integration.test.utils.CarbonUtils; import org.wso2.identity.integration.test.utils.OAuth2Constant; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenPasswordGrantTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenPasswordGrantTestCase.java index 3956fca5a1f..223f17edb13 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenPasswordGrantTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenPasswordGrantTestCase.java @@ -42,7 +42,6 @@ import org.wso2.identity.integration.test.rest.api.user.common.model.PatchOperationRequestObject; import org.wso2.identity.integration.test.rest.api.user.common.model.RoleItemAddGroupobj; import org.wso2.identity.integration.test.rest.api.user.common.model.UserObject; -import org.wso2.identity.integration.test.restclients.ActionsRestClient; import org.wso2.identity.integration.test.restclients.SCIM2RestClient; import org.wso2.identity.integration.test.utils.CarbonUtils; import org.wso2.identity.integration.test.utils.OAuth2Constant; From f7f828c60a419d08f8dac5efe8cf7aa69127e84a Mon Sep 17 00:00:00 2001 From: Shenali Date: Thu, 5 Sep 2024 16:53:12 +0530 Subject: [PATCH 3/3] Close http clients used in rest clients --- ...IssueAccessTokenClientCredentialsGrantTestCase.java | 5 ++++- .../PreIssueAccessTokenPasswordGrantTestCase.java | 4 +++- .../test/restclients/ActionsRestClient.java | 10 ++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenClientCredentialsGrantTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenClientCredentialsGrantTestCase.java index acc0a03ae3c..f57f568bf04 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenClientCredentialsGrantTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenClientCredentialsGrantTestCase.java @@ -199,8 +199,11 @@ public void atEnd() throws Exception { deleteApp(applicationId); deleteDomainAPI(domainAPIId); scim2RestClient.deleteUser(userId); - scim2RestClient = null; MockServer.shutDownMockServer(); + restClient.closeHttpClient(); + scim2RestClient.closeHttpClient(); + actionsRestClient.closeHttpClient(); + client.close(); accessToken = null; jwtClaims = null; } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenPasswordGrantTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenPasswordGrantTestCase.java index 223f17edb13..d9b43c98b83 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenPasswordGrantTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/actions/PreIssueAccessTokenPasswordGrantTestCase.java @@ -155,8 +155,10 @@ public void atEnd() throws Exception { deleteApp(applicationId); deleteDomainAPI(domainAPIId); scim2RestClient.deleteUser(userId); - scim2RestClient = null; MockServer.shutDownMockServer(); + restClient.closeHttpClient(); + scim2RestClient.closeHttpClient(); + actionsRestClient.closeHttpClient(); accessToken = null; jwtClaims = null; } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ActionsRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ActionsRestClient.java index bb8a0fca19c..bfe0bb13f4e 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ActionsRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/ActionsRestClient.java @@ -143,4 +143,14 @@ private Header[] getHeaders() { return headerList; } + + /** + * Close the HTTP client. + * + * @throws IOException If an error occurred while closing the Http Client. + */ + public void closeHttpClient() throws IOException { + + client.close(); + } }