Search in sources :

Example 1 with MetricService

use of org.wso2.carbon.metrics.manager.MetricService in project carbon-apimgt by wso2.

the class APIKeyValidationServiceTest method Init.

@Before
public void Init() throws Exception {
    System.setProperty(CARBON_HOME, "");
    privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
    serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
    apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
    apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    metricService = Mockito.mock(MetricService.class);
    org.wso2.carbon.metrics.manager.ServiceReferenceHolder serviceReferenceHolder1 = Mockito.mock(org.wso2.carbon.metrics.manager.ServiceReferenceHolder.class);
    Timer timer = Mockito.mock(Timer.class);
    Timer.Context timerContext = Mockito.mock(Timer.Context.class);
    MessageContext messageContext = Mockito.mock(MessageContext.class);
    OperationContext operationContext = Mockito.mock(OperationContext.class);
    MessageContext responseMessageContext = Mockito.mock(MessageContext.class);
    PowerMockito.mockStatic(PrivilegedCarbonContext.class);
    PowerMockito.mockStatic(ApiMgtDAO.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.mockStatic(org.wso2.carbon.metrics.manager.ServiceReferenceHolder.class);
    PowerMockito.mockStatic(APIKeyMgtUtil.class);
    PowerMockito.mockStatic(MessageContext.class);
    PowerMockito.mockStatic(APIKeyMgtDataHolder.class);
    PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
    PowerMockito.when(privilegedCarbonContext.getUsername()).thenReturn(USER_NAME);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
    PowerMockito.when(MessageContext.getCurrentMessageContext()).thenReturn(messageContext);
    PowerMockito.when(APIKeyMgtDataHolder.isJwtGenerationEnabled()).thenReturn(true);
    Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_KEY_MANGER_VALIDATIONHANDLER_CLASS_NAME)).thenReturn(API_KEY_MANGER_VALIDATION_HANDLER_CLASS_NAME);
    Mockito.when(org.wso2.carbon.metrics.manager.ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder1);
    Mockito.when(serviceReferenceHolder1.getMetricService()).thenReturn(metricService);
    Mockito.when(timer.start()).thenReturn(timerContext);
    Mockito.when(metricService.timer(Mockito.anyString(), Mockito.any(org.wso2.carbon.metrics.manager.Level.class))).thenReturn(timer);
    Mockito.when(messageContext.getOperationContext()).thenReturn(operationContext);
    Mockito.when(operationContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE)).thenReturn(responseMessageContext);
    Map headers = new HashMap();
    headers.put("activityID", "1s2f2g4g5");
    Mockito.when(messageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS)).thenReturn(headers);
    String cacheKey = APIUtil.getAccessTokenCacheKey(ACCESS_TOKEN, API_CONTEXT, API_VERSION, "/*", "GET", REQUIRED_AUTHENTICATION_LEVEL);
    APIKeyValidationInfoDTO infoDTO = new APIKeyValidationInfoDTO();
    infoDTO.setApiPublisher(USER_NAME);
    infoDTO.setEndUserName(USER_NAME);
    PowerMockito.when(APIKeyMgtUtil.getFromKeyManagerCache(cacheKey)).thenReturn(infoDTO);
}
Also used : OperationContext(org.apache.axis2.context.OperationContext) ServiceReferenceHolder(org.wso2.carbon.apimgt.keymgt.internal.ServiceReferenceHolder) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) HashMap(java.util.HashMap) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) MetricService(org.wso2.carbon.metrics.manager.MetricService) Timer(org.wso2.carbon.metrics.manager.Timer) MessageContext(org.apache.axis2.context.MessageContext) HashMap(java.util.HashMap) Map(java.util.Map) APIKeyValidationInfoDTO(org.wso2.carbon.apimgt.impl.dto.APIKeyValidationInfoDTO) Before(org.junit.Before)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 MessageContext (org.apache.axis2.context.MessageContext)1 OperationContext (org.apache.axis2.context.OperationContext)1 Before (org.junit.Before)1 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)1 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)1 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)1 APIKeyValidationInfoDTO (org.wso2.carbon.apimgt.impl.dto.APIKeyValidationInfoDTO)1 ServiceReferenceHolder (org.wso2.carbon.apimgt.keymgt.internal.ServiceReferenceHolder)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1 MetricService (org.wso2.carbon.metrics.manager.MetricService)1 Timer (org.wso2.carbon.metrics.manager.Timer)1