diff --git a/components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/pom.xml b/components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/pom.xml index 6c48de0d11ee..09fb33b2d040 100644 --- a/components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/pom.xml +++ b/components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/pom.xml @@ -198,4 +198,4 @@ - \ No newline at end of file + diff --git a/components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/src/main/java/org/wso2/carbon/ai/service/mgt/token/AIAccessTokenManager.java b/components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/src/main/java/org/wso2/carbon/ai/service/mgt/token/AIAccessTokenManager.java index 7b45d6676947..e7688e38ae4b 100644 --- a/components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/src/main/java/org/wso2/carbon/ai/service/mgt/token/AIAccessTokenManager.java +++ b/components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/src/main/java/org/wso2/carbon/ai/service/mgt/token/AIAccessTokenManager.java @@ -53,8 +53,8 @@ */ public class AIAccessTokenManager { - private static volatile AIAccessTokenManager instance; // Volatile for thread safety - private static final Object lock = new Object(); // Lock for synchronization + private static volatile AIAccessTokenManager instance; // Volatile for thread safety. + private static final Object lock = new Object(); // Lock for synchronization. private static final Log LOG = LogFactory.getLog(AIAccessTokenManager.class); diff --git a/components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/src/test/java/org/wso2/carbon/ai/service/mgt/token/AIAccessTokenManagerTest.java b/components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/src/test/java/org/wso2/carbon/ai/service/mgt/token/AIAccessTokenManagerTest.java index 0f54d6746e31..1de03cf92b08 100644 --- a/components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/src/test/java/org/wso2/carbon/ai/service/mgt/token/AIAccessTokenManagerTest.java +++ b/components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/src/test/java/org/wso2/carbon/ai/service/mgt/token/AIAccessTokenManagerTest.java @@ -29,7 +29,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -49,6 +48,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +/** + * Test class for AIAccessTokenManager. + */ public class AIAccessTokenManagerTest { @Mock @@ -69,32 +71,24 @@ public class AIAccessTokenManagerTest { private CountDownLatch latch; @BeforeMethod - public void setUp() throws Exception { + public void setUp() { MockitoAnnotations.openMocks(this); testHelper = new TestAccessTokenRequestHelper(mockHttpClient); tokenManager = AIAccessTokenManager.getInstance(); tokenManager.setAccessTokenRequestHelper(testHelper); -// mockClient = mock(CloseableHttpAsyncClient.class); helper = new AIAccessTokenManager.AccessTokenRequestHelper("key", "endpoint", mockHttpClient); latch = new CountDownLatch(1); } @AfterMethod - public void tearDown() throws Exception { + public void tearDown() { - // Reset other mocks and state + // Reset other mocks and state. tokenManager = null; testHelper = null; } - - @AfterClass - public void tearDownClass() { - // Close the static mock after all tests are complete -// logFactoryMockedStatic.close(); - } - @Test public void testGetInstance() { @@ -238,7 +232,7 @@ private void setupMockHttpResponse(int statusCode, String responseBody) throws E when(mockFuture.get()).thenReturn(mockResponse); } - // Custom AccessTokenRequestHelper for testing + // Custom AccessTokenRequestHelper for testing. private class TestAccessTokenRequestHelper extends AIAccessTokenManager.AccessTokenRequestHelper { public TestAccessTokenRequestHelper(CloseableHttpAsyncClient client) { super("testKey", "https://test.endpoint", client); @@ -249,7 +243,7 @@ public String requestAccessToken() throws AIServerException { try { return super.requestAccessToken(); } catch (AIServerException e) { - // Rethrow AIServerException directly for testing purposes + // Rethrow AIServerException directly for testing purposes. throw e; } catch (Exception e) { throw new AIServerException("Test exception", e); diff --git a/components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/src/test/java/org/wso2/carbon/ai/service/mgt/util/AIHttpClientUtilTest.java b/components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/src/test/java/org/wso2/carbon/ai/service/mgt/util/AIHttpClientUtilTest.java index 87bf3f84e3e0..253c4605d32a 100644 --- a/components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/src/test/java/org/wso2/carbon/ai/service/mgt/util/AIHttpClientUtilTest.java +++ b/components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/src/test/java/org/wso2/carbon/ai/service/mgt/util/AIHttpClientUtilTest.java @@ -58,6 +58,9 @@ import static org.mockito.MockitoAnnotations.openMocks; import static org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; +/** + * Test class for AIHttpClientUtil. + */ public class AIHttpClientUtilTest { @Mock diff --git a/components/ai-services-mgt/pom.xml b/components/ai-services-mgt/pom.xml index 985e3a91f971..65195c69b8b3 100644 --- a/components/ai-services-mgt/pom.xml +++ b/components/ai-services-mgt/pom.xml @@ -41,4 +41,4 @@ org.wso2.carbon.ai.service.mgt - \ No newline at end of file + diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAIManager.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAIManager.java index 25052619aa44..ad242539e5eb 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAIManager.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAIManager.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. 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 + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.carbon.identity.application.mgt.ai; import org.json.JSONArray; diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAIManagerImpl.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAIManagerImpl.java index 99502163df08..11d901c531c5 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAIManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAIManagerImpl.java @@ -70,7 +70,6 @@ public String generateAuthenticationSequence(String userQuery, JSONArray userCla AIClientException { ObjectMapper objectMapper = new ObjectMapper(); - Map requestBody = new HashMap<>(); requestBody.put("user_query", userQuery); try {