javax.validation.constraints.AssertTrue Java Examples

The following examples show how to use javax.validation.constraints.AssertTrue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BigQueryConfig.java    From presto with Apache License 2.0 7 votes vote down vote up
@AssertTrue(message = "Exactly one of 'bigquery.credentials-key' or 'bigquery.credentials-file' must be specified, or the default GoogleCredentials could be created")
public boolean isCredentialsConfigurationValid()
{
    // only one of them (at most) should be present
    if (credentialsKey.isPresent() && credentialsFile.isPresent()) {
        return false;
    }
    // if no credentials were supplied, let's check if we can create the default ones
    if (credentialsKey.isEmpty() && credentialsFile.isEmpty()) {
        try {
            GoogleCredentials.getApplicationDefault();
        }
        catch (IOException e) {
            return false;
        }
    }
    return true;
}
 
Example #2
Source File: recurringSchedule.java    From open-Autoscaler with Apache License 2.0 6 votes vote down vote up
@AssertTrue(message="{recurringSchedule.isTimeValid.AssertTrue}")
private boolean isTimeValid() {
	try {
		SimpleDateFormat parser = new SimpleDateFormat("HH:mm");
		parser.setLenient(false);
       	ParsePosition position = new ParsePosition(0);
		Date start_time = parser.parse(this.startTime, position);
       	if (( start_time == null) || (position.getIndex() != this.startTime.length()))
       		return false;
       	position = new ParsePosition(0);
		Date end_time = parser.parse(this.endTime, position);
       	if (( end_time == null) || (position.getIndex() != this.endTime.length()))
       		return false;
       	return start_time.before(end_time);
	} catch (Exception e) {
		return false;
	}
}
 
Example #3
Source File: recurringSchedule.java    From open-Autoscaler with Apache License 2.0 6 votes vote down vote up
@AssertTrue(message="{recurringSchedule.isRepeatOnValid.AssertTrue}")
private boolean isRepeatOnValid() {
	String[] s_values = this.repeatOn.replace("\"", "").replace("[", "").replace("]", "").split(",");
	String[] weekday = {"1", "2", "3", "4", "5", "6", "7"};
    List<String> weekday_list = Arrays.asList(weekday);
    Set<String> validValues = new HashSet<String>(weekday_list);

    List<String> value_list = Arrays.asList(s_values);
    Set<String> value_set = new HashSet<String>(value_list);

    if ( s_values.length > value_set.size()) {
		return false;
	}
	for (String s: s_values){
		if(!validValues.contains(s)) {
			return false;
		}
	}
	if ( s_values.length > validValues.size()) {
		return false;
	}
	return true;
}
 
Example #4
Source File: specificDate.java    From open-Autoscaler with Apache License 2.0 6 votes vote down vote up
@AssertTrue(message="{specificDate.isDateTimeValid.AssertTrue}")
private boolean isDateTimeValid() {
	try {
		SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		dateformat.setLenient(false);
		ParsePosition position = new ParsePosition(0);
       	String firstDateTime = this.startDate + " " + this.startTime;
       	String secondDateTime = this.endDate + " " + this.endTime;
       	Date first = dateformat.parse(firstDateTime, position);
       	if (( first == null) || (position.getIndex() != firstDateTime.length()))
       		return false;
       	position = new ParsePosition(0);
       	Date second = dateformat.parse(secondDateTime, position);
       	if (( second == null) || (position.getIndex() != secondDateTime.length()))
       		return false;
       	return first.before(second);
	} catch (Exception e) {
		BeanValidation.logger.info(e.getMessage());
		return false;
	}
}
 
Example #5
Source File: TransferedPolicy.java    From open-Autoscaler with Apache License 2.0 5 votes vote down vote up
@AssertTrue(message="{Policy.isSpecificDateTimeValid.AssertTrue}")
private boolean isSpecificDateTimeValid() {
	if ((this.schedules != null) && (SpecificDateTimeValid(this.schedules.specificDate) == false)) {
		return false;
	}
	return true;
}
 
Example #6
Source File: ReflectionMagicWorksTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
/**
 * Makes sure that the Reflections helper stuff is working properly and capturing all annotation possibilities (class type, constructor, constructor param, method, method param, and field).
 */
@Test
public void verifyThatTheReflectionsConfigurationIsCapturingAllAnnotationPossibilities() {
    List<Pair<Annotation, AnnotatedElement>> annotationOptionsClassAnnotations = getSubAnnotationListForElementsOfOwnerClass(TROLLER.allConstraintAnnotationsMasterList,
            DifferentValidationAnnotationOptions.class);
    assertThat(annotationOptionsClassAnnotations.size(), is(10));
    assertThat(getSubAnnotationListForAnnotationsOfClassType(annotationOptionsClassAnnotations, SomeClassLevelJsr303Annotation.class).size(), is(2));
    assertThat(getSubAnnotationListForAnnotationsOfClassType(annotationOptionsClassAnnotations, OtherClassLevelJsr303Annotation.class).size(), is(1));
    assertThat(getSubAnnotationListForAnnotationsOfClassType(annotationOptionsClassAnnotations, AssertTrue.class).size(), is(1));
    assertThat(getSubAnnotationListForAnnotationsOfClassType(annotationOptionsClassAnnotations, AssertFalse.class).size(), is(1));
    assertThat(getSubAnnotationListForAnnotationsOfClassType(annotationOptionsClassAnnotations, NotNull.class).size(), is(2));
    assertThat(getSubAnnotationListForAnnotationsOfClassType(annotationOptionsClassAnnotations, Min.class).size(), is(2));
    assertThat(getSubAnnotationListForAnnotationsOfClassType(annotationOptionsClassAnnotations, Max.class).size(), is(1));
}
 
Example #7
Source File: ReflectionMagicWorksTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@AssertTrue(message = "I am a constructor annotated with a constraint even though it doesn't really make sense")
public DifferentValidationAnnotationOptions(String nonAnnotatedConstructorParam,
                                            @NotNull(message = "I am a constructor param annotated with a constraint 1") String annotatedConstructorParam1,
                                            @NotNull(message = "I am a constructor param annotated with a constraint 2") String annotatedConstructorParam2,
                                            String alsoNotAnnotatedConstructorParam) {

}
 
Example #8
Source File: HistoryData.java    From open-Autoscaler with Apache License 2.0 5 votes vote down vote up
@AssertTrue(message="{HistoryData.isTimeZoneValid.AssertTrue}")
private boolean isTimeZoneValid() {
	Set<String> timezoneset = new HashSet<String>(Arrays.asList(Constants.timezones));
    if(timezoneset.contains(this.timeZone))
    	return true;
    return false;
}
 
Example #9
Source File: GenieTest.java    From java-di with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegisteredPostConstructProcessor() {
    genie.registerPostConstructProcessor(AssertTrue.class, new AssertTrueHandler());
    yes(genie.get(FooToPass.class).val);
    try {
        genie.get(FooToFail.class);
        fail("Expect ValidationException here");
    } catch (ValidationException e) {
        // test pass
    }
}
 
Example #10
Source File: Schedule.java    From open-Autoscaler with Apache License 2.0 5 votes vote down vote up
@AssertTrue(message="{Schedule.isTimeZoneValid.AssertTrue}") //debug
private boolean isTimeZoneValid() {
	if ((null != this.timezone) && (this.timezone.trim().length() != 0)) {
		BeanValidation.logger.debug("In schedules timezone is " + this.timezone);//debug
		Set<String> timezoneset = new HashSet<String>(Arrays.asList(Constants.timezones));
	    if(timezoneset.contains(this.timezone))
	    	return true;
	    else
	    	return false;
	}
	else { 
		BeanValidation.logger.debug("timezone is empty in schedules");//debug
              return false; //timezone must be specified in Schedule
          }
}
 
Example #11
Source File: TransferedPolicy.java    From open-Autoscaler with Apache License 2.0 5 votes vote down vote up
@AssertTrue(message="{Policy.isMetricTypeValid.AssertTrue}")
private boolean isMetricTypeUnique() {
	Set<String> metric_types = new HashSet<String>();
	for (PolicyTrigger trigger : this.policyTriggers){
		metric_types.add(trigger.metricType);
	}
	if (metric_types.size() != this.policyTriggers.size())
		return false;
	else 
		return true;
}
 
Example #12
Source File: Schedule.java    From open-Autoscaler with Apache License 2.0 5 votes vote down vote up
@AssertTrue(message="{Schedule.isScheduleValid.AssertTrue}") //debug
private boolean isScheduleValid() {
	if (((null == this.recurringSchedule) || (this.recurringSchedule.size() == 0) ) && ((null == this.specificDate) || (this.specificDate.size() == 0)) ){
              return false;  //at least one setting should be exist
          }
	return true;
}
 
Example #13
Source File: TransferedPolicy.java    From open-Autoscaler with Apache License 2.0 5 votes vote down vote up
@AssertTrue(message="{PolicyTrigger.isInstanceStepCountUpValid.AssertTrue}")
private boolean isInstanceStepCountUpValid() {		//debug we support count instead of percent change only currently
	for (PolicyTrigger trigger : this.policyTriggers){
		if (trigger.instanceStepCountUp > (instanceMaxCount -1))
			return false;
	}
	return true;
}
 
Example #14
Source File: TransferedPolicy.java    From open-Autoscaler with Apache License 2.0 5 votes vote down vote up
@AssertTrue(message="{Policy.isMetricTypeMatched.AssertTrue}")
private boolean isMetricTypeSupported() {
	String [] supported_metrics = Constants.getMetricTypeByAppType(this.appType);
	BeanValidation.logger.info("supported metrics are: " + Arrays.toString(supported_metrics));
	if (supported_metrics != null) {
		for (PolicyTrigger trigger : this.policyTriggers) {
			if  (!(Arrays.asList(supported_metrics).contains(trigger.metricType)))
				return false;
		}
	}
	return true;
}
 
Example #15
Source File: TransferedPolicy.java    From open-Autoscaler with Apache License 2.0 5 votes vote down vote up
@AssertTrue(message="{Policy.isRecurringScheduleTimeValid.AssertTrue}")
private boolean isRecurringScheduleTimeValid() {
	if ((this.schedules != null) && (RecurringScheduleTimeValid(this.schedules.recurringSchedule) == false)) {
		return false;
	}
	return true;

}
 
Example #16
Source File: specificDate.java    From open-Autoscaler with Apache License 2.0 5 votes vote down vote up
@AssertTrue(message="{specificDate.isInstCountValid.AssertTrue}")
private boolean isInstCountValid() {
	if (this.maxInstCount > 0) { //maxInstCount is set
		if (this.minInstCount > this.maxInstCount) {
		    	return false;
		}
	}
    return true;
}
 
Example #17
Source File: AssertTruePostProcessor.java    From RestDoc with Apache License 2.0 5 votes vote down vote up
@Override
public PropertyModel postProcessInternal(PropertyModel propertyModel) {
    AssertTrue assertTrueAnno = propertyModel.getPropertyItem().getAnnotation(AssertTrue.class);
    if (assertTrueAnno == null) return propertyModel;

    propertyModel.setDescription(TextUtils.combine(propertyModel.getDescription(), " (值只能为true)"));
    return propertyModel;
}
 
Example #18
Source File: MySqlJdbcConfig.java    From presto with Apache License 2.0 5 votes vote down vote up
@AssertTrue(message = "Database (catalog) must not be specified in JDBC URL for MySQL connector")
public boolean isUrlWithoutDatabase()
{
    try {
        Driver driver = new Driver();
        Properties properties = driver.parseURL(getConnectionUrl(), null);
        return (properties == null) || (driver.database(properties) == null);
    }
    catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
 
Example #19
Source File: MySqlJdbcConfig.java    From presto with Apache License 2.0 5 votes vote down vote up
@AssertTrue(message = "Invalid JDBC URL for MySQL connector")
public boolean isUrlValid()
{
    try {
        Driver driver = new Driver();
        Properties properties = driver.parseURL(getConnectionUrl(), null);
        return properties != null;
    }
    catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
 
Example #20
Source File: TestLdapConfig.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidation()
{
    assertValidates(new LdapConfig()
            .setLdapUrl("ldaps://localhost")
            .setUserBindSearchPattern("uid=${USER},ou=org,dc=test,dc=com")
            .setUserBaseDistinguishedName("dc=test,dc=com")
            .setGroupAuthorizationSearchPattern("&(objectClass=user)(memberOf=cn=group)(user=username)"));

    assertValidates(new LdapConfig()
            .setLdapUrl("ldap://localhost")
            .setAllowInsecure(true)
            .setUserBindSearchPattern("uid=${USER},ou=org,dc=test,dc=com")
            .setUserBaseDistinguishedName("dc=test,dc=com")
            .setGroupAuthorizationSearchPattern("&(objectClass=user)(memberOf=cn=group)(user=username)"));

    assertFailsValidation(
            new LdapConfig()
                    .setLdapUrl("ldap://")
                    .setAllowInsecure(false),
            "urlConfigurationValid",
            "Connecting to the LDAP server without SSL enabled requires `ldap.allow-insecure=true`",
            AssertTrue.class);

    assertFailsValidation(new LdapConfig().setLdapUrl("localhost"), "ldapUrl", "Invalid LDAP server URL. Expected ldap:// or ldaps://", Pattern.class);
    assertFailsValidation(new LdapConfig().setLdapUrl("ldaps:/localhost"), "ldapUrl", "Invalid LDAP server URL. Expected ldap:// or ldaps://", Pattern.class);

    assertFailsValidation(new LdapConfig(), "ldapUrl", "may not be null", NotNull.class);
}
 
Example #21
Source File: ResetPasswordForm.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 4 votes vote down vote up
@AssertTrue(message="密碼與再次確認密碼不相符")
private boolean isValid() {
  return password.equals(password2);
}
 
Example #22
Source File: ResetPasswordForm.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 4 votes vote down vote up
@AssertTrue(message="密碼與再次確認密碼不相符")
private boolean isValid() {
  return password.equals(password2);
}
 
Example #23
Source File: RegisterForm.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 4 votes vote down vote up
@AssertTrue(message="密碼與再次確認密碼不相符")
private boolean isValid() {
  return password.equals(password2);
}
 
Example #24
Source File: PmmlProcessorProperties.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
@AssertTrue(message = "At most one of 'modelName' and 'modelNameExpression' is allowed")
public boolean isAtMostOneModelName() {
	return modelName == null || modelNameExpression == null;
}
 
Example #25
Source File: ResetPasswordForm.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 4 votes vote down vote up
@AssertTrue(message="密碼與再次確認密碼不相符")
private boolean isValid() {
  return password.equals(password2);
}
 
Example #26
Source File: ResetPasswordForm.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 4 votes vote down vote up
@AssertTrue(message="密碼與再次確認密碼不相符")
private boolean isValid() {
  return password.equals(password2);
}
 
Example #27
Source File: RegisterForm.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 4 votes vote down vote up
@AssertTrue(message="密碼與再次確認密碼不相符")
private boolean isValid() {
  return password.equals(password2);
}
 
Example #28
Source File: SyslogSourceProperties.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
@AssertTrue(message = "protocl must be 'udp' or 'tcp' or 'both'")
public boolean isSupportedProtocol() {
	return "tcp".equals(this.protocol) || "udp".equals(this.protocol) || "both".equals(this.protocol);
}
 
Example #29
Source File: RegisterForm.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 4 votes vote down vote up
@AssertTrue(message="密碼與再次確認密碼不相符")
private boolean isValid() {
  return password.equals(password2);
}
 
Example #30
Source File: FileSinkProperties.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
@AssertTrue(message = "Exactly one of 'name' or 'nameExpression' must be set")
public boolean isMutuallyExclusiveNameAndNameExpression() {
	return DEFAULT_NAME.equals(name) || nameExpression == null;
}