Skip to content

Commit

Permalink
Fix test failures and address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ashera96 committed Mar 23, 2024
1 parent 6984829 commit f9052ee
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public class APIManagerConfiguration {
private JSONArray applicationAttributes = new JSONArray();
private CacheInvalidationConfiguration cacheInvalidationConfiguration;


private HttpClientConfigurationDTO httpClientConfiguration;

private RecommendationEnvironment recommendationEnvironment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -177,4 +174,4 @@ private void deleteRequest(APIEvent apiEvent) throws NotifierException {
log.error(errorMessage);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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':

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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':

Expand Down

0 comments on commit f9052ee

Please sign in to comment.