com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse Java Examples

The following examples show how to use com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse. 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: TaskExtensionTest.java    From gocd with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldValidateTask() {
    GoPluginApiResponse response = mock(GoPluginApiResponse.class);
    TaskExtension jsonBasedTaskExtension = new TaskExtension(pluginManager, extensionsRegistry);
    TaskConfig taskConfig = mock(TaskConfig.class);

    when(response.responseCode()).thenReturn(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE);
    when(pluginManager.isPluginOfType(PLUGGABLE_TASK_EXTENSION, pluginId)).thenReturn(true);
    when(response.responseBody()).thenReturn("{\"errors\":{\"key\":\"error\"}}");
    when(pluginManager.submitTo(eq(pluginId), eq(PLUGGABLE_TASK_EXTENSION), any(GoPluginApiRequest.class))).thenReturn(response);

    ValidationResult validationResult = jsonBasedTaskExtension.validate(pluginId, taskConfig);

    verify(pluginManager).submitTo(eq(pluginId), eq(PLUGGABLE_TASK_EXTENSION), any(GoPluginApiRequest.class));
    assertFalse(validationResult.isSuccessful());
    assertEquals(validationResult.getErrors().get(0).getKey(), "key");
    assertEquals(validationResult.getErrors().get(0).getMessage(), "error");
}
 
Example #2
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 #3
Source File: CheckMkTask.java    From gocd-plugins with Apache License 2.0 6 votes vote down vote up
@Override
protected GoPluginApiResponse handleTaskView(GoPluginApiRequest request) {
    int responseCode = DefaultGoApiResponse.SUCCESS_RESPONSE_CODE;
    HashMap view = new HashMap();
    view.put("displayValue", "Monitoring - Check MK");
    try {
        String checkMkTemplate = IOUtils.toString(getClass().getResourceAsStream("/views/checkMk.template.html"), "UTF-8");
        view.put("template", checkMkTemplate);
    } catch (Exception e) {
        responseCode = DefaultGoApiResponse.INTERNAL_ERROR;
        String errorMessage = "Failed to find template: " + e.getMessage();
        view.put("exception", errorMessage);
        logger.error(errorMessage, e);
    }
    return createResponse(responseCode, view);
}
 
Example #4
Source File: PluginSettingsRequestProcessor.java    From gocd with Apache License 2.0 6 votes vote down vote up
@Override
public GoApiResponse process(GoPluginDescriptor pluginDescriptor, GoApiRequest goPluginApiRequest) {
    try {
        MessageHandlerForPluginSettingsRequestProcessor processor = versionToMessageHandlerMap.get(goPluginApiRequest.apiVersion());

        DefaultGoApiResponse response = new DefaultGoApiResponse(200);
        response.setResponseBody(processor.pluginSettingsToJSON(pluginSettingsFor(pluginDescriptor.id())));

        return response;
    } catch (Exception e) {
        LOGGER.error(format("Error processing PluginSettings request from plugin: %s.", pluginDescriptor.id()), e);

        DefaultGoApiResponse errorResponse = new DefaultGoApiResponse(400);
        errorResponse.setResponseBody(format("Error while processing get PluginSettings request - %s", e.getMessage()));

        return errorResponse;
    }
}
 
Example #5
Source File: ConsoleLogRequestProcessor.java    From gocd with Apache License 2.0 6 votes vote down vote up
@Override
public GoApiResponse process(GoPluginDescriptor pluginDescriptor, GoApiRequest request) {
    try {
        validatePluginRequest(request);

        final MessageHandlerForConsoleLogRequestProcessor handler = versionToMessageHandlerMap.get(request.apiVersion());
        final ConsoleLogAppendRequest logUpdateRequest = handler.deserializeConsoleLogAppendRequest(request.requestBody());
        consoleService.appendToConsoleLog(logUpdateRequest.jobIdentifier(), logUpdateRequest.text());
    } catch (Exception e) {
        DefaultGoApiResponse response = new DefaultGoApiResponse(DefaultGoApiResponse.INTERNAL_ERROR);
        response.setResponseBody(format("'{' \"message\": \"Error: {0}\" '}'", e.getMessage()));
        LOGGER.warn("Failed to handle message from plugin {}: {}", pluginDescriptor.id(), request.requestBody(), e);
        return response;
    }

    return new DefaultGoApiResponse(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE);
}
 
Example #6
Source File: ServerHealthRequestProcessor.java    From gocd with Apache License 2.0 6 votes vote down vote up
@Override
public GoApiResponse process(GoPluginDescriptor pluginDescriptor, GoApiRequest goPluginApiRequest) {
    String errorMessageTitle = format("Message from plugin: {0}", pluginDescriptor.id());
    HealthStateScope scope = HealthStateScope.fromPlugin(pluginDescriptor.id());

    try {
        MessageHandlerForServerHealthRequestProcessor messageHandler = versionToMessageHandlerMap.get(goPluginApiRequest.apiVersion());
        List<PluginHealthMessage> pluginHealthMessages = messageHandler.deserializeServerHealthMessages(goPluginApiRequest.requestBody());
        replaceServerHealthMessages(errorMessageTitle, scope, pluginHealthMessages);
    } catch (Exception e) {
        DefaultGoApiResponse response = new DefaultGoApiResponse(DefaultGoApiResponse.INTERNAL_ERROR);
        response.setResponseBody(format("'{' \"message\": \"{0}\" '}'", e.getMessage()));
        LOGGER.warn("Failed to handle message from plugin {}: {}", pluginDescriptor.id(), goPluginApiRequest.requestBody(), e);
        return response;
    }

    return new DefaultGoApiResponse(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE);
}
 
Example #7
Source File: PluginRequestHelperTest.java    From gocd with Apache License 2.0 6 votes vote down vote up
@Test
void shouldConstructTheRequest() {
    final String requestBody = "request_body";
    when(response.responseCode()).thenReturn(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE);

    final GoPluginApiRequest[] generatedRequest = {null};
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            generatedRequest[0] = (GoPluginApiRequest) invocationOnMock.getArguments()[2];
            return response;
        }
    }).when(pluginManager).submitTo(eq(pluginId), eq(extensionName), any(GoPluginApiRequest.class));


    helper.submitRequest(pluginId, requestName, new DefaultPluginInteractionCallback<Object>() {
        @Override
        public String requestBody(String resolvedExtensionVersion) {
            return requestBody;
        }
    });
    assertThat(generatedRequest[0].requestBody()).isEqualTo(requestBody);
    assertThat(generatedRequest[0].extension()).isEqualTo(extensionName);
    assertThat(generatedRequest[0].requestName()).isEqualTo(requestName);
    assertThat(generatedRequest[0].requestParameters().isEmpty()).isTrue();
}
 
Example #8
Source File: ConsoleLogRequestProcessorV2Test.java    From gocd with Apache License 2.0 6 votes vote down vote up
@Test
void shouldRouteMessageToConsoleService() throws IOException, IllegalArtifactLocationException {
    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("pipeline_name", "p1");
    requestMap.put("pipeline_counter", "1");
    requestMap.put("stage_name", "s1");
    requestMap.put("stage_counter", "2");
    requestMap.put("job_name", "j1");
    requestMap.put("text", "message1");

    DefaultGoApiRequest goApiRequest = new DefaultGoApiRequest(APPEND_TO_CONSOLE_LOG, VERSION_2, null);
    goApiRequest.setRequestBody(new GsonBuilder().create().toJson(requestMap));

    final ConsoleLogRequestProcessor processor = new ConsoleLogRequestProcessor(pluginRequestProcessorRegistry, consoleService);
    final GoApiResponse response = processor.process(pluginDescriptor, goApiRequest);

    assertThat(response.responseCode(), is(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE));

    final JobIdentifier jobIdentifier = new JobIdentifier("p1", 1, null, "s1", "2", "j1");
    verify(consoleService).appendToConsoleLog(jobIdentifier, "message1");
}
 
Example #9
Source File: ConsoleLogRequestProcessorV1Test.java    From gocd with Apache License 2.0 6 votes vote down vote up
@Test
void shouldRouteMessageToConsoleService() throws IOException, IllegalArtifactLocationException {
    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("pipelineName", "p1");
    requestMap.put("pipelineCounter", "1");
    requestMap.put("stageName", "s1");
    requestMap.put("stageCounter", "2");
    requestMap.put("jobName", "j1");
    requestMap.put("text", "message1");

    DefaultGoApiRequest goApiRequest = new DefaultGoApiRequest(APPEND_TO_CONSOLE_LOG, VERSION_1, null);
    goApiRequest.setRequestBody(new GsonBuilder().create().toJson(requestMap));

    final ConsoleLogRequestProcessor processor = new ConsoleLogRequestProcessor(pluginRequestProcessorRegistry, consoleService);
    final GoApiResponse response = processor.process(pluginDescriptor, goApiRequest);

    assertThat(response.responseCode(), is(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE));

    final JobIdentifier jobIdentifier = new JobIdentifier("p1", 1, null, "s1", "2", "j1");
    verify(consoleService).appendToConsoleLog(jobIdentifier, "message1");
}
 
Example #10
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 #11
Source File: StashBuildStatusNotifierPluginTest.java    From gocd-build-status-notifier with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    initMocks(this);

    plugin = new StashBuildStatusNotifierPlugin();

    DefaultGoApiResponse pluginSettingsResponse = new DefaultGoApiResponse(200);
    pluginSettingsResponse.setResponseBody(JSONUtils.toJSON(new HashMap<String, String>()));
    when(goApplicationAccessor.submit(any(GoApiRequest.class))).thenReturn(pluginSettingsResponse);
    when(provider.pluginId()).thenReturn(PLUGIN_ID);
    when(provider.pollerPluginId()).thenReturn(POLLER_PLUGIN_ID);

    plugin.initializeGoApplicationAccessor(goApplicationAccessor);
    plugin.setProvider(provider);
}
 
Example #12
Source File: JsonBasedTaskExecutorTest.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    context = mock(TaskExecutionContext.class);
    pluginManager = mock(PluginManager.class);
    pluginId = "pluginId";
    response = mock(GoPluginApiResponse.class);
    handler = mock(JsonBasedTaskExtensionHandler.class);
    handlerHashMap.put("1.0", handler);
    final List<String> goSupportedVersions = asList("1.0");
    pluginRequestHelper = new PluginRequestHelper(pluginManager, goSupportedVersions, PLUGGABLE_TASK_EXTENSION);
    when(pluginManager.resolveExtensionVersion(pluginId, PLUGGABLE_TASK_EXTENSION, goSupportedVersions)).thenReturn(extensionVersion);
    when(response.responseCode()).thenReturn(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE);
    when(pluginManager.isPluginOfType(PLUGGABLE_TASK_EXTENSION, pluginId)).thenReturn(true);
}
 
Example #13
Source File: JsonBasedPluggableTaskTest.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    pluginManager = mock(PluginManager.class);
    pluginId = "plugin-id";
    final List<String> goSupportedVersions = asList("1.0");
    final HashMap<String, JsonBasedTaskExtensionHandler> handlerMap = new HashMap<>();
    handlerMap.put("1.0", new JsonBasedTaskExtensionHandler_V1());

    task = new JsonBasedPluggableTask(pluginId, new PluginRequestHelper(pluginManager, goSupportedVersions, PLUGGABLE_TASK_EXTENSION), handlerMap);
    goPluginApiResponse = mock(GoPluginApiResponse.class);
    when(pluginManager.submitTo(eq(pluginId), eq(PLUGGABLE_TASK_EXTENSION), any(GoPluginApiRequest.class))).thenReturn(goPluginApiResponse);
    when(pluginManager.resolveExtensionVersion(pluginId, PLUGGABLE_TASK_EXTENSION, goSupportedVersions)).thenReturn("1.0");
    when(goPluginApiResponse.responseCode()).thenReturn(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE);
    when(pluginManager.isPluginOfType(PLUGGABLE_TASK_EXTENSION, pluginId)).thenReturn(true);
}
 
Example #14
Source File: PluginRequestHelperTest.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Test
void shouldInvokeSuccessBlockOnSuccessfulResponse() {
    when(response.responseCode()).thenReturn(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE);
    when(pluginManager.submitTo(eq(pluginId), eq(extensionName), any(GoPluginApiRequest.class))).thenReturn(response);

    helper.submitRequest(pluginId, requestName, new DefaultPluginInteractionCallback<Object>() {
        @Override
        public Object onSuccess(String responseBody, Map<String, String> responseHeaders, String resolvedExtensionVersion) {
            isSuccessInvoked[0] = true;
            return null;
        }
    });
    assertThat(isSuccessInvoked[0]).isTrue();
    verify(pluginManager).submitTo(eq(pluginId), eq(extensionName), any(GoPluginApiRequest.class));
}
 
Example #15
Source File: PluginRequestHelperTest.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Test
void shouldErrorOutOnValidationFailure() {
    when(response.responseCode()).thenReturn(DefaultGoApiResponse.VALIDATION_ERROR);
    when(pluginManager.submitTo(eq(pluginId), eq(extensionName), any(GoPluginApiRequest.class))).thenReturn(response);

    thrown.expect(RuntimeException.class);

    helper.submitRequest(pluginId, requestName, new DefaultPluginInteractionCallback<Object>() {
        @Override
        public Object onSuccess(String responseBody, Map<String, String> responseHeaders, String resolvedExtensionVersion) {
            isSuccessInvoked[0] = true;
            return null;
        }
    });
}
 
Example #16
Source File: ConsoleLogRequestProcessorV1Test.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Test
void shouldRespondWithAMessageIfSomethingGoesWrong() {
    DefaultGoApiRequest goApiRequest = new DefaultGoApiRequest(APPEND_TO_CONSOLE_LOG, VERSION_1, null);
    goApiRequest.setRequestBody("this_is_invalid_JSON");

    final ConsoleLogRequestProcessor processor = new ConsoleLogRequestProcessor(pluginRequestProcessorRegistry, consoleService);
    final GoApiResponse response = processor.process(pluginDescriptor, goApiRequest);

    assertThat(response.responseCode(), is(DefaultGoApiResponse.INTERNAL_ERROR));

    final Map responseContents = new Gson().fromJson(response.responseBody(), Map.class);
    assertThat((String) responseContents.get("message"), containsString("Error:"));
}
 
Example #17
Source File: ConsoleLogRequestProcessorV2Test.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Test
void shouldRespondWithAMessageIfSomethingGoesWrong() {
    DefaultGoApiRequest goApiRequest = new DefaultGoApiRequest(APPEND_TO_CONSOLE_LOG, VERSION_2, null);
    goApiRequest.setRequestBody("this_is_invalid_JSON");

    final ConsoleLogRequestProcessor processor = new ConsoleLogRequestProcessor(pluginRequestProcessorRegistry, consoleService);
    final GoApiResponse response = processor.process(pluginDescriptor, goApiRequest);

    assertThat(response.responseCode(), is(DefaultGoApiResponse.INTERNAL_ERROR));

    final Map responseContents = new Gson().fromJson(response.responseBody(), Map.class);
    assertThat((String) responseContents.get("message"), containsString("Error:"));
}
 
Example #18
Source File: ConsoleLoggerTest.java    From docker-registry-artifact-plugin with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() {
    accessor = mock(GoApplicationAccessor.class);
    argumentCaptor = ArgumentCaptor.forClass(GoApiRequest.class);

    consoleLogger = ConsoleLogger.getLogger(accessor);

    when(accessor.submit(argumentCaptor.capture())).thenReturn(DefaultGoApiResponse.success(null));
}
 
Example #19
Source File: AuthorizationRequestProcessor.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Override
public GoApiResponse process(GoPluginDescriptor pluginDescriptor, GoApiRequest request) {

    validatePluginRequest(request);
    switch (Request.fromString(request.api())) {
        case INVALIDATE_CACHE_REQUEST:
            return processInvalidateCacheRequest(pluginDescriptor);
        default:
            return DefaultGoApiResponse.error("Illegal api request");
    }
}
 
Example #20
Source File: ElasticAgentRequestProcessorV1.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Override
public GoApiResponse process(final GoPluginDescriptor pluginDescriptor, GoApiRequest goPluginApiRequest) {
    switch (goPluginApiRequest.api()) {
        case REQUEST_DISABLE_AGENTS:
            return processDisableAgent(pluginDescriptor, goPluginApiRequest);
        case REQUEST_DELETE_AGENTS:
            return processDeleteAgent(pluginDescriptor, goPluginApiRequest);
        case REQUEST_SERVER_LIST_AGENTS:
            return processListAgents(pluginDescriptor, goPluginApiRequest);
        default:
            return DefaultGoApiResponse.error("Illegal api request");
    }
}
 
Example #21
Source File: ElasticAgentRequestProcessorV1.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Override
public GoApiResponse processDisableAgent(GoPluginDescriptor pluginDescriptor, GoApiRequest goPluginApiRequest) {
    Collection<AgentMetadata> agentsToDisable = elasticAgentProcessorConverterV1.deleteAndDisableAgentRequestBody(goPluginApiRequest.requestBody());
    final String pluginId = pluginDescriptor.id();
    disableAgents(pluginId, agentsToDisable);
    return new DefaultGoApiResponse(200);
}
 
Example #22
Source File: ArtifactRequestProcessor.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Override
public GoApiResponse process(GoPluginDescriptor pluginDescriptor, GoApiRequest request) {
    validatePluginRequest(request);
    switch (Request.fromString(request.api())) {
        case CONSOLE_LOG:
            return processConsoleLogRequest(pluginDescriptor, request);
        default:
            return DefaultGoApiResponse.error("Illegal api request");
    }
}
 
Example #23
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 #24
Source File: EditHostTaskExecutorTests.java    From gocd-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void Execute_RequestSuccess_ReturnsOkMessage() throws Exception {
    CheckMkStub.SetupRequestOk();
    EditHostTaskExecutor taskExecutor = new EditHostTaskExecutor(consoleLogger, context, config);
    taskExecutor.setCheckMkClient(CheckMkStub.checkMkClient);
    Result result = taskExecutor.execute();

    assertEquals(result.responseCode(), DefaultGoApiResponse.SUCCESS_RESPONSE_CODE);
}
 
Example #25
Source File: ConsoleLogger.java    From docker-registry-artifact-plugin with Apache License 2.0 5 votes vote down vote up
private void sendLog(ConsoleLogMessage consoleLogMessage) {
    DefaultGoApiRequest request = new DefaultGoApiRequest(Constants.SEND_CONSOLE_LOG, CONSOLE_LOG_PROCESSOR_API_VERSION, PLUGIN_IDENTIFIER);
    request.setRequestBody(consoleLogMessage.toJSON());

    GoApiResponse response = accessor.submit(request);
    if (response.responseCode() != DefaultGoApiResponse.SUCCESS_RESPONSE_CODE) {
        LOG.error(String.format("Failed to submit console log: %s", response.responseBody()));
    }
}
 
Example #26
Source File: PluginRequestTest.java    From kubernetes-elastic-agents with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotThrowAnExceptionIfConsoleLogAppenderCallFails() {
    final JobIdentifier jobIdentifier = new JobIdentifier("p1", 1L, "l1", "s1", "1", "j1", 1L);

    GoApplicationAccessor accessor = mock(GoApplicationAccessor.class);
    when(accessor.submit(any())).thenReturn(DefaultGoApiResponse.badRequest("Something went wrong"));

    final PluginRequest pluginRequest = new PluginRequest(accessor);
    pluginRequest.appendToConsoleLog(jobIdentifier, "text1");
}
 
Example #27
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 #28
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 #29
Source File: PluginRequestTest.java    From docker-elastic-agents-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotThrowAnExceptionIfConsoleLogAppenderCallFails() {
    final JobIdentifier jobIdentifier = new JobIdentifier("p1", 1L, "l1", "s1", "1", "j1", 1L);

    GoApplicationAccessor accessor = mock(GoApplicationAccessor.class);
    when(accessor.submit(any())).thenReturn(DefaultGoApiResponse.badRequest("Something went wrong"));

    final PluginRequest pluginRequest = new PluginRequest(accessor);
    pluginRequest.appendToConsoleLog(jobIdentifier, "text1");
}
 
Example #30
Source File: AddHostTaskExecutorTests.java    From gocd-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void Execute_OneRequestFailed_ReturnFalseResult() throws Exception {
    CheckMkStub.SetupRequestError();
    AddHostTaskExecutor taskExecutor = new AddHostTaskExecutor(consoleLogger, context, config);
    taskExecutor.setCheckMkClient(CheckMkStub.checkMkClient);
    Result result = taskExecutor.execute();

    assertEquals(result.responseCode(), DefaultGoApiResponse.INTERNAL_ERROR);
}