List of usage examples for org.springframework.util Assert isTrue
public static void isTrue(boolean expression, Supplier<String> messageSupplier)
From source file:org.jasig.cas.event.TicketEvent.java
/** * Constructs a TicketEvent with either the ticketId or the ticket as the * source object (depending on whether a Ticket is provided). * //from w ww . jav a 2 s . c o m * @param ticket The ticket the event is for. * @param ticketEventType the event type. * @param ticketId the id of the ticket. * @throws IllegalArgumentException if the EventType is null. * @throws IllegalArgumentException if the ticketId and the ticket are null. */ private TicketEvent(final Ticket ticket, final TicketEventType ticketEventType, final String ticketId) { super((ticket == null) ? (Object) ticketId : ticket); Assert.notNull(ticketEventType, "ticketEventType cannot be null"); Assert.isTrue(ticketId != null || ticket != null, "ticketId or ticket is required"); if (ticket != null) { this.ticketId = ticket.getId(); } else { this.ticketId = ticketId; } this.ticketEventType = ticketEventType; }
From source file:grails.plugin.searchable.internal.compass.search.DefaultStringQuerySearchableCompassQueryBuilder.java
public CompassQuery buildQuery(GrailsApplication grailsApplication, CompassSession compassSession, Map options, Object query) {/*from ww w . j av a 2 s .c o m*/ Assert.notNull(query, "query cannot be null"); Assert.isInstanceOf(String.class, query, "query must be a String but is [" + query.getClass().getName() + "]"); String analyzer = (String) getOption(ANALYZER_NAMES, options); String parser = (String) getOption(PARSER_NAMES, options); String defaultSearchProperty = (String) getOption(DEFAULT_PROPERTY_NAMES, options); Collection properties = (Collection) getOption(PROPERTIES_NAMES, options); Boolean useAndDefaultOperator = (Boolean) getOption(USE_AND_DEFAULT_OPERATOR_NAMES, options); String defaultOperator = (String) getOption(DEFAULT_OPERATOR_NAMES, options); Boolean escape = MapUtils.getBoolean(options, "escape", false); Assert.isTrue(!(properties != null && defaultSearchProperty != null), "The " + DefaultGroovyMethods.join(DEFAULT_PROPERTY_NAMES, "/") + " and " + DefaultGroovyMethods.join(PROPERTIES_NAMES, "/") + " options cannot be combined"); Assert.isTrue(!(defaultOperator != null && useAndDefaultOperator != null), "The [" + DefaultGroovyMethods.join(USE_AND_DEFAULT_OPERATOR_NAMES, ", ") + "] and [" + DEFAULT_PROPERTY_NAMES[0] + "] options indicate the same thing so cannot be used together: [" + DEFAULT_PROPERTY_NAMES + "] is better"); String queryString = (String) query; if (escape) { queryString = CompassQueryParser.escape(queryString); } CompassQueryBuilder compassQueryBuilder = compassSession.queryBuilder(); CompassQueryBuilder.ToCompassQuery stringBuilder; if (properties != null && !properties.isEmpty()) { stringBuilder = compassQueryBuilder.multiPropertyQueryString(queryString); for (Iterator iter = properties.iterator(); iter.hasNext();) { ((CompassQueryBuilder.CompassMultiPropertyQueryStringBuilder) stringBuilder) .add((String) iter.next()); } } else { stringBuilder = compassQueryBuilder.queryString(queryString); } if (analyzer != null) { InvokerHelper.invokeMethod(stringBuilder, "setAnalyzer", analyzer); } if (parser != null) { InvokerHelper.invokeMethod(stringBuilder, "setQueryParser", parser); } if (defaultSearchProperty != null) { InvokerHelper.invokeMethod(stringBuilder, "setDefaultSearchProperty", defaultSearchProperty); } // todo deprecate "useAndDefaultOperator" - "defaultOperator" is better if (useAndDefaultOperator != null) { if (useAndDefaultOperator) { InvokerHelper.invokeMethod(stringBuilder, "useAndDefaultOperator", null); } else { InvokerHelper.invokeMethod(stringBuilder, "useOrDefaultOperator", null); } } if (defaultOperator != null) { if (defaultOperator.equalsIgnoreCase("and")) { InvokerHelper.invokeMethod(stringBuilder, "useAndDefaultOperator", null); } else if (defaultOperator.equalsIgnoreCase("or")) { InvokerHelper.invokeMethod(stringBuilder, "useOrDefaultOperator", null); } else { throw new IllegalArgumentException("The [" + DEFAULT_OPERATOR_NAMES[0] + "] option only accepts 'and' or 'or' values but [" + defaultOperator + "] was supplied"); } } return stringBuilder.toQuery(); }
From source file:org.agatom.springatom.data.oid.creators.DefaultSOidCreator.java
@Override public SOid fromString(final String from) throws Exception { if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("fromString(from=%s)", from)); }//from w w w .jav a 2 s . c om final SOid oid; final Stopwatch stopwatch = Stopwatch.createStarted(); try { final String split[] = from.split(":"); Assert.isTrue(split.length == 3, String.format("OID[%s] is invalid, it should be in format A:B:C", from)); final String oidPrefix = split[TYPE_PREFIX_INDEX]; final Class<?> oidClass = Class.forName(split[CLASS_NAME_INDEX]); final String oidId = split[ID_INDEX]; oid = this.getOidObject(oidPrefix, oidClass, oidId); } catch (Exception exp) { LOGGER.error(String.format("fromString(from=%s) failed...", from), Throwables.getRootCause(exp)); throw exp; } stopwatch.stop(); if (LOGGER.isTraceEnabled()) { final long elapsed = stopwatch.elapsed(TimeUnit.MILLISECONDS); LOGGER.trace(String.format("fromString(from=%s) to SOid(oid=%s) took %d ms", from, oid, elapsed)); } return oid; }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.ClaimDAOJPATest.java
@Test public void testAddNewClaim() { Claim claim5 = new Claim(); claim5.setClaimType(URI.create("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/town")); claim5.setDisplayName("Town"); claim5.setDescription("Town Description"); claimDAO.addClaim(claim5);// w w w . j a v a 2 s. c o m List<Claim> claims = claimDAO.getClaims(0, 999); Assert.isTrue(6 == claims.size(), "Size doesn't match. Claim not added"); }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.IdpDAOJPATest.java
@Test public void testReadExistingIdpEmbeddedAll() throws MalformedURLException { Idp idp = idpDAO.getIdp("urn:org:apache:cxf:fediz:idp:realm-A", Arrays.asList("all")); Assert.isTrue("stsKeystoreA.properties".equals(idp.getCertificate()), "Certificate doesn't match"); Assert.isTrue("realma".equals(idp.getCertificatePassword()), "Certificate password doesn't match"); Assert.isTrue("urn:org:apache:cxf:fediz:idp:realm-A".equals(idp.getRealm()), "Realm doesn't match"); Assert.isTrue("IDP of Realm A".equals(idp.getServiceDescription()), "ServiceDescription doesn't match"); Assert.isTrue("REALM A".equals(idp.getServiceDisplayName()), "ServiceDisplayName doesn't match"); Assert.isTrue(new URL("https://localhost:9443/fediz-idp/federation").equals(idp.getIdpUrl()), "IdpUrl doesn't match"); Assert.isTrue(new URL("https://localhost:9443/fediz-idp-sts/REALMA").equals(idp.getStsUrl()), "StsUrl doesn't match"); Assert.isTrue("realma".equals(idp.getUri()), "Uri doesn't match"); Assert.isTrue(idp.isProvideIdpList(), "ProvideIDPList doesn't match"); Assert.isTrue(idp.isUseCurrentIdp(), "UseCurrentIDP doesn't match"); Assert.isTrue(4 == idp.getAuthenticationURIs().size(), "Number of AuthenticationURIs doesn't match"); Assert.isTrue(2 == idp.getSupportedProtocols().size(), "Number of SupportedProtocols doesn't match"); Assert.isTrue(2 == idp.getTokenTypesOffered().size(), "Number of TokenTypesOffered doesn't match"); Assert.isTrue(1 == idp.getApplications().size(), "Number of applications doesn't match"); Assert.isTrue(1 == idp.getTrustedIdps().size(), "Number of trusted IDPs doesn't match"); Assert.isTrue(4 == idp.getClaimTypesOffered().size(), "Number of claims doesn't match"); }
From source file:com.azaptree.services.security.domain.impl.SubjectImpl.java
@Override public void setMaxSessions(final int maxSessions) { Assert.isTrue(maxSessions > 0, "constraint check failed: maxSessions > 0"); this.maxSessions = maxSessions; }
From source file:cat.albirar.framework.proxy.ProxyFactory.java
/** * Create a proxy for the indicated type. * @param handler The handler/*from ww w .j av a 2 s.c o m*/ * @param type The type, should to be a interface type * @return The proxy */ @SuppressWarnings("unchecked") private <T> T newProxyForInterface(java.lang.reflect.InvocationHandler handler, Class<T> type) { Assert.isTrue(type.isInterface(), "The type should to be an interface"); return (T) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, handler); }
From source file:org.cleverbus.core.common.asynch.confirm.ConfirmationServiceImpl.java
@Transactional @Override//from w ww .j a va 2 s . co m public void confirmationFailed(ExternalCall extCall) { Assert.notNull(extCall, "the extCall must not be null"); Assert.isTrue(ExternalCall.CONFIRM_OPERATION.equals(extCall.getOperationName()), "the extCall must be a " + ExternalCall.CONFIRM_OPERATION + ", but is " + extCall.getOperationName()); Assert.isTrue(extCall.getState() == ExternalCallStateEnum.PROCESSING, "the confirmation must be PROCESSING state, but is in " + extCall.getState()); int failedCount = extCall.getFailedCount() + 1; extCall.setFailedCount(failedCount); ExternalCallStateEnum state = ExternalCallStateEnum.FAILED; if (failedCount > failedCountLimit) { state = ExternalCallStateEnum.FAILED_END; } extCall.setState(state); extCallDao.update(extCall); Log.debug("Confirmation call " + extCall.toHumanString() + " changed state to " + state); }
From source file:org.netxilia.spi.impl.storage.db.ddl.schema.DbColumn.java
/** Has no effect if column's type has fixed size. However, the value is recorded. */ public void setScale(Integer scale) { Assert.isTrue((scale == null) || (scale.intValue() > 0), "Column scale must be > 0"); this.scale = scale; }