use of org.wso2.carbon.apimgt.rest.api.store.dto.APIListDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method apisGetTestCase.
@Test
public void apisGetTestCase() throws Exception {
String labels = "ZONE_ONE,ZONE_TWO";
String[] gatewayLabels = labels.split(",");
List<String> labelList = new ArrayList<String>(Arrays.asList(gatewayLabels));
APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
List<API> apiList = new ArrayList<>();
apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
Mockito.when(apiMgtAdminService.getAPIsByStatus(labelList, "Published")).thenReturn(apiList);
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
Response response = apisApiService.apisGet(labels, "Published", getRequest());
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
Integer count = ((APIListDTO) response.getEntity()).getCount();
Assert.assertEquals(count.intValue(), 3);
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.APIListDTO in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImpl method compositeApisGet.
@Override
public Response compositeApisGet(Integer limit, Integer offset, String query, String ifNoneMatch, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
CompositeAPIListDTO apiListDTO = null;
try {
apiListDTO = CompositeAPIMappingUtil.toCompositeAPIListDTO(RestApiUtil.getConsumer(username).searchCompositeAPIs(query, offset, limit));
return Response.ok().entity(apiListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving APIs";
HashMap<String, String> paramList = new HashMap<String, String>();
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.APIListDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisGet.
/**
* Retrives all APIs that qualifies for the given fitering attributes
*
* @param limit maximum APIs to return
* @param offset starting position of the pagination
* @param query search query
* @param ifNoneMatch If-None-Match header value
* @param request msf4j request object
* @return a list of qualifying APIs
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisGet(Integer limit, Integer offset, String query, String ifNoneMatch, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
APIListDTO apiListDTO = null;
try {
apiListDTO = MappingUtil.toAPIListDTO(RestAPIPublisherUtil.getApiPublisher(username).searchAPIs(limit, offset, query));
return Response.ok().entity(apiListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving APIs";
HashMap<String, String> paramList = new HashMap<String, String>();
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList, e);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.APIListDTO in project carbon-apimgt by wso2.
the class MappingUtilTestCase method toAPIListDTOTest.
@Test
public void toAPIListDTOTest() {
List<API> apiList = new ArrayList<>();
apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
APIListDTO apDTOList = MappingUtil.toAPIListDTO(apiList);
Assert.assertEquals(apiList.size(), apDTOList.getList().size());
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.APIListDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisGet.
/**
* Retrieves APIs qualifying under given search condition
*
* @param limit maximum number of APIs returns
* @param offset starting index
* @param labels Labels of the store for which the apis need to be retrieved
* @param query search condition
* @param ifNoneMatch If-None-Match header value
* @param request msf4j request object
* @return matched APIs for the given search condition
*/
@Override
public Response apisGet(Integer limit, Integer offset, String labels, String query, String ifNoneMatch, Request request) throws NotFoundException {
List<API> apisResult = null;
APIListDTO apiListDTO = null;
try {
String username = RestApiUtil.getLoggedInUsername(request);
APIStore apiStore = RestApiUtil.getConsumer(username);
List<String> labelList = new ArrayList<>();
if (labels != null) {
labelList = Arrays.asList(labels.split(","));
}
apisResult = apiStore.searchAPIsByStoreLabels(query, offset, limit, labelList);
// convert API
apiListDTO = APIMappingUtil.toAPIListDTO(apisResult);
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving APIs ";
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_NAME, query);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
return Response.ok().entity(apiListDTO).build();
}
Aggregations