use of org.wso2.msf4j.Request in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdRatingsRatingIdGetErrorCase.
@Test
public void testApisApiIdRatingsRatingIdGetErrorCase() throws APIManagementException, NotFoundException {
printTestMethodName();
String apiId = UUID.randomUUID().toString();
String rateId = UUID.randomUUID().toString();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
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 APIRatingException("Error occurred", ExceptionCodes.RATING_NOT_FOUND)).when(apiStore).getRatingForApiFromUser(apiId, USER);
Response response = apisApiService.apisApiIdRatingsGet(apiId, 10, 0, request);
Assert.assertEquals(404, response.getStatus());
}
use of org.wso2.msf4j.Request in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdContentGetErrorCase.
@Test
public void testApisApiIdDocumentsDocumentIdContentGetErrorCase() throws APIManagementException, NotFoundException {
printTestMethodName();
String apiId = UUID.randomUUID().toString();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
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);
String documentIdFile = UUID.randomUUID().toString();
String documentIdInline = UUID.randomUUID().toString();
Mockito.doThrow(new APIManagementException("Error Occurred", ExceptionCodes.DOCUMENT_CONTENT_NOT_FOUND)).when(apiStore).getDocumentationContent(documentIdFile);
Mockito.doThrow(new APIManagementException("Error Occurred", ExceptionCodes.DOCUMENT_CONTENT_NOT_FOUND)).when(apiStore).getDocumentationContent(documentIdInline);
Response responseFile = apisApiService.apisApiIdDocumentsDocumentIdContentGet(apiId, documentIdFile, null, null, request);
Response responseInline = apisApiService.apisApiIdDocumentsDocumentIdContentGet(apiId, documentIdInline, null, null, request);
Assert.assertEquals(404, responseFile.getStatus());
Assert.assertEquals(404, responseInline.getStatus());
}
use of org.wso2.msf4j.Request in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDocumentsGetErrorCase.
@Test
public void testApisApiIdDocumentsGetErrorCase() throws APIManagementException, NotFoundException {
printTestMethodName();
String apiId = UUID.randomUUID().toString();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
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.DOCUMENT_NOT_FOUND)).when(apiStore).getAllDocumentation(apiId, 0, 10);
Response response = apisApiService.apisApiIdDocumentsGet(apiId, 10, 0, null, request);
Assert.assertEquals(404, response.getStatus());
}
use of org.wso2.msf4j.Request in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdWsdlGetArchive.
@Test
public void testApisApiIdWsdlGetArchive() throws Exception {
printTestMethodName();
final String uuid = "11112222-3333-4444-5555-666677778888";
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
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.doReturn(true).when(apiStore).isWSDLExists(uuid);
Mockito.doReturn(true).when(apiStore).isWSDLArchiveExists(uuid);
WSDLArchiveInfo archiveInfo = new WSDLArchiveInfo(WSDL_ZIP_LOCATION, WSDL_ZIP);
Mockito.doReturn(archiveInfo).when(apiStore).getAPIWSDLArchive(uuid, "Sample");
Response response = apisApiService.apisApiIdWsdlGet(uuid, "Sample", null, null, request);
Assert.assertEquals(response.getStatus(), 200);
Assert.assertTrue(response.getEntity() instanceof File);
}
use of org.wso2.msf4j.Request in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImplTestCase method testApplicationsPost.
@Test
public void testApplicationsPost() 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);
Application application = getSampleApplication(applicationId);
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);
List<ApplicationKeysDTO> applicationKeysDTOList = new ArrayList<>();
applicationKeysDTOList.add(applicationKeysDTO);
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setApplicationId(applicationId);
applicationDTO.setDescription("sample application");
applicationDTO.setName("app1");
applicationDTO.setSubscriber("subscriber");
applicationDTO.setPermission("permission");
applicationDTO.setLifeCycleStatus("APPROVED");
applicationDTO.setThrottlingTier("UNLIMITED");
applicationDTO.setToken(applicationTokenDTO);
applicationDTO.setKeys(applicationKeysDTOList);
Mockito.doThrow(new APIManagementException("Error Occurred", ExceptionCodes.INTERNAL_ERROR)).when(apiStore).addApplication(application);
Response response = applicationsApiService.applicationsPost(applicationDTO, request);
Assert.assertEquals(500, response.getStatus());
}
Aggregations