use of io.gravitee.rest.api.model.log.ApplicationRequest in project gravitee-management-rest-api by gravitee-io.
the class LogMapperTest method testConvertFull.
@Test
public void testConvertFull() {
// init
ApplicationRequest applicationRequest = new ApplicationRequest();
applicationRequest.setApi(LOG_API);
applicationRequest.setHost(LOG_HOST);
applicationRequest.setId(LOG_APPLICATION);
Map<String, Map<String, String>> metadata = new HashMap<String, Map<String, String>>();
HashMap<String, String> appMetadata = new HashMap<String, String>();
appMetadata.put(LOG_API, LOG_API);
metadata.put(LOG_APPLICATION, appMetadata);
applicationRequest.setMetadata(metadata);
applicationRequest.setMethod(HttpMethod.CONNECT);
applicationRequest.setPath(LOG_PATH);
applicationRequest.setPlan(LOG_PLAN);
Request request = new Request();
request.setBody(LOG_REQUEST_BODY);
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.add(HttpHeaders.ACCEPT, LOG_ID);
request.setHeaders(requestHeaders);
request.setMethod(HttpMethod.CONNECT);
request.setUri(LOG_REQUEST_URI);
applicationRequest.setRequest(request);
applicationRequest.setRequestContentLength(1L);
Response response = new Response();
response.setBody(LOG_RESPONSE_BODY);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add(HttpHeaders.ACCEPT_CHARSET, LOG_ID);
response.setHeaders(responseHeaders);
response.setStatus(1);
applicationRequest.setResponse(response);
applicationRequest.setResponseContentLength(1L);
applicationRequest.setResponseTime(1);
applicationRequest.setSecurityToken(LOG_SECURITY_TOKEN);
applicationRequest.setSecurityType(LOG_SECURITY_TYPE);
applicationRequest.setStatus(1);
applicationRequest.setTimestamp(1);
applicationRequest.setTransactionId(LOG_TRANSACTION);
applicationRequest.setUser(LOG_USER);
// Test
Log log = logMapper.convert(applicationRequest);
assertNotNull(log);
assertEquals(LOG_API, log.getApi());
assertEquals(LOG_HOST, log.getHost());
assertEquals(LOG_APPLICATION, log.getId());
assertEquals(metadata, log.getMetadata());
assertEquals(io.gravitee.rest.api.portal.rest.model.HttpMethod.CONNECT, log.getMethod());
assertEquals(LOG_PATH, log.getPath());
assertEquals(LOG_PLAN, log.getPlan());
final io.gravitee.rest.api.portal.rest.model.Request logRequest = log.getRequest();
assertNotNull(logRequest);
assertEquals(LOG_REQUEST_BODY, logRequest.getBody());
assertEquals(requestHeaders, logRequest.getHeaders());
assertEquals(io.gravitee.rest.api.portal.rest.model.HttpMethod.CONNECT, logRequest.getMethod());
assertEquals(LOG_REQUEST_URI, logRequest.getUri());
assertEquals(1L, log.getRequestContentLength().longValue());
final io.gravitee.rest.api.portal.rest.model.Response logResponse = log.getResponse();
assertNotNull(logResponse);
assertEquals(LOG_RESPONSE_BODY, logResponse.getBody());
assertEquals(responseHeaders, logResponse.getHeaders());
assertEquals(1, logResponse.getStatus().intValue());
assertEquals(1L, log.getResponseContentLength().longValue());
assertEquals(1L, log.getResponseTime().longValue());
assertEquals(LOG_SECURITY_TOKEN, log.getSecurityToken());
assertEquals(LOG_SECURITY_TYPE, log.getSecurityType());
assertEquals(1, log.getStatus().intValue());
assertEquals(1L, log.getTimestamp().longValue());
assertEquals(LOG_TRANSACTION, log.getTransactionId());
assertEquals(LOG_USER, log.getUser());
}
use of io.gravitee.rest.api.model.log.ApplicationRequest in project gravitee-management-rest-api by gravitee-io.
the class ApplicationLogsResource method applicationLog.
@GET
@Path("/{logId}")
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_LOG, acls = RolePermissionAction.READ) })
public Response applicationLog(@PathParam("applicationId") String applicationId, @PathParam("logId") String logId, @QueryParam("timestamp") Long timestamp) {
// Does application exists ?
applicationService.findById(applicationId);
ApplicationRequest applicationLogs = logsService.findApplicationLog(logId, timestamp);
return Response.ok(logMapper.convert(applicationLogs)).build();
}
use of io.gravitee.rest.api.model.log.ApplicationRequest in project gravitee-management-rest-api by gravitee-io.
the class ApplicationLogsResourceTest method shouldGetLog.
@Test
public void shouldGetLog() {
final ApplicationRequest toBeReturned = new ApplicationRequest();
toBeReturned.setId(LOG);
doReturn(toBeReturned).when(logsService).findApplicationLog(eq(LOG), any());
final Response response = target(APPLICATION).path("logs").path(LOG).queryParam("timestamp", 1).request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
Mockito.verify(logMapper).convert(toBeReturned);
Mockito.verify(logsService).findApplicationLog(LOG, 1L);
Log Log = response.readEntity(Log.class);
assertNotNull(Log);
}
use of io.gravitee.rest.api.model.log.ApplicationRequest in project gravitee-management-rest-api by gravitee-io.
the class LogMapper method convert.
public Log convert(ApplicationRequest applicationRequest) {
final Log logItem = new Log();
logItem.setApi(applicationRequest.getApi());
logItem.setHost(applicationRequest.getHost());
logItem.setId(applicationRequest.getId());
logItem.setMetadata(applicationRequest.getMetadata() == null ? null : new HashMap(applicationRequest.getMetadata()));
logItem.setMethod(HttpMethod.fromValue(applicationRequest.getMethod().name()));
logItem.setPath(applicationRequest.getPath());
logItem.setPlan(applicationRequest.getPlan());
if (applicationRequest.getRequest() != null) {
logItem.setRequest(new Request().body(applicationRequest.getRequest().getBody()).headers(applicationRequest.getRequest().getHeaders()).method(HttpMethod.fromValue(applicationRequest.getRequest().getMethod().name())).uri(applicationRequest.getRequest().getUri()));
}
logItem.setRequestContentLength(applicationRequest.getRequestContentLength());
if (applicationRequest.getResponse() != null) {
logItem.setResponse(new Response().body(applicationRequest.getResponse().getBody()).status(applicationRequest.getResponse().getStatus()).headers(applicationRequest.getResponse().getHeaders()));
}
logItem.setResponseContentLength(applicationRequest.getResponseContentLength());
logItem.setResponseTime(applicationRequest.getResponseTime());
logItem.setSecurityToken(applicationRequest.getSecurityToken());
logItem.setSecurityType(applicationRequest.getSecurityType());
logItem.setStatus(applicationRequest.getStatus());
logItem.setTimestamp(applicationRequest.getTimestamp());
logItem.setTransactionId(applicationRequest.getTransactionId());
logItem.setUser(applicationRequest.getUser());
return logItem;
}
Aggregations