Search in sources :

Example 1 with Request

use of io.gravitee.rest.api.model.log.extended.Request 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());
}
Also used : HttpHeaders(io.gravitee.common.http.HttpHeaders) HashMap(java.util.HashMap) Log(io.gravitee.rest.api.portal.rest.model.Log) ApplicationRequest(io.gravitee.rest.api.model.log.ApplicationRequest) Request(io.gravitee.rest.api.model.log.extended.Request) Response(io.gravitee.rest.api.model.log.extended.Response) ApplicationRequest(io.gravitee.rest.api.model.log.ApplicationRequest) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with Request

use of io.gravitee.rest.api.model.log.extended.Request in project gravitee-management-rest-api by gravitee-io.

the class LogsServiceImpl method createRequest.

private Request createRequest(io.gravitee.repository.log.model.Request repoRequest) {
    if (repoRequest == null) {
        return null;
    }
    Request request = new Request();
    request.setUri(repoRequest.getUri());
    request.setMethod(repoRequest.getMethod());
    request.setHeaders(repoRequest.getHeaders());
    request.setBody(repoRequest.getBody());
    return request;
}
Also used : Request(io.gravitee.rest.api.model.log.extended.Request)

Aggregations

Request (io.gravitee.rest.api.model.log.extended.Request)2 HttpHeaders (io.gravitee.common.http.HttpHeaders)1 ApplicationRequest (io.gravitee.rest.api.model.log.ApplicationRequest)1 Response (io.gravitee.rest.api.model.log.extended.Response)1 Log (io.gravitee.rest.api.portal.rest.model.Log)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1