use of org.wso2.siddhi.service.api.NotFoundException in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImplTestCase method testApplicationsApplicationIdGenerateTokenPostErrorCase.
@Test
public void testApplicationsApplicationIdGenerateTokenPostErrorCase() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String applicationId = UUID.randomUUID().toString();
String accessToken = UUID.randomUUID().toString();
String clientID = UUID.randomUUID().toString();
String clientSecret = UUID.randomUUID().toString();
ApplicationsApiServiceImpl applicationsApiService = new ApplicationsApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
ApplicationTokenGenerateRequestDTO generateRequestDTO = new ApplicationTokenGenerateRequestDTO();
generateRequestDTO.setConsumerKey(clientID);
generateRequestDTO.setConsumerSecret(clientSecret);
generateRequestDTO.setRevokeToken("revokeToken");
generateRequestDTO.setScopes("SCOPE1");
generateRequestDTO.setValidityPeriod(10000);
Mockito.doThrow(new APIManagementException("Error Occurred", ExceptionCodes.APPLICATION_TOKEN_GENERATION_FAILED)).when(apiStore).generateApplicationToken(clientID, clientSecret, "SCOPE1", 10000, "revokeToken");
Response response = applicationsApiService.applicationsApplicationIdGenerateTokenPost(applicationId, generateRequestDTO, null, null, request);
Assert.assertEquals(500, response.getStatus());
}
use of org.wso2.siddhi.service.api.NotFoundException in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImplTestCase method testApplicationsApplicationIdDelete.
@Test
public void testApplicationsApplicationIdDelete() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String applicationId = UUID.randomUUID().toString();
ApplicationsApiServiceImpl applicationsApiService = new ApplicationsApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
Mockito.when(apiStore.deleteApplication(applicationId)).thenReturn(workflowResponse);
Response response = applicationsApiService.applicationsApplicationIdDelete(applicationId, null, null, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.siddhi.service.api.NotFoundException in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImplTestCase method testApplicationsApplicationIdGenerateKeysPostErrorCase.
@Test
public void testApplicationsApplicationIdGenerateKeysPostErrorCase() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String applicationId = UUID.randomUUID().toString();
ApplicationsApiServiceImpl applicationsApiService = new ApplicationsApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
List<String> grantTypes = new ArrayList<>();
grantTypes.add("password");
grantTypes.add("jwt");
OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
oAuthApplicationInfo.setKeyType("PRODUCTION");
oAuthApplicationInfo.setClientId(UUID.randomUUID().toString());
oAuthApplicationInfo.setClientSecret(UUID.randomUUID().toString());
oAuthApplicationInfo.setGrantTypes(grantTypes);
Mockito.doThrow(new APIManagementException("Error Occurred", ExceptionCodes.APPLICATION_TOKEN_GENERATION_FAILED)).when(apiStore).generateApplicationKeys(applicationId, "PRODUCTION", null, grantTypes);
ApplicationKeyGenerateRequestDTO applicationKeyGenerateRequestDTO = new ApplicationKeyGenerateRequestDTO();
applicationKeyGenerateRequestDTO.setKeyType(ApplicationKeyGenerateRequestDTO.KeyTypeEnum.PRODUCTION);
applicationKeyGenerateRequestDTO.setCallbackUrl(null);
applicationKeyGenerateRequestDTO.setGrantTypesToBeSupported(grantTypes);
Response response = applicationsApiService.applicationsApplicationIdGenerateKeysPost(applicationId, applicationKeyGenerateRequestDTO, request);
Assert.assertEquals(500, response.getStatus());
}
use of org.wso2.siddhi.service.api.NotFoundException in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImplTestCase method testApplicationsApplicationIdKeysKeyTypeGet.
@Test
public void testApplicationsApplicationIdKeysKeyTypeGet() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String applicationId = UUID.randomUUID().toString();
String keyType = "PRODUCTION";
ApplicationsApiServiceImpl applicationsApiService = new ApplicationsApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
List<String> grantTypes = new ArrayList<>();
grantTypes.add("password");
grantTypes.add("jwt");
OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
oAuthApplicationInfo.setKeyType(keyType);
oAuthApplicationInfo.setClientId(UUID.randomUUID().toString());
oAuthApplicationInfo.setClientSecret(UUID.randomUUID().toString());
oAuthApplicationInfo.setGrantTypes(grantTypes);
Mockito.when(apiStore.getApplicationKeys(applicationId, keyType)).thenReturn(oAuthApplicationInfo);
Response response = applicationsApiService.applicationsApplicationIdKeysKeyTypeGet(applicationId, keyType, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.siddhi.service.api.NotFoundException in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImplTestCase method testApplicationsApplicationIdGetErrorCase.
@Test
public void testApplicationsApplicationIdGetErrorCase() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String applicationId = UUID.randomUUID().toString();
ApplicationsApiServiceImpl applicationsApiService = new ApplicationsApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
Mockito.doThrow(new APIManagementException("Error Occurred", ExceptionCodes.APPLICATION_NOT_FOUND)).when(apiStore).getApplication(applicationId, USER);
Response response = applicationsApiService.applicationsApplicationIdGet(applicationId, null, null, request);
Assert.assertEquals(404, response.getStatus());
}
Aggregations