AsyncOperationCollection implements IAsyncOperationCollection { @Override public void delete(final String token) throws DeleteAsyncOperationException { try (IPoolGuard poolGuard = new PoolGuard(connectionPool)) { ITask task = IOC.resolve( Keys.getOrAdd("db.async_ops_collection.delete"), poolGuard.getObject(), collectionName, token ); task.execute(); } catch (TaskExecutionException e) { throw new DeleteAsyncOperationException("Error during execution complete.", e); } catch (PoolGuardException e) { throw new DeleteAsyncOperationException("Can't get connection from pool.", e); } catch (ResolutionException e) { throw new DeleteAsyncOperationException("Can't get Task from IOC", e); } } AsyncOperationCollection(final IPool connectionPool, final String collectionName); @Override IObject getAsyncOperation(final String token); @Override void createAsyncOperation(final IObject data, final String token, final String expiredTime); @Override void delete(final String token); @Override void complete(final IObject document);  }
@Test public void ShouldDeleteObject() throws Exception { String token = mock(String.class); IObject deleteQuery = mock(IObject.class); IKey keyIObject = mock(IKey.class); when(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject")).thenReturn(keyIObject); when(IOC.resolve(keyIObject)).thenReturn(deleteQuery); IDatabaseTask deleteTask = mock(IDatabaseTask.class); IKey keyTask = mock(IKey.class); when(Keys.getOrAdd("db.async_ops_collection.delete")).thenReturn(keyTask); when(IOC.resolve(eq(keyTask), any(), any(), eq(token))).thenReturn(deleteTask); collection.delete(token); verify(deleteTask).execute(); }
@Test(expected = DeleteAsyncOperationException.class) public void ShouldThrowDeleteItemException_When_NestedExceptionIsOccurred() throws Exception { String query = mock(String.class); when(IOC.resolve(any(), any(), any(), any())).thenThrow(new ResolutionException("")); collection.delete(query); }