use of org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationKeyGenerateRequestDTO 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.carbon.apimgt.rest.api.store.dto.ApplicationKeyGenerateRequestDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsApplicationIdGenerateKeysPost.
/**
* Generate application keys
*
* @param applicationId Application ID
* @param body Application information which are required to generate keys
* @param request msf4j request object
* @return Generated application key detials
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response applicationsApplicationIdGenerateKeysPost(String applicationId, ApplicationKeyGenerateRequestDTO body, Request request) throws NotFoundException {
try {
String username = RestApiUtil.getLoggedInUsername(request);
APIStore apiConsumer = RestApiUtil.getConsumer(username);
OAuthApplicationInfo oAuthApp = apiConsumer.generateApplicationKeys(applicationId, body.getKeyType().name(), body.getCallbackUrl(), body.getGrantTypesToBeSupported());
ApplicationKeysDTO appKeys = ApplicationKeyMappingUtil.fromApplicationKeysToDTO(oAuthApp);
return Response.ok().entity(appKeys).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while generating application keys for application: " + applicationId;
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_ID, applicationId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationKeyGenerateRequestDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImplTestCase method testApplicationsApplicationIdGenerateKeysPost.
@Test
public void testApplicationsApplicationIdGenerateKeysPost() 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.when(apiStore.generateApplicationKeys(applicationId, "PRODUCTION", null, grantTypes)).thenReturn(oAuthApplicationInfo);
ApplicationKeyGenerateRequestDTO applicationKeyGenerateRequestDTO = new ApplicationKeyGenerateRequestDTO();
applicationKeyGenerateRequestDTO.setKeyType(ApplicationKeyGenerateRequestDTO.KeyTypeEnum.PRODUCTION);
applicationKeyGenerateRequestDTO.setCallbackUrl(null);
applicationKeyGenerateRequestDTO.setGrantTypesToBeSupported(grantTypes);
Response response = applicationsApiService.applicationsApplicationIdGenerateKeysPost(applicationId, applicationKeyGenerateRequestDTO, request);
Assert.assertEquals(200, response.getStatus());
}
Aggregations