Search in sources :

Example 41 with APIPublisher

use of org.wso2.carbon.apimgt.core.api.APIPublisher in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testGetThumbnailImage.

@Test(description = "Get thumbnail image for API")
public void testGetThumbnailImage() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    String uuid = api.getId();
    Mockito.when(apiDAO.getImage(uuid)).thenReturn(null);
    apiPublisher.getThumbnailImage(uuid);
    Mockito.verify(apiDAO, Mockito.times(1)).getImage(uuid);
}
Also used : API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 42 with APIPublisher

use of org.wso2.carbon.apimgt.core.api.APIPublisher in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testUploadDocumentationFile.

@Test(description = "Upload Documentation File")
public void testUploadDocumentationFile() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
    apiPublisher.uploadDocumentationFile(DOC_ID, null, "text/plain");
    Mockito.verify(apiDAO, Mockito.times(1)).addDocumentFileContent(DOC_ID, null, "text/plain", USER);
}
Also used : ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 43 with APIPublisher

use of org.wso2.carbon.apimgt.core.api.APIPublisher in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testUpdateDocumentationInfoJsonParseException.

@Test(description = "Parse exception when updating documentation info", expectedExceptions = APIManagementException.class)
public void testUpdateDocumentationInfoJsonParseException() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    DocumentInfo documentInfo = new DocumentInfo.Builder().fileName("sample_doc.pdf").name("howto_guide").id("").permission("data").build();
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
    apiPublisher.updateDocumentation(API_ID, documentInfo);
}
Also used : ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) Test(org.testng.annotations.Test)

Example 44 with APIPublisher

use of org.wso2.carbon.apimgt.core.api.APIPublisher in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testUpdateEndpoint.

@Test(description = "Update endpoint")
public void testUpdateEndpoint() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, gatewaySourceGenerator, gateway);
    Endpoint endpoint = new Endpoint.Builder(SampleTestObjectCreator.createMockEndpoint()).build();
    Mockito.when(apiDAO.updateEndpoint(endpoint)).thenReturn(true);
    apiPublisher.updateEndpoint(endpoint);
    Mockito.verify(apiDAO, Mockito.times(1)).updateEndpoint(endpoint);
    // Error path
    Mockito.when(apiDAO.updateEndpoint(endpoint)).thenThrow(APIMgtDAOException.class);
    try {
        apiPublisher.updateEndpoint(endpoint);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Failed to update Endpoint : " + endpoint.getName());
    }
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) Test(org.testng.annotations.Test)

Example 45 with APIPublisher

use of org.wso2.carbon.apimgt.core.api.APIPublisher in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testRemovePendingLifecycleWorkflowTaskForAPI.

@Test(description = "Remove api pending lc status change request")
public void testRemovePendingLifecycleWorkflowTaskForAPI() throws APIManagementException, LifecycleException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiLifecycleManager, apiDAO, workflowDAO, gateway);
    APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
    builder.workflowStatus(APILCWorkflowStatus.PENDING.toString());
    API api = builder.build();
    String uuid = api.getId();
    String externalRef = UUID.randomUUID().toString();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    Mockito.when(workflowDAO.getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE)).thenReturn(Optional.of(externalRef));
    apiPublisher.removePendingLifecycleWorkflowTaskForAPI(uuid);
    Mockito.verify(apiDAO, Mockito.times(1)).updateAPIWorkflowStatus(uuid, APILCWorkflowStatus.APPROVED);
    Mockito.verify(workflowDAO, Mockito.times(1)).getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Aggregations

APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)199 Test (org.testng.annotations.Test)185 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)168 Response (javax.ws.rs.core.Response)144 Test (org.junit.Test)143 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)143 API (org.wso2.carbon.apimgt.core.models.API)124 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)120 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)99 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)99 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)93 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)75 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)61 HashMap (java.util.HashMap)60 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)53 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)52 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)45 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)44 DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)41 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)39