<commit_before>/* DigiDoc4J library
 *
 * This software is released under either the GNU Library General Public
 * License (see LICENSE.LGPL).
 *
 * Note that the only valid version of the LGPL license as far as this
 * project is concerned is the original GNU Library General Public License
 * Version 2.1, February 1999
 */

package org.digidoc4j.impl;

import eu.europa.esig.dss.DigestAlgorithm;
import eu.europa.esig.dss.Policy;
import org.apache.commons.lang3.SerializationUtils;
import org.digidoc4j.AbstractTest;
import org.digidoc4j.Configuration;
import org.digidoc4j.Container;
import org.digidoc4j.ContainerBuilder;
import org.digidoc4j.DataFile;
import org.digidoc4j.DataToSign;
import org.digidoc4j.DetachedXadesSignatureBuilder;
import org.digidoc4j.Signature;
import org.digidoc4j.SignatureBuilder;
import org.digidoc4j.SignatureProfile;
import org.digidoc4j.ValidationResult;
import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class DataToSignSerializationTest extends AbstractTest {

  private static final List<Integer> FILE_SIZES_IN_KILOBYTES = Arrays.asList(1, 100, 10000);
  private static final int DATA_TO_SIGN_DIGEST_EXPECTED_CEILING_SIZE = 1000;
  private static final int SIGNATURE_SIZE = 256;

  @Test
  public void finalizeSignature_emptyBDOCContainer_dataFilesFromPath() {
    for (int fileSize : FILE_SIZES_IN_KILOBYTES) {
      Container container = ContainerBuilder.aContainer(Container.DocumentType.BDOC).build();
      container.addDataFile("src/test/resources/testFiles/helper-files/sized-files/" + fileSize + "KB.txt", "text/plain");
      Signature signature = finalizeAndValidateContainerSignature(container, 0);
      assertTimestampSignature(signature);
      container.addSignature(signature);
      assertTrue(container.validate().isValid());
    }
  }

  @Test
  public void finalizeSignature_emptyASICEContainer_dataFilesFromPath() {
    for (int fileSize : FILE_SIZES_IN_KILOBYTES) {
      Container container = ContainerBuilder.aContainer(Container.DocumentType.ASICE).build();<commit_msg>MAINTENANCE: Ignore DataToSignSerializationTest by default, should be run separately or with performance tests<commit_after>/* DigiDoc4J library
 *
 * This software is released under either the GNU Library General Public
 * License (see LICENSE.LGPL).
 *
 * Note that the only valid version of the LGPL license as far as this
 * project is concerned is the original GNU Library General Public License
 * Version 2.1, February 1999
 */

package org.digidoc4j.impl;

import eu.europa.esig.dss.DigestAlgorithm;
import eu.europa.esig.dss.Policy;
import org.apache.commons.lang3.SerializationUtils;
import org.digidoc4j.AbstractTest;
import org.digidoc4j.Configuration;
import org.digidoc4j.Container;
import org.digidoc4j.ContainerBuilder;
import org.digidoc4j.DataFile;
import org.digidoc4j.DataToSign;
import org.digidoc4j.DetachedXadesSignatureBuilder;
import org.digidoc4j.Signature;
import org.digidoc4j.SignatureBuilder;
import org.digidoc4j.SignatureProfile;
import org.digidoc4j.ValidationResult;
import org.junit.Ignore;
import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

// These tests might take long and are not necessary to be run in every build.
// They fit more into performance tests category, so at the moment they will be run with them.
@Ignore
public class DataToSignSerializationTest extends AbstractTest {

  private static final List<Integer> FILE_SIZES_IN_KILOBYTES = Arrays.asList(1, 100, 10000);
  private static final int DATA_TO_SIGN_DIGEST_EXPECTED_CEILING_SIZE = 1000;
  private static final int SIGNATURE_SIZE = 256;

  @Test
  public void finalizeSignature_emptyBDOCContainer_dataFilesFromPath() {
    for (int fileSize : FILE_SIZES_IN_KILOBYTES) {
      Container container = ContainerBuilder.aContainer(Container.DocumentType.BDOC).build();
      container.addDataFile("src/test/resources/testFiles/helper-files/sized-files/" + fileSize + "KB.txt", "text/plain");
      Signature signature = finalizeAndValidateContainerSignature(container, 0);
      assertTimestampSignature(signature);
      container.addSignature(signature);
      assertTrue(container.validate().isValid());
    }
  }

  @Test
  public void finalizeSignature_emptyASICEContainer_dataFilesFromPath() {
    for (int fileSize : FILE_SIZES_IN_KILOBYTES) {
      Container container = ContainerBuilder.aContainer(Container.DocumentType.ASICE).build();
{'fraction_non_alphanumeric': 0.08353462157809984, 'fraction_numerical': 0.014895330112721417, 'mean_word_length': 5.470052083333333, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3022858', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1494, 'n_words': 360}