test_class.declarator: receiverTask
test_class.modifier: @Autowired
      private
test_class.original_string: @Autowired
      private ReceiverTask receiverTask;
test_class.type: ReceiverTask
test_class.var_name: receiverTask
test_class.declarator: pesAllerService
test_class.modifier: @MockBean
      private
test_class.original_string: @MockBean
      private PesAllerService pesAllerService;
test_class.type: PesAllerService
test_class.var_name: pesAllerService
test_class.declarator: pesRetourRepository
test_class.modifier: @MockBean
      private
test_class.original_string: @MockBean
      private PesRetourRepository pesRetourRepository;
test_class.type: PesRetourRepository
test_class.var_name: pesRetourRepository
test_class.declarator: pesAllerRepository
test_class.modifier: @MockBean
      private
test_class.original_string: @MockBean
      private PesAllerRepository pesAllerRepository;
test_class.type: PesAllerRepository
test_class.var_name: pesAllerRepository
test_class.declarator: localAuthorityService
test_class.modifier: @MockBean
      private
test_class.original_string: @MockBean
      private LocalAuthorityService localAuthorityService;
test_class.type: LocalAuthorityService
test_class.var_name: localAuthorityService
test_class.declarator: defaultFtpSessionFactory
test_class.modifier: @MockBean
      private
test_class.original_string: @MockBean
      private DefaultFtpSessionFactory defaultFtpSessionFactory;
test_class.type: DefaultFtpSessionFactory
test_class.var_name: defaultFtpSessionFactory
test_class.declarator: storageService
test_class.modifier: @MockBean
      private
test_class.original_string: @MockBean
      private StorageService storageService;
test_class.type: StorageService
test_class.var_name: storageService
test_class.declarator: notificationService
test_class.modifier: @MockBean
      private
test_class.original_string: @MockBean
      private NotificationService notificationService;
test_class.type: NotificationService
test_class.var_name: notificationService
test_class.file: pes-service/src/test/java/fr/sictiam/stela/pesservice/scheduler/ReceiverTaskTest.java
test_class.identifier: ReceiverTaskTest
test_case.body: @Test
      public void testAckKoWithInnerDetailLigne() throws Exception {
  
          PesAller pesAller = gimmePesAller();
          given(pesAllerService.getByFileName("PesDepense-02-2019-5-11112222333344445"))
                  .willReturn(Optional.of(pesAller));
          doNothing().when(pesAllerService).updateStatus(anyString(), any(), any(), anyString(), anyList());
  
          InputStream pesFile = new ClassPathResource("data/pes-ack-ko/006111_190130123456-ACK-A3020100_A0000IDL_KO.xml")
                  .getInputStream();
          receiverTask.readACK(IOUtils.toByteArray(pesFile), "ackName");
  
          verify(pesAllerService).updateStatus(eq(pesAller.getUuid()), eq(StatusType.NACK_RECEIVED),
                  any(), eq("ackName"), argThat(errors ->
                          errors.size() == 6 &&
                                  errors.stream().allMatch(pesHistoryError -> pesHistoryError.getTitle().equals("ERREUR_AUTRE")) &&
                                  errors.stream().filter(pesHistoryError -> pesHistoryError.getMessage().startsWith("1971")).count() == 5 &&
                                  errors.stream().noneMatch(pesHistoryError -> pesHistoryError.getSource().isEmpty())));
      }
test_case.class_method_signature: ReceiverTaskTest.testAckKoWithInnerDetailLigne()
test_case.full_signature: @Test public void testAckKoWithInnerDetailLigne()
test_case.identifier: testAckKoWithInnerDetailLigne
test_case.invocations: gimmePesAller willReturn given getByFileName of updateStatus when doNothing anyString any any anyString anyList getInputStream readACK toByteArray updateStatus verify eq getUuid eq any eq argThat size allMatch stream equals getTitle count filter stream startsWith getMessage noneMatch stream isEmpty getSource
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testAckKoWithInnerDetailLigne()
focal_class.declarator: LOGGER = LoggerFactory.getLogger(ReceiverTask.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOGGER = LoggerFactory.getLogger(ReceiverTask.class);
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.declarator: pesService
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private PesAllerService pesService;
focal_class.type: PesAllerService
focal_class.var_name: pesService
focal_class.declarator: pesRetourRepository
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private PesRetourRepository pesRetourRepository;
focal_class.type: PesRetourRepository
focal_class.var_name: pesRetourRepository
focal_class.declarator: localAuthorityService
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private LocalAuthorityService localAuthorityService;
focal_class.type: LocalAuthorityService
focal_class.var_name: localAuthorityService
focal_class.declarator: defaultFtpSessionFactory
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private DefaultFtpSessionFactory defaultFtpSessionFactory;
focal_class.type: DefaultFtpSessionFactory
focal_class.var_name: defaultFtpSessionFactory
focal_class.declarator: storageService
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private StorageService storageService;
focal_class.type: StorageService
focal_class.var_name: storageService
focal_class.declarator: notificationService
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private NotificationService notificationService;
focal_class.type: NotificationService
focal_class.var_name: notificationService
focal_class.declarator: hoursWithoutNewFiles
focal_class.modifier: @Value("${application.receiverTask.hoursWithoutNewFiles}")
      private
focal_class.original_string: @Value("${application.receiverTask.hoursWithoutNewFiles}")
      private int hoursWithoutNewFiles;
focal_class.type: int
focal_class.var_name: hoursWithoutNewFiles
focal_class.declarator: maxWaitingPes
focal_class.modifier: @Value("${application.receiverTask.maxWaitingPes}")
      private
focal_class.original_string: @Value("${application.receiverTask.maxWaitingPes}")
      private int maxWaitingPes;
focal_class.type: int
focal_class.var_name: maxWaitingPes
focal_class.declarator: alertEmail
focal_class.modifier: @Value("${application.receiverTask.alertEmail}")
      private
focal_class.original_string: @Value("${application.receiverTask.alertEmail}")
      private String alertEmail;
focal_class.type: String
focal_class.var_name: alertEmail
focal_class.declarator: runsWithoutNewFiles = 0L
focal_class.modifier: private
focal_class.original_string: private Long runsWithoutNewFiles = 0L;
focal_class.type: Long
focal_class.var_name: runsWithoutNewFiles
focal_class.declarator: alertSent = false
focal_class.modifier: private
focal_class.original_string: private boolean alertSent = false;
focal_class.type: boolean
focal_class.var_name: alertSent
focal_class.declarator: timeout
focal_class.modifier: @Value("${application.ftp.timeout}")
      private
focal_class.original_string: @Value("${application.ftp.timeout}")
      private Integer timeout;
focal_class.type: Integer
focal_class.var_name: timeout
focal_class.file: pes-service/src/main/java/fr/sictiam/stela/pesservice/scheduler/ReceiverTask.java
focal_class.identifier: ReceiverTask
focal_class.class_method_signature: ReceiverTask.receive()
focal_class.full_signature: @Scheduled(fixedDelay = 60000) public void receive()
focal_class.identifier: receive
focal_class.modifiers: @Scheduled(fixedDelay = 60000) public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void receive()
focal_class.class_method_signature: ReceiverTask.readACK(byte[] targetArray, String ackName)
focal_class.full_signature: public void readACK(byte[] targetArray, String ackName)
focal_class.identifier: readACK
focal_class.modifiers: public
focal_class.parameters: (byte[] targetArray, String ackName)
focal_class.return: void
focal_class.signature: void readACK(byte[] targetArray, String ackName)
focal_class.class_method_signature: ReceiverTask.readPesRetour(byte[] targetArray, String pesRetourName)
focal_class.full_signature: public void readPesRetour(byte[] targetArray, String pesRetourName)
focal_class.identifier: readPesRetour
focal_class.modifiers: public
focal_class.parameters: (byte[] targetArray, String pesRetourName)
focal_class.return: void
focal_class.signature: void readPesRetour(byte[] targetArray, String pesRetourName)
focal_method.body: public void readACK(byte[] targetArray, String ackName)
              throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
  
          LOGGER.debug("Received ack file : {}", ackName);
          ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(targetArray);
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          DocumentBuilder builder = factory.newDocumentBuilder();
          XPathFactory xpf = XPathFactory.newInstance();
          XPath path = xpf.newXPath();
          Document document = builder.parse(byteArrayInputStream);
          String fileName = path.evaluate("/PES_ACQUIT/Enveloppe/Parametres/NomFic/@V", document);
          LOGGER.debug("Extracted PES filename : {}", fileName);
  
          PesAller pesAller = pesService.getByFileName(fileName).orElseThrow(PesNotFoundException::new);
  
          boolean isAckOk = true;
          List<PesHistoryError> errors = new ArrayList<>();
          NodeList nodes = (NodeList) path.evaluate("/PES_ACQUIT/ACQUIT/ElementACQUIT", document, XPathConstants.NODESET);
          for (int i = 0; i < nodes.getLength(); i++) {
              Node node = nodes.item(i);
              boolean isCurrentNodeValid = path.evaluate("EtatAck/@V", node).equals("1");
              isAckOk = isAckOk && isCurrentNodeValid;
  
              if (isCurrentNodeValid)
                  continue;
  
              NodeList innerNodes = (NodeList) path.evaluate("DetailPiece", node, XPathConstants.NODESET);
              if (innerNodes.getLength() != 0) {
                  for (int j = 0; j < innerNodes.getLength(); j++) {
                      Node in = innerNodes.item(j);
                      NodeList detailLigneNode = (NodeList) path.evaluate("DetailLigne", in, XPathConstants.NODESET);
                      if (detailLigneNode.getLength() != 0) {
                          /*
                           * Error pattern #1
                           *
                           * <DetailPiece>
                           *     <NumPiece V="20"/>
                           *     <DetailLigne>
                           *         <NumLigne V="1"/>
                           *         <Erreur>
                           *             <NumAnoAck V="ERREUR_AUTRE"/>
                           *             <LibelleAnoAck V="1971 - Compte fonction présent à tort"/>
                           *         </Erreur>
                           *     </DetailLigne>
                           *     [...]
                           * </DetailPiece>
                           * <DetailPiece>
                           *     [...]
                           * </DetailPiece>
                           */
                          for (int k = 0; k < detailLigneNode.getLength(); k++) {
                              Node detail = detailLigneNode.item(k);
                              PesHistoryError e = new PesHistoryError(
                                      path.evaluate("Erreur/NumAnoAck/@V", detail),
                                      path.evaluate("Erreur/LibelleAnoAck/@V", detail),
                                      path.evaluate("NumPiece/@V", in)
                              );
                              errors.add(e);
                          }
                      } else {
                          /*
                           * Error pattern #2
                           *
                           * <DetailPiece>
                           *     <NumPiece V="5129"/>
                           *     <Erreur>
                           *         <NumAnoAck V="ERREUR_AUTRE"/>
                           *         <LibelleAnoAck V="2559 - Le code service de la structure publique destinataire est inconnu ou inactif dans Chorus Pro"/>
                           *     </Erreur>
                           * </DetailPiece>
                           */
                          PesHistoryError e = new PesHistoryError(
                                  path.evaluate("Erreur/NumAnoAck/@V", in),
                                  path.evaluate("Erreur/LibelleAnoAck/@V", in),
                                  path.evaluate("NumPiece/@V", in)
                          );
                          errors.add(e);
                      }
                  }
              } else {
                  /*
                   * Error pattern #3
                   *
                   * <IdUnique V="TI00064567"/>
                   * <Erreur>
                   *     <NumAnoAck V="ERREUR_DOUBLON_PJ"/>
                   *     <LibelleAnoAck V="1984 - L'identifiant unique de la PJ a déjà été intégré dans HELIOS"/>
                   * </Erreur>
                   */
                  PesHistoryError e = new PesHistoryError(
                          path.evaluate("Erreur/NumAnoAck/@V", node),
                          path.evaluate("Erreur/LibelleAnoAck/@V", node),
                          path.evaluate("IdUnique/@V", node)
                  );
                  errors.add(e);
              }
          }
  
          if (isAckOk) {
              pesService.updateStatus(pesAller.getUuid(), StatusType.ACK_RECEIVED, targetArray, ackName);
          } else {
              pesService.updateStatus(pesAller.getUuid(), StatusType.NACK_RECEIVED, targetArray, ackName, errors);
          }
  
      }
focal_method.class_method_signature: ReceiverTask.readACK(byte[] targetArray, String ackName)
focal_method.full_signature: public void readACK(byte[] targetArray, String ackName)
focal_method.identifier: readACK
focal_method.invocations: debug newInstance newDocumentBuilder newInstance newXPath parse evaluate debug orElseThrow getByFileName evaluate getLength item equals evaluate evaluate getLength getLength item evaluate getLength getLength item evaluate evaluate evaluate add evaluate evaluate evaluate add evaluate evaluate evaluate add updateStatus getUuid updateStatus getUuid
focal_method.modifiers: public
focal_method.parameters: (byte[] targetArray, String ackName)
focal_method.return: void
focal_method.signature: void readACK(byte[] targetArray, String ackName)