Search in sources :

Example 61 with APIStore

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

the class APIStoreImplTestCase method testAddApplicationNullPolicy.

@Test(description = "Add an application with null policy", expectedExceptions = APIManagementException.class)
public void testAddApplicationNullPolicy() throws Exception {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO, policyDAO, workflowDAO);
    Application application = new Application(APP_NAME, USER_NAME);
    application.setPolicy(new ApplicationPolicy(TIER));
    Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
    Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, TIER)).thenReturn(null);
    apiStore.addApplication(application);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) 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)

Example 62 with APIStore

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

the class APIStoreImplTestCase method testGetLabelInfoException.

@Test(description = "Exception when retrieving labels", expectedExceptions = LabelException.class)
public void testGetLabelInfoException() throws APIManagementException {
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    APIStore apiStore = getApiStoreImpl(labelDAO);
    List<String> labels = new ArrayList<>();
    labels.add("label");
    Mockito.when(labelDAO.getLabelsByName(labels)).thenThrow(new APIMgtDAOException("Error occurred while retrieving label information", new SQLException()));
    apiStore.getLabelInfo(labels, USER_NAME);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) 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 63 with APIStore

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

the class APIStoreImplTestCase method testGetAPIWithNotAllowedLifecycleStates.

@Test(description = "Test get API with not allowed lifecycle states (Created, Maintenance, Retired)")
public void testGetAPIWithNotAllowedLifecycleStates() throws APIManagementException {
    String exceptionShouldThrowError = "Exception should be thrown when accessing an API in %s state";
    String matchedErrorMessage = "Attempt to access an API which is in a restricted state";
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    Policy policy = new SubscriptionPolicy(UUID, TIER);
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, TIER)).thenReturn(policy);
    APIStore apiStore = getApiStoreImpl(apiDAO, Mockito.mock(ApplicationDAO.class), Mockito.mock(APISubscriptionDAO.class), Mockito.mock(WorkflowDAO.class), Mockito.mock(APIGateway.class), policyDAO);
    API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
    String apiId = apiBuilder.getId();
    List<String> notAllowedStates = new ArrayList<String>() {

        {
            add(APIStatus.CREATED.getStatus());
            add(APIStatus.MAINTENANCE.getStatus());
            add(APIStatus.RETIRED.getStatus());
        }
    };
    for (String notAllowedState : notAllowedStates) {
        apiBuilder.lifeCycleStatus(notAllowedState);
        API api = apiBuilder.build();
        Mockito.when(apiDAO.getAPI(apiId)).thenReturn(api);
        try {
            apiStore.getAPIbyUUID(apiId);
            Assert.fail(exceptionShouldThrowError);
        } catch (APIManagementException e) {
            Assert.assertTrue(e.getMessage().contains(matchedErrorMessage));
        }
    }
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) ArrayList(java.util.ArrayList) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) 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)

Example 64 with APIStore

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

the class APIStoreImplTestCase method getLabelsByTypeException.

@Test(description = "get labels by type Exception", expectedExceptions = Exception.class)
public void getLabelsByTypeException() throws Exception {
    LabelDAO labelDao = Mockito.mock(LabelDAO.class);
    APIStore apiStore = getApiStoreImpl();
    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);
    Mockito.doThrow(new LabelException("Error occurred while retrieving labels ")).when(labelDao).getLabelsByType("STORE");
    apiStore.getLabelsByType("STORE");
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) LabelException(org.wso2.carbon.apimgt.core.exception.LabelException) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 65 with APIStore

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

the class APIStoreImplTestCase method testDeleteCommentDaoException.

@Test(description = "Exception in dao when deleting a specific comment", expectedExceptions = APIMgtResourceNotFoundException.class)
public void testDeleteCommentDaoException() 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);
    Comment comment = SampleTestObjectCreator.createDefaultComment(api.getId());
    Mockito.when(apiDAO.getCommentByUUID(comment.getUuid(), api.getId())).thenReturn(comment);
    Mockito.doThrow(new APIMgtDAOException("Error occurred while deleting comment " + comment.getUuid(), new SQLException())).when(apiDAO).deleteComment(comment.getUuid(), api.getId());
    apiStore.deleteComment(comment.getUuid(), api.getId(), "admin");
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) 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)

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