@Test void cancel() 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)); Query query = mock(Query.class); when(queryManager.createQuery(any(),any())).thenReturn(query); when(query.setLimit(anyInt())).thenReturn(query); when(query.bindValue(any(), any())).thenReturn(query); when(query.setWiki(any())).thenReturn(query); when(query.execute()).thenReturn(Arrays.asList("space.document")); when(resolver.resolve("space.document", EntityType.DOCUMENT)) .thenReturn(new DocumentReference("wiki", "space", "document")); InterruptedException e = new InterruptedException(); doThrow(e).when(status).ask(any(), anyLong(), any()); when(this.documentAccessBridge.isAdvancedUser(any())).thenReturn(true); DocumentsDeletingEvent event = mock(DocumentsDeletingEvent.class); this.deletingListener.onEvent(event, job, concernedEntities); verify(status, times(1)).ask(any(), eq(5L), eq(TimeUnit.MINUTES)); verify(event).cancel(eq("Question has been interrupted.")); assertEquals("Confirm question has been interrupted.", this.logCapture.getMessage(0)); }
@Override public void onEvent(Event event, Object source, Object data) { Job job = (Job) source; CancelableEvent cancelableEvent = (CancelableEvent) event; XClassBreakingQuestion question = this.buildQuestion(job, cancelableEvent, data); if (question == null) { return; } if (!question.getImpactedObjects().isEmpty()) { JobStatus jobStatus = job.getStatus(); try { if (this.documentAccessBridge.isAdvancedUser(job.getRequest().getProperty("user.reference"))) { question.unselectAll(); boolean ack = job.getStatus().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); } } else { question.setRefactoringForbidden(true); boolean ack = jobStatus.ask(question, 1, TimeUnit.MINUTES); if (!ack) { String message = "The question has been canceled because this refactoring is forbidden."; 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(); } } } }
XClassDeletingListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { Job job = (Job) source; CancelableEvent cancelableEvent = (CancelableEvent) event; XClassBreakingQuestion question = this.buildQuestion(job, cancelableEvent, data); if (question == null) { return; } if (!question.getImpactedObjects().isEmpty()) { JobStatus jobStatus = job.getStatus(); try { if (this.documentAccessBridge.isAdvancedUser(job.getRequest().getProperty("user.reference"))) { question.unselectAll(); boolean ack = job.getStatus().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); } } else { question.setRefactoringForbidden(true); boolean ack = jobStatus.ask(question, 1, TimeUnit.MINUTES); if (!ack) { String message = "The question has been canceled because this refactoring is forbidden."; 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(); } } } } }
XClassDeletingListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { Job job = (Job) source; CancelableEvent cancelableEvent = (CancelableEvent) event; XClassBreakingQuestion question = this.buildQuestion(job, cancelableEvent, data); if (question == null) { return; } if (!question.getImpactedObjects().isEmpty()) { JobStatus jobStatus = job.getStatus(); try { if (this.documentAccessBridge.isAdvancedUser(job.getRequest().getProperty("user.reference"))) { question.unselectAll(); boolean ack = job.getStatus().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); } } else { question.setRefactoringForbidden(true); boolean ack = jobStatus.ask(question, 1, TimeUnit.MINUTES); if (!ack) { String message = "The question has been canceled because this refactoring is forbidden."; 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(); } } } } XClassDeletingListener(); }
XClassDeletingListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { Job job = (Job) source; CancelableEvent cancelableEvent = (CancelableEvent) event; XClassBreakingQuestion question = this.buildQuestion(job, cancelableEvent, data); if (question == null) { return; } if (!question.getImpactedObjects().isEmpty()) { JobStatus jobStatus = job.getStatus(); try { if (this.documentAccessBridge.isAdvancedUser(job.getRequest().getProperty("user.reference"))) { question.unselectAll(); boolean ack = job.getStatus().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); } } else { question.setRefactoringForbidden(true); boolean ack = jobStatus.ask(question, 1, TimeUnit.MINUTES); if (!ack) { String message = "The question has been canceled because this refactoring is forbidden."; 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(); } } } } XClassDeletingListener(); @Override void onEvent(Event event, Object source, Object data); }
XClassDeletingListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { Job job = (Job) source; CancelableEvent cancelableEvent = (CancelableEvent) event; XClassBreakingQuestion question = this.buildQuestion(job, cancelableEvent, data); if (question == null) { return; } if (!question.getImpactedObjects().isEmpty()) { JobStatus jobStatus = job.getStatus(); try { if (this.documentAccessBridge.isAdvancedUser(job.getRequest().getProperty("user.reference"))) { question.unselectAll(); boolean ack = job.getStatus().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); } } else { question.setRefactoringForbidden(true); boolean ack = jobStatus.ask(question, 1, TimeUnit.MINUTES); if (!ack) { String message = "The question has been canceled because this refactoring is forbidden."; 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(); } } } } XClassDeletingListener(); @Override void onEvent(Event event, Object source, Object data);  }