Search in sources :

Example 1 with BFInputDataException

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);
    }
}
Also used : CSVParser(org.apache.commons.csv.CSVParser) IOException(java.io.IOException) BFInputDataException(com.capgemini.ntc.test.core.exceptions.BFInputDataException) File(java.io.File)

Example 2 with BFInputDataException

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 "";
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) BFInputDataException(com.capgemini.ntc.test.core.exceptions.BFInputDataException)

Example 3 with BFInputDataException

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;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) BFInputDataException(com.capgemini.ntc.test.core.exceptions.BFInputDataException)

Example 4 with BFInputDataException

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;
}
Also used : BFInputDataException(com.capgemini.ntc.test.core.exceptions.BFInputDataException) File(java.io.File)

Example 5 with BFInputDataException

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;
}
Also used : ParseException(java.text.ParseException) BFInputDataException(com.capgemini.ntc.test.core.exceptions.BFInputDataException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

BFInputDataException (com.capgemini.ntc.test.core.exceptions.BFInputDataException)6 File (java.io.File)2 IOException (java.io.IOException)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 CSVParser (org.apache.commons.csv.CSVParser)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1