Search in sources :

Example 1 with ApplicationRequestItem

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());
}
Also used : Log(io.gravitee.rest.api.portal.rest.model.Log) ApplicationRequestItem(io.gravitee.rest.api.model.log.ApplicationRequestItem) Test(org.junit.Test)

Example 2 with ApplicationRequestItem

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);
}
Also used : Log(io.gravitee.rest.api.portal.rest.model.Log) HashMap(java.util.HashMap) ApplicationRequestItem(io.gravitee.rest.api.model.log.ApplicationRequestItem) HashMap(java.util.HashMap) Map(java.util.Map) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 3 with ApplicationRequestItem

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);
}
Also used : LogsResponse(io.gravitee.rest.api.portal.rest.model.LogsResponse) Response(javax.ws.rs.core.Response) SearchLogResponse(io.gravitee.rest.api.model.log.SearchLogResponse) LogsResponse(io.gravitee.rest.api.portal.rest.model.LogsResponse) ApplicationRequestItem(io.gravitee.rest.api.model.log.ApplicationRequestItem) SearchLogResponse(io.gravitee.rest.api.model.log.SearchLogResponse) Links(io.gravitee.rest.api.portal.rest.model.Links) Test(org.junit.Test)

Example 4 with ApplicationRequestItem

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));
}
Also used : HashMap(java.util.HashMap) Log(io.gravitee.rest.api.portal.rest.model.Log) ApplicationRequestItem(io.gravitee.rest.api.model.log.ApplicationRequestItem) ApplicationRequest(io.gravitee.rest.api.model.log.ApplicationRequest) HashMap(java.util.HashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Map(java.util.Map) Before(org.junit.Before)

Aggregations

ApplicationRequestItem (io.gravitee.rest.api.model.log.ApplicationRequestItem)4 Log (io.gravitee.rest.api.portal.rest.model.Log)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 ApplicationRequest (io.gravitee.rest.api.model.log.ApplicationRequest)1 SearchLogResponse (io.gravitee.rest.api.model.log.SearchLogResponse)1 Links (io.gravitee.rest.api.portal.rest.model.Links)1 LogsResponse (io.gravitee.rest.api.portal.rest.model.LogsResponse)1 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1 Response (javax.ws.rs.core.Response)1 Before (org.junit.Before)1