Search in sources :

Example 31 with ArgumentValue

use of com.axway.ats.agent.core.action.ArgumentValue in project ats-framework by Axway.

the class Test_FileNamesParameterDataProvider method testComplexFileNameRegex_Negative.

@Test
public void testComplexFileNameRegex_Negative() throws AgentException {
    List<FileContainer> fileContainers = new ArrayList<FileContainer>();
    fileContainers.add(new FileContainer(folderName, 100, "${fileNamePart}.*"));
    FileNamesParameterDataProvider fileNamesDP = new FileNamesParameterDataProvider("fileNameParam", fileContainers, false, true, ParameterProviderLevel.PER_THREAD);
    fileNamesDP.initialize();
    ArgumentValue previousValue = new ArgumentValue("fileNamePart", "wrongFileNamePart");
    List<ArgumentValue> previousValues = new ArrayList<ArgumentValue>();
    previousValues.add(previousValue);
    try {
        fileNamesDP.getValue(previousValues);
        Assert.fail();
    } catch (RuntimeException re) {
        assertTrue(re.getMessage().startsWith("No files matching regex pattern 'wrongFileNamePart.*' in directory"));
    }
}
Also used : ArrayList(java.util.ArrayList) ArgumentValue(com.axway.ats.agent.core.action.ArgumentValue) Test(org.junit.Test) BaseTest(com.axway.ats.agent.core.BaseTest)

Example 32 with ArgumentValue

use of com.axway.ats.agent.core.action.ArgumentValue in project ats-framework by Axway.

the class Test_FileNamesParameterDataProvider method perThreadGenerationNonRecursive.

@Test
public void perThreadGenerationNonRecursive() throws AgentException {
    FileNamesParameterDataProvider dataProvider = new FileNamesParameterDataProvider("param1", fileContainers, false, true, ParameterProviderLevel.PER_THREAD);
    dataProvider.initialize();
    ArgumentValue generatedValue = dataProvider.getValue(new ArrayList<ArgumentValue>());
    assertEquals("param1", generatedValue.getName());
    assertTrue(((String) generatedValue.getValue()).matches(".*[\\\\/](classloader|readme).html"));
    String firstValue = (String) generatedValue.getValue();
    //make sure new instance per thread is returned
    generatedValue = dataProvider.getValue(new ArrayList<ArgumentValue>());
    assertEquals("param1", generatedValue.getName());
    assertFalse(((String) generatedValue.getValue()).equals(firstValue));
}
Also used : ArrayList(java.util.ArrayList) ArgumentValue(com.axway.ats.agent.core.action.ArgumentValue) Test(org.junit.Test) BaseTest(com.axway.ats.agent.core.BaseTest)

Example 33 with ArgumentValue

use of com.axway.ats.agent.core.action.ArgumentValue in project ats-framework by Axway.

the class FileContainer method getFileName.

/**
     *
     * @param currentThreadId current thread id
     * @param isStaticValue if the wanted value is static
     * @param previousValues previous data config parameters with their values
     * @return the next/same file name for the current thread
     */
public String getFileName(Long currentThreadId, Boolean isStaticValue, List<ArgumentValue> previousValues) {
    int index = getNextFileIndex(currentThreadId, isStaticValue);
    String fileName = fileList.get(index);
    if (this.patternParameters != null) {
        String currentPattern = this.pattern;
        for (ArgumentValue arg : previousValues) {
            if (this.patternParameters.contains(arg.getName())) {
                currentPattern = currentPattern.replace("${" + arg.getName() + "}", (String) arg.getValue());
            }
        }
        int startIndex = index;
        Pattern p = Pattern.compile(currentPattern);
        while (!p.matcher(IoUtils.getFileName(fileName)).matches()) {
            // if (isStaticValue) then this is a case when the file name didn't match the pattern and
            // getNextFileIndex() will retrieve the same index every time, so we have to force change the
            // current thread index => isStaticValue = false
            index = getNextFileIndex(currentThreadId, false);
            if (index == startIndex) {
                //we check all files in the directory and there is no file matching our pattern
                throw new RuntimeException("No files matching regex pattern '" + currentPattern + "' in directory: " + this.folderName);
            }
            fileName = fileList.get(index);
        }
    }
    return fileName;
}
Also used : Pattern(java.util.regex.Pattern) ArgumentValue(com.axway.ats.agent.core.action.ArgumentValue)

Aggregations

ArgumentValue (com.axway.ats.agent.core.action.ArgumentValue)33 BaseTest (com.axway.ats.agent.core.BaseTest)32 Test (org.junit.Test)32 ArrayList (java.util.ArrayList)25 RangeDataConfig (com.axway.ats.agent.core.threading.data.config.RangeDataConfig)2 HashMap (java.util.HashMap)2 FileNamesDataConfig (com.axway.ats.agent.core.threading.data.config.FileNamesDataConfig)1 ListDataConfig (com.axway.ats.agent.core.threading.data.config.ListDataConfig)1 File (java.io.File)1 URL (java.net.URL)1 Pattern (java.util.regex.Pattern)1