@Test public void should_return_KO_when_ATR_has_ReplyCode_other_than_ko_or_warning() throws Exception { String messageRequestIdentifier = "AWESOME-ID"; String replyCode = "KO"; given(unmarshaller.unmarshal(any(XMLStreamReader.class), eq((ArchiveTransferReplyType.class)))).willReturn(getJaxbAtr(messageRequestIdentifier,replyCode)); given(logbookOperationsClient.selectOperationById(messageRequestIdentifier)).willReturn(getLogbookOperation(StatusCode.KO)); TestHandlerIO handler = new TestHandlerIO(); handler.setInputStreamFromWorkspace(new ByteArrayInputStream("<ArchiveTransferReply></ArchiveTransferReply>".getBytes())); ItemStatus result = verifyAtrPlugin.execute(null, handler); assertThat(result.getGlobalStatus()).isEqualTo(KO); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { XMLStreamReader xmlStreamReader = null; try (InputStream atr = handler.getInputStreamFromWorkspace("ATR-for-transfer-reply-in-workspace.xml")) { xmlStreamReader = XMLInputFactoryUtils.newInstance().createXMLStreamReader(atr, "UTF-8"); Unmarshaller unmarshaller = createUnmarshaller(); ArchiveTransferReplyType transferReply = unmarshaller.unmarshal(xmlStreamReader, ArchiveTransferReplyType.class) .getValue(); handler.addOutputResult(0, transferReply); if (hasExistingTransferOperation(transferReply.getMessageRequestIdentifier()) && hasReplyCode(transferReply.getReplyCode())) { return buildItemStatus(PLUGIN_NAME, OK, EventDetails.of("ATR file is valid and serialized.")); } return buildItemStatus(PLUGIN_NAME, KO, EventDetails.of("Field MessageRequestIdentifier in ATR does not correspond to an existing transfer operation.")); } catch (UnmarshalException e) { LOGGER.error(e); return buildItemStatus(PLUGIN_NAME, KO, EventDetails.of(e.getMessage())); } catch (JAXBException | ContentAddressableStorageNotFoundException | IOException | XMLStreamException | LogbookClientException | InvalidParseOperationException | ContentAddressableStorageServerException | SAXException e) { LOGGER.error(e); return buildItemStatus(PLUGIN_NAME, FATAL, EventDetails.of(e.getMessage())); } finally { closeXmlReader(xmlStreamReader); } }
VerifyAtrPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { XMLStreamReader xmlStreamReader = null; try (InputStream atr = handler.getInputStreamFromWorkspace("ATR-for-transfer-reply-in-workspace.xml")) { xmlStreamReader = XMLInputFactoryUtils.newInstance().createXMLStreamReader(atr, "UTF-8"); Unmarshaller unmarshaller = createUnmarshaller(); ArchiveTransferReplyType transferReply = unmarshaller.unmarshal(xmlStreamReader, ArchiveTransferReplyType.class) .getValue(); handler.addOutputResult(0, transferReply); if (hasExistingTransferOperation(transferReply.getMessageRequestIdentifier()) && hasReplyCode(transferReply.getReplyCode())) { return buildItemStatus(PLUGIN_NAME, OK, EventDetails.of("ATR file is valid and serialized.")); } return buildItemStatus(PLUGIN_NAME, KO, EventDetails.of("Field MessageRequestIdentifier in ATR does not correspond to an existing transfer operation.")); } catch (UnmarshalException e) { LOGGER.error(e); return buildItemStatus(PLUGIN_NAME, KO, EventDetails.of(e.getMessage())); } catch (JAXBException | ContentAddressableStorageNotFoundException | IOException | XMLStreamException | LogbookClientException | InvalidParseOperationException | ContentAddressableStorageServerException | SAXException e) { LOGGER.error(e); return buildItemStatus(PLUGIN_NAME, FATAL, EventDetails.of(e.getMessage())); } finally { closeXmlReader(xmlStreamReader); } } }
VerifyAtrPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { XMLStreamReader xmlStreamReader = null; try (InputStream atr = handler.getInputStreamFromWorkspace("ATR-for-transfer-reply-in-workspace.xml")) { xmlStreamReader = XMLInputFactoryUtils.newInstance().createXMLStreamReader(atr, "UTF-8"); Unmarshaller unmarshaller = createUnmarshaller(); ArchiveTransferReplyType transferReply = unmarshaller.unmarshal(xmlStreamReader, ArchiveTransferReplyType.class) .getValue(); handler.addOutputResult(0, transferReply); if (hasExistingTransferOperation(transferReply.getMessageRequestIdentifier()) && hasReplyCode(transferReply.getReplyCode())) { return buildItemStatus(PLUGIN_NAME, OK, EventDetails.of("ATR file is valid and serialized.")); } return buildItemStatus(PLUGIN_NAME, KO, EventDetails.of("Field MessageRequestIdentifier in ATR does not correspond to an existing transfer operation.")); } catch (UnmarshalException e) { LOGGER.error(e); return buildItemStatus(PLUGIN_NAME, KO, EventDetails.of(e.getMessage())); } catch (JAXBException | ContentAddressableStorageNotFoundException | IOException | XMLStreamException | LogbookClientException | InvalidParseOperationException | ContentAddressableStorageServerException | SAXException e) { LOGGER.error(e); return buildItemStatus(PLUGIN_NAME, FATAL, EventDetails.of(e.getMessage())); } finally { closeXmlReader(xmlStreamReader); } } VerifyAtrPlugin(); @VisibleForTesting  VerifyAtrPlugin(JAXBContext jaxbContext, LogbookOperationsClientFactory logbookOperationsClientFactory); }
VerifyAtrPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { XMLStreamReader xmlStreamReader = null; try (InputStream atr = handler.getInputStreamFromWorkspace("ATR-for-transfer-reply-in-workspace.xml")) { xmlStreamReader = XMLInputFactoryUtils.newInstance().createXMLStreamReader(atr, "UTF-8"); Unmarshaller unmarshaller = createUnmarshaller(); ArchiveTransferReplyType transferReply = unmarshaller.unmarshal(xmlStreamReader, ArchiveTransferReplyType.class) .getValue(); handler.addOutputResult(0, transferReply); if (hasExistingTransferOperation(transferReply.getMessageRequestIdentifier()) && hasReplyCode(transferReply.getReplyCode())) { return buildItemStatus(PLUGIN_NAME, OK, EventDetails.of("ATR file is valid and serialized.")); } return buildItemStatus(PLUGIN_NAME, KO, EventDetails.of("Field MessageRequestIdentifier in ATR does not correspond to an existing transfer operation.")); } catch (UnmarshalException e) { LOGGER.error(e); return buildItemStatus(PLUGIN_NAME, KO, EventDetails.of(e.getMessage())); } catch (JAXBException | ContentAddressableStorageNotFoundException | IOException | XMLStreamException | LogbookClientException | InvalidParseOperationException | ContentAddressableStorageServerException | SAXException e) { LOGGER.error(e); return buildItemStatus(PLUGIN_NAME, FATAL, EventDetails.of(e.getMessage())); } finally { closeXmlReader(xmlStreamReader); } } VerifyAtrPlugin(); @VisibleForTesting  VerifyAtrPlugin(JAXBContext jaxbContext, LogbookOperationsClientFactory logbookOperationsClientFactory); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); }
VerifyAtrPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { XMLStreamReader xmlStreamReader = null; try (InputStream atr = handler.getInputStreamFromWorkspace("ATR-for-transfer-reply-in-workspace.xml")) { xmlStreamReader = XMLInputFactoryUtils.newInstance().createXMLStreamReader(atr, "UTF-8"); Unmarshaller unmarshaller = createUnmarshaller(); ArchiveTransferReplyType transferReply = unmarshaller.unmarshal(xmlStreamReader, ArchiveTransferReplyType.class) .getValue(); handler.addOutputResult(0, transferReply); if (hasExistingTransferOperation(transferReply.getMessageRequestIdentifier()) && hasReplyCode(transferReply.getReplyCode())) { return buildItemStatus(PLUGIN_NAME, OK, EventDetails.of("ATR file is valid and serialized.")); } return buildItemStatus(PLUGIN_NAME, KO, EventDetails.of("Field MessageRequestIdentifier in ATR does not correspond to an existing transfer operation.")); } catch (UnmarshalException e) { LOGGER.error(e); return buildItemStatus(PLUGIN_NAME, KO, EventDetails.of(e.getMessage())); } catch (JAXBException | ContentAddressableStorageNotFoundException | IOException | XMLStreamException | LogbookClientException | InvalidParseOperationException | ContentAddressableStorageServerException | SAXException e) { LOGGER.error(e); return buildItemStatus(PLUGIN_NAME, FATAL, EventDetails.of(e.getMessage())); } finally { closeXmlReader(xmlStreamReader); } } VerifyAtrPlugin(); @VisibleForTesting  VerifyAtrPlugin(JAXBContext jaxbContext, LogbookOperationsClientFactory logbookOperationsClientFactory); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); static final String PLUGIN_NAME; }