Skip to content

Commit

Permalink
Fix checkstyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sahandilshan committed Nov 15, 2024
1 parent bbf57d7 commit d928d9a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,6 +48,9 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
* Test class for AIAccessTokenManager.
*/
public class AIAccessTokenManagerTest {

@Mock
Expand All @@ -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() {

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/ai-services-mgt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
<module>org.wso2.carbon.ai.service.mgt</module>
</modules>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public String generateAuthenticationSequence(String userQuery, JSONArray userCla
AIClientException {

ObjectMapper objectMapper = new ObjectMapper();

Map<String, Object> requestBody = new HashMap<>();
requestBody.put("user_query", userQuery);
try {
Expand Down

0 comments on commit d928d9a

Please sign in to comment.