Search in sources :

Example 31 with RepositoryRequestSpec

use of io.crnk.core.engine.dispatcher.RepositoryRequestSpec in project crnk-framework by crnk-project.

the class RepositoryFilterTest method findBulkOneTargetsBulkImpl.

@SuppressWarnings({ "unchecked" })
@Test
public void findBulkOneTargetsBulkImpl() throws Exception {
    taskRelationAdapter.findBulkManyTargets(Arrays.asList(1L), assignedTasksField, queryAdapter);
    ArgumentCaptor<RepositoryFilterContext> contexts = ArgumentCaptor.forClass(RepositoryFilterContext.class);
    Mockito.verify(filter, Mockito.times(0)).filterRequest(contexts.capture(), Mockito.any(RepositoryRequestFilterChain.class));
    Mockito.verify(filter, Mockito.times(1)).filterBulkRequest(contexts.capture(), Mockito.any(RepositoryBulkRequestFilterChain.class));
    Mockito.verify(filter, Mockito.times(1)).filterResult(Mockito.any(RepositoryFilterContext.class), Mockito.any(RepositoryResultFilterChain.class));
    Mockito.verify(filter, Mockito.times(1)).filterLinks(Mockito.any(RepositoryFilterContext.class), Mockito.any(Iterable.class), Mockito.any(RepositoryLinksFilterChain.class));
    Mockito.verify(filter, Mockito.times(1)).filterMeta(Mockito.any(RepositoryFilterContext.class), Mockito.any(Iterable.class), Mockito.any(RepositoryMetaFilterChain.class));
    Assert.assertEquals(1, contexts.getAllValues().size());
    RepositoryFilterContext context1 = contexts.getAllValues().get(0);
    RepositoryRequestSpec requestSpec1 = context1.getRequest();
    Assert.assertEquals(queryAdapter, requestSpec1.getQueryAdapter());
    Assert.assertNull(requestSpec1.getEntity());
    Assert.assertEquals("assignedTasks", requestSpec1.getRelationshipField().getUnderlyingName());
    Assert.assertEquals(HttpMethod.GET, requestSpec1.getMethod());
    Assert.assertEquals(Arrays.asList(1L), requestSpec1.getIds());
    Assert.assertSame(querySpec, requestSpec1.getQuerySpec(userInfo));
}
Also used : RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) ResourceRegistryTest(io.crnk.core.resource.registry.ResourceRegistryTest) Test(org.junit.Test)

Example 32 with RepositoryRequestSpec

use of io.crnk.core.engine.dispatcher.RepositoryRequestSpec in project crnk-framework by crnk-project.

the class SleuthRepositoryFilter method filterRequest.

@Override
public JsonApiResponse filterRequest(RepositoryFilterContext context, RepositoryRequestFilterChain chain) {
    RepositoryRequestSpec request = context.getRequest();
    String query = SleuthUtil.getQuery(request, moduleContext.getResourceRegistry());
    Span span = tracer.createSpan(SleuthUtil.getSpanName(request));
    JsonApiResponse result = null;
    Exception exception = null;
    try {
        span.tag("lc", COMPONENT_NAME);
        result = chain.doFilter(context);
        return result;
    } catch (RuntimeException e) {
        exception = e;
        throw e;
    } finally {
        boolean resultError = result != null && result.getErrors() != null && result.getErrors().iterator().hasNext();
        boolean failed = exception != null || resultError;
        String status = failed ? STRING_EXCEPTION : STRING_OK;
        span.tag(STATUS_CODE_ANNOTATION, status);
        writeQuery(span, query);
        writeResults(span, result);
        tracer.close(span);
    }
}
Also used : RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) Span(org.springframework.cloud.sleuth.Span)

Example 33 with RepositoryRequestSpec

use of io.crnk.core.engine.dispatcher.RepositoryRequestSpec in project crnk-framework by crnk-project.

the class BraveRepositoryFilter method filterRequest.

@Override
public JsonApiResponse filterRequest(RepositoryFilterContext context, RepositoryRequestFilterChain chain) {
    Tracer tracer = tracing.tracer();
    RepositoryRequestSpec request = context.getRequest();
    String query = BraveUtil.getQuery(request, moduleContext.getResourceRegistry());
    Span span = tracer.nextSpan();
    span.name(BraveUtil.getSpanName(request));
    span.tag(Constants.LOCAL_COMPONENT, COMPONENT_NAME);
    span.start();
    JsonApiResponse result = null;
    Exception exception = null;
    try (Tracer.SpanInScope ws = tracer.withSpanInScope(span)) {
        result = chain.doFilter(context);
        return result;
    } catch (RuntimeException e) {
        exception = e;
        throw e;
    } finally {
        boolean resultError = result != null && result.getErrors() != null && result.getErrors().iterator().hasNext();
        boolean failed = exception != null || resultError;
        String status = failed ? STRING_EXCEPTION : STRING_OK;
        span.tag(STATUS_CODE_ANNOTATION, status);
        writeQuery(span, query);
        writeResults(span, result);
        span.finish();
    }
}
Also used : RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) Tracer(brave.Tracer) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) Span(brave.Span)

Aggregations

RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)33 ResourceRegistryTest (io.crnk.core.resource.registry.ResourceRegistryTest)17 Test (org.junit.Test)17 RepositoryFilterContext (io.crnk.core.engine.filter.RepositoryFilterContext)13 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)12 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)10 ResourceField (io.crnk.core.engine.information.resource.ResourceField)8 BulkRelationshipRepositoryV2 (io.crnk.core.repository.BulkRelationshipRepositoryV2)8 RelationshipRepositoryV2 (io.crnk.core.repository.RelationshipRepositoryV2)6 Serializable (java.io.Serializable)6 ResourceRepositoryV2 (io.crnk.core.repository.ResourceRepositoryV2)5 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)4 AnnotatedRelationshipRepositoryAdapter (io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter)4 ResourceRepository (io.crnk.legacy.repository.ResourceRepository)4 QuerySpec (io.crnk.core.queryspec.QuerySpec)3 HashMap (java.util.HashMap)3 User (io.crnk.core.mock.models.User)2 RelationshipRepository (io.crnk.legacy.repository.RelationshipRepository)2 Span (brave.Span)1 Tracer (brave.Tracer)1