From f9052eea1b85d6e35e35bfb0c5a8ba69304cba05 Mon Sep 17 00:00:00 2001 From: Ashera Silva Date: Sat, 23 Mar 2024 23:25:32 +0530 Subject: [PATCH] Fix test failures and address review comments --- .../apimgt/impl/APIManagerConfiguration.java | 1 - ...arketplaceAssistantApiPublisherNotifier.java | 9 +++------ .../apimgt/impl/utils/LifeCycleUtils.java | 14 ++++++++------ .../APIManagerComponentImagePermissionTest.java | 5 +++++ .../impl/internal/APIManagerComponentTest.java | 5 +++++ .../src/main/resources/devportal-api.yaml | 2 +- .../api/store/v1/MarketplaceAssistantApi.java | 2 +- .../api/store/v1/impl/ApisApiServiceImpl.java | 1 + .../MarketplaceAssistantApiServiceImpl.java | 17 +++++++++++++++++ .../src/main/resources/devportal-api.yaml | 2 +- 10 files changed, 42 insertions(+), 16 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java index 3cb3cdb86ca7..b6e289da9843 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java @@ -108,7 +108,6 @@ public class APIManagerConfiguration { private JSONArray applicationAttributes = new JSONArray(); private CacheInvalidationConfiguration cacheInvalidationConfiguration; - private HttpClientConfigurationDTO httpClientConfiguration; private RecommendationEnvironment recommendationEnvironment; diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/notifier/MarketplaceAssistantApiPublisherNotifier.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/notifier/MarketplaceAssistantApiPublisherNotifier.java index becd7da09907..1e923265f390 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/notifier/MarketplaceAssistantApiPublisherNotifier.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/notifier/MarketplaceAssistantApiPublisherNotifier.java @@ -17,8 +17,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.http.HttpStatus; -import org.apache.http.client.methods.CloseableHttpResponse; import org.json.simple.JSONObject; import org.wso2.carbon.apimgt.api.APIManagementException; import org.wso2.carbon.apimgt.api.APIProvider; @@ -77,7 +75,6 @@ private void process (Event event) throws NotifierException { return; } - // [ **Publish**, **Deploy as a Prototype**, **Demote to Created**, **Block**, **Deprecate**, **Re-Publish**, **Retire** ] if (APIConstants.EventType.API_LIFECYCLE_CHANGE.name().equals(event.getType())) { String lifecycleEvent = apiEvent.getLifecycleEvent(); String currentStatus = apiEvent.getCurrentStatus().toUpperCase(); @@ -161,8 +158,8 @@ private void postRequest(APIEvent apiEvent) throws NotifierException { APIUtil.MarketplaceAssistantPostService(marketplaceAssistantConfigurationDto.getEndpoint(), marketplaceAssistantConfigurationDto.getAccessToken(), marketplaceAssistantConfigurationDto.getApiPublishResource(), payload.toString()); } catch (APIManagementException e) { - String errorMessage = "Error encountered while Uploading the API to the vector database"; - log.error(errorMessage); + String errorMessage = "Error encountered while Uploading the API to the vector database" + e.getMessage(); + log.error(errorMessage, e); } } @@ -177,4 +174,4 @@ private void deleteRequest(APIEvent apiEvent) throws NotifierException { log.error(errorMessage); } } -} \ No newline at end of file +} diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/LifeCycleUtils.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/LifeCycleUtils.java index bbce60b8a3c5..33377a0ece13 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/LifeCycleUtils.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/LifeCycleUtils.java @@ -392,14 +392,16 @@ private static void addLCStateChangeInDatabase(String user, ApiTypeWrapper apiTy * @param apiOrApiProductId unique ID of API or API product * @param uuid unique UUID of API or API Product */ - private static void sendLCStateChangeNotification(String apiName, String apiType, String apiContext, String apiVersion, - String targetStatus, String provider, int apiOrApiProductId, - String uuid, String organization, String securityScheme, String action, String currentStatus, String apiVisibility) throws - APIManagementException { + private static void sendLCStateChangeNotification(String apiName, String apiType, String apiContext, + String apiVersion, String targetStatus, String provider, int apiOrApiProductId, String uuid, + String organization, String securityScheme, String action, String currentStatus, String apiVisibility) + throws APIManagementException { APIEvent apiEvent = new APIEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), - APIConstants.EventType.API_LIFECYCLE_CHANGE.name(), APIUtil.getInternalOrganizationId(organization), organization, apiName, apiOrApiProductId, - uuid, apiVersion, apiType, apiContext, APIUtil.replaceEmailDomainBack(provider), targetStatus, securityScheme, action, currentStatus, apiVisibility); + APIConstants.EventType.API_LIFECYCLE_CHANGE.name(), APIUtil.getInternalOrganizationId(organization), + organization, apiName, apiOrApiProductId, uuid, apiVersion, apiType, apiContext, + APIUtil.replaceEmailDomainBack(provider), targetStatus, securityScheme, action, currentStatus, + apiVisibility); APIUtil.sendNotification(apiEvent, APIConstants.NotifierType.API.name()); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/internal/APIManagerComponentImagePermissionTest.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/internal/APIManagerComponentImagePermissionTest.java index f4af4b012c2e..f15822cb5e89 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/internal/APIManagerComponentImagePermissionTest.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/internal/APIManagerComponentImagePermissionTest.java @@ -25,6 +25,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.wso2.carbon.apimgt.impl.APIManagerConfiguration; +import org.wso2.carbon.apimgt.impl.ai.MarketplaceAssistantConfigurationDto; import org.wso2.carbon.apimgt.impl.utils.APIMgtDBUtil; import org.wso2.carbon.apimgt.impl.utils.APIUtil; import org.wso2.carbon.base.MultitenantConstants; @@ -68,6 +69,8 @@ public void setup() throws Exception { Registry registry = Mockito.mock(Registry.class); CarbonContext carbonContext = Mockito.mock(CarbonContext.class); APIManagerConfiguration configuration = Mockito.mock(APIManagerConfiguration.class); + MarketplaceAssistantConfigurationDto marketplaceAssistantConfigurationDto = Mockito.mock( + MarketplaceAssistantConfigurationDto.class); Mockito.when(componentContext.getBundleContext()).thenReturn(bundleContext); Mockito.when(realmService.getTenantUserRealm(MultitenantConstants.SUPER_TENANT_ID)).thenReturn(userRealm); @@ -77,6 +80,8 @@ public void setup() throws Exception { Mockito.when(carbonContext.getRegistry(RegistryType.USER_GOVERNANCE)).thenReturn(registry); Mockito.doNothing().when(configuration).load(Mockito.anyString()); Mockito.when(configuration.getFirstProperty(Mockito.anyString())).thenReturn(""); + Mockito.when(configuration.getMarketplaceAssistantConfigurationDto()) + .thenReturn(marketplaceAssistantConfigurationDto); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); PowerMockito.when(APIUtil.getMountedPath(null, "")).thenReturn(""); PowerMockito.when(RegistryUtils.getAbsolutePath(null, null)).thenReturn(""); diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/internal/APIManagerComponentTest.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/internal/APIManagerComponentTest.java index 62e6f431fb79..91fcf50cf282 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/internal/APIManagerComponentTest.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/internal/APIManagerComponentTest.java @@ -30,6 +30,7 @@ import org.wso2.carbon.apimgt.impl.APIConstants; import org.wso2.carbon.apimgt.impl.APIManagerConfiguration; import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; +import org.wso2.carbon.apimgt.impl.ai.MarketplaceAssistantConfigurationDto; import org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO; import org.wso2.carbon.apimgt.impl.dto.EventHubConfigurationDto; import org.wso2.carbon.apimgt.impl.dto.GatewayArtifactSynchronizerProperties; @@ -79,6 +80,8 @@ public void testShouldActivateWhenAllPrerequisitesMet() throws Exception { UserRealm userRealm = Mockito.mock(UserRealm.class); OutputEventAdapterService adapterService = Mockito.mock(OutputEventAdapterService.class); ThrottleProperties throttleProperties = new ThrottleProperties(); + MarketplaceAssistantConfigurationDto marketplaceAssistantConfigurationDto = Mockito.mock( + MarketplaceAssistantConfigurationDto.class); Mockito.doNothing().when(configuration).load(Mockito.anyString()); Mockito.doNothing().when(authManager) @@ -97,6 +100,8 @@ public void testShouldActivateWhenAllPrerequisitesMet() throws Exception { Mockito.when(realmService.getTenantUserRealm(Mockito.anyInt())).thenReturn(userRealm); Mockito.when(userRealm.getAuthorizationManager()).thenReturn(authManager); Mockito.when(configuration.getThrottleProperties()).thenReturn(throttleProperties); + Mockito.when(configuration.getMarketplaceAssistantConfigurationDto()) + .thenReturn(marketplaceAssistantConfigurationDto); PowerMockito.doNothing().when(APIMgtDBUtil.class, "initialize"); PowerMockito.doNothing().when(APIUtil.class, "loadTenantExternalStoreConfig", Mockito.anyString()); PowerMockito.doNothing().when(AuthorizationUtils.class ,"addAuthorizeRoleListener", diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/devportal-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/devportal-api.yaml index 121a13640033..ce504bb89217 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/devportal-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/devportal-api.yaml @@ -3683,7 +3683,7 @@ paths: 500: description: | Internal Server Error. - An error occurred while checking the health status of API Chat service. + An error occurred while retrieving the API count. '/marketplace-assistant/chat': diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/MarketplaceAssistantApi.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/MarketplaceAssistantApi.java index 869d54c5cd0c..993e15fdca4d 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/MarketplaceAssistantApi.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/MarketplaceAssistantApi.java @@ -47,7 +47,7 @@ public class MarketplaceAssistantApi { @ApiResponse(code = 200, message = "OK. Api Count is returned. ", response = MarketplaceAssistantApiCountResponseDTO.class), @ApiResponse(code = 400, message = "Bad Request. Invalid request or validation error.", response = ErrorDTO.class), @ApiResponse(code = 401, message = "Unauthorized. The user is not authorized.", response = ErrorDTO.class), - @ApiResponse(code = 500, message = "Internal Server Error. An error occurred while checking the health status of API Chat service. ", response = Void.class) }) + @ApiResponse(code = 500, message = "Internal Server Error. An error occurred while retrieving the API count. ", response = Void.class) }) public Response getMarketplaceAssistantApiCount() throws APIManagementException{ return delegate.getMarketplaceAssistantApiCount(securityContext); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/impl/ApisApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/impl/ApisApiServiceImpl.java index a266766547b4..4c4cfbc8e205 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/impl/ApisApiServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/impl/ApisApiServiceImpl.java @@ -55,6 +55,7 @@ import org.wso2.carbon.apimgt.rest.api.store.v1.ApisApiService; import com.fasterxml.jackson.databind.ObjectMapper; + import java.io.File; import java.io.IOException; import java.net.URI; diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/impl/MarketplaceAssistantApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/impl/MarketplaceAssistantApiServiceImpl.java index e4c2d000970e..5fbb2c74a3ca 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/impl/MarketplaceAssistantApiServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/impl/MarketplaceAssistantApiServiceImpl.java @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * 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.apimgt.rest.api.store.v1.impl; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/resources/devportal-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/resources/devportal-api.yaml index 121a13640033..ce504bb89217 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/resources/devportal-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/resources/devportal-api.yaml @@ -3683,7 +3683,7 @@ paths: 500: description: | Internal Server Error. - An error occurred while checking the health status of API Chat service. + An error occurred while retrieving the API count. '/marketplace-assistant/chat':