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

The following examples show how to use com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse. These examples are extracted from open source projects. 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
@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 Project: gocd-plugins   Source File: CheckMkTask.java    License: 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 3
Source Project: gocd   Source File: TaskExtensionTest.java    License: 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 4
Source Project: gocd   Source File: PluginRequestHelperTest.java    License: 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 5
Source Project: gocd   Source File: ConsoleLogRequestProcessorV1Test.java    License: 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 6
Source Project: gocd   Source File: ConsoleLogRequestProcessorV2Test.java    License: 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 7
Source Project: gocd   Source File: ServerHealthRequestProcessor.java    License: 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 8
Source Project: gocd   Source File: ConsoleLogRequestProcessor.java    License: 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 9
Source Project: gocd   Source File: PluginSettingsRequestProcessor.java    License: 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 10
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 11
@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 12
@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 13
@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 14
@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 15
@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 16
Source Project: gocd-plugins   Source File: AddHostTaskExecutorTests.java    License: 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);
}
 
Example 17
Source Project: gocd-plugins   Source File: AddHostTaskExecutorTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void Execute_RequestSuccess_ReturnsOkMessage() throws Exception {
    CheckMkStub.SetupRequestOk();
    AddHostTaskExecutor taskExecutor = new AddHostTaskExecutor(consoleLogger, context, config);
    taskExecutor.setCheckMkClient(CheckMkStub.checkMkClient);
    Result result = taskExecutor.execute();

    assertEquals(result.responseCode(), DefaultGoApiResponse.SUCCESS_RESPONSE_CODE);
}
 
Example 18
Source Project: gocd-plugins   Source File: RemoveHostTaskExecutorTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void Execute_OneRequestFailed_ReturnOkResult() throws Exception {
    CheckMkStub.SetupRequestError();
    RemoveHostTaskExecutor taskExecutor = new RemoveHostTaskExecutor(consoleLogger, context, config);
    taskExecutor.setCheckMkClient(CheckMkStub.checkMkClient);
    Result result = taskExecutor.execute();

    assertEquals(result.responseCode(), DefaultGoApiResponse.SUCCESS_RESPONSE_CODE);
}
 
Example 19
Source Project: gocd-plugins   Source File: RemoveHostTaskExecutorTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void Execute_RequestSuccess_ReturnsOkMessage() throws Exception {
    CheckMkStub.SetupRequestOk();
    RemoveHostTaskExecutor taskExecutor = new RemoveHostTaskExecutor(consoleLogger, context, config);
    taskExecutor.setCheckMkClient(CheckMkStub.checkMkClient);
    Result result = taskExecutor.execute();

    assertEquals(result.responseCode(), DefaultGoApiResponse.SUCCESS_RESPONSE_CODE);
}
 
Example 20
Source Project: gocd-plugins   Source File: EditHostTaskExecutorTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void Execute_OneRequestFailed_ReturnFalseResult() throws Exception {
    CheckMkStub.SetupRequestError();
    EditHostTaskExecutor taskExecutor = new EditHostTaskExecutor(consoleLogger, context, config);
    taskExecutor.setCheckMkClient(CheckMkStub.checkMkClient);
    Result result = taskExecutor.execute();

    assertEquals(result.responseCode(), DefaultGoApiResponse.INTERNAL_ERROR);
}
 
Example 21
Source Project: gocd-plugins   Source File: EditHostTaskExecutorTests.java    License: 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 22
Source Project: gocd-plugins   Source File: NessusScanTask.java    License: Apache License 2.0 5 votes vote down vote up
private GoPluginApiResponse handleTaskView() {
    int responseCode = DefaultGoApiResponse.SUCCESS_RESPONSE_CODE;
    HashMap view = new HashMap();
    view.put("displayValue", "Security Scan - Nessus");
    try {
        view.put("template", IOUtils.toString(getClass().getResourceAsStream("/views/task.template.html"), "UTF-8"));
    } 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 23
Source Project: gocd-docker   Source File: DockerTask.java    License: Apache License 2.0 5 votes vote down vote up
private GoPluginApiResponse handleTaskView() {
    int responseCode = DefaultGoApiResponse.SUCCESS_RESPONSE_CODE;
    Map view = new HashMap();
    view.put("displayValue", "Docker Task");
    try {
        view.put("template", IOUtils.toString(getClass().getResourceAsStream("/views/task.template.html"), "UTF-8"));
    } 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 24
@Before
public void setUp() {
    initMocks(this);

    plugin = new GitHubBuildStatusNotifierPlugin();

    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 25
@Before
public void setUp() {
    initMocks(this);

    plugin = new GerritBuildStatusNotifierPlugin();

    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 26
@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 27
Source Project: gocd   Source File: JsonBasedTaskExecutorTest.java    License: 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 28
Source Project: gocd   Source File: JsonBasedPluggableTaskTest.java    License: 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 29
Source Project: gocd   Source File: PluginRequestHelperTest.java    License: 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 30
Source Project: gocd   Source File: PluginRequestHelperTest.java    License: 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;
        }
    });
}