Search in sources :

Example 86 with NotFoundException

use of org.wso2.siddhi.service.api.NotFoundException 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 87 with NotFoundException

use of org.wso2.siddhi.service.api.NotFoundException 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 88 with NotFoundException

use of org.wso2.siddhi.service.api.NotFoundException 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 89 with NotFoundException

use of org.wso2.siddhi.service.api.NotFoundException 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)

Example 90 with NotFoundException

use of org.wso2.siddhi.service.api.NotFoundException in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisApiIdCommentsGetNotFound.

@Test
public void testApisApiIdCommentsGetNotFound() 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);
    Mockito.doThrow(new APICommentException("Error occurred", ExceptionCodes.COMMENT_NOT_FOUND)).when(apiStore).getCommentsForApi(apiId);
    Response response = apisApiService.apisApiIdCommentsGet(apiId, 3, 0, request);
    Assert.assertEquals(404, response.getStatus());
}
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)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)171 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)142 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)120 HashMap (java.util.HashMap)117 Response (javax.ws.rs.core.Response)106 Test (org.junit.Test)100 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)99 Request (org.wso2.msf4j.Request)75 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)48 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)44 ArrayList (java.util.ArrayList)35 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)31 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)29 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)25 Map (java.util.Map)24 ApplicationCreationResponse (org.wso2.carbon.apimgt.core.workflow.ApplicationCreationResponse)23 PoliciesApiServiceImpl (org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl)20 Application (org.wso2.carbon.apimgt.core.models.Application)19 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)18 CharonException (org.wso2.charon3.core.exceptions.CharonException)18