Search in sources :

Example 6 with ActionPath

use of io.crnk.core.engine.internal.dispatcher.path.ActionPath in project crnk-framework by crnk-project.

the class BasicActionTest method testInvokeResourceAction.

@Test
public void testInvokeResourceAction() {
    Schedule schedule = new Schedule();
    schedule.setId(1L);
    schedule.setName("scheduleName");
    scheduleRepo.create(schedule);
    String result = scheduleRepo.resourceAction(1, "hello");
    Assert.assertEquals("resource action: hello@scheduleName", result);
    // check filters
    ArgumentCaptor<DocumentFilterContext> contexts = ArgumentCaptor.forClass(DocumentFilterContext.class);
    Mockito.verify(filter, Mockito.times(2)).filter(contexts.capture(), Mockito.any(DocumentFilterChain.class));
    DocumentFilterContext actionContext = contexts.getAllValues().get(1);
    Assert.assertEquals("GET", actionContext.getMethod());
    Assert.assertTrue(actionContext.getJsonPath() instanceof ActionPath);
}
Also used : DocumentFilterContext(io.crnk.core.engine.filter.DocumentFilterContext) Schedule(io.crnk.test.mock.models.Schedule) DocumentFilterChain(io.crnk.core.engine.filter.DocumentFilterChain) ActionPath(io.crnk.core.engine.internal.dispatcher.path.ActionPath) Test(org.junit.Test) AbstractClientTest(io.crnk.client.AbstractClientTest)

Example 7 with ActionPath

use of io.crnk.core.engine.internal.dispatcher.path.ActionPath in project crnk-framework by crnk-project.

the class BasicActionTest method testInvokeRepositoryAction.

@Test
@Ignore
public // The DocumentFilterContext is not invoked with this request any more
void testInvokeRepositoryAction() {
    String result = scheduleRepo.repositoryAction("hello");
    Assert.assertEquals("repository action: hello", result);
    // check filters
    ArgumentCaptor<DocumentFilterContext> contexts = ArgumentCaptor.forClass(DocumentFilterContext.class);
    Mockito.verify(filter, Mockito.times(1)).filter(contexts.capture(), Mockito.any(DocumentFilterChain.class));
    DocumentFilterContext actionContext = contexts.getAllValues().get(0);
    Assert.assertEquals("GET", actionContext.getMethod());
    Assert.assertTrue(actionContext.getJsonPath() instanceof ActionPath);
}
Also used : DocumentFilterContext(io.crnk.core.engine.filter.DocumentFilterContext) DocumentFilterChain(io.crnk.core.engine.filter.DocumentFilterChain) ActionPath(io.crnk.core.engine.internal.dispatcher.path.ActionPath) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractClientTest(io.crnk.client.AbstractClientTest)

Example 8 with ActionPath

use of io.crnk.core.engine.internal.dispatcher.path.ActionPath in project crnk-framework by crnk-project.

the class JsonApiActionResponseTest method testInvokeRepositoryActionWithException.

@Test
public void testInvokeRepositoryActionWithException() {
    // resources should be received in json api format
    String url = getBaseUri() + "schedules/repositoryActionWithException?msg=hello";
    io.restassured.response.Response response = RestAssured.get(url);
    Assert.assertEquals(403, response.getStatusCode());
    response.then().assertThat().body("errors[0].status", Matchers.equalTo("403"));
    // check filters
    ArgumentCaptor<DocumentFilterContext> contexts = ArgumentCaptor.forClass(DocumentFilterContext.class);
    Mockito.verify(filter, Mockito.times(1)).filter(contexts.capture(), Mockito.any(DocumentFilterChain.class));
    DocumentFilterContext actionContext = contexts.getAllValues().get(0);
    Assert.assertEquals("GET", actionContext.getMethod());
    Assert.assertTrue(actionContext.getJsonPath() instanceof ActionPath);
}
Also used : DocumentFilterContext(io.crnk.core.engine.filter.DocumentFilterContext) DocumentFilterChain(io.crnk.core.engine.filter.DocumentFilterChain) ActionPath(io.crnk.core.engine.internal.dispatcher.path.ActionPath) Test(org.junit.Test) AbstractClientTest(io.crnk.client.AbstractClientTest)

Example 9 with ActionPath

use of io.crnk.core.engine.internal.dispatcher.path.ActionPath in project crnk-framework by crnk-project.

the class JsonApiActionResponseTest method testInvokeRepositoryAction.

@Test
@Ignore
public // The DocumentFilterContext is not invoked with this request any more
void testInvokeRepositoryAction() {
    // tag::invokeService[]
    String result = scheduleRepository.repositoryAction("hello");
    Assert.assertEquals("repository action: hello", result);
    // end::invokeService[]
    // check filters
    ArgumentCaptor<DocumentFilterContext> contexts = ArgumentCaptor.forClass(DocumentFilterContext.class);
    Mockito.verify(filter, Mockito.times(1)).filter(contexts.capture(), Mockito.any(DocumentFilterChain.class));
    DocumentFilterContext actionContext = contexts.getAllValues().get(0);
    Assert.assertEquals("GET", actionContext.getMethod());
    Assert.assertTrue(actionContext.getJsonPath() instanceof ActionPath);
}
Also used : DocumentFilterContext(io.crnk.core.engine.filter.DocumentFilterContext) DocumentFilterChain(io.crnk.core.engine.filter.DocumentFilterChain) ActionPath(io.crnk.core.engine.internal.dispatcher.path.ActionPath) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractClientTest(io.crnk.client.AbstractClientTest)

Example 10 with ActionPath

use of io.crnk.core.engine.internal.dispatcher.path.ActionPath in project crnk-framework by crnk-project.

the class JsonApiActionResponseTest method testInvokeRepositoryActionWithResourceResult.

@Test
public void testInvokeRepositoryActionWithResourceResult() {
    // resources should be received in json api format
    String url = getBaseUri() + "schedules/repositoryActionWithResourceResult?msg=hello";
    io.restassured.response.Response response = RestAssured.get(url);
    Assert.assertEquals(200, response.getStatusCode());
    response.then().assertThat().body("data.attributes.name", Matchers.equalTo("hello"));
    // check filters
    ArgumentCaptor<DocumentFilterContext> contexts = ArgumentCaptor.forClass(DocumentFilterContext.class);
    Mockito.verify(filter, Mockito.times(1)).filter(contexts.capture(), Mockito.any(DocumentFilterChain.class));
    DocumentFilterContext actionContext = contexts.getAllValues().get(0);
    Assert.assertEquals("GET", actionContext.getMethod());
    Assert.assertTrue(actionContext.getJsonPath() instanceof ActionPath);
}
Also used : DocumentFilterContext(io.crnk.core.engine.filter.DocumentFilterContext) DocumentFilterChain(io.crnk.core.engine.filter.DocumentFilterChain) ActionPath(io.crnk.core.engine.internal.dispatcher.path.ActionPath) Test(org.junit.Test) AbstractClientTest(io.crnk.client.AbstractClientTest)

Aggregations

ActionPath (io.crnk.core.engine.internal.dispatcher.path.ActionPath)10 DocumentFilterChain (io.crnk.core.engine.filter.DocumentFilterChain)9 DocumentFilterContext (io.crnk.core.engine.filter.DocumentFilterContext)9 Test (org.junit.Test)9 AbstractClientTest (io.crnk.client.AbstractClientTest)6 RequestDispatcher (io.crnk.core.engine.dispatcher.RequestDispatcher)2 Schedule (io.crnk.test.mock.models.Schedule)2 Set (java.util.Set)2 Ignore (org.junit.Ignore)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Response (io.crnk.core.engine.dispatcher.Response)1 Document (io.crnk.core.engine.document.Document)1 ControllerRegistry (io.crnk.core.engine.internal.dispatcher.ControllerRegistry)1 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)1 PathBuilder (io.crnk.core.engine.internal.dispatcher.path.PathBuilder)1 ExceptionMapperRegistryTest (io.crnk.core.engine.internal.exception.ExceptionMapperRegistryTest)1 HttpRequestProcessorImpl (io.crnk.core.engine.internal.http.HttpRequestProcessorImpl)1 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)1 DefaultQuerySpecDeserializer (io.crnk.core.queryspec.DefaultQuerySpecDeserializer)1