package at.gv.egiz.param_tests.provider;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import at.gv.egiz.pdfas.lib.api.PdfAsFactory;
/**
* Abstract base class for test data providers. The subclasses of it shall read
* configuration properties and provide test parameters for parameterized unit
* tests. This offers some functionality, which is needed by all tests, e.g. it
* reads basic configuration data, which is needed for signing a PDF file, which
* is done by all tests.
*
* @author mtappler
*
*/
public abstract class BaseSignatureDataProvider {
/**
* config-property key for specifying the type of the test
*/
public static final String TEST_TYPE = "test.type";
/**
* config-property key for specifying the name of the test, if no name is
* specified, the test directory will be used as name
*/
public static final String TEST_NAME = "test.name";
/**
* config-property for specifying signature profile
*/
public static final String PROFILE_ID = "profile.id";
/**
* config-property key for specifying the name of the output file
*/
public static final String OUTPUT_FILE = "output.file";
/**
* config-property key for specifying the type of connector, which is used
* for signing
*/
public static final String CONNECTOR = "connector";
/**
* config-property key for PDF-AS configuration file location
*/
public static final String CONFIG_FILE = "config.file";
/**
* config-property key for PDF input file name, the file which is signed
*/
public static final String INPUT_FILE = "input.file";
public static final String PARENT_CFG = "parent";
/**
* default location for PDF-AS config file
*/
public static final String STANDARD_CONFIG_LOCATION = System
.getProperty("user.home") + "/.pdfas/";
/**
* config-property key for the filename of the keystore, required if ks
* (keystore) is used as connector
*/
public static final String KS_FILE_NAME = "ks.filename";
/**
* config-property key for the key alias, required if ks (keystore) is used
* as connector
*/
public static final String KS_ALIAS = "ks.alias";
/**
* config-property key for the keystore type, optional value if ks
* (keystore) is used as connector
*/
public static final String KS_TYPE = "ks.type";
/**
* config-property key for the password of the keystore, required if ks
* (keystore) is used as connector
*/
public static final String KS_PASS = "ks.pass";
/**
* config-property key for the password of the key, required if ks
* (keystore) is used as connector
*/
public static final String KS_KEY_PASS = "ks.keypass";
/**
* logger for this class
*/
private static final Logger logger = LoggerFactory
.getLogger(BaseSignatureDataProvider.class);
/**
* Interface for test classes: This method should be invoked to get the data
* for parameterized unit tests. It calls two template method style (design
* pattern) methods to perform different actions for different test types.
* Generally it loops over all directories in the test directory and filters
* using a wildcard-filter and then calls abstract methods, one to decide if
* the subclass is a provider the given test type
* isSupportedTestType and one to extract configuration data
* extractDataFromConfig.
*
* @return parameters for the parameterized unit tests
*/
public List