Search in sources :

Example 6 with CRParseResult

use of com.thoughtworks.go.plugin.access.configrepo.contract.CRParseResult in project gocd by gocd.

the class JsonMessageHandler1_0Test method shouldNotErrorWhenTargetVersionInResponse.

@Test
public void shouldNotErrorWhenTargetVersionInResponse() {
    String json = "{\n" + "  \"target_version\" : 1,\n" + "  \"pipelines\" : [],\n" + "  \"errors\" : []\n" + "}";
    makeMigratorReturnSameJSON();
    CRParseResult result = handler.responseMessageForParseDirectory(json);
    assertFalse(result.hasErrors());
}
Also used : CRParseResult(com.thoughtworks.go.plugin.access.configrepo.contract.CRParseResult) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 7 with CRParseResult

use of com.thoughtworks.go.plugin.access.configrepo.contract.CRParseResult in project gocd by gocd.

the class ConfigRepoPlugin method load.

@Override
public PartialConfig load(File configRepoCheckoutDirectory, PartialConfigLoadContext context) {
    Collection<CRConfigurationProperty> cRconfigurations = getCrConfigurations(context.configuration());
    CRParseResult crPartialConfig = parseDirectory(configRepoCheckoutDirectory, cRconfigurations);
    return configConverter.toPartialConfig(crPartialConfig, context);
}
Also used : CRConfigurationProperty(com.thoughtworks.go.plugin.access.configrepo.contract.CRConfigurationProperty) CRParseResult(com.thoughtworks.go.plugin.access.configrepo.contract.CRParseResult)

Example 8 with CRParseResult

use of com.thoughtworks.go.plugin.access.configrepo.contract.CRParseResult in project gocd by gocd.

the class JsonMessageHandler1_0 method responseMessageForParseDirectory.

@Override
public CRParseResult responseMessageForParseDirectory(String responseBody) {
    ErrorCollection errors = new ErrorCollection();
    try {
        ResponseScratch responseMap = parseResponseForMigration(responseBody);
        ParseDirectoryResponseMessage parseDirectoryResponseMessage;
        if (responseMap.target_version == null) {
            errors.addError("Plugin response message", "missing 'target_version' field");
            return new CRParseResult(errors);
        } else {
            int version = responseMap.target_version;
            while (version < CURRENT_CONTRACT_VERSION) {
                version++;
                responseBody = migrate(responseBody, version);
            }
            // after migration, json should match contract
            parseDirectoryResponseMessage = codec.getGson().fromJson(responseBody, ParseDirectoryResponseMessage.class);
            parseDirectoryResponseMessage.validateResponse(errors);
            errors.addErrors(parseDirectoryResponseMessage.getPluginErrors());
            return new CRParseResult(parseDirectoryResponseMessage.getEnvironments(), parseDirectoryResponseMessage.getPipelines(), errors);
        }
    } catch (Exception ex) {
        StringBuilder builder = new StringBuilder();
        builder.append("Unexpected error when handling plugin response").append('\n');
        builder.append(ex);
        // "location" of error is runtime. This is what user will see in config repo errors list.
        errors.addError("runtime", builder.toString());
        LOGGER.error(builder.toString(), ex);
        return new CRParseResult(errors);
    }
}
Also used : ParseDirectoryResponseMessage(com.thoughtworks.go.plugin.access.configrepo.messages.ParseDirectoryResponseMessage) CRParseResult(com.thoughtworks.go.plugin.access.configrepo.contract.CRParseResult)

Aggregations

CRParseResult (com.thoughtworks.go.plugin.access.configrepo.contract.CRParseResult)8 Test (org.junit.Test)5 Matchers.anyString (org.mockito.Matchers.anyString)3 ErrorCollection (com.thoughtworks.go.plugin.access.configrepo.ErrorCollection)2 Collection (java.util.Collection)2 ConfigRepoExtension (com.thoughtworks.go.plugin.access.configrepo.ConfigRepoExtension)1 CRConfigurationProperty (com.thoughtworks.go.plugin.access.configrepo.contract.CRConfigurationProperty)1 ParseDirectoryResponseMessage (com.thoughtworks.go.plugin.access.configrepo.messages.ParseDirectoryResponseMessage)1 File (java.io.File)1 Before (org.junit.Before)1