Search in sources :

Example 86 with ApiDAO

use of org.wso2.carbon.apimgt.core.dao.ApiDAO in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testIsEndpointExist.

@Test(description = "Test if endpoint exists")
public void testIsEndpointExist() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
    Mockito.when(apiDAO.isEndpointExist(ENDPOINT_NAME)).thenReturn(true);
    apiPublisher.isEndpointExist(ENDPOINT_NAME);
    // Error path
    Mockito.when(apiDAO.isEndpointExist(ENDPOINT_NAME)).thenThrow(APIMgtDAOException.class);
    try {
        apiPublisher.isEndpointExist(ENDPOINT_NAME);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't find existence of endpoint :" + ENDPOINT_NAME);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 87 with ApiDAO

use of org.wso2.carbon.apimgt.core.dao.ApiDAO in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testUpdateSwagger20DefinitionWithDifferentSwagger2.

@Test(description = "Save swagger definition for API")
public void testUpdateSwagger20DefinitionWithDifferentSwagger2() throws APIManagementException, IOException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    String uuid = api.getId();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
    KeyManager keyManager = Mockito.mock(KeyManager.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, gatewaySourceGenerator, gateway, keyManager);
    Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.DEVELOPER_ROLE_ID)).thenReturn(DEVELOPER_ROLE);
    Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.ADMIN_ROLE_ID)).thenReturn(ADMIN_ROLE);
    String newSwagger = IOUtils.toString(new FileInputStream("src" + File.separator + "test" + File.separator + "resources" + File.separator + "swagger" + File.separator + "swaggerWithAuthorization" + ".yaml"));
    Mockito.when(apiDAO.getApiSwaggerDefinition(uuid)).thenReturn(SampleTestObjectCreator.apiDefinition);
    Mockito.when(keyManager.retrieveScope("apim:api_create")).thenReturn(new Scope("apim:api_create", "Create " + "API"));
    apiPublisher.saveSwagger20Definition(uuid, newSwagger);
    Mockito.verify(apiDAO, Mockito.times(1)).updateApiDefinition(uuid, newSwagger, USER);
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) API(org.wso2.carbon.apimgt.core.models.API) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) KeyManager(org.wso2.carbon.apimgt.core.api.KeyManager) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) FileInputStream(java.io.FileInputStream) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) Test(org.testng.annotations.Test)

Example 88 with ApiDAO

use of org.wso2.carbon.apimgt.core.dao.ApiDAO 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 89 with ApiDAO

use of org.wso2.carbon.apimgt.core.dao.ApiDAO 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 90 with ApiDAO

use of org.wso2.carbon.apimgt.core.dao.ApiDAO 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)

Aggregations

ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)315 Test (org.testng.annotations.Test)305 API (org.wso2.carbon.apimgt.core.models.API)210 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)108 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)102 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)75 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)65 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)62 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)59 BeforeTest (org.testng.annotations.BeforeTest)50 ArrayList (java.util.ArrayList)48 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)47 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)46 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)45 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)43 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)36 HashMap (java.util.HashMap)31 SQLException (java.sql.SQLException)30 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)30 LifecycleState (org.wso2.carbon.lcm.core.impl.LifecycleState)27