com.thoughtworks.go.plugin.api.request.DefaultGoPluginApiRequest Java Examples

The following examples show how to use com.thoughtworks.go.plugin.api.request.DefaultGoPluginApiRequest. 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 shouldContainFilePatternInResponseToGetConfigurationRequest() throws UnhandledRequestTypeException {
    DefaultGoPluginApiRequest getConfigRequest = new DefaultGoPluginApiRequest("configrepo", "1.0", "go.plugin-settings.get-configuration");

    GoPluginApiResponse response = plugin.handle(getConfigRequest);
    assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE));
    JsonObject responseJsonObject = getJsonObjectFromResponse(response);
    JsonElement pattern = responseJsonObject.get("file_pattern");
    assertNotNull(pattern);
    JsonObject patternAsJsonObject = pattern.getAsJsonObject();
    assertThat(patternAsJsonObject.get("display-name").getAsString(), is("Go YAML files pattern"));
    assertThat(patternAsJsonObject.get("default-value").getAsString(), is("**/*.gocd.yaml,**/*.gocd.yml"));
    assertThat(patternAsJsonObject.get("required").getAsBoolean(), is(false));
    assertThat(patternAsJsonObject.get("secure").getAsBoolean(), is(false));
    assertThat(patternAsJsonObject.get("display-order").getAsInt(), is(0));
}
 
Example #4
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 #5
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 #6
Source File: DefaultPluginManagerIntegrationTest.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Test
void shouldSetCurrentThreadContextClassLoaderToBundleClassLoaderToAvoidDependenciesFromWebappClassloaderMessingAroundWithThePluginBehavior() {
    GoPluginDescriptor plugin = pluginManager.getPluginDescriptorFor(PLUGIN_TO_TEST_CLASSLOADER);
    assertThat(plugin.id()).isEqualTo(PLUGIN_TO_TEST_CLASSLOADER);
    String extensionType = "notification";
    GoPluginApiResponse goPluginApiResponse = pluginManager.submitTo(PLUGIN_TO_TEST_CLASSLOADER, extensionType,
            new DefaultGoPluginApiRequest(extensionType, "2.0",
                    "Thread.currentThread.getContextClassLoader"));
    assertThat(goPluginApiResponse.responseBody()).isEqualTo(BundleClassLoader.class.getCanonicalName());
    goPluginApiResponse = pluginManager.submitTo(PLUGIN_TO_TEST_CLASSLOADER, extensionType,
            new DefaultGoPluginApiRequest(extensionType, "2.0",
                    "this.getClass.getClassLoader"));
    assertThat(goPluginApiResponse.responseBody()).isEqualTo(BundleClassLoader.class.getCanonicalName());
}
 
Example #7
Source File: DefaultPluginManagerIntegrationTest.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Test
void shouldRegisterTheExtensionClassesOfAPluginAndInitializeAccessorUponFirstCall() {
    GoPluginDescriptor plugin = pluginManager.getPluginDescriptorFor(PLUGIN_ID_1);
    assertThat(plugin.id()).isEqualTo(PLUGIN_ID_1);

    assertThat(plugin.bundleDescriptor().bundleSymbolicName()).isEqualTo(PLUGIN_ID_1);
    assertThat(plugin.isInvalid()).isFalse();

    String extensionType = "notification";
    pluginManager.submitTo(PLUGIN_ID_1, extensionType, new DefaultGoPluginApiRequest(extensionType, "2.0", "test-request"));
    assertThat(System.getProperty(PLUGIN_DESC_PROPERTY_SET_BY_TEST_PLUGIN_1)).isEqualTo("PluginLoad: 1, InitAccessor");
}
 
Example #8
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 #9
Source File: YamlConfigPluginIntegrationTest.java    From gocd-yaml-config-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRespondWithGetIcon() throws UnhandledRequestTypeException, IOException {
    DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest("configrepo", "2.0", "get-icon");

    GoPluginApiResponse response = plugin.handle(request);
    assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE));
    JsonObject jsonObject = getJsonObjectFromResponse(response);
    assertEquals(jsonObject.entrySet().size(), 2);
    assertEquals(jsonObject.get("content_type").getAsString(), "image/svg+xml");
    byte[] actualData = Base64.getDecoder().decode(jsonObject.get("data").getAsString());
    byte[] expectedData = IOUtils.toByteArray(getClass().getResourceAsStream("/yaml.svg"));
    assertArrayEquals(expectedData, actualData);
}
 
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 shouldRespondWithCapabilities() throws UnhandledRequestTypeException {
    String expected = new Gson().toJson(new Capabilities());
    DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest("configrepo", "2.0", "get-capabilities");

    GoPluginApiResponse response = plugin.handle(request);

    assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE));
    assertThat(response.responseBody(), is(expected));
}
 
Example #11
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 #12
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 #13
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 #14
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 #15
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 #16
Source File: YamlConfigPluginIntegrationTest.java    From gocd-yaml-config-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRespondSuccessToValidateConfigRequest() throws UnhandledRequestTypeException {
    DefaultGoPluginApiRequest validateRequest = new DefaultGoPluginApiRequest("configrepo", "1.0", "go.plugin-settings.validate-configuration");

    GoPluginApiResponse response = plugin.handle(validateRequest);
    assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE));
}
 
Example #17
Source File: YamlConfigPluginIntegrationTest.java    From gocd-yaml-config-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRespondSuccessToGetViewRequest() throws UnhandledRequestTypeException {
    DefaultGoPluginApiRequest getConfigRequest = new DefaultGoPluginApiRequest("configrepo", "1.0", "go.plugin-settings.get-view");

    GoPluginApiResponse response = plugin.handle(getConfigRequest);
    assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE));
}
 
Example #18
Source File: YamlConfigPluginIntegrationTest.java    From gocd-yaml-config-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRespondSuccessToGetConfigurationRequest() throws UnhandledRequestTypeException {
    DefaultGoPluginApiRequest getConfigRequest = new DefaultGoPluginApiRequest("configrepo", "1.0", "go.plugin-settings.get-configuration");

    GoPluginApiResponse response = plugin.handle(getConfigRequest);
    assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE));
}
 
Example #19
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 #20
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 #21
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 #22
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 #23
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 #24
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 #25
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");
}