@Test public void unsupportedCommunicationType() { serverConfig.setCommunicationType(CommunicationType.WEB_SOCKET); assertThat(validator.isValid(serverConfig, cvc)).isFalse(); verify(cvc).disableDefaultConstraintViolation(); verify(cvc).buildConstraintViolationWithTemplate(anyString()); }
@Override public boolean isValid(ServerConfig serverConfig, ConstraintValidatorContext constraintContext) { if (serverConfig == null) { return true; } if (serverConfig.getApp() == null || AppType.ADMIN.toString().equals(serverConfig.getApp().toString())) { String supportedAppTypes = Arrays.stream(AppType.values()) .filter(t -> t != AppType.ADMIN) .map(AppType::name) .map(n -> "THIRD_PARTY".equals(n) ? "ThirdParty" : n) .collect(Collectors.joining(", ")); constraintContext.disableDefaultConstraintViolation(); constraintContext .buildConstraintViolationWithTemplate( "app must be provided for serverConfig and be one of " + supportedAppTypes) .addConstraintViolation(); return false; } if (!serverConfig.getApp().getAllowedCommunicationTypes().contains(serverConfig.getCommunicationType())) { LOGGER.debug( "Invalid communicationType '" + serverConfig.getCommunicationType() + "' specified for serverConfig with app " + serverConfig.getApp()); constraintContext.disableDefaultConstraintViolation(); constraintContext .buildConstraintViolationWithTemplate( "Invalid communicationType '" + serverConfig.getCommunicationType() + "' specified for serverConfig with app " + serverConfig.getApp()) .addConstraintViolation(); return false; } if (serverConfig.getApp() != AppType.THIRD_PARTY) { if (serverConfig.getCrossDomainConfig() != null) { LOGGER.debug("Invalid server config. CrossDomainConfig is only allowed in ThirdParty server"); constraintContext.disableDefaultConstraintViolation(); constraintContext .buildConstraintViolationWithTemplate( "Invalid server config. CrossDomainConfig is only allowed in ThirdParty server") .addConstraintViolation(); return false; } } return true; }
ServerConfigValidator implements ConstraintValidator<ValidServerConfig, ServerConfig> { @Override public boolean isValid(ServerConfig serverConfig, ConstraintValidatorContext constraintContext) { if (serverConfig == null) { return true; } if (serverConfig.getApp() == null || AppType.ADMIN.toString().equals(serverConfig.getApp().toString())) { String supportedAppTypes = Arrays.stream(AppType.values()) .filter(t -> t != AppType.ADMIN) .map(AppType::name) .map(n -> "THIRD_PARTY".equals(n) ? "ThirdParty" : n) .collect(Collectors.joining(", ")); constraintContext.disableDefaultConstraintViolation(); constraintContext .buildConstraintViolationWithTemplate( "app must be provided for serverConfig and be one of " + supportedAppTypes) .addConstraintViolation(); return false; } if (!serverConfig.getApp().getAllowedCommunicationTypes().contains(serverConfig.getCommunicationType())) { LOGGER.debug( "Invalid communicationType '" + serverConfig.getCommunicationType() + "' specified for serverConfig with app " + serverConfig.getApp()); constraintContext.disableDefaultConstraintViolation(); constraintContext .buildConstraintViolationWithTemplate( "Invalid communicationType '" + serverConfig.getCommunicationType() + "' specified for serverConfig with app " + serverConfig.getApp()) .addConstraintViolation(); return false; } if (serverConfig.getApp() != AppType.THIRD_PARTY) { if (serverConfig.getCrossDomainConfig() != null) { LOGGER.debug("Invalid server config. CrossDomainConfig is only allowed in ThirdParty server"); constraintContext.disableDefaultConstraintViolation(); constraintContext .buildConstraintViolationWithTemplate( "Invalid server config. CrossDomainConfig is only allowed in ThirdParty server") .addConstraintViolation(); return false; } } return true; } }
ServerConfigValidator implements ConstraintValidator<ValidServerConfig, ServerConfig> { @Override public boolean isValid(ServerConfig serverConfig, ConstraintValidatorContext constraintContext) { if (serverConfig == null) { return true; } if (serverConfig.getApp() == null || AppType.ADMIN.toString().equals(serverConfig.getApp().toString())) { String supportedAppTypes = Arrays.stream(AppType.values()) .filter(t -> t != AppType.ADMIN) .map(AppType::name) .map(n -> "THIRD_PARTY".equals(n) ? "ThirdParty" : n) .collect(Collectors.joining(", ")); constraintContext.disableDefaultConstraintViolation(); constraintContext .buildConstraintViolationWithTemplate( "app must be provided for serverConfig and be one of " + supportedAppTypes) .addConstraintViolation(); return false; } if (!serverConfig.getApp().getAllowedCommunicationTypes().contains(serverConfig.getCommunicationType())) { LOGGER.debug( "Invalid communicationType '" + serverConfig.getCommunicationType() + "' specified for serverConfig with app " + serverConfig.getApp()); constraintContext.disableDefaultConstraintViolation(); constraintContext .buildConstraintViolationWithTemplate( "Invalid communicationType '" + serverConfig.getCommunicationType() + "' specified for serverConfig with app " + serverConfig.getApp()) .addConstraintViolation(); return false; } if (serverConfig.getApp() != AppType.THIRD_PARTY) { if (serverConfig.getCrossDomainConfig() != null) { LOGGER.debug("Invalid server config. CrossDomainConfig is only allowed in ThirdParty server"); constraintContext.disableDefaultConstraintViolation(); constraintContext .buildConstraintViolationWithTemplate( "Invalid server config. CrossDomainConfig is only allowed in ThirdParty server") .addConstraintViolation(); return false; } } return true; }  }
ServerConfigValidator implements ConstraintValidator<ValidServerConfig, ServerConfig> { @Override public boolean isValid(ServerConfig serverConfig, ConstraintValidatorContext constraintContext) { if (serverConfig == null) { return true; } if (serverConfig.getApp() == null || AppType.ADMIN.toString().equals(serverConfig.getApp().toString())) { String supportedAppTypes = Arrays.stream(AppType.values()) .filter(t -> t != AppType.ADMIN) .map(AppType::name) .map(n -> "THIRD_PARTY".equals(n) ? "ThirdParty" : n) .collect(Collectors.joining(", ")); constraintContext.disableDefaultConstraintViolation(); constraintContext .buildConstraintViolationWithTemplate( "app must be provided for serverConfig and be one of " + supportedAppTypes) .addConstraintViolation(); return false; } if (!serverConfig.getApp().getAllowedCommunicationTypes().contains(serverConfig.getCommunicationType())) { LOGGER.debug( "Invalid communicationType '" + serverConfig.getCommunicationType() + "' specified for serverConfig with app " + serverConfig.getApp()); constraintContext.disableDefaultConstraintViolation(); constraintContext .buildConstraintViolationWithTemplate( "Invalid communicationType '" + serverConfig.getCommunicationType() + "' specified for serverConfig with app " + serverConfig.getApp()) .addConstraintViolation(); return false; } if (serverConfig.getApp() != AppType.THIRD_PARTY) { if (serverConfig.getCrossDomainConfig() != null) { LOGGER.debug("Invalid server config. CrossDomainConfig is only allowed in ThirdParty server"); constraintContext.disableDefaultConstraintViolation(); constraintContext .buildConstraintViolationWithTemplate( "Invalid server config. CrossDomainConfig is only allowed in ThirdParty server") .addConstraintViolation(); return false; } } return true; }  @Override boolean isValid(ServerConfig serverConfig, ConstraintValidatorContext constraintContext); }
ServerConfigValidator implements ConstraintValidator<ValidServerConfig, ServerConfig> { @Override public boolean isValid(ServerConfig serverConfig, ConstraintValidatorContext constraintContext) { if (serverConfig == null) { return true; } if (serverConfig.getApp() == null || AppType.ADMIN.toString().equals(serverConfig.getApp().toString())) { String supportedAppTypes = Arrays.stream(AppType.values()) .filter(t -> t != AppType.ADMIN) .map(AppType::name) .map(n -> "THIRD_PARTY".equals(n) ? "ThirdParty" : n) .collect(Collectors.joining(", ")); constraintContext.disableDefaultConstraintViolation(); constraintContext .buildConstraintViolationWithTemplate( "app must be provided for serverConfig and be one of " + supportedAppTypes) .addConstraintViolation(); return false; } if (!serverConfig.getApp().getAllowedCommunicationTypes().contains(serverConfig.getCommunicationType())) { LOGGER.debug( "Invalid communicationType '" + serverConfig.getCommunicationType() + "' specified for serverConfig with app " + serverConfig.getApp()); constraintContext.disableDefaultConstraintViolation(); constraintContext .buildConstraintViolationWithTemplate( "Invalid communicationType '" + serverConfig.getCommunicationType() + "' specified for serverConfig with app " + serverConfig.getApp()) .addConstraintViolation(); return false; } if (serverConfig.getApp() != AppType.THIRD_PARTY) { if (serverConfig.getCrossDomainConfig() != null) { LOGGER.debug("Invalid server config. CrossDomainConfig is only allowed in ThirdParty server"); constraintContext.disableDefaultConstraintViolation(); constraintContext .buildConstraintViolationWithTemplate( "Invalid server config. CrossDomainConfig is only allowed in ThirdParty server") .addConstraintViolation(); return false; } } return true; }  @Override boolean isValid(ServerConfig serverConfig, ConstraintValidatorContext constraintContext);  }