Search in sources :

Example 66 with APIStore

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

the class APIStoreImplTestCase method testGetApplicationByUUIDException.

@Test(description = "Exception when retrieving an application by uuid", expectedExceptions = APIManagementException.class)
public void testGetApplicationByUUIDException() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO);
    Mockito.when(applicationDAO.getApplication(UUID)).thenThrow(new APIMgtDAOException("Error occurred while retrieving application - " + UUID, new SQLException()));
    apiStore.getApplicationByUuid(UUID);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 67 with APIStore

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

the class APIStoreImplTestCase method searchAPIsByStoreLabels.

@Test(description = "Search APIs with labels")
public void searchAPIsByStoreLabels() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APIStore apiStore = getApiStoreImpl(apiDAO);
    List<API> apimResultsFromDAO = new ArrayList<>();
    List<String> labelList = new ArrayList<>();
    labelList.add("Default");
    Mockito.when(apiDAO.searchAPIsByStoreLabel(new HashSet<>(), "admin", "pizza", 1, 2, labelList)).thenReturn(apimResultsFromDAO);
    List<API> apis = apiStore.searchAPIsByStoreLabels("pizza", 1, 2, labelList);
    Assert.assertNotNull(apis);
    Mockito.verify(apiDAO, Mockito.atLeastOnce()).searchAPIsByStoreLabel(APIUtils.getAllRolesOfUser("admin"), "admin", "pizza", 1, 2, labelList);
}
Also used : ArrayList(java.util.ArrayList) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 68 with APIStore

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

the class APIStoreImplTestCase method testGetAllCommentsForApiException.

@Test(description = "Exception in dao when retrieving all comments", expectedExceptions = APIManagementException.class)
public void testGetAllCommentsForApiException() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APIStore apiStore = getApiStoreImpl(apiDAO);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    Mockito.when(apiDAO.getAPI(api.getId())).thenReturn(api);
    Mockito.doThrow(new APIMgtDAOException("Error occurred while retrieving all comments for api " + api.getId(), new SQLException())).when(apiDAO).getCommentsForApi(api.getId());
    apiStore.getCommentsForApi(api.getId());
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 69 with APIStore

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

the class APIStoreImplTestCase method getLabelsByType.

@Test(description = "get  labels by STORE type")
public void getLabelsByType() throws Exception {
    LabelDAO labelDao = Mockito.mock(LabelDAO.class);
    APIStore apiStore = getApiStoreImpl(labelDao);
    List<Label> labels = new ArrayList<>();
    Label label = new Label.Builder().id("123").name("Default").type("STORE").accessUrls(new ArrayList<>()).build();
    labels.add(label);
    Mockito.when(labelDao.getLabelsByType("STORE")).thenReturn(labels);
    List<Label> returnedLabels = apiStore.getLabelsByType("STORE");
    Assert.assertNotNull(returnedLabels);
    Mockito.verify(labelDao, Mockito.atLeastOnce()).getLabelsByType("STORE");
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 70 with APIStore

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

the class APIStoreImplTestCase method testGetPolicy.

@Test(description = "Get policy given policy name and policy level")
public void testGetPolicy() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIStore apiStore = getApiStoreImpl(policyDAO);
    apiStore.getPolicy(APIMgtAdminService.PolicyLevel.application, POLICY_NAME);
    Mockito.verify(policyDAO, Mockito.times(1)).getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME);
}
Also used : PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

APIStore (org.wso2.carbon.apimgt.core.api.APIStore)226 Test (org.testng.annotations.Test)109 Test (org.junit.Test)98 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)96 BeforeTest (org.testng.annotations.BeforeTest)93 Response (javax.ws.rs.core.Response)90 Request (org.wso2.msf4j.Request)87 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)72 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)56 API (org.wso2.carbon.apimgt.core.models.API)51 HashMap (java.util.HashMap)49 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)49 ArrayList (java.util.ArrayList)47 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)47 Application (org.wso2.carbon.apimgt.core.models.Application)46 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)38 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)32 SQLException (java.sql.SQLException)31 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)31 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)29