use of org.wso2.carbon.apimgt.rest.api.common.interceptors.RESTAPISecurityInterceptor in project carbon-apimgt by wso2.
the class RESTAPISecurityInterceptorTestCase method testGetApisSuccess.
@Test
public void testGetApisSuccess() throws APIManagementException {
HTTPCarbonMessage carbonMessage = Mockito.mock(HTTPCarbonMessage.class);
Request requestObj = Mockito.mock(Request.class);
try {
PowerMockito.whenNew(Request.class).withArguments(carbonMessage).thenReturn(requestObj);
} catch (Exception e) {
throw new APIMgtSecurityException("Error while mocking Request Object ", e);
}
Response responseObj = Mockito.mock(Response.class);
Mockito.when(requestObj.getHeader(RestApiConstants.AUTHORIZATION_HTTP_HEADER)).thenReturn("Authorization: 053d68ee-12bc-36b0-ab9c-31752ef5bda9");
Mockito.when(requestObj.getHeader("REQUEST_URL")).thenReturn("http://localhost:9090/api/am/publisher/v1/api");
ServiceMethodInfo serviceMethodInfoObj = Mockito.mock(ServiceMethodInfo.class);
RESTAPISecurityInterceptor interceptor = Mockito.mock(RESTAPISecurityInterceptor.class);
boolean isAuthorized = interceptor.preCall(requestObj, responseObj, serviceMethodInfoObj);
if (isAuthorized) {
Assert.assertEquals(isAuthorized, true);
} else {
Assert.assertEquals(isAuthorized, false);
}
}
Aggregations