use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdGetNotFound.
@Test
public void testApisApiIdDocumentsDocumentIdGetNotFound() throws Exception {
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String documentId = UUID.randomUUID().toString();
String apiId = UUID.randomUUID().toString();
Mockito.doReturn(null).doThrow(new IllegalArgumentException()).when(apiPublisher).getDocumentationSummary(documentId);
Response response = apisApiService.apisApiIdDocumentsDocumentIdGet(apiId, documentId, null, null, getRequest());
assertEquals(response.getStatus(), 404);
assertTrue(response.getEntity().toString().contains("Documntation not found"));
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisImportDefinitionPostWSDLWithInvalidImplementationType.
@Test
public void testApisImportDefinitionPostWSDLWithInvalidImplementationType() throws Exception {
printTestMethodName();
File file = new File(getClass().getClassLoader().getResource(WSDL_FILE_LOCATION).getFile());
FileInputStream fis = new FileInputStream(file);
FileInfo fileInfo = new FileInfo();
fileInfo.setFileName(WSDL_FILE);
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
String apiId = UUID.randomUUID().toString();
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().id(apiId);
API api = apiBuilder.build();
APIDTO apiDto = MappingUtil.toAPIDto(api);
ObjectMapper objectMapper = new ObjectMapper();
String additionalProperties = objectMapper.writeValueAsString(apiDto);
powerMockDefaultAPIPublisher();
Response response = apisApiService.apisImportDefinitionPost(WSDL, fis, fileInfo, null, additionalProperties, "InvalidType", null, null, getRequest());
fis.close();
assertEquals(response.getStatus(), 400);
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisChangeLifecyclePostWithChecklistItemChange.
@Test
public void testApisChangeLifecyclePostWithChecklistItemChange() throws Exception {
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
String checklist = "test1:test1,test2:test2";
String action = "CheckListItemChange";
WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
Map<String, Boolean> lifecycleChecklistMap = new HashMap<>();
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String apiId = UUID.randomUUID().toString();
Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiPublisher).updateCheckListItem(apiId, action, lifecycleChecklistMap);
Response response = apisApiService.apisChangeLifecyclePost(action, apiId, checklist, null, null, getRequest());
assertEquals(response.getStatus(), 200);
assertTrue(response.getEntity().toString().contains("APPROVED"));
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisValidateDefinitionPostException.
@Test
public void testApisValidateDefinitionPostException() throws Exception {
printTestMethodName();
File file = new File(getClass().getClassLoader().getResource(WSDL_ZIP_LOCATION).getFile());
FileInputStream fis = new FileInputStream(file);
FileInfo fileInfo = new FileInfo();
fileInfo.setFileName(WSDL_ZIP);
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = powerMockDefaultAPIPublisher();
Mockito.doThrow(new APIMgtWSDLException("Error while validation", ExceptionCodes.INTERNAL_WSDL_EXCEPTION)).when(apiPublisher).extractAndValidateWSDLArchive(fis);
Response response = apisApiService.apisValidateDefinitionPost(WSDL, fis, fileInfo, null, getRequest());
fis.close();
assertEquals(response.getStatus(), 500);
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdScopesPostWithInvalidscopebindingType.
@Test
public void testApisApiIdScopesPostWithInvalidscopebindingType() throws Exception {
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String apiId = UUID.randomUUID().toString();
Scope scope = new Scope("api_view", "api view");
Mockito.doNothing().when(apiPublisher).addScopeToTheApi(apiId, scope);
Response response = apisApiService.apisApiIdScopesPost(apiId, MappingUtil.scopeDto(scope, "permission"), null, null, getRequest());
assertEquals(response.getStatus(), 412);
}
Aggregations