Java Code Examples for com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse#success()

The following examples show how to use com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse#success() . 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: YamlConfigPluginIntegrationTest.java    From gocd-yaml-config-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldContainValidFieldsInResponseMessage() throws UnhandledRequestTypeException {
    GoApiResponse settingsResponse = DefaultGoApiResponse.success("{}");
    when(goAccessor.submit(any(GoApiRequest.class))).thenReturn(settingsResponse);

    GoPluginApiResponse response = parseAndGetResponseForDir(tempDir.getRoot());

    assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE));
    final JsonParser parser = new JsonParser();
    JsonElement responseObj = parser.parse(response.responseBody());
    assertTrue(responseObj.isJsonObject());
    JsonObject obj = responseObj.getAsJsonObject();
    assertTrue(obj.has("errors"));
    assertTrue(obj.has("pipelines"));
    assertTrue(obj.has("environments"));
    assertTrue(obj.has("target_version"));
}
 
Example 2
Source File: YamlConfigPluginIntegrationTest.java    From gocd-yaml-config-plugin with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    plugin = new YamlConfigPlugin();
    goAccessor = mock(GoApplicationAccessor.class);
    plugin.initializeGoApplicationAccessor(goAccessor);
    GoApiResponse settingsResponse = DefaultGoApiResponse.success("{}");
    when(goAccessor.submit(any(GoApiRequest.class))).thenReturn(settingsResponse);
    parser = new JsonParser();
}
 
Example 3
Source File: YamlConfigPluginIntegrationTest.java    From gocd-yaml-config-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRespondSuccessToParseDirectoryRequestWhenPluginHasConfiguration() throws UnhandledRequestTypeException {
    GoApiResponse settingsResponse = DefaultGoApiResponse.success("{}");
    when(goAccessor.submit(any(GoApiRequest.class))).thenReturn(settingsResponse);

    GoPluginApiResponse response = parseAndGetResponseForDir(tempDir.getRoot());

    verify(goAccessor, times(1)).submit(any(GoApiRequest.class));
    assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE));
}
 
Example 4
Source File: ServerInfoRequestProcessor.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Override
public GoApiResponse process(GoPluginDescriptor pluginDescriptor, GoApiRequest goPluginApiRequest) {
    try {
        MessageHandlerForServerInfoRequestProcessor requestProcessor = this.versionToMessageHandlerMap.get(goPluginApiRequest.apiVersion());
        ServerConfig serverConfig = configService.serverConfig();

        String serverInfoJSON = requestProcessor.serverInfoToJSON(serverConfig);

        return DefaultGoApiResponse.success(serverInfoJSON);
    } catch (Exception e) {
        LOGGER.error(format("Error processing ServerInfo request from plugin: %s.", pluginDescriptor.id()), e);
        return DefaultGoApiResponse.badRequest(format("Error while processing get ServerInfo request - %s", e.getMessage()));
    }
}
 
Example 5
Source File: ArtifactRequestProcessor.java    From gocd with Apache License 2.0 5 votes vote down vote up
private GoApiResponse processConsoleLogRequest(GoPluginDescriptor pluginDescriptor, GoApiRequest request) {
    final ConsoleLogMessage consoleLogMessage = ConsoleLogMessage.fromJSON(request.requestBody());
    final String message = format("[%s] %s", pluginDescriptor.id(), consoleLogMessage.getMessage());
    Optional<String> parsedTag = parseTag(processType, consoleLogMessage.getLogLevel());
    if (parsedTag.isPresent()) {
        safeOutputStreamConsumer.taggedStdOutput(parsedTag.get(), message);
        return DefaultGoApiResponse.success(null);
    }
    return DefaultGoApiResponse.error(format("Unsupported log level `%s`.", consoleLogMessage.getLogLevel()));
}
 
Example 6
Source File: AuthorizationRequestProcessor.java    From gocd with Apache License 2.0 4 votes vote down vote up
private GoApiResponse processInvalidateCacheRequest(GoPluginDescriptor pluginDescriptor) {
    pluginRoleService.invalidateRolesFor(pluginDescriptor.id());
    return DefaultGoApiResponse.success(null);
}
 
Example 7
Source File: ElasticAgentRequestProcessorV1.java    From gocd with Apache License 2.0 4 votes vote down vote up
@Override
public GoApiResponse processListAgents(GoPluginDescriptor pluginDescriptor, GoApiRequest goPluginApiRequest) {
    final Collection<AgentMetadata> metadata = getAgentMetadataForPlugin(pluginDescriptor.id());
    String responseBody = elasticAgentProcessorConverterV1.listAgentsResponseBody(metadata);
    return DefaultGoApiResponse.success(responseBody);
}