@Test public void handleFailure() throws Throwable { Map<String, Object> context = Collections.<String, Object>singletonMap("tenantAccessor", tenantAccessor); Exception e = new Exception(); lockProcessInstanceWork.handleFailure(e, context); verify(wrappedWork).handleFailure(e, context); }
@Test public void testRescheduleWorkOnLockTimeout() throws Exception { // On first try to lock : exception to reschedule the work // On the second try : return a correct lock when(lockService.tryLock( eq(processInstanceId), eq(PROCESS), eq(20L), eq(TimeUnit.MILLISECONDS), eq(TENANT_ID))) .thenReturn(null); Map<String, Object> context = Collections.<String, Object>singletonMap("tenantAccessor", tenantAccessor); LockProcessInstanceWork spiedWork = spy(lockProcessInstanceWork); spiedWork.work(context); // in fact we should ensure the rootWork of the lockProcessInstanceWork has been re-executed. We // should check the method getRootWork has been called verify(lockService) .tryLock( eq(processInstanceId), eq(PROCESS), eq(20L), eq(TimeUnit.MILLISECONDS), eq(TENANT_ID)); verify(workService).executeWork(spiedWork); verify(spiedWork).getRootWork(); }
@Test public void workDidNotLock() throws Exception { when(lockService.tryLock( eq(processInstanceId), eq(PROCESS), eq(20L), eq(TimeUnit.MILLISECONDS), eq(TENANT_ID))) .thenReturn(null); Map<String, Object> singletonMap = Collections.<String, Object>singletonMap("tenantAccessor", tenantAccessor); lockProcessInstanceWork.work(singletonMap); verify(lockService, times(1)) .tryLock( eq(processInstanceId), eq(PROCESS), eq(20L), eq(TimeUnit.MILLISECONDS), eq(TENANT_ID)); verify(wrappedWork, times(0)).work(singletonMap); }
@Test public void testWork() throws Exception { BonitaLock bonitaLock = new BonitaLock(new ReentrantLock(), PROCESS, processInstanceId); when(lockService.tryLock( eq(processInstanceId), eq(PROCESS), eq(20L), eq(TimeUnit.MILLISECONDS), eq(TENANT_ID))) .thenReturn(bonitaLock); Map<String, Object> singletonMap = Collections.<String, Object>singletonMap("tenantAccessor", tenantAccessor); lockProcessInstanceWork.work(singletonMap); verify(lockService, times(1)) .tryLock( eq(processInstanceId), eq(PROCESS), eq(20L), eq(TimeUnit.MILLISECONDS), eq(TENANT_ID)); verify(lockService, times(1)).unlock(bonitaLock, TENANT_ID); verify(wrappedWork, times(1)).work(singletonMap); }
@Test public void getRecoveryProcedure() { when(wrappedWork.getRecoveryProcedure()).thenReturn("recoveryProcedure"); assertEquals("recoveryProcedure", lockProcessInstanceWork.getRecoveryProcedure()); }
@Test public void getDescription() { when(wrappedWork.getDescription()).thenReturn("The description"); assertEquals("The description", lockProcessInstanceWork.getDescription()); }
@Test public void testToString() { when(wrappedWork.toString()).thenReturn("the to string"); assertEquals("the to string", lockProcessInstanceWork.toString()); }
@Test public void getWrappedWork() { assertEquals(wrappedWork, lockProcessInstanceWork.getWrappedWork()); }
@Test public void setTenantId() { lockProcessInstanceWork.setTenantId(12L); verify(wrappedWork).setTenantId(12L); }
@Test public void getTenantId() { when(wrappedWork.getTenantId()).thenReturn(12L); assertEquals(12, lockProcessInstanceWork.getTenantId()); }