use of org.wso2.carbon.apimgt.rest.api.store.dto.DedicatedGatewayDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdDedicatedGatewayPutForInvalidAPI.
@Test
public void testApisApiIdDedicatedGatewayPutForInvalidAPI() throws Exception {
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String apiId = UUID.randomUUID().toString();
Mockito.doReturn(false).when(apiPublisher).isAPIExists(apiId);
Response response = apisApiService.apisApiIdDedicatedGatewayPut(apiId, new DedicatedGatewayDTO(), null, null, getRequest());
assertEquals(ExceptionCodes.API_NOT_FOUND.getHttpStatusCode(), response.getStatus());
assertTrue(response.getEntity().toString().contains(ExceptionCodes.API_NOT_FOUND.getErrorMessage()));
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.DedicatedGatewayDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdDedicatedGatewayGet.
/**
* Retrive Dedicated Gateway of an API
*
* @param apiId UUID of API
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return 200 OK if the opration was successful
* @throws NotFoundException when the particular resource does not exist
*/
@Override
public Response apisApiIdDedicatedGatewayGet(String apiId, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
if (!apiPublisher.isAPIExists(apiId)) {
String errorMessage = "API not found : " + apiId;
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.API_NOT_FOUND);
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
String existingFingerprint = apisApiIdGetFingerprint(apiId, null, null, request);
if (!StringUtils.isEmpty(ifNoneMatch) && !StringUtils.isEmpty(existingFingerprint) && ifNoneMatch.contains(existingFingerprint)) {
return Response.notModified().build();
}
DedicatedGateway dedicatedGateway = apiPublisher.getDedicatedGateway(apiId);
if (dedicatedGateway != null) {
DedicatedGatewayDTO dedicatedGatewayDTO = MappingUtil.toDedicatedGatewayDTO(dedicatedGateway);
return Response.ok().header(HttpHeaders.ETAG, "\"" + existingFingerprint + "\"").entity(dedicatedGatewayDTO).build();
} else {
String msg = "Dedicated Gateway not found for " + apiId;
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(msg, ExceptionCodes.DEDICATED_GATEWAY_DETAILS_NOT_FOUND);
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
APIUtils.logDebug(msg, log);
return Response.status(Response.Status.NOT_FOUND).entity(errorDTO).build();
}
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving dedicated gateway of the API : " + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.DedicatedGatewayDTO in project carbon-apimgt by wso2.
the class DedicatedGatewayMappingUtil method toDedicatedGatewayDTO.
/**
* This method maps the the DedicatedGateway object to DedicatedGatewayDTO
*
* @param dedicatedGateway DedicatedGateway object
* @return Dedicated Gateway Object
*/
public static DedicatedGatewayDTO toDedicatedGatewayDTO(DedicatedGateway dedicatedGateway) {
DedicatedGatewayDTO dedicatedGatewayDTO = new DedicatedGatewayDTO();
dedicatedGatewayDTO.setIsEnabled(dedicatedGateway.isEnabled());
return dedicatedGatewayDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.DedicatedGatewayDTO in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImplTestCase method testCompositeApisApiIdDedicatedGatewayPutForInvalidAPI.
@Test
public void testCompositeApisApiIdDedicatedGatewayPutForInvalidAPI() throws Exception {
TestUtil.printTestMethodName();
String apiID = UUID.randomUUID().toString();
CompositeApisApiServiceImpl compositeApisApiService = new CompositeApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
Request request = TestUtil.getRequest();
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Mockito.when(apiStore.isCompositeAPIExist(apiID)).thenReturn(Boolean.FALSE);
Response response = compositeApisApiService.compositeApisApiIdDedicatedGatewayPut(apiID, new DedicatedGatewayDTO(), null, null, request);
Assert.assertEquals(ExceptionCodes.API_NOT_FOUND.getHttpStatusCode(), response.getStatus());
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.DedicatedGatewayDTO in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImpl method compositeApisApiIdDedicatedGatewayGet.
/**
* Retrieve Dedicated Gateway of an API
*
* @param apiId UUID of API
* @param ifNoneMatch ifNoneMatch header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return 200 OK if the operation was successful
* @throws NotFoundException when the particular resource does not exist
*/
@Override
public Response compositeApisApiIdDedicatedGatewayGet(String apiId, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
if (!apiStore.isCompositeAPIExist(apiId)) {
String errorMessage = "API not found : " + apiId;
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.API_NOT_FOUND);
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
String existingFingerprint = compositeApisApiIdGetFingerprint(apiId, ifNoneMatch, ifModifiedSince, request);
if (!StringUtils.isEmpty(ifNoneMatch) && !StringUtils.isEmpty(existingFingerprint) && ifNoneMatch.contains(existingFingerprint)) {
return Response.notModified().build();
}
DedicatedGateway dedicatedGateway = apiStore.getDedicatedGateway(apiId);
if (dedicatedGateway != null) {
DedicatedGatewayDTO dedicatedGatewayDTO = DedicatedGatewayMappingUtil.toDedicatedGatewayDTO(dedicatedGateway);
return Response.ok().header(HttpHeaders.ETAG, "\"" + existingFingerprint + "\"").entity(dedicatedGatewayDTO).build();
} else {
String msg = "Dedicated Gateway not found for " + apiId;
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(msg, ExceptionCodes.DEDICATED_GATEWAY_DETAILS_NOT_FOUND);
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(errorDTO).build();
}
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving dedicated gateway of the API : " + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations