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"));
}
}
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));
}
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;
}
Aggregations