use of io.gravitee.rest.api.model.log.ApplicationRequestItem in project gravitee-management-rest-api by gravitee-io.
the class LogMapperTest method testConvertListItem.
@Test
public void testConvertListItem() {
// init
ApplicationRequestItem applicationRequestItem = new ApplicationRequestItem();
applicationRequestItem.setApi(LOG_API);
applicationRequestItem.setId(LOG_ID);
applicationRequestItem.setMethod(HttpMethod.CONNECT);
applicationRequestItem.setPath(LOG_PATH);
applicationRequestItem.setPlan(LOG_PLAN);
applicationRequestItem.setResponseTime(1);
applicationRequestItem.setStatus(1);
applicationRequestItem.setTimestamp(1);
applicationRequestItem.setTransactionId(LOG_TRANSACTION);
applicationRequestItem.setUser(LOG_USER);
// Test
Log log = logMapper.convert(applicationRequestItem);
assertNotNull(log);
assertEquals(LOG_API, log.getApi());
assertNull(log.getHost());
assertEquals(LOG_ID, log.getId());
assertNull(log.getMetadata());
assertEquals(io.gravitee.rest.api.portal.rest.model.HttpMethod.CONNECT, log.getMethod());
assertEquals(LOG_PATH, log.getPath());
assertEquals(LOG_PLAN, log.getPlan());
assertNull(log.getRequest());
assertNull(log.getRequestContentLength());
assertNull(log.getResponse());
assertNull(log.getResponseContentLength());
assertEquals(1L, log.getResponseTime().longValue());
assertNull(log.getSecurityToken());
assertNull(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.ApplicationRequestItem in project gravitee-management-rest-api by gravitee-io.
the class ApplicationLogsResource method applicationLogs.
@GET
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_LOG, acls = RolePermissionAction.READ) })
public Response applicationLogs(@PathParam("applicationId") String applicationId, @BeanParam PaginationParam paginationParam, @BeanParam LogsParam logsParam) {
// Does application exists ?
applicationService.findById(applicationId);
final SearchLogResponse<ApplicationRequestItem> searchLogResponse = getSearchLogResponse(applicationId, paginationParam, logsParam);
List<Log> logs = searchLogResponse.getLogs().stream().map(logMapper::convert).collect(Collectors.toList());
final Map<String, Object> metadataTotal = new HashMap<>();
metadataTotal.put(METADATA_DATA_TOTAL_KEY, searchLogResponse.getTotal());
final Map<String, Map<String, Object>> metadata = searchLogResponse.getMetadata() == null ? new HashMap() : new HashMap(searchLogResponse.getMetadata());
metadata.put(METADATA_DATA_KEY, metadataTotal);
// No pagination, because logsService did it already
return createListResponse(logs, paginationParam, metadata, false);
}
use of io.gravitee.rest.api.model.log.ApplicationRequestItem in project gravitee-management-rest-api by gravitee-io.
the class ApplicationLogsResourceTest method shouldGetNoLogAndNoLink.
@Test
public void shouldGetNoLogAndNoLink() {
SearchLogResponse<ApplicationRequestItem> emptySearchResponse = new SearchLogResponse<>(0);
emptySearchResponse.setLogs(Collections.emptyList());
doReturn(emptySearchResponse).when(logsService).findByApplication(eq(APPLICATION), any());
final Response response = target(APPLICATION).path("logs").queryParam("page", 1).queryParam("size", 10).queryParam("query", APPLICATION).queryParam("from", 0).queryParam("to", 100).queryParam("field", APPLICATION).queryParam("order", "ASC").request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
LogsResponse logsResponse = response.readEntity(LogsResponse.class);
assertEquals(0, logsResponse.getData().size());
Links links = logsResponse.getLinks();
assertNull(links);
}
use of io.gravitee.rest.api.model.log.ApplicationRequestItem in project gravitee-management-rest-api by gravitee-io.
the class ApplicationLogsResourceTest method init.
@Before
public void init() {
resetAllMocks();
ApplicationRequestItem appLogItem1 = new ApplicationRequestItem();
appLogItem1.setId("A");
ApplicationRequestItem appLogItem2 = new ApplicationRequestItem();
appLogItem2.setId("B");
searchResponse = new SearchLogResponse<>(2);
searchResponse.setLogs(Arrays.asList(appLogItem1, appLogItem2));
metadata = new HashMap<String, Map<String, String>>();
HashMap<String, String> appMetadata = new HashMap<String, String>();
appMetadata.put(APPLICATION, APPLICATION);
metadata.put(APPLICATION, appMetadata);
searchResponse.setMetadata(metadata);
doReturn(searchResponse).when(logsService).findByApplication(eq(APPLICATION), any());
doReturn(new Log()).when(logMapper).convert(any(ApplicationRequestItem.class));
doReturn(new Log()).when(logMapper).convert(any(ApplicationRequest.class));
}
Aggregations