@Test void taskShouldThrowWhenRunOnAnUnknownQueue() { MailQueueFactory<ManageableMailQueue> mailQueueFactory = mock(MailQueueFactory.class); when(mailQueueFactory.getQueue(any(MailQueueName.class))).thenReturn(Optional.empty()); JsonTaskSerializer testee = JsonTaskSerializer.of(DeleteMailsFromMailQueueTaskDTO.module(mailQueueFactory)); String serializedJson = "{\"type\": \"delete-mails-from-mail-queue\", \"queue\": \"anyQueue\", \"sender\": \"a@b.c\"}"; assertThatThrownBy(() -> testee.deserialize(serializedJson).run()) .isInstanceOf(DeleteMailsFromMailQueueTask.UnknownSerializedQueue.class); }
@Override public Result run() { try (ManageableMailQueue queue = factory.create(queueName)) { this.initialCount = Optional.of(getRemainingSize(queue)); this.queue = Optional.of(queue); optionalSender.ifPresent(Throwing.consumer( (MailAddress sender) -> queue.remove(ManageableMailQueue.Type.Sender, sender.asString()))); optionalName.ifPresent(Throwing.consumer( (String name) -> queue.remove(ManageableMailQueue.Type.Name, name))); optionalRecipient.ifPresent(Throwing.consumer( (MailAddress recipient) -> queue.remove(ManageableMailQueue.Type.Recipient, recipient.asString()))); this.lastAdditionalInformation = details(); return Result.COMPLETED; } catch (IOException | MailQueue.MailQueueException e) { LOGGER.error("Delete mails from MailQueue got an exception", e); return Result.PARTIAL; } finally { this.queue = Optional.empty(); } }
DeleteMailsFromMailQueueTask implements Task { @Override public Result run() { try (ManageableMailQueue queue = factory.create(queueName)) { this.initialCount = Optional.of(getRemainingSize(queue)); this.queue = Optional.of(queue); optionalSender.ifPresent(Throwing.consumer( (MailAddress sender) -> queue.remove(ManageableMailQueue.Type.Sender, sender.asString()))); optionalName.ifPresent(Throwing.consumer( (String name) -> queue.remove(ManageableMailQueue.Type.Name, name))); optionalRecipient.ifPresent(Throwing.consumer( (MailAddress recipient) -> queue.remove(ManageableMailQueue.Type.Recipient, recipient.asString()))); this.lastAdditionalInformation = details(); return Result.COMPLETED; } catch (IOException | MailQueue.MailQueueException e) { LOGGER.error("Delete mails from MailQueue got an exception", e); return Result.PARTIAL; } finally { this.queue = Optional.empty(); } } }
DeleteMailsFromMailQueueTask implements Task { @Override public Result run() { try (ManageableMailQueue queue = factory.create(queueName)) { this.initialCount = Optional.of(getRemainingSize(queue)); this.queue = Optional.of(queue); optionalSender.ifPresent(Throwing.consumer( (MailAddress sender) -> queue.remove(ManageableMailQueue.Type.Sender, sender.asString()))); optionalName.ifPresent(Throwing.consumer( (String name) -> queue.remove(ManageableMailQueue.Type.Name, name))); optionalRecipient.ifPresent(Throwing.consumer( (MailAddress recipient) -> queue.remove(ManageableMailQueue.Type.Recipient, recipient.asString()))); this.lastAdditionalInformation = details(); return Result.COMPLETED; } catch (IOException | MailQueue.MailQueueException e) { LOGGER.error("Delete mails from MailQueue got an exception", e); return Result.PARTIAL; } finally { this.queue = Optional.empty(); } } DeleteMailsFromMailQueueTask(MailQueueName queueName, MailQueueFactory factory,
                                        Optional<MailAddress> optionalSender,
                                        Optional<String> optionalName,
                                        Optional<MailAddress> optionalRecipient); }
DeleteMailsFromMailQueueTask implements Task { @Override public Result run() { try (ManageableMailQueue queue = factory.create(queueName)) { this.initialCount = Optional.of(getRemainingSize(queue)); this.queue = Optional.of(queue); optionalSender.ifPresent(Throwing.consumer( (MailAddress sender) -> queue.remove(ManageableMailQueue.Type.Sender, sender.asString()))); optionalName.ifPresent(Throwing.consumer( (String name) -> queue.remove(ManageableMailQueue.Type.Name, name))); optionalRecipient.ifPresent(Throwing.consumer( (MailAddress recipient) -> queue.remove(ManageableMailQueue.Type.Recipient, recipient.asString()))); this.lastAdditionalInformation = details(); return Result.COMPLETED; } catch (IOException | MailQueue.MailQueueException e) { LOGGER.error("Delete mails from MailQueue got an exception", e); return Result.PARTIAL; } finally { this.queue = Optional.empty(); } } DeleteMailsFromMailQueueTask(MailQueueName queueName, MailQueueFactory factory,
                                        Optional<MailAddress> optionalSender,
                                        Optional<String> optionalName,
                                        Optional<MailAddress> optionalRecipient); @Override Result run(); MailQueueName getQueueName(); @Override TaskType type(); @Override Optional<TaskExecutionDetails.AdditionalInformation> details(); long getRemainingSize(ManageableMailQueue queue); }
DeleteMailsFromMailQueueTask implements Task { @Override public Result run() { try (ManageableMailQueue queue = factory.create(queueName)) { this.initialCount = Optional.of(getRemainingSize(queue)); this.queue = Optional.of(queue); optionalSender.ifPresent(Throwing.consumer( (MailAddress sender) -> queue.remove(ManageableMailQueue.Type.Sender, sender.asString()))); optionalName.ifPresent(Throwing.consumer( (String name) -> queue.remove(ManageableMailQueue.Type.Name, name))); optionalRecipient.ifPresent(Throwing.consumer( (MailAddress recipient) -> queue.remove(ManageableMailQueue.Type.Recipient, recipient.asString()))); this.lastAdditionalInformation = details(); return Result.COMPLETED; } catch (IOException | MailQueue.MailQueueException e) { LOGGER.error("Delete mails from MailQueue got an exception", e); return Result.PARTIAL; } finally { this.queue = Optional.empty(); } } DeleteMailsFromMailQueueTask(MailQueueName queueName, MailQueueFactory factory,
                                        Optional<MailAddress> optionalSender,
                                        Optional<String> optionalName,
                                        Optional<MailAddress> optionalRecipient); @Override Result run(); MailQueueName getQueueName(); @Override TaskType type(); @Override Optional<TaskExecutionDetails.AdditionalInformation> details(); long getRemainingSize(ManageableMailQueue queue); static final TaskType TYPE; }