@Test public void testCancel() throws Exception { Request request = mock(Request.class); Job job = mock(Job.class); JobStatus status = mock(JobStatus.class); when(job.getRequest()).thenReturn(request); when(request.isInteractive()).thenReturn(true); when(job.getStatus()).thenReturn(status); Map<EntityReference, EntitySelection> concernedEntities = new HashMap<>(); DocumentReference doc1 = new DocumentReference("a", "b", "c1"); concernedEntities.put(doc1, new EntitySelection(doc1)); XarInstalledExtension ext1 = mock(XarInstalledExtension.class); when(ext1.getId()).thenReturn(new ExtensionId("ext1")); when(repository.getXarInstalledExtensions(doc1)).thenReturn(Arrays.asList(ext1)); InterruptedException e = new InterruptedException(); doThrow(e).when(status).ask(any(), anyLong(), any()); DocumentsDeletingEvent event = mock(DocumentsDeletingEvent.class); mocker.getComponentUnderTest().onEvent(event, job, concernedEntities); verify(status, times(1)).ask(any(), eq(5L), eq(TimeUnit.MINUTES)); verify(event).cancel(eq("Question has been interrupted.")); verify(mocker.getMockedLogger()).warn("Confirm question has been interrupted."); }
@Override public void onEvent(Event event, Object source, Object data) { Job job = (Job) source; CancelableEvent cancelableEvent = (CancelableEvent) event; if (!this.shouldListenerBeTriggered(job, cancelableEvent)) { return; } Map<EntityReference, EntitySelection> concernedEntities = (Map<EntityReference, EntitySelection>) data; ExtensionBreakingQuestion question = new ExtensionBreakingQuestion(concernedEntities); for (EntitySelection entitySelection : concernedEntities.values()) { if (entitySelection.getEntityReference() instanceof DocumentReference) { checkIfDeleteIsAllowed(entitySelection, question); } } JobStatus jobStatus = job.getStatus(); if (!question.getExtensions().isEmpty()) { question.unselectAll(); try { boolean ack = jobStatus.ask(question, 5, TimeUnit.MINUTES); if (!ack) { String message = "The question has been asked, however no answer has been received."; this.logger.warn(message); cancelableEvent.cancel(message); } } catch (InterruptedException e) { this.logger.warn("Confirm question has been interrupted."); cancelableEvent.cancel("Question has been interrupted."); } if (jobStatus instanceof CancelableJobStatus) { CancelableJobStatus cancelableJobStatus = (CancelableJobStatus) jobStatus; if (cancelableJobStatus.isCanceled()) { cancelableEvent.cancel(); } if (cancelableEvent.isCanceled()) { cancelableJobStatus.cancel(); } } } }
DocumentsDeletingListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { Job job = (Job) source; CancelableEvent cancelableEvent = (CancelableEvent) event; if (!this.shouldListenerBeTriggered(job, cancelableEvent)) { return; } Map<EntityReference, EntitySelection> concernedEntities = (Map<EntityReference, EntitySelection>) data; ExtensionBreakingQuestion question = new ExtensionBreakingQuestion(concernedEntities); for (EntitySelection entitySelection : concernedEntities.values()) { if (entitySelection.getEntityReference() instanceof DocumentReference) { checkIfDeleteIsAllowed(entitySelection, question); } } JobStatus jobStatus = job.getStatus(); if (!question.getExtensions().isEmpty()) { question.unselectAll(); try { boolean ack = jobStatus.ask(question, 5, TimeUnit.MINUTES); if (!ack) { String message = "The question has been asked, however no answer has been received."; this.logger.warn(message); cancelableEvent.cancel(message); } } catch (InterruptedException e) { this.logger.warn("Confirm question has been interrupted."); cancelableEvent.cancel("Question has been interrupted."); } if (jobStatus instanceof CancelableJobStatus) { CancelableJobStatus cancelableJobStatus = (CancelableJobStatus) jobStatus; if (cancelableJobStatus.isCanceled()) { cancelableEvent.cancel(); } if (cancelableEvent.isCanceled()) { cancelableJobStatus.cancel(); } } } } }
DocumentsDeletingListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { Job job = (Job) source; CancelableEvent cancelableEvent = (CancelableEvent) event; if (!this.shouldListenerBeTriggered(job, cancelableEvent)) { return; } Map<EntityReference, EntitySelection> concernedEntities = (Map<EntityReference, EntitySelection>) data; ExtensionBreakingQuestion question = new ExtensionBreakingQuestion(concernedEntities); for (EntitySelection entitySelection : concernedEntities.values()) { if (entitySelection.getEntityReference() instanceof DocumentReference) { checkIfDeleteIsAllowed(entitySelection, question); } } JobStatus jobStatus = job.getStatus(); if (!question.getExtensions().isEmpty()) { question.unselectAll(); try { boolean ack = jobStatus.ask(question, 5, TimeUnit.MINUTES); if (!ack) { String message = "The question has been asked, however no answer has been received."; this.logger.warn(message); cancelableEvent.cancel(message); } } catch (InterruptedException e) { this.logger.warn("Confirm question has been interrupted."); cancelableEvent.cancel("Question has been interrupted."); } if (jobStatus instanceof CancelableJobStatus) { CancelableJobStatus cancelableJobStatus = (CancelableJobStatus) jobStatus; if (cancelableJobStatus.isCanceled()) { cancelableEvent.cancel(); } if (cancelableEvent.isCanceled()) { cancelableJobStatus.cancel(); } } } } DocumentsDeletingListener(); }
DocumentsDeletingListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { Job job = (Job) source; CancelableEvent cancelableEvent = (CancelableEvent) event; if (!this.shouldListenerBeTriggered(job, cancelableEvent)) { return; } Map<EntityReference, EntitySelection> concernedEntities = (Map<EntityReference, EntitySelection>) data; ExtensionBreakingQuestion question = new ExtensionBreakingQuestion(concernedEntities); for (EntitySelection entitySelection : concernedEntities.values()) { if (entitySelection.getEntityReference() instanceof DocumentReference) { checkIfDeleteIsAllowed(entitySelection, question); } } JobStatus jobStatus = job.getStatus(); if (!question.getExtensions().isEmpty()) { question.unselectAll(); try { boolean ack = jobStatus.ask(question, 5, TimeUnit.MINUTES); if (!ack) { String message = "The question has been asked, however no answer has been received."; this.logger.warn(message); cancelableEvent.cancel(message); } } catch (InterruptedException e) { this.logger.warn("Confirm question has been interrupted."); cancelableEvent.cancel("Question has been interrupted."); } if (jobStatus instanceof CancelableJobStatus) { CancelableJobStatus cancelableJobStatus = (CancelableJobStatus) jobStatus; if (cancelableJobStatus.isCanceled()) { cancelableEvent.cancel(); } if (cancelableEvent.isCanceled()) { cancelableJobStatus.cancel(); } } } } DocumentsDeletingListener(); @Override void onEvent(Event event, Object source, Object data); }
DocumentsDeletingListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { Job job = (Job) source; CancelableEvent cancelableEvent = (CancelableEvent) event; if (!this.shouldListenerBeTriggered(job, cancelableEvent)) { return; } Map<EntityReference, EntitySelection> concernedEntities = (Map<EntityReference, EntitySelection>) data; ExtensionBreakingQuestion question = new ExtensionBreakingQuestion(concernedEntities); for (EntitySelection entitySelection : concernedEntities.values()) { if (entitySelection.getEntityReference() instanceof DocumentReference) { checkIfDeleteIsAllowed(entitySelection, question); } } JobStatus jobStatus = job.getStatus(); if (!question.getExtensions().isEmpty()) { question.unselectAll(); try { boolean ack = jobStatus.ask(question, 5, TimeUnit.MINUTES); if (!ack) { String message = "The question has been asked, however no answer has been received."; this.logger.warn(message); cancelableEvent.cancel(message); } } catch (InterruptedException e) { this.logger.warn("Confirm question has been interrupted."); cancelableEvent.cancel("Question has been interrupted."); } if (jobStatus instanceof CancelableJobStatus) { CancelableJobStatus cancelableJobStatus = (CancelableJobStatus) jobStatus; if (cancelableJobStatus.isCanceled()) { cancelableEvent.cancel(); } if (cancelableEvent.isCanceled()) { cancelableJobStatus.cancel(); } } } } DocumentsDeletingListener(); @Override void onEvent(Event event, Object source, Object data);  }