use of org.wso2.carbon.apimgt.core.api.APIStore 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.core.api.APIStore 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.carbon.apimgt.core.api.APIStore 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());
}
use of org.wso2.carbon.apimgt.core.api.APIStore in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImplTestCase method testApplicationsApplicationIdKeysKeyTypePut.
@Test
public void testApplicationsApplicationIdKeysKeyTypePut() 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();
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);
ApplicationTokenDTO applicationTokenDTO = new ApplicationTokenDTO();
applicationTokenDTO.setAccessToken(accessToken);
applicationTokenDTO.setTokenScopes("SCOPE1");
applicationTokenDTO.setValidityTime((long) 100000);
List<String> grantTypes = new ArrayList<>();
grantTypes.add("password");
grantTypes.add("jwt");
ApplicationKeysDTO applicationKeysDTO = new ApplicationKeysDTO();
applicationKeysDTO.setConsumerKey(clientID);
applicationKeysDTO.setConsumerSecret(clientSecret);
applicationKeysDTO.setKeyType(ApplicationKeysDTO.KeyTypeEnum.PRODUCTION);
applicationKeysDTO.setCallbackUrl(null);
applicationKeysDTO.setSupportedGrantTypes(grantTypes);
OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
oAuthApplicationInfo.setKeyType(keyType);
oAuthApplicationInfo.setClientId(UUID.randomUUID().toString());
oAuthApplicationInfo.setClientSecret(UUID.randomUUID().toString());
oAuthApplicationInfo.setGrantTypes(grantTypes);
Mockito.when(apiStore.updateGrantTypesAndCallbackURL(applicationId, keyType, grantTypes, null)).thenReturn(oAuthApplicationInfo);
Response response = applicationsApiService.applicationsApplicationIdKeysKeyTypePut(applicationId, keyType, applicationKeysDTO, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.carbon.apimgt.core.api.APIStore in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImplTestCase method testApplicationsGetQueryErrorCase.
@Test
public void testApplicationsGetQueryErrorCase() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
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).getApplicationByName(USER, "*");
Response response = applicationsApiService.applicationsGet("*", 10, 0, null, request);
Assert.assertEquals(404, response.getStatus());
}
Aggregations