当前位置: 首页>>代码示例>>Java>>正文


Java ValidationError类代码示例

本文整理汇总了Java中com.thoughtworks.go.plugin.api.response.validation.ValidationError的典型用法代码示例。如果您正苦于以下问题:Java ValidationError类的具体用法?Java ValidationError怎么用?Java ValidationError使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ValidationError类属于com.thoughtworks.go.plugin.api.response.validation包,在下文中一共展示了ValidationError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validate

import com.thoughtworks.go.plugin.api.response.validation.ValidationError; //导入依赖的package包/类
@Override
public ValidationResult validate(TaskConfig configuration) {
    ValidationResult validationResult = new ValidationResult();
    String bitness = configuration.getValue(BITNESS);
    if (StringUtils.isBlank(bitness)) {
        validationResult.addError(new ValidationError(BITNESS, "Bitness must be specified"));
    }

    String scriptFile = configuration.getValue(FILE);
    if (StringUtils.isBlank(scriptFile)) {
        validationResult.addError(new ValidationError(FILE, "Script to be run cannot be empty"));
    }

    String executionMode = configuration.getValue(MODE);
    if (StringUtils.isBlank(executionMode)) {
        validationResult.addError(new ValidationError(MODE, "Execution mode must be specified"));
    }

    return validationResult;
}
 
开发者ID:manojlds,项目名称:gocd-powershell-runner,代码行数:21,代码来源:PowershellTask.java

示例2: isRepositoryConfigurationValid

import com.thoughtworks.go.plugin.api.response.validation.ValidationError; //导入依赖的package包/类
@Override
@EntryPoint
public ValidationResult isRepositoryConfigurationValid(RepositoryConfiguration repositoryConfiguration) {
    SaferConfiguration configuration = new SaferConfiguration(repositoryConfiguration);
    String forgeUrl = configuration.get(FORGE_URL);
    LOG.info("Validating configuration for forge (URL = %s)", forgeUrl);

    ValidationResult validationResult = new ValidationResult();
    if (forgeUrl.isEmpty()) {
        validationResult.addError(new ValidationError(FORGE_URL, "Forge URL is mandatory"));
    } else {
        try {
            URL url = new URL(forgeUrl);
            if (!url.getProtocol().matches("^https?$")) {
                validationResult.addError(new ValidationError(FORGE_URL, "Forge URL must be an HTTP(S) URL"));
            }
        } catch (MalformedURLException e) {
            validationResult.addError(new ValidationError(FORGE_URL, "Forge URL must be a URL"));
        }
    }
    return validationResult;
}
 
开发者ID:drrb,项目名称:go-puppet-forge-poller,代码行数:23,代码来源:ForgePollerPluginConfig.java

示例3: validateData

import com.thoughtworks.go.plugin.api.response.validation.ValidationError; //导入依赖的package包/类
/**
 * Validate the data of both configuration.
 * 
 * @param repositoryConfigurations
 * @param packageConfigurations 
 */
private void validateData(
        final RepositoryConfiguration repositoryConfigurations, 
        final PackageConfiguration packageConfigurations) {
    
    ValidationResult validationResult = new ValidationResult();
    new DockerMaterialConfiguration().validate(packageConfigurations, repositoryConfigurations, validationResult);
    if (!validationResult.isSuccessful()) {
        StringBuilder stringBuilder = new StringBuilder();
        for (ValidationError validationError : validationResult.getErrors()) {
            stringBuilder.append(validationError.getMessage()).append("; ");
        }
        String errorString = stringBuilder.toString();
        String message = errorString.substring(0, errorString.length() - 2);
        LOG.warn(String.format("Data validation failed: %s", message));
        throw new RuntimeException(message);
    }
}
 
开发者ID:decoomanj,项目名称:gocd-docker-material-poller,代码行数:24,代码来源:DockerMaterialPoller.java

示例4: isRepositoryConfigurationValid

import com.thoughtworks.go.plugin.api.response.validation.ValidationError; //导入依赖的package包/类
/**
 * Check the validity of the supplied repository fields. It does a syntax
 * check. It does not check if the repository is available. It checks if the
 * repository contains unwanted fields.
 *
 * NOTE: A package in Go is the repository from Docker.
 *
 * @param repositoryConfiguration
 * @return ValidationResult
 */
@Override
public ValidationResult isRepositoryConfigurationValid(
        final RepositoryConfiguration repositoryConfiguration) {

    LOG.info("Validating repository: " + repositoryConfiguration.get(Constants.REGISTRY).getValue());
    ValidationResult validationResult = new ValidationResult();
    this.validateKeys(getRepositoryConfiguration(), repositoryConfiguration, validationResult);

    Property registry = repositoryConfiguration.get(Constants.REGISTRY);
    if (registry == null) {
        validationResult.addError(new ValidationError(Constants.REGISTRY, "Registry url not specified"));
        return validationResult;
    }

    DockerRegistry.getInstance(registry.getValue()).validate(validationResult);
    return validationResult;
}
 
开发者ID:decoomanj,项目名称:gocd-docker-material-poller,代码行数:28,代码来源:DockerMaterialConfiguration.java

示例5: validate

import com.thoughtworks.go.plugin.api.response.validation.ValidationError; //导入依赖的package包/类
/**
 * Validate the URL.
 *
 * @param validationResult The list with invalid fields.
 */
public void validate(final ValidationResult validationResult) {
    try {
        if (StringUtils.isBlank(url)) {
            validationResult.addError(new ValidationError(Constants.REGISTRY, "URL is empty"));
            return;
        }
        URL validatedUrl = new URL(this.url);
        if (!protocols.contains(validatedUrl.getProtocol())) {
            validationResult.addError(new ValidationError(Constants.REGISTRY, "Invalid URL: Only 'http' and 'https' protocols are supported."));
        }

        if (StringUtils.isNotBlank(validatedUrl.getUserInfo())) {
            validationResult.addError(new ValidationError(Constants.REGISTRY, "User info should not be provided as part of the URL. Please provide credentials using USERNAME and PASSWORD configuration keys."));
        }
    } catch (MalformedURLException e) {
        validationResult.addError(new ValidationError(Constants.REGISTRY, "Invalid URL : " + url));
    }
}
 
开发者ID:decoomanj,项目名称:gocd-docker-material-poller,代码行数:24,代码来源:DockerRegistry.java

示例6: toValidationResult

import com.thoughtworks.go.plugin.api.response.validation.ValidationError; //导入依赖的package包/类
@Override
public ValidationResult toValidationResult(String responseBody) {
    ValidationResult validationResult = new ValidationResult();
    ArrayList<String> exceptions = new ArrayList<>();
    try {
        Map result = (Map) new GsonBuilder().create().fromJson(responseBody, Object.class);
        if (result == null) return validationResult;
        final Map<String, Object> errors = (Map<String, Object>) result.get("errors");
        if (errors != null) {
            for (Map.Entry<String, Object> entry : errors.entrySet()) {
                if (!(entry.getValue() instanceof String)) {
                    exceptions.add(String.format("Key: '%s' - The Json for Validation Request must contain a not-null error message of type String", entry.getKey()));
                } else {
                    validationResult.addError(new ValidationError(entry.getKey(), entry.getValue().toString()));
                }
            }
        }
        if (!exceptions.isEmpty()) {
            throw new RuntimeException(StringUtils.join(exceptions, ", "));
        }
        return validationResult;
    } catch (Exception e) {
        LOGGER.error("Error occurred while converting the Json to Validation Result. Error: {}. The Json received was '{}'.", e.getMessage(), responseBody);
        throw new RuntimeException(String.format("Error occurred while converting the Json to Validation Result. Error: %s.", e.getMessage()));
    }
}
 
开发者ID:gocd,项目名称:gocd,代码行数:27,代码来源:JsonBasedTaskExtensionHandler_V1.java

示例7: shouldConvertJsonResponseToValidationResultWhenValidationFails

import com.thoughtworks.go.plugin.api.response.validation.ValidationError; //导入依赖的package包/类
@Test
public void shouldConvertJsonResponseToValidationResultWhenValidationFails() {
    String jsonResponse = "{\"errors\":{\"key1\":\"err1\",\"key2\":\"err2\"}}";

    TaskConfig configuration = new TaskConfig();
    TaskConfigProperty property = new TaskConfigProperty("URL", "http://foo");
    property.with(Property.SECURE, false);
    property.with(Property.REQUIRED, true);
    configuration.add(property);

    ValidationResult result = new JsonBasedTaskExtensionHandler_V1().toValidationResult(jsonResponse);

    Assert.assertThat(result.isSuccessful(), CoreMatchers.is(false));


    ValidationError error1 = result.getErrors().get(0);
    ValidationError error2 = result.getErrors().get(1);

    Assert.assertThat(error1.getKey(), CoreMatchers.is("key1"));
    Assert.assertThat(error1.getMessage(), CoreMatchers.is("err1"));
    Assert.assertThat(error2.getKey(), CoreMatchers.is("key2"));
    Assert.assertThat(error2.getMessage(), CoreMatchers.is("err2"));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:24,代码来源:JsonBasedTaskExtensionHandler_V1Test.java

示例8: shouldValidateArtifactStoreConfig

import com.thoughtworks.go.plugin.api.response.validation.ValidationError; //导入依赖的package包/类
@Test
public void shouldValidateArtifactStoreConfig() {
    String responseBody = "[{\"message\":\"ACCESS_KEY must not be blank.\",\"key\":\"ACCESS_KEY\"}]";

    when(pluginManager.submitTo(eq(PLUGIN_ID), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));

    ValidationResult validationResult = artifactExtension.validateArtifactStoreConfig(PLUGIN_ID, Collections.singletonMap("ACCESS_KEY", ""));

    final GoPluginApiRequest request = requestArgumentCaptor.getValue();

    assertThat(request.extension(), is(ARTIFACT_EXTENSION));
    assertThat(request.requestName(), is(REQUEST_STORE_CONFIG_VALIDATE));
    assertThat(request.requestBody(), is("{\"ACCESS_KEY\":\"\"}"));

    assertThat(validationResult.isSuccessful(), is(false));
    assertThat(validationResult.getErrors(), containsInAnyOrder(
            new ValidationError("ACCESS_KEY", "ACCESS_KEY must not be blank.")
    ));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:20,代码来源:ArtifactExtensionTest.java

示例9: shouldValidatePluggableArtifactConfig

import com.thoughtworks.go.plugin.api.response.validation.ValidationError; //导入依赖的package包/类
@Test
public void shouldValidatePluggableArtifactConfig() {
    String responseBody = "[{\"message\":\"Filename must not be blank.\",\"key\":\"Filename\"}]";

    when(pluginManager.submitTo(eq(PLUGIN_ID), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));

    ValidationResult validationResult = artifactExtension.validatePluggableArtifactConfig(PLUGIN_ID, Collections.singletonMap("Filename", ""));

    final GoPluginApiRequest request = requestArgumentCaptor.getValue();

    assertThat(request.extension(), is(ARTIFACT_EXTENSION));
    assertThat(request.requestName(), is(REQUEST_PUBLISH_ARTIFACT_VALIDATE));
    assertThat(request.requestBody(), is("{\"Filename\":\"\"}"));

    assertThat(validationResult.isSuccessful(), is(false));
    assertThat(validationResult.getErrors(), containsInAnyOrder(
            new ValidationError("Filename", "Filename must not be blank.")
    ));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:20,代码来源:ArtifactExtensionTest.java

示例10: shouldValidateFetchArtifactConfig

import com.thoughtworks.go.plugin.api.response.validation.ValidationError; //导入依赖的package包/类
@Test
public void shouldValidateFetchArtifactConfig() {
    String responseBody = "[{\"message\":\"Filename must not be blank.\",\"key\":\"Filename\"}]";

    when(pluginManager.submitTo(eq(PLUGIN_ID), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));

    ValidationResult validationResult = artifactExtension.validateFetchArtifactConfig(PLUGIN_ID, Collections.singletonMap("Filename", ""));

    final GoPluginApiRequest request = requestArgumentCaptor.getValue();

    assertThat(request.extension(), is(ARTIFACT_EXTENSION));
    assertThat(request.requestName(), is(REQUEST_FETCH_ARTIFACT_VALIDATE));
    assertThat(request.requestBody(), is("{\"Filename\":\"\"}"));

    assertThat(validationResult.isSuccessful(), is(false));
    assertThat(validationResult.getErrors(), containsInAnyOrder(
            new ValidationError("Filename", "Filename must not be blank.")
    ));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:20,代码来源:ArtifactExtensionTest.java

示例11: shouldValidateMandatoryFields

import com.thoughtworks.go.plugin.api.response.validation.ValidationError; //导入依赖的package包/类
@Test
public void shouldValidateMandatoryFields() {
    Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
    PluggableTask modifiedTask = new PluggableTask(new PluginConfiguration(pluginId, "1"), configuration);
    ValidationResult validationResult = new ValidationResult();
    when(taskExtension.validate(eq(modifiedTask.getPluginConfiguration().getId()), any(TaskConfig.class))).thenReturn(validationResult);
    when(localizer.localize("MANDATORY_CONFIGURATION_FIELD")).thenReturn("MANDATORY_CONFIGURATION_FIELD");

    pluggableTaskService.validate(modifiedTask);

    final List<ValidationError> validationErrors = validationResult.getErrors();
    assertFalse(validationErrors.isEmpty());
    final ValidationError validationError = validationErrors.stream().filter(new Predicate<ValidationError>() {
        @Override
        public boolean test(ValidationError item) {
            return ((ValidationError) item).getKey().equals("KEY1");
        }
    }).findFirst().orElse(null);
    assertNotNull(validationError);
    assertThat(validationError.getMessage(), is("MANDATORY_CONFIGURATION_FIELD"));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:22,代码来源:PluggableTaskServiceTest.java

示例12: isValidShouldMapPluginValidationErrorsToPluggableTaskConfigrations

import com.thoughtworks.go.plugin.api.response.validation.ValidationError; //导入依赖的package包/类
@Test
public void isValidShouldMapPluginValidationErrorsToPluggableTaskConfigrations() {
    PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin_id", "version");
    Configuration configuration = new Configuration();
    configuration.add(ConfigurationPropertyMother.create("source", false, "src_dir"));
    configuration.add(ConfigurationPropertyMother.create("destination", false, "dest_dir"));

    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(new ValidationError("source", "source directory format is invalid"));
    validationResult.addError(new ValidationError("destination", "destination directory format is invalid"));

    PluggableTask pluggableTask = mock(PluggableTask.class);

    when(pluggableTask.isValid()).thenReturn(true);
    when(pluggableTask.getPluginConfiguration()).thenReturn(pluginConfiguration);
    when(pluggableTask.getConfiguration()).thenReturn(configuration);
    when(taskExtension.validate(any(String.class), any(TaskConfig.class))).thenReturn(validationResult);

    assertFalse(pluggableTaskService.isValid(pluggableTask));
    assertThat(configuration.getProperty("source").errors().get("source").get(0), is("source directory format is invalid"));
    assertThat(configuration.getProperty("destination").errors().get("destination").get(0), is("destination directory format is invalid"));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:23,代码来源:PluggableTaskServiceTest.java

示例13: isValidShouldMapPluginValidationErrorsToPluggableTaskForMissingConfigurations

import com.thoughtworks.go.plugin.api.response.validation.ValidationError; //导入依赖的package包/类
@Test
public void isValidShouldMapPluginValidationErrorsToPluggableTaskForMissingConfigurations() {
    PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin_id", "version");

    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(new ValidationError("source", "source is mandatory"));

    PluggableTask pluggableTask = mock(PluggableTask.class);

    when(pluggableTask.isValid()).thenReturn(true);
    when(pluggableTask.getPluginConfiguration()).thenReturn(pluginConfiguration);
    when(pluggableTask.getConfiguration()).thenReturn(new Configuration());
    when(taskExtension.validate(any(String.class), any(TaskConfig.class))).thenReturn(validationResult);

    assertFalse(pluggableTaskService.isValid(pluggableTask));
    verify(pluggableTask).addError("source", "source is mandatory");
}
 
开发者ID:gocd,项目名称:gocd,代码行数:18,代码来源:PluggableTaskServiceTest.java

示例14: shouldPerformPluginValidationsUsingMetaDataBeforeSavingPackageRepository

import com.thoughtworks.go.plugin.api.response.validation.ValidationError; //导入依赖的package包/类
@Test
public void shouldPerformPluginValidationsUsingMetaDataBeforeSavingPackageRepository() throws Exception {
    Configuration configuration = new Configuration();
    configuration.add(ConfigurationPropertyMother.create("required", false, ""));
    configuration.add(ConfigurationPropertyMother.create("required_secure", true, ""));
    configuration.add(ConfigurationPropertyMother.create("secure", true, ""));
    configuration.add(ConfigurationPropertyMother.create("not_required_not_secure", false, ""));
    configuration.add(ConfigurationPropertyMother.create("spec", false, "xyz?"));
    PackageDefinition packageDefinition = PackageDefinitionMother.create("1", "name", configuration, packageRepository);

    ValidationResult expectedValidationResult = new ValidationResult();
    expectedValidationResult.addError(new ValidationError("spec", "invalid spec"));
    when(packageRepositoryExtension.isPackageConfigurationValid(eq(packageRepository.getPluginConfiguration().getId()),
            any(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration.class),
            any(RepositoryConfiguration.class))).thenReturn(expectedValidationResult);
    service.performPluginValidationsFor(packageDefinition);

    assertThat(packageDefinition.getConfiguration().get(0).getConfigurationValue().errors().getAllOn("value"), is(Arrays.asList("mandatory field")));
    assertThat(packageDefinition.getConfiguration().get(1).getEncryptedConfigurationValue().errors().getAllOn("value"), is(Arrays.asList("mandatory field")));
    assertThat(packageDefinition.getConfiguration().get(2).getEncryptedConfigurationValue().errors().isEmpty(), is(true));
    assertThat(packageDefinition.getConfiguration().get(3).getConfigurationValue().errors().isEmpty(), is(true));
    assertThat(packageDefinition.getConfiguration().get(4).getConfigurationValue().errors().getAllOn("value"), is(Arrays.asList("invalid spec")));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:24,代码来源:PackageDefinitionServiceTest.java

示例15: shouldPerformPluginValidationsBeforeValidationsByGoAndGoDoesNotAddErrorIfAlreadyPresent

import com.thoughtworks.go.plugin.api.response.validation.ValidationError; //导入依赖的package包/类
@Test
public void shouldPerformPluginValidationsBeforeValidationsByGoAndGoDoesNotAddErrorIfAlreadyPresent() throws Exception {
    Configuration configuration = new Configuration();
    configuration.add(ConfigurationPropertyMother.create("required-field", false, ""));
    PackageDefinition packageDefinition = PackageDefinitionMother.create("1", "name", configuration, packageRepository);

    ValidationResult expectedValidationResult = new ValidationResult();
    expectedValidationResult.addError(new ValidationError("required-field", "error-one"));
    expectedValidationResult.addError(new ValidationError("required-field", "error-two"));

    when(packageRepositoryExtension.isPackageConfigurationValid(eq(packageRepository.getPluginConfiguration().getId()),
            any(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration.class),
            any(RepositoryConfiguration.class))).thenReturn(expectedValidationResult);
    service.performPluginValidationsFor(packageDefinition);
    assertThat(packageDefinition.getConfiguration().get(0).getConfigurationValue().errors().getAllOn("value").size(), is(2));
    assertThat(packageDefinition.getConfiguration().get(0).getConfigurationValue().errors().getAllOn("value"), is(hasItems("error-one", "error-two")));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:18,代码来源:PackageDefinitionServiceTest.java


注:本文中的com.thoughtworks.go.plugin.api.response.validation.ValidationError类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。