Search in sources :

Example 71 with APIStore

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

the class APIStoreImplTestCase method testDeleteCommentApiMissingException.

@Test(description = "Exception when deleting a comment due to missing api", expectedExceptions = APIManagementException.class)
public void testDeleteCommentApiMissingException() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APIStore apiStore = getApiStoreImpl(apiDAO);
    String randomUUIDForApi = java.util.UUID.randomUUID().toString();
    Mockito.when(apiDAO.getAPI(randomUUIDForApi)).thenReturn(null);
    String randomUUIDForComment = java.util.UUID.randomUUID().toString();
    apiStore.deleteComment(randomUUIDForComment, randomUUIDForApi, "admin");
}
Also used : 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 72 with APIStore

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

the class APIStoreImplTestCase method testGetAPIWSDLArchive.

@Test(description = "Retrieve a WSDL archive of an API")
public void testGetAPIWSDLArchive() throws APIManagementException, IOException {
    final String labelName = "SampleLabel";
    Label label = SampleTestObjectCreator.createLabel(labelName, SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    List<String> labels = new ArrayList<>();
    labels.add(label.getName());
    API api = SampleTestObjectCreator.createDefaultAPI().labels(labels).build();
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    APIStore apiStore = getApiStoreImpl(apiDAO, labelDAO);
    Mockito.when(apiDAO.getAPI(api.getId())).thenReturn(api);
    Mockito.when(labelDAO.getLabelByName(labelName)).thenReturn(label);
    Mockito.when(apiDAO.getWSDLArchive(api.getId())).thenReturn(SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream());
    String expectedEndpoint = SampleTestObjectCreator.ACCESS_URL + labelName + (api.getContext().startsWith("/") ? api.getContext() : "/" + api.getContext());
    WSDLArchiveInfo archiveInfo = apiStore.getAPIWSDLArchive(api.getId(), label.getName());
    Assert.assertNotNull(archiveInfo);
    Assert.assertNotNull(archiveInfo.getWsdlInfo());
    Assert.assertNotNull(archiveInfo.getWsdlInfo().getEndpoints());
    Map<String, String> endpoints = archiveInfo.getWsdlInfo().getEndpoints();
    Assert.assertTrue(endpoints.containsValue(expectedEndpoint));
    Assert.assertFalse(endpoints.containsValue(SampleTestObjectCreator.ORIGINAL_ENDPOINT_STOCK_QUOTE));
    Assert.assertFalse(endpoints.containsValue(SampleTestObjectCreator.ORIGINAL_ENDPOINT_WEATHER));
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) WSDLArchiveInfo(org.wso2.carbon.apimgt.core.models.WSDLArchiveInfo) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) 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 73 with APIStore

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

the class APIStoreImplTestCase method testCompleteApplicationWorkflowWithoutReference.

// End of exception testing
@Test(description = "Exception when completing application creation workflow without a reference", expectedExceptions = APIManagementException.class)
public void testCompleteApplicationWorkflowWithoutReference() throws Exception {
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO, workflowDAO);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    WorkflowExecutor executor = new DefaultWorkflowExecutor();
    Workflow workflow = new ApplicationCreationWorkflow(applicationDAO, workflowDAO, apiGateway);
    workflow.setWorkflowReference(null);
    apiStore.completeWorkflow(executor, workflow);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow) ApplicationCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow) ApplicationUpdateWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationUpdateWorkflow) SubscriptionCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.SubscriptionCreationWorkflow) ApplicationCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow) WorkflowExecutor(org.wso2.carbon.apimgt.core.api.WorkflowExecutor) DefaultWorkflowExecutor(org.wso2.carbon.apimgt.core.workflow.DefaultWorkflowExecutor) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) DefaultWorkflowExecutor(org.wso2.carbon.apimgt.core.workflow.DefaultWorkflowExecutor) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 74 with APIStore

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

the class APIStoreImplTestCase method testAddRatingDaoException.

/**
 * Tests to catch exceptions in methods
 */
@Test(description = "Add rating exception in dao", expectedExceptions = APIRatingException.class)
public void testAddRatingDaoException() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APIStore apiStore = getApiStoreImpl(apiDAO);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    Mockito.when(apiDAO.isAPIExists(api.getId())).thenReturn(true);
    Rating rating = SampleTestObjectCreator.createDefaultRating(api.getId());
    Mockito.when(apiDAO.getRatingByUUID(api.getId(), rating.getUuid())).thenReturn(rating);
    Mockito.doThrow(new APIMgtDAOException("Error occurred while adding rating for api", new SQLException())).when(apiDAO).addRating(api.getId(), rating);
    apiStore.addRating(api.getId(), rating);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Rating(org.wso2.carbon.apimgt.core.models.Rating) 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 75 with APIStore

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

the class APIStoreImplTestCase method testDeleteComment.

@Test(description = "Delete comment")
public void testDeleteComment() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APIStore apiStore = getApiStoreImpl(apiDAO);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    Mockito.when(apiDAO.isAPIExists(api.getId())).thenReturn(true);
    Comment comment = SampleTestObjectCreator.createDefaultComment(api.getId());
    Mockito.when(apiDAO.getCommentByUUID(comment.getUuid(), api.getId())).thenReturn(comment);
    apiStore.deleteComment(comment.getUuid(), api.getId(), "admin");
    Mockito.verify(apiDAO, Mockito.times(1)).isAPIExists(api.getId());
    Mockito.verify(apiDAO, Mockito.times(1)).deleteComment(comment.getUuid(), api.getId());
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) 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