All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sqlancer.common.query.ExpectedErrors Maven / Gradle / Ivy

Go to download

SQLancer finds logic bugs in Database Management Systems through automatic testing

There is a newer version: 2.0.0
Show newest version
package sqlancer.common.query;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * This class represents the errors that executing a statement might result in. For example, an INSERT statement might
 * result in an error "UNIQUE constraint violated" when it attempts to insert a duplicate value in a column declared as
 * UNIQUE.
 */
public class ExpectedErrors {

    private final Set errors = new HashSet<>();

    public ExpectedErrors add(String error) {
        if (error == null) {
            throw new IllegalArgumentException();
        }
        errors.add(error);
        return this;
    }

    /**
     * Checks whether the error message (e.g., returned by the DBMS under test) contains any of the added error
     * messages.
     *
     * @param error
     *            the error message
     *
     * @return whether the error message contains any of the substrings specified as expected errors
     */
    public boolean errorIsExpected(String error) {
        if (error == null) {
            throw new IllegalArgumentException();
        }
        for (String s : errors) {
            if (error.contains(s)) {
                return true;
            }
        }
        return false;
    }

    public ExpectedErrors addAll(Collection list) {
        errors.addAll(list);
        return this;
    }

    public static ExpectedErrors from(String... errors) {
        ExpectedErrors expectedErrors = new ExpectedErrors();
        for (String error : errors) {
            expectedErrors.add(error);
        }
        return expectedErrors;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy