Search in sources :

Example 46 with APIStore

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

the class ApisApiServiceImplTestCase method testApisApiIdCommentsCommentIdDeleteNotFound.

@Test
public void testApisApiIdCommentsCommentIdDeleteNotFound() throws APIManagementException, NotFoundException {
    printTestMethodName();
    String apiId = UUID.randomUUID().toString();
    String commentId = UUID.randomUUID().toString();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
    Request request = getRequest();
    PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
    Mockito.doThrow(new APICommentException("Error occurred", ExceptionCodes.COMMENT_NOT_FOUND)).when(apiStore).deleteComment(commentId, apiId, USER);
    Response response = apisApiService.apisApiIdCommentsCommentIdDelete(commentId, apiId, IF_MATCH, IF_UNMODIFIED_SINCE, request);
    assertEquals(response.getStatus(), 404);
}
Also used : Response(javax.ws.rs.core.Response) Request(org.wso2.msf4j.Request) APICommentException(org.wso2.carbon.apimgt.core.exception.APICommentException) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 47 with APIStore

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

the class ApisApiServiceImplTestCase method testApisApiIdDocumentsDocumentIdGet.

@Test
public void testApisApiIdDocumentsDocumentIdGet() throws APIManagementException, NotFoundException {
    printTestMethodName();
    String apiId = UUID.randomUUID().toString();
    String documentId = UUID.randomUUID().toString();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
    Request request = getRequest();
    PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
    DocumentInfo documentInfoFile = TestUtil.createAPIDoc(documentId, "documentInfo", "", "API1 documentation file", DocumentInfo.DocType.HOWTO, "other type", DocumentInfo.SourceType.FILE, "", DocumentInfo.Visibility.PRIVATE);
    Mockito.when(apiStore.getDocumentationSummary(documentId)).thenReturn(documentInfoFile);
    Response response = apisApiService.apisApiIdDocumentsDocumentIdGet(apiId, documentId, null, null, request);
    Assert.assertEquals(200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Request(org.wso2.msf4j.Request) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 48 with APIStore

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

the class ApisApiServiceImplTestCase method testApisGet.

@Test
public void testApisGet() throws APIManagementException, NotFoundException {
    printTestMethodName();
    String apiId = UUID.randomUUID().toString();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
    Request request = getRequest();
    PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
    Endpoint api1SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
    Endpoint api1ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
    API api = TestUtil.createApi("provider1", apiId, "testapi1", "1.0.0", "Test API 1 - version 1.0.0", TestUtil.createEndpointTypeToIdMap(api1SandBoxEndpointId, api1ProdEndpointId)).build();
    List<API> apiList = new ArrayList<>();
    apiList.add(api);
    Mockito.when(apiStore.searchAPIsByStoreLabels("", 0, 1, new ArrayList<>())).thenReturn(apiList);
    Response response = apisApiService.apisGet(10, 0, "", null, null, request);
    Assert.assertEquals(200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Request(org.wso2.msf4j.Request) ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 49 with APIStore

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

the class ApisApiServiceImplTestCase method testApisApiIdCommentsCommentIdDeleteIfMatchStringExistingFingerprintCheck.

@Test
public void testApisApiIdCommentsCommentIdDeleteIfMatchStringExistingFingerprintCheck() throws APIManagementException, NotFoundException {
    printTestMethodName();
    String apiId = UUID.randomUUID().toString();
    String commentId = UUID.randomUUID().toString();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
    Request request = getRequest();
    PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
    String existingFingerprint = "existingFingerprint";
    Mockito.when(apisApiService.apisApiIdCommentsCommentIdDeleteFingerprint(commentId, apiId, "test", "test", request)).thenReturn(existingFingerprint);
    Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiStore).deleteComment(commentId, apiId, USER);
    Response response = apisApiService.apisApiIdCommentsCommentIdDelete(commentId, apiId, "test", "test", request);
    assertEquals(response.getStatus(), 412);
}
Also used : Response(javax.ws.rs.core.Response) Request(org.wso2.msf4j.Request) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 50 with APIStore

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

the class ApisApiServiceImplTestCase method testApisApiIdUserRatingPut.

@Test
public void testApisApiIdUserRatingPut() throws APIManagementException, NotFoundException {
    printTestMethodName();
    String apiId = UUID.randomUUID().toString();
    String rateId = UUID.randomUUID().toString();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
    Request request = getRequest();
    PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
    Rating rating = new Rating();
    rating.setApiId(apiId);
    rating.setRating(5);
    rating.setUsername(USER);
    rating.setUuid(rateId);
    rating.setCreatedUser(USER);
    rating.setCreatedTime(LocalDateTime.now().minusHours(2));
    rating.setLastUpdatedUser(USER);
    rating.setLastUpdatedTime(LocalDateTime.now());
    RatingDTO ratingDTO = RatingMappingUtil.fromRatingToDTO(rating);
    Rating ratingNow = new Rating();
    ratingNow.setApiId(apiId);
    ratingNow.setRating(3);
    ratingNow.setUsername(USER);
    ratingNow.setUuid(rateId);
    ratingNow.setCreatedUser(USER);
    ratingNow.setCreatedTime(LocalDateTime.now().minusHours(2));
    ratingNow.setLastUpdatedUser(USER);
    ratingNow.setLastUpdatedTime(LocalDateTime.now());
    Mockito.when(apiStore.getRatingForApiFromUser(apiId, USER)).thenReturn(ratingNow);
    Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiStore).updateRating(apiId, ratingNow.getUuid(), rating);
    Mockito.when(apiStore.getRatingByUUID(apiId, ratingNow.getUuid())).thenReturn(ratingNow);
    Response response = apisApiService.apisApiIdUserRatingPut(apiId, ratingDTO, request);
    Assert.assertEquals(200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Rating(org.wso2.carbon.apimgt.core.models.Rating) Request(org.wso2.msf4j.Request) RatingDTO(org.wso2.carbon.apimgt.rest.api.store.dto.RatingDTO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

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