use of org.wso2.carbon.apimgt.api.model.APIPublisher in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisValidateDefinitionPostWSDLArchive.
@Test
public void testApisValidateDefinitionPostWSDLArchive() 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();
WSDLArchiveInfo archiveInfo = new WSDLArchiveInfo("/tmp", "sample.zip");
WSDLInfo wsdlInfo = new WSDLInfo();
wsdlInfo.setVersion("1.1");
archiveInfo.setWsdlInfo(wsdlInfo);
Mockito.doReturn(archiveInfo).doThrow(new IllegalArgumentException()).when(apiPublisher).extractAndValidateWSDLArchive(fis);
Response response = apisApiService.apisValidateDefinitionPost(WSDL, fis, fileInfo, null, getRequest());
fis.close();
assertEquals(response.getStatus(), 200);
assertTrue(response.getEntity() instanceof APIDefinitionValidationResponseDTO);
assertTrue(((APIDefinitionValidationResponseDTO) response.getEntity()).getIsValid());
}
use of org.wso2.carbon.apimgt.api.model.APIPublisher in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdPut.
@Test
public void testApisApiIdDocumentsDocumentIdPut() throws Exception {
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
DocumentInfo documentInfo1 = SampleTestObjectCreator.createDefaultDocumentationInfo().build();
DocumentInfo documentInfo2 = SampleTestObjectCreator.createDefaultDocumentationInfo().id(documentInfo1.getId()).summary("My new summary").build();
DocumentDTO documentDTO = MappingUtil.toDocumentDTO(documentInfo2);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String documentId = UUID.randomUUID().toString();
String apiId = UUID.randomUUID().toString();
Mockito.doReturn(documentInfo1).doReturn(documentInfo2).doThrow(new IllegalArgumentException()).when(apiPublisher).getDocumentationSummary(documentId);
Mockito.doReturn("updated").doThrow(new IllegalArgumentException()).when(apiPublisher).updateDocumentation(apiId, documentInfo1);
Response response = apisApiService.apisApiIdDocumentsDocumentIdPut(apiId, documentId, documentDTO, null, null, getRequest());
assertEquals(response.getStatus(), 200);
assertTrue(response.getEntity().toString().contains("My new summary"));
}
use of org.wso2.carbon.apimgt.api.model.APIPublisher in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdContentPostAPIManagementException.
@Test
public void testApisApiIdDocumentsDocumentIdContentPostAPIManagementException() throws Exception {
String inlineContent = "INLINE CONTENT";
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String api1Id = UUID.randomUUID().toString();
String documentId = UUID.randomUUID().toString();
Mockito.doThrow(new APIManagementException("Error Occurred", ExceptionCodes.DOCUMENT_CONTENT_NOT_FOUND)).when(apiPublisher).getDocumentationSummary(documentId);
Response response = apisApiService.apisApiIdDocumentsDocumentIdContentPost(api1Id, documentId, null, null, null, null, null, getRequest());
assertEquals(response.getStatus(), 404);
assertTrue(response.getEntity().toString().contains("Document content not found"));
}
use of org.wso2.carbon.apimgt.api.model.APIPublisher in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDedicatedGatewayPutForInvalidAPI.
@Test
public void testApisApiIdDedicatedGatewayPutForInvalidAPI() 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();
Mockito.doReturn(false).when(apiPublisher).isAPIExists(apiId);
Response response = apisApiService.apisApiIdDedicatedGatewayPut(apiId, new DedicatedGatewayDTO(), null, null, getRequest());
assertEquals(ExceptionCodes.API_NOT_FOUND.getHttpStatusCode(), response.getStatus());
assertTrue(response.getEntity().toString().contains(ExceptionCodes.API_NOT_FOUND.getErrorMessage()));
}
use of org.wso2.carbon.apimgt.api.model.APIPublisher in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisHeadNoWord.
@Test
public void testApisHeadNoWord() throws Exception {
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Mockito.doReturn(true).doThrow(new IllegalArgumentException()).when(apiPublisher).checkIfAPIContextExists("testContext");
Response response = apisApiService.apisHead("", null, getRequest());
assertEquals(response.getStatus(), 400);
}
Aggregations