use of com.capgemini.ntc.test.core.exceptions.BFInputDataException in project devonfw-testing by devonfw.
the class SpreadsheetEnvironmentService method fetchEnvData.
private void fetchEnvData(String path) throws BFInputDataException {
File csvData = new File(path);
try {
CSVParser parser = CSVParser.parse(csvData, Charset.defaultCharset(), CSVFormat.RFC4180);
records = parser.getRecords();
} catch (IOException e) {
throw new BFInputDataException("Unable to parse CSV: " + path);
}
}
use of com.capgemini.ntc.test.core.exceptions.BFInputDataException in project devonfw-testing by devonfw.
the class StringUtils method findSubstring.
/**
* Searches for occurrence of regex in textToMatch
*
* @param textToMatch
* @param regex
* to find
* @param groupNumber
* number of group to return <b>counting from 1</b>
* @return first found match or empty string
*/
public static String findSubstring(String textToMatch, String regex, int groupNumber) {
Pattern pattern = Pattern.compile(regex);
Matcher patternMatcher = pattern.matcher(textToMatch);
if (patternMatcher.find()) {
int groupCount = patternMatcher.groupCount();
if (groupNumber > groupCount) {
throw new BFInputDataException("Unable to return group number " + groupNumber + ". Only " + groupCount + " groups were found for regex \"" + regex + "\" in text \"" + textToMatch + "\".");
}
return patternMatcher.group(groupNumber);
}
return "";
}
use of com.capgemini.ntc.test.core.exceptions.BFInputDataException in project devonfw-testing by devonfw.
the class StringUtils method findSubstrings.
/**
* Searches for occurrences of regex in textToMatch
*
* @param textToMatch
* @param regex
* to find
* @param groupNumber
* number of group to return <b>counting from 1</b>
* @return all found matches or empty list
*/
public static List<String> findSubstrings(String textToMatch, String regex, int groupNumber) {
Pattern pattern = Pattern.compile(regex);
Matcher patternMatcher = pattern.matcher(textToMatch);
List<String> toReturn = new ArrayList<String>();
while (patternMatcher.find()) {
int groupCount = patternMatcher.groupCount();
if (groupNumber > groupCount) {
throw new BFInputDataException("Unable to return group number " + groupNumber + ". Only " + groupCount + " groups were found for regex \"" + regex + "\" in text \"" + textToMatch + "\".");
}
toReturn.add(patternMatcher.group(groupNumber));
}
return toReturn;
}
use of com.capgemini.ntc.test.core.exceptions.BFInputDataException in project devonfw-testing by devonfw.
the class TestUtils method getAbsolutePathFor.
/**
* Generates absolute path to the file saved in test resources (/src/test/resources) Input: path - like
* 'environments/environments.csv' Output: absolute path to the file based on current OS
*/
public static String getAbsolutePathFor(String path) {
String absolutePath = "";
try {
String resourceFile = TestUtils.class.getClassLoader().getResource(path).getFile();
absolutePath = new File(resourceFile).getAbsolutePath();
} catch (NullPointerException e) {
throw new BFInputDataException("Given path: (" + path + ") does not exists in src/test/resources");
}
return absolutePath;
}
use of com.capgemini.ntc.test.core.exceptions.BFInputDataException in project devonfw-testing by devonfw.
the class TimeUtills method stringToDate.
/**
* To transform date in String to Date object
*
* @param value
* @param format
* @return Date
* @author
*/
public static Date stringToDate(String value, String format) {
Date date = null;
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
try {
date = dateFormat.parse(value);
} catch (ParseException e) {
String exceptionMessage = "stringToDate failed : value is " + value + ", format is " + format;
BFLogger.logDebug(exceptionMessage);
throw new BFInputDataException(exceptionMessage);
}
return date;
}
Aggregations