Search in sources :

Example 26 with Schedule

use of io.crnk.test.mock.models.Schedule in project crnk-framework by crnk-project.

the class ApprovalManagerTest method checkRequestApproval.

@Test
public void checkRequestApproval() {
    Schedule changedEntity = new Schedule();
    changedEntity.setId(mockId);
    changedEntity.setName("John");
    Assert.assertFalse(manager.needsApproval(changedEntity, HttpMethod.POST));
    Assert.assertTrue(manager.needsApproval(changedEntity, HttpMethod.PATCH));
    manager.requestApproval(changedEntity, HttpMethod.PATCH);
    ArgumentCaptor<Map> processVariablesCaptor = ArgumentCaptor.forClass(Map.class);
    Mockito.verify(runtimeService, Mockito.times(1)).startProcessInstanceByKey(Mockito.eq("scheduleChange"), processVariablesCaptor.capture());
    Map processVariables = processVariablesCaptor.getValue();
    Assert.assertEquals(4, processVariables.size());
    Assert.assertEquals(mockId.toString(), processVariables.get("resourceId"));
    Assert.assertEquals("schedule", processVariables.get("resourceType"));
    Assert.assertEquals("John", processVariables.get("newValues.name"));
    Assert.assertEquals("Jane", processVariables.get("previousValues.name"));
}
Also used : Schedule(io.crnk.test.mock.models.Schedule) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 27 with Schedule

use of io.crnk.test.mock.models.Schedule in project crnk-framework by crnk-project.

the class ApprovalManagerTest method setup.

@Before
public void setup() {
    runtimeService = Mockito.mock(RuntimeService.class);
    TaskService taskService = Mockito.mock(TaskService.class);
    repositoryFacade = Mockito.mock(ResourceRepositoryV2.class);
    ApprovalMapper approvalMapper = new ApprovalMapper();
    ActivitiResourceMapper resourceMapper = new ActivitiResourceMapper(new TypeParser(), new DefaultDateTimeMapper());
    ResourceInformation information = Mockito.mock(ResourceInformation.class);
    registryEntry = Mockito.mock(RegistryEntry.class);
    ResourceRegistry resourceRegistry = Mockito.mock(ResourceRegistry.class);
    Mockito.when(registryEntry.getResourceInformation()).thenReturn(information);
    Mockito.when(registryEntry.getResourceRepositoryFacade()).thenReturn(repositoryFacade);
    Mockito.when(information.getResourceType()).thenReturn("schedule");
    Mockito.when(information.getId(Mockito.any())).thenReturn(mockId);
    Mockito.when(resourceRegistry.getEntry(Mockito.any(Class.class))).thenReturn(registryEntry);
    Mockito.when(resourceRegistry.getEntry(Mockito.any(String.class))).thenReturn(registryEntry);
    ModuleRegistry moduleRegistry = Mockito.mock(ModuleRegistry.class);
    Mockito.when(moduleRegistry.getResourceRegistry()).thenReturn(resourceRegistry);
    originalResource = new Schedule();
    originalResource.setId(mockId);
    originalResource.setName("Jane");
    Mockito.when(repositoryFacade.findOne(Mockito.any(Long.class), Mockito.any(QuerySpec.class))).thenReturn(originalResource);
    manager = new ApprovalManager();
    manager.init(runtimeService, taskService, resourceMapper, approvalMapper, moduleRegistry);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) TypeParser(io.crnk.core.engine.parser.TypeParser) RuntimeService(org.activiti.engine.RuntimeService) ActivitiResourceMapper(io.crnk.activiti.mapper.ActivitiResourceMapper) TaskService(org.activiti.engine.TaskService) DefaultDateTimeMapper(io.crnk.activiti.mapper.DefaultDateTimeMapper) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) ApprovalManager(io.crnk.activiti.example.approval.ApprovalManager) Schedule(io.crnk.test.mock.models.Schedule) QuerySpec(io.crnk.core.queryspec.QuerySpec) ApprovalMapper(io.crnk.activiti.example.approval.ApprovalMapper) Before(org.junit.Before)

Example 28 with Schedule

use of io.crnk.test.mock.models.Schedule in project crnk-framework by crnk-project.

the class ScheduleRepositoryImpl method repositoryActionWithResourceResult.

@Override
public Schedule repositoryActionWithResourceResult(String msg) {
    Schedule schedule = new Schedule();
    schedule.setId(1L);
    schedule.setName(msg);
    return schedule;
}
Also used : Schedule(io.crnk.test.mock.models.Schedule)

Example 29 with Schedule

use of io.crnk.test.mock.models.Schedule 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 30 with Schedule

use of io.crnk.test.mock.models.Schedule in project crnk-framework by crnk-project.

the class QuerySpecClientTest method testCreate.

@Test
public void testCreate() {
    ScheduleRepository scheduleRepository = client.getResourceRepository(ScheduleRepository.class);
    Schedule schedule = new Schedule();
    schedule.setName("mySchedule");
    scheduleRepository.create(schedule);
    QuerySpec querySpec = new QuerySpec(Schedule.class);
    ScheduleList list = scheduleRepository.findAll(querySpec);
    Assert.assertEquals(1, list.size());
    schedule = list.get(0);
    Assert.assertNotNull(schedule.getId());
    ScheduleListMeta meta = list.getMeta();
    ScheduleListLinks links = list.getLinks();
    Assert.assertNotNull(meta);
    Assert.assertNotNull(links);
}
Also used : Schedule(io.crnk.test.mock.models.Schedule) ScheduleRepository(io.crnk.test.mock.repository.ScheduleRepository) ScheduleListMeta(io.crnk.test.mock.repository.ScheduleRepository.ScheduleListMeta) ScheduleList(io.crnk.test.mock.repository.ScheduleRepository.ScheduleList) ScheduleListLinks(io.crnk.test.mock.repository.ScheduleRepository.ScheduleListLinks) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

Aggregations

Schedule (io.crnk.test.mock.models.Schedule)37 Test (org.junit.Test)24 QuerySpec (io.crnk.core.queryspec.QuerySpec)21 Task (io.crnk.test.mock.models.Task)10 ScheduleRepository (io.crnk.test.mock.repository.ScheduleRepository)5 AbstractClientTest (io.crnk.client.AbstractClientTest)4 ObjectProxy (io.crnk.client.internal.proxy.ObjectProxy)4 Project (io.crnk.test.mock.models.Project)3 DocumentFilterChain (io.crnk.core.engine.filter.DocumentFilterChain)2 DocumentFilterContext (io.crnk.core.engine.filter.DocumentFilterContext)2 ActionPath (io.crnk.core.engine.internal.dispatcher.path.ActionPath)2 ScheduleList (io.crnk.test.mock.repository.ScheduleRepository.ScheduleList)2 ScheduleListLinks (io.crnk.test.mock.repository.ScheduleRepository.ScheduleListLinks)2 ScheduleListMeta (io.crnk.test.mock.repository.ScheduleRepository.ScheduleListMeta)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ApprovalManager (io.crnk.activiti.example.approval.ApprovalManager)1 ApprovalMapper (io.crnk.activiti.example.approval.ApprovalMapper)1 ApprovalRelationshipRepository (io.crnk.activiti.example.approval.ApprovalRelationshipRepository)1 ApproveTask (io.crnk.activiti.example.model.ApproveTask)1