Search in sources :

Example 1 with ReprocessContentRequestJson

use of com.enonic.xp.impl.server.rest.model.ReprocessContentRequestJson in project xp by enonic.

the class ReprocessRunnableTaskTest method reprocess_incl_children.

@Test
public void reprocess_incl_children() throws Exception {
    Content content = createContent("content-id", ContentPath.from("/path/to/content"));
    Content reprocessedContent = Content.create(content).displayName("new name").build();
    Content childContent = createContent("child-id", ContentPath.from(content.getPath(), "child"));
    Content reprocessedChildContent = Content.create(childContent).displayName("new name").build();
    FindContentIdsByQueryResult countResult = FindContentIdsByQueryResult.create().totalHits(1).build();
    Mockito.when(this.contentService.getByPath(content.getPath())).thenReturn(content);
    Mockito.when(this.contentService.reprocess(content.getId())).thenReturn(reprocessedContent);
    Mockito.when(this.contentService.reprocess(childContent.getId())).thenReturn(reprocessedChildContent);
    Mockito.when(this.contentService.find(Mockito.isA(ContentQuery.class))).thenReturn(countResult);
    Mockito.when(this.contentService.findByParent(FindContentByParentParams.create().parentId(content.getId()).from(0).size(5).build())).thenReturn(FindContentByParentResult.create().contents(Contents.create().add(childContent).build()).build());
    Mockito.when(this.contentService.findByParent(FindContentByParentParams.create().parentId(childContent.getId()).from(0).size(5).build())).thenReturn(FindContentByParentResult.create().contents(Contents.create().build()).build());
    final ReprocessRunnableTask task = createAndRunTask(new ReprocessContentRequestJson("branch:/path/to/content", false));
    task.createTaskResult();
    Mockito.verify(progressReporter, Mockito.times(1)).info(contentQueryArgumentCaptor.capture());
    Mockito.verify(taskService, Mockito.times(1)).submitTask(Mockito.isA(RunnableTask.class), Mockito.eq("reprocess"));
    final String result = contentQueryArgumentCaptor.getAllValues().get(0);
    jsonTestHelper.assertJsonEquals(jsonTestHelper.loadTestJson("incl_children_result.json"), jsonTestHelper.stringToJson(result));
}
Also used : FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) RunnableTask(com.enonic.xp.task.RunnableTask) ReprocessContentRequestJson(com.enonic.xp.impl.server.rest.model.ReprocessContentRequestJson) Test(org.junit.jupiter.api.Test) AbstractRunnableTaskTest(com.enonic.xp.task.AbstractRunnableTaskTest)

Example 2 with ReprocessContentRequestJson

use of com.enonic.xp.impl.server.rest.model.ReprocessContentRequestJson in project xp by enonic.

the class ReprocessRunnableTaskTest method reprocess_skip_children.

@Test
public void reprocess_skip_children() {
    final Content content = createContent("content-id", ContentPath.from("/path/to/content"));
    final Content reprocessedContent = Content.create(content).displayName("new name").build();
    Mockito.when(this.contentService.getByPath(content.getPath())).thenReturn(content);
    Mockito.when(this.contentService.reprocess(content.getId())).thenReturn(reprocessedContent);
    final ReprocessRunnableTask task = createAndRunTask(new ReprocessContentRequestJson("branch:/path/to/content", true));
    task.createTaskResult();
    Mockito.verify(progressReporter, Mockito.times(1)).info(contentQueryArgumentCaptor.capture());
    Mockito.verify(taskService, Mockito.times(1)).submitTask(Mockito.isA(RunnableTask.class), Mockito.eq("reprocess"));
    final String result = contentQueryArgumentCaptor.getAllValues().get(0);
    jsonTestHelper.assertJsonEquals(jsonTestHelper.loadTestJson("skip_children_result.json"), jsonTestHelper.stringToJson(result));
}
Also used : Content(com.enonic.xp.content.Content) RunnableTask(com.enonic.xp.task.RunnableTask) ReprocessContentRequestJson(com.enonic.xp.impl.server.rest.model.ReprocessContentRequestJson) Test(org.junit.jupiter.api.Test) AbstractRunnableTaskTest(com.enonic.xp.task.AbstractRunnableTaskTest)

Example 3 with ReprocessContentRequestJson

use of com.enonic.xp.impl.server.rest.model.ReprocessContentRequestJson in project xp by enonic.

the class ReprocessRunnableTaskTest method reprocess_root_incl_children.

@Test
public void reprocess_root_incl_children() throws Exception {
    Content content = createContent("content-id", ContentPath.from("/content"));
    Content reprocessedContent = Content.create(content).displayName("new name").build();
    Content childContent = createContent("child-id", ContentPath.from(content.getPath(), "child"));
    Content reprocessedChildContent = Content.create(childContent).displayName("new name").build();
    FindContentIdsByQueryResult countResult = FindContentIdsByQueryResult.create().totalHits(1).build();
    Mockito.when(this.contentService.getByPath(ContentPath.ROOT)).thenReturn(content);
    Mockito.when(this.contentService.reprocess(content.getId())).thenReturn(reprocessedContent);
    Mockito.when(this.contentService.reprocess(childContent.getId())).thenReturn(reprocessedChildContent);
    Mockito.when(this.contentService.find(Mockito.isA(ContentQuery.class))).thenReturn(countResult);
    Mockito.when(this.contentService.findByParent(FindContentByParentParams.create().parentId(content.getId()).from(0).size(5).build())).thenReturn(FindContentByParentResult.create().contents(Contents.create().add(childContent).build()).build());
    Mockito.when(this.contentService.findByParent(FindContentByParentParams.create().parentId(childContent.getId()).from(0).size(5).build())).thenReturn(FindContentByParentResult.create().contents(Contents.create().build()).build());
    final ReprocessRunnableTask task = createAndRunTask(new ReprocessContentRequestJson("branch:/", false));
    task.createTaskResult();
    Mockito.verify(progressReporter, Mockito.times(1)).info(contentQueryArgumentCaptor.capture());
    Mockito.verify(taskService, Mockito.times(1)).submitTask(Mockito.isA(RunnableTask.class), Mockito.eq("reprocess"));
    final String result = contentQueryArgumentCaptor.getAllValues().get(0);
    jsonTestHelper.assertJsonEquals(jsonTestHelper.loadTestJson("root_incl_children_result.json"), jsonTestHelper.stringToJson(result));
}
Also used : FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) RunnableTask(com.enonic.xp.task.RunnableTask) ReprocessContentRequestJson(com.enonic.xp.impl.server.rest.model.ReprocessContentRequestJson) Test(org.junit.jupiter.api.Test) AbstractRunnableTaskTest(com.enonic.xp.task.AbstractRunnableTaskTest)

Example 4 with ReprocessContentRequestJson

use of com.enonic.xp.impl.server.rest.model.ReprocessContentRequestJson in project xp by enonic.

the class ReprocessRunnableTaskTest method reprocess_invalid.

@Test
public void reprocess_invalid() throws Exception {
    Content content = createContent("content-id", ContentPath.from("/path/to/content"));
    Mockito.when(this.contentService.getByPath(content.getPath())).thenReturn(content);
    Mockito.when(this.contentService.reprocess(content.getId())).thenThrow(new RuntimeException("exceptionMessage"));
    final ReprocessRunnableTask task = createAndRunTask(new ReprocessContentRequestJson("branch:/path/to/content", true));
    task.createTaskResult();
    Mockito.verify(progressReporter, Mockito.times(1)).info(contentQueryArgumentCaptor.capture());
    Mockito.verify(taskService, Mockito.times(1)).submitTask(Mockito.isA(RunnableTask.class), Mockito.eq("reprocess"));
    final String result = contentQueryArgumentCaptor.getAllValues().get(0);
    jsonTestHelper.assertJsonEquals(jsonTestHelper.loadTestJson("skip_children_error_result.json"), jsonTestHelper.stringToJson(result));
}
Also used : Content(com.enonic.xp.content.Content) RunnableTask(com.enonic.xp.task.RunnableTask) ReprocessContentRequestJson(com.enonic.xp.impl.server.rest.model.ReprocessContentRequestJson) Test(org.junit.jupiter.api.Test) AbstractRunnableTaskTest(com.enonic.xp.task.AbstractRunnableTaskTest)

Example 5 with ReprocessContentRequestJson

use of com.enonic.xp.impl.server.rest.model.ReprocessContentRequestJson in project xp by enonic.

the class ReprocessRunnableTaskTest method reprocess_incl_invalid_children.

@Test
public void reprocess_incl_invalid_children() throws Exception {
    Content content = createContent("content-id", ContentPath.from("/path/to/content"));
    Content reprocessedContent = Content.create(content).displayName("new name").build();
    Content childContent = createContent("child-id", ContentPath.from(content.getPath(), "child"));
    FindContentIdsByQueryResult countResult = FindContentIdsByQueryResult.create().totalHits(1).build();
    Mockito.when(this.contentService.getByPath(content.getPath())).thenReturn(content);
    Mockito.when(this.contentService.reprocess(content.getId())).thenReturn(reprocessedContent);
    Mockito.when(this.contentService.reprocess(childContent.getId())).thenThrow(new RuntimeException("childException"));
    Mockito.when(this.contentService.find(Mockito.isA(ContentQuery.class))).thenReturn(countResult);
    Mockito.when(this.contentService.findByParent(FindContentByParentParams.create().parentId(content.getId()).from(0).size(5).build())).thenReturn(FindContentByParentResult.create().contents(Contents.create().add(childContent).build()).build());
    Mockito.when(this.contentService.findByParent(FindContentByParentParams.create().parentId(childContent.getId()).from(0).size(5).build())).thenReturn(FindContentByParentResult.create().contents(Contents.create().build()).build());
    final ReprocessRunnableTask task = createAndRunTask(new ReprocessContentRequestJson("branch:/path/to/content", false));
    task.createTaskResult();
    Mockito.verify(progressReporter, Mockito.times(1)).info(contentQueryArgumentCaptor.capture());
    Mockito.verify(taskService, Mockito.times(1)).submitTask(Mockito.isA(RunnableTask.class), Mockito.eq("reprocess"));
    final String result = contentQueryArgumentCaptor.getAllValues().get(0);
    jsonTestHelper.assertJsonEquals(jsonTestHelper.loadTestJson("incl_children_error_result.json"), jsonTestHelper.stringToJson(result));
}
Also used : FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) RunnableTask(com.enonic.xp.task.RunnableTask) ReprocessContentRequestJson(com.enonic.xp.impl.server.rest.model.ReprocessContentRequestJson) Test(org.junit.jupiter.api.Test) AbstractRunnableTaskTest(com.enonic.xp.task.AbstractRunnableTaskTest)

Aggregations

Content (com.enonic.xp.content.Content)6 ReprocessContentRequestJson (com.enonic.xp.impl.server.rest.model.ReprocessContentRequestJson)6 AbstractRunnableTaskTest (com.enonic.xp.task.AbstractRunnableTaskTest)6 RunnableTask (com.enonic.xp.task.RunnableTask)6 Test (org.junit.jupiter.api.Test)6 ContentQuery (com.enonic.xp.content.ContentQuery)4 FindContentIdsByQueryResult (com.enonic.xp.content.FindContentIdsByQueryResult)4