Java Code Examples for com.thoughtworks.go.plugin.api.request.DefaultGoPluginApiRequest#setRequestBody()

The following examples show how to use com.thoughtworks.go.plugin.api.request.DefaultGoPluginApiRequest#setRequestBody() . 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 respondsToParseContentRequest() throws Exception {
    final Gson gson = new Gson();
    DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest("configrepo", "2.0", ConfigRepoMessages.REQ_PARSE_CONTENT);

    StringWriter w = new StringWriter();
    IOUtils.copy(getResourceAsStream("examples/simple.gocd.yaml"), w);
    request.setRequestBody(gson.toJson(
            Collections.singletonMap("contents",
                    Collections.singletonMap("simple.gocd.yaml", w.toString())
            )
    ));

    GoPluginApiResponse response = plugin.handle(request);
    assertEquals(SUCCESS_RESPONSE_CODE, response.responseCode());
    JsonObject responseJsonObject = getJsonObjectFromResponse(response);
    assertNoError(responseJsonObject);

    JsonArray pipelines = responseJsonObject.get("pipelines").getAsJsonArray();
    assertThat(pipelines.size(), is(1));
    JsonObject expected = (JsonObject) readJsonObject("examples.out/simple.gocd.json");
    assertThat(responseJsonObject, is(new JsonObjectMatcher(expected)));
}
 
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 respondsToGetConfigFiles() throws Exception {
    final Gson gson = new Gson();
    DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest("configrepo", "3.0", ConfigRepoMessages.REQ_CONFIG_FILES);
    FileUtils.copyInputStreamToFile(
            getResourceAsStream("/examples/simple.gocd.yaml"), tempDir.newFile("valid.gocd.yaml")
    );
    FileUtils.copyInputStreamToFile(
            getResourceAsStream("/examples/simple-invalid.gocd.yaml"), tempDir.newFile("invalid.gocd.yaml")
    );

    request.setRequestBody(gson.toJson(
            Collections.singletonMap("directory", tempDir.getRoot().toString())
    ));

    GoPluginApiResponse response = plugin.handle(request);
    assertEquals(SUCCESS_RESPONSE_CODE, response.responseCode());

    JsonArray files = getJsonObjectFromResponse(response).get("files").getAsJsonArray();
    assertThat(files.size(), is(2));
    assertTrue(files.contains(new JsonPrimitive("valid.gocd.yaml")));
    assertTrue(files.contains(new JsonPrimitive("invalid.gocd.yaml")));
}
 
Example 3
Source File: YamlConfigPluginIntegrationTest.java    From gocd-yaml-config-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldParseDirectoryWithCustomPatternWhenInConfigurations() throws UnhandledRequestTypeException, IOException {
    File simpleCaseDir = setupCase("simple", "go.yml");
    DefaultGoPluginApiRequest parseDirectoryRequest = new DefaultGoPluginApiRequest("configrepo", "1.0", "parse-directory");
    String requestBody = "{\n" +
            "    \"directory\":\"" + simpleCaseDir + "\",\n" +
            "    \"configurations\":[" +
            "{" +
            "\"key\" : \"file_pattern\"," +
            "\"value\" : \"simple.go.yml\" " +
            "}" +
            "]\n" +
            "}";
    parseDirectoryRequest.setRequestBody(requestBody);

    GoPluginApiResponse response = plugin.handle(parseDirectoryRequest);
    assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE));
    JsonObject responseJsonObject = getJsonObjectFromResponse(response);
    assertNoError(responseJsonObject);
    JsonArray pipelines = responseJsonObject.get("pipelines").getAsJsonArray();
    assertThat(pipelines.size(), is(1));
}
 
Example 4
Source File: VerifyConnectionRequestExecutorTest.java    From gocd-filebased-authentication-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void execute_shouldVerifyIfThePasswordFileExists() throws Exception {
    DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest(null, null, null);
    request.setRequestBody("{\"PasswordFilePath\": \"some_path\"}");

    GoPluginApiResponse response = new VerifyConnectionRequestExecutor(request).execute();

    String expectedResponse = "{\"message\":\"No password file at path `some_path`.\",\"status\":\"failure\"}";
    assertThat(response.responseBody(), is(expectedResponse));
}
 
Example 5
Source File: YamlConfigPluginIntegrationTest.java    From gocd-yaml-config-plugin with Apache License 2.0 5 votes vote down vote up
private GoPluginApiResponse parseAndGetResponseForDir(File directory) throws UnhandledRequestTypeException {
    DefaultGoPluginApiRequest parseDirectoryRequest = new DefaultGoPluginApiRequest("configrepo", "1.0", "parse-directory");
    String requestBody = "{\n" +
            "    \"directory\":\"" + directory + "\",\n" +
            "    \"configurations\":[]\n" +
            "}";
    parseDirectoryRequest.setRequestBody(requestBody);

    return plugin.handle(parseDirectoryRequest);
}
 
Example 6
Source File: YamlConfigPluginIntegrationTest.java    From gocd-yaml-config-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldConsumePluginSettingsOnConfigChangeRequest() throws UnhandledRequestTypeException {
    DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest("configrepo", "2.0", REQ_PLUGIN_SETTINGS_CHANGED);
    request.setRequestBody("{\"file_pattern\": \"*.foo.gocd.yaml\"}");

    assertEquals(DEFAULT_FILE_PATTERN, plugin.getFilePattern());
    GoPluginApiResponse response = plugin.handle(request);

    assertEquals("*.foo.gocd.yaml", plugin.getFilePattern());
    assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE));
}
 
Example 7
Source File: YamlConfigPluginIntegrationTest.java    From gocd-yaml-config-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRespondBadRequestToParseDirectoryRequestWhenRequestBodyIsNotJson() throws UnhandledRequestTypeException {
    DefaultGoPluginApiRequest parseDirectoryRequest = new DefaultGoPluginApiRequest("configrepo", "1.0", "parse-directory");
    parseDirectoryRequest.setRequestBody("{bla");

    GoPluginApiResponse response = plugin.handle(parseDirectoryRequest);
    assertThat(response.responseCode(), is(DefaultGoPluginApiResponse.BAD_REQUEST));
}
 
Example 8
Source File: YamlConfigPluginIntegrationTest.java    From gocd-yaml-config-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRespondBadRequestToParseDirectoryRequestWhenRequestBodyIsEmpty() throws UnhandledRequestTypeException {
    DefaultGoPluginApiRequest parseDirectoryRequest = new DefaultGoPluginApiRequest("configrepo", "1.0", "parse-directory");
    parseDirectoryRequest.setRequestBody("{}");

    GoPluginApiResponse response = plugin.handle(parseDirectoryRequest);
    assertThat(response.responseCode(), is(DefaultGoPluginApiResponse.BAD_REQUEST));
}
 
Example 9
Source File: YamlConfigPluginIntegrationTest.java    From gocd-yaml-config-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRespondBadRequestToParseDirectoryRequestWhenRequestBodyIsNull() throws UnhandledRequestTypeException {
    DefaultGoPluginApiRequest parseDirectoryRequest = new DefaultGoPluginApiRequest("configrepo", "1.0", "parse-directory");
    String requestBody = null;
    parseDirectoryRequest.setRequestBody(requestBody);

    GoPluginApiResponse response = plugin.handle(parseDirectoryRequest);
    assertThat(response.responseCode(), is(DefaultGoPluginApiResponse.BAD_REQUEST));
}
 
Example 10
Source File: YamlConfigPluginIntegrationTest.java    From gocd-yaml-config-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRespondBadRequestToParseDirectoryRequestWhenDirectoryIsNotSpecified() throws UnhandledRequestTypeException {
    DefaultGoPluginApiRequest parseDirectoryRequest = new DefaultGoPluginApiRequest("configrepo", "1.0", "parse-directory");
    String requestBody = "{\n" +
            "    \"configurations\":[]\n" +
            "}";
    parseDirectoryRequest.setRequestBody(requestBody);

    GoPluginApiResponse response = plugin.handle(parseDirectoryRequest);
    assertThat(response.responseCode(), is(DefaultGoPluginApiResponse.BAD_REQUEST));
}
 
Example 11
Source File: VerifyConnectionRequestExecutorTest.java    From gocd-filebased-authentication-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void execute_shouldReturnASuccessResponseIfValidationAndVerificationPasses() throws Exception {
    File passwordFile = this.folder.newFile("password.properties");

    DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest(null, null, null);
    request.setRequestBody(String.format("{\"PasswordFilePath\": \"%s\"}", passwordFile.getAbsolutePath()));

    GoPluginApiResponse response = new VerifyConnectionRequestExecutor(request).execute();

    assertThat(response.responseBody(), is("{\"message\":\"Connection ok\",\"status\":\"success\"}"));
}
 
Example 12
Source File: VerifyConnectionRequestExecutorTest.java    From gocd-filebased-authentication-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void execute_shouldVerifyIfPasswordFilePathPointsToANormalFile() throws Exception {
    File folder = this.folder.newFolder("subfolder");

    DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest(null, null, null);
    request.setRequestBody(String.format("{\"PasswordFilePath\": \"%s\"}", folder.getAbsolutePath()));

    GoPluginApiResponse response = new VerifyConnectionRequestExecutor(request).execute();

    String expectedResponse = String.format("{\"message\":\"Password file path `%s` is not a normal file.\",\"status\":\"failure\"}", folder.getAbsolutePath());
    assertThat(response.responseBody(), is(expectedResponse));
}
 
Example 13
Source File: VerifyConnectionRequestExecutorTest.java    From gocd-filebased-authentication-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void execute_shouldValidateTheConfiguration() throws Exception {
    DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest(null, null, null);
    request.setRequestBody("{}");

    GoPluginApiResponse response = new VerifyConnectionRequestExecutor(request).execute();

    String expectedResponse = "{\"message\":\"Validation failed for the given Auth Config\",\"errors\":[{\"message\":\"PasswordFilePath must not be blank.\",\"key\":\"PasswordFilePath\"}],\"status\":\"validation-failed\"}";
    assertThat(response.responseBody(), is(expectedResponse));
}
 
Example 14
Source File: GitHubBuildStatusNotifierPluginTest.java    From gocd-build-status-notifier with Apache License 2.0 4 votes vote down vote up
private DefaultGoPluginApiRequest createGoPluginAPIRequest(Map requestBody) {
    DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest(BuildStatusNotifierPlugin.EXTENSION_NAME, "1.0", BuildStatusNotifierPlugin.REQUEST_STAGE_STATUS);
    request.setRequestBody(JSONUtils.toJSON(requestBody));
    return request;
}
 
Example 15
Source File: GerritBuildStatusNotifierPluginTest.java    From gocd-build-status-notifier with Apache License 2.0 4 votes vote down vote up
private DefaultGoPluginApiRequest createGoPluginAPIRequest(Map requestBody) {
    DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest(BuildStatusNotifierPlugin.EXTENSION_NAME, "1.0", BuildStatusNotifierPlugin.REQUEST_STAGE_STATUS);
    request.setRequestBody(JSONUtils.toJSON(requestBody));
    return request;
}
 
Example 16
Source File: StashBuildStatusNotifierPluginTest.java    From gocd-build-status-notifier with Apache License 2.0 4 votes vote down vote up
private DefaultGoPluginApiRequest createGoPluginAPIRequest(Map requestBody) {
    DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest(BuildStatusNotifierPlugin.EXTENSION_NAME, "1.0", BuildStatusNotifierPlugin.REQUEST_STAGE_STATUS);
    request.setRequestBody(JSONUtils.toJSON(requestBody));
    return request;
}
 
Example 17
Source File: MultipleExtensionPluginWithPluginManagerIntegrationTest.java    From gocd with Apache License 2.0 3 votes vote down vote up
@Test
void shouldNotReinitializeWithAccessorIfAlreadyInitialized() {
    DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest("task", "1.0", "request1");
    request.setRequestBody("{ \"abc\": 1 }");

    pluginManager.submitTo(PLUGIN_ID, "task", request);

    assertThat(System.getProperty(EXTENSION_1_PROPERTY_PREFIX + "initialize_accessor.count")).isEqualTo("1");

    pluginManager.submitTo(PLUGIN_ID, "task", request);

    assertThat(System.getProperty(EXTENSION_1_PROPERTY_PREFIX + "initialize_accessor.count")).isEqualTo("1");
}