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);
}
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());
}
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());
}
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);
}
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());
}
Aggregations