Example usage for org.springframework.util Assert isTrue

List of usage examples for org.springframework.util Assert isTrue

Introduction

In this page you can find the example usage for org.springframework.util Assert isTrue.

Prototype

public static void isTrue(boolean expression, Supplier<String> messageSupplier) 

Source Link

Document

Assert a boolean expression, throwing an IllegalArgumentException if the expression evaluates to false .

Usage

From source file:demo.domain.VehicleIdentificationNumber.java

public VehicleIdentificationNumber(String vin) {
    Assert.notNull(vin, "VIN must not be null");
    Assert.isTrue(vin.length() == 17, "VIN must be exactly 17 characters");
    this.vin = vin;
}

From source file:com.azaptree.services.domain.entity.dao.Page.java

public Page(final int page, final int pageSize) {
    Assert.isTrue(page >= 0, "contraint check failed: page >= 0");
    Assert.isTrue(pageSize >= 1, "contraint check failed: pageSize >= 1");
    this.page = page;
    this.pageSize = pageSize;
}

From source file:com.androidwhy.modules.test.selenium.WebDriverFactory.java

/**
 * ?driverName??WebDriver./*w  ww .j a  v a2s . com*/
 * 
 * ????Windows, IE?XWindows, ?remote driverWindows.
 * drivernameremote:192.168.0.2:4444:firefox, ??http://192.168.0.2:4444/wd/hub?selenium remote?.
 * @throws MalformedURLException 
 */
public static WebDriver createDriver(String driverName) {
    WebDriver driver = null;

    if (BrowserType.firefox.name().equals(driverName)) {
        driver = new FirefoxDriver();
    } else if (BrowserType.ie.name().equals(driverName)) {
        driver = new InternetExplorerDriver();
    } else if (BrowserType.chrome.name().equals(driverName)) {
        driver = new ChromeDriver();
    } else if (BrowserType.htmlunit.name().equals(driverName)) {
        driver = new HtmlUnitDriver(true);
    } else if (driverName.startsWith(BrowserType.remote.name())) {
        String[] params = driverName.split(":");
        Assert.isTrue(params.length == 4,
                "Remote driver is not right, accept format is \"remote:localhost:4444:firefox\", but the input is\""
                        + driverName + "\"");

        String remoteHost = params[1];
        String remotePort = params[2];
        String driverType = params[3];
        DesiredCapabilities cap = null;

        if (BrowserType.firefox.name().equals(driverType)) {
            cap = DesiredCapabilities.firefox();
        } else if (BrowserType.ie.name().equals(driverType)) {
            cap = DesiredCapabilities.internetExplorer();
        } else if (BrowserType.chrome.name().equals(driverType)) {
            cap = DesiredCapabilities.chrome();
        }

        try {
            driver = new RemoteWebDriver(new URL("http://" + remoteHost + ":" + remotePort + "/wd/hub"), cap);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }

    Assert.notNull(driver, "Driver could be found by name:" + driverName);

    return driver;
}

From source file:com.ewcms.common.query.Result.java

public Result setCount(int count) {
    Assert.isTrue(count >= 0, "count is not < 0");
    this.count = count;
    return this;
}

From source file:org.javelin.sws.ext.utils.NamespaceUtils.java

/**
 * Converts package name to URL for namespace according to JAXB/JAX-WS conventions with separate domain and path fragments
 * //from  w w  w  .  j ava 2s . com
 * @param pkg
 * @param domainComponentCount number of package components to be converted into domain part of URL. If zero than entire package will be a domain
 * @return
 */
public static String packageNameToNamespace(Package pkg, int domainComponentCount) {
    Assert.notNull(pkg, "Package should not be null");
    Assert.isTrue(domainComponentCount != 1,
            "The domain part should not consist of one component. It may be zero or more than 1.");

    List<String> elements = new ArrayList<String>(Arrays.asList(pkg.getName().split("\\.")));
    if (domainComponentCount > 0) {
        List<String> domain = elements.subList(0, domainComponentCount);
        List<String> path = elements.subList(domainComponentCount, elements.size());
        Collections.reverse(domain);
        return "http://" + StringUtils.collectionToDelimitedString(domain, ".") + "/"
                + StringUtils.collectionToDelimitedString(path, "/");
    } else {
        Collections.reverse(elements);
        return "http://" + StringUtils.collectionToDelimitedString(elements, ".") + "/";
    }
}

From source file:org.springside.modules.test.functional.WebDriverFactory.java

/**
 * ?driverName??WebDriver.//w  w  w  .j ava  2s  . c  o m
 * 
 * ????Windows, IE?XWindows, ?remote driverWindows.
 * drivernameremote:192.168.0.2:3000:firefox, ??http://192.168.0.2:3000/wd?selenium remote?.
 * @throws MalformedURLException 
 */
public static WebDriver createDriver(String driverName) {
    WebDriver driver = null;

    if (BrowserType.firefox.name().equals(driverName)) {
        driver = new FirefoxDriver();
    } else if (BrowserType.ie.name().equals(driverName)) {
        driver = new InternetExplorerDriver();
    } else if (BrowserType.chrome.name().equals(driverName)) {
        driver = new ChromeDriver();
    } else if (BrowserType.htmlunit.name().equals(driverName)) {
        driver = new HtmlUnitDriver();
    } else if (driverName.startsWith(BrowserType.remote.name())) {
        String[] params = driverName.split(":");
        Assert.isTrue(params.length == 4,
                "Remote driver is not right, accept format is \"remote:localhost:3000:firefox\", but the input is\""
                        + driverName + "\"");

        String remoteHost = params[1];
        String remotePort = params[2];
        String driverType = params[3];
        DesiredCapabilities cap = null;

        if (BrowserType.firefox.name().equals(driverType)) {
            cap = DesiredCapabilities.firefox();
        } else if (BrowserType.ie.name().equals(driverType)) {
            cap = DesiredCapabilities.internetExplorer();
        }

        try {
            driver = new RemoteWebDriver(new URL("http://" + remoteHost + ":" + remotePort + "/wd"), cap);
        } catch (MalformedURLException e) {
            Exceptions.unchecked(e);
        }
    }

    Assert.notNull(driver, "Driver could be found by name:" + driverName);

    return driver;
}

From source file:com.consol.citrus.validation.ValidationUtils.java

/**
 * Validates actual against expected value of element
 * @param actualValue/* www  .j  a  v a 2s.co m*/
 * @param expectedValue
 * @param pathExpression
 * @param context
 * @throws com.consol.citrus.exceptions.ValidationException if validation fails
 */
public static void validateValues(Object actualValue, Object expectedValue, String pathExpression,
        TestContext context) throws ValidationException {
    try {
        if (actualValue != null) {
            Assert.isTrue(expectedValue != null, ValidationUtils.buildValueMismatchErrorMessage(
                    "Values not equal for element '" + pathExpression + "'", null, actualValue));

            if (expectedValue instanceof Matcher) {
                Assert.isTrue(((Matcher) expectedValue).matches(actualValue),
                        ValidationUtils.buildValueMismatchErrorMessage(
                                "Values not matching for element '" + pathExpression + "'", expectedValue,
                                actualValue));
                return;
            }

            if (!(expectedValue instanceof String)) {
                Object converted = TypeConversionUtils.convertIfNecessary(actualValue,
                        expectedValue.getClass());

                if (converted instanceof List) {
                    Assert.isTrue(converted.toString().equals(expectedValue.toString()),
                            ValidationUtils.buildValueMismatchErrorMessage(
                                    "Values not equal for element '" + pathExpression + "'",
                                    expectedValue.toString(), converted.toString()));
                } else if (converted instanceof String[]) {
                    String convertedDelimitedString = StringUtils
                            .arrayToCommaDelimitedString((String[]) converted);
                    String expectedDelimitedString = StringUtils
                            .arrayToCommaDelimitedString((String[]) expectedValue);

                    Assert.isTrue(convertedDelimitedString.equals(expectedDelimitedString),
                            ValidationUtils.buildValueMismatchErrorMessage(
                                    "Values not equal for element '" + pathExpression + "'",
                                    expectedDelimitedString, convertedDelimitedString));
                } else if (converted instanceof byte[]) {
                    String convertedBase64 = Base64.encodeBase64String((byte[]) converted);
                    String expectedBase64 = Base64.encodeBase64String((byte[]) expectedValue);

                    Assert.isTrue(convertedBase64.equals(expectedBase64),
                            ValidationUtils.buildValueMismatchErrorMessage(
                                    "Values not equal for element '" + pathExpression + "'", expectedBase64,
                                    convertedBase64));
                } else {
                    Assert.isTrue(converted.equals(expectedValue),
                            ValidationUtils.buildValueMismatchErrorMessage(
                                    "Values not equal for element '" + pathExpression + "'", expectedValue,
                                    converted));
                }
            } else {
                String expectedValueString = expectedValue.toString();
                String actualValueString;
                if (List.class.isAssignableFrom(actualValue.getClass())) {
                    actualValueString = StringUtils.arrayToCommaDelimitedString(
                            ((List) actualValue).toArray(new Object[((List) actualValue).size()]));
                    expectedValueString = expectedValueString.replaceAll("^\\[", "").replaceAll("\\]$", "")
                            .replaceAll(",\\s", ",");
                } else {
                    actualValueString = actualValue.toString();
                }

                if (ValidationMatcherUtils.isValidationMatcherExpression(String.valueOf(expectedValueString))) {
                    ValidationMatcherUtils.resolveValidationMatcher(pathExpression, actualValueString,
                            String.valueOf(expectedValueString), context);
                } else {
                    Assert.isTrue(actualValueString.equals(expectedValueString),
                            ValidationUtils.buildValueMismatchErrorMessage(
                                    "Values not equal for element '" + pathExpression + "'",
                                    expectedValueString, actualValueString));
                }
            }
        } else {
            Assert.isTrue(expectedValue == null || String.valueOf(expectedValue).length() == 0,
                    ValidationUtils.buildValueMismatchErrorMessage(
                            "Values not equal for element '" + pathExpression + "'", expectedValue, null));
        }
    } catch (IllegalArgumentException e) {
        throw new ValidationException("Validation failed:", e);
    }
}

From source file:oop.appengine.modules.test.selenium.WebDriverFactory.java

/**
 * ?driverName??WebDriver./*from w  w  w .  j  ava 2s  .c om*/
 * 
 * ??firefox,ie,chrome??.
 * 
 * ??????HtmlUnit.
 * 
 * ????Windows, IE?XWindows, ???remote driverWindows.
 * drivernameremote:192.168.0.2:4444:firefox, ??http://192.168.0.2:4444/wd/hub?selenium remote?.
 */
public static WebDriver createDriver(String driverName) {
    WebDriver driver = null;

    if (BrowserType.firefox.name().equals(driverName)) {
        driver = new FirefoxDriver();
    } else if (BrowserType.ie.name().equals(driverName)) {
        driver = new InternetExplorerDriver();
    } else if (BrowserType.chrome.name().equals(driverName)) {
        driver = new ChromeDriver();
    } else if (BrowserType.htmlunit.name().equals(driverName)) {
        driver = new HtmlUnitDriver(true);
    } else if (driverName.startsWith(BrowserType.remote.name())) {
        String[] params = driverName.split(":");
        Assert.isTrue(params.length == 4,
                "Remote driver is not right, accept format is \"remote:localhost:4444:firefox\", but the input is\""
                        + driverName + "\"");

        String remoteHost = params[1];
        String remotePort = params[2];
        String driverType = params[3];

        String remoteUrl = "http://" + remoteHost + ":" + remotePort + "/wd/hub";

        DesiredCapabilities cap = null;
        if (BrowserType.firefox.name().equals(driverType)) {
            cap = DesiredCapabilities.firefox();
        } else if (BrowserType.ie.name().equals(driverType)) {
            cap = DesiredCapabilities.internetExplorer();
        } else if (BrowserType.chrome.name().equals(driverType)) {
            cap = DesiredCapabilities.chrome();
        }

        try {
            driver = new RemoteWebDriver(new URL(remoteUrl), cap);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }

    Assert.notNull(driver, "Driver could be found by name:" + driverName);

    return driver;
}

From source file:com.oreilly.springdata.neo4j.core.EmailAddress.java

public EmailAddress(String emailAddress) {
    Assert.isTrue(isValid(emailAddress), "Invalid email address!");
    this.email = emailAddress;
}

From source file:org.springmodules.validation.valang.EqualsFunction.java

protected void validateArguments(Function[] arguments) {
    Assert.isTrue(arguments.length == 2, "EqualsFunction can only be initialized with two arguments");
}