com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse Java Examples
The following examples show how to use
com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse.
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: ArtifactExtensionTestBase.java From gocd with Apache License 2.0 | 6 votes |
@Test public void shouldGetArtifactStoreMetadataFromPlugin() { String responseBody = "[{\"key\":\"BUCKET_NAME\",\"metadata\":{\"required\":true,\"secure\":false}},{\"key\":\"AWS_ACCESS_KEY\",\"metadata\":{\"required\":true,\"secure\":true}}]"; when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody)); final List<PluginConfiguration> response = artifactExtension.getArtifactStoreMetadata(PLUGIN_ID); final GoPluginApiRequest request = requestArgumentCaptor.getValue(); assertThat(request.extension(), is(ARTIFACT_EXTENSION)); assertThat(request.requestName(), is(REQUEST_STORE_CONFIG_METADATA)); assertNull(request.requestBody()); assertThat(response.size(), is(2)); assertThat(response, containsInAnyOrder( new PluginConfiguration("BUCKET_NAME", new Metadata(true, false)), new PluginConfiguration("AWS_ACCESS_KEY", new Metadata(true, true)) )); }
Example #2
Source File: PublishTask.java From gocd-s3-artifacts with Apache License 2.0 | 6 votes |
private GoPluginApiResponse handleGetConfigRequest() { HashMap config = new HashMap(); HashMap sourceDestinations = new HashMap(); sourceDestinations.put("default-value", ""); sourceDestinations.put("required", true); config.put(SOURCEDESTINATIONS, sourceDestinations); HashMap destinationPrefix = new HashMap(); destinationPrefix.put("default-value", ""); destinationPrefix.put("required", false); config.put(DESTINATION_PREFIX, destinationPrefix); HashMap artifactsBucket = new HashMap(); artifactsBucket.put("default-value", ""); artifactsBucket.put("required", false); config.put(ARTIFACTS_BUCKET, artifactsBucket); return createResponse(DefaultGoPluginApiResponse.SUCCESS_RESPONSE_CODE, config); }
Example #3
Source File: PackageRepositoryExtensionTest.java From gocd with Apache License 2.0 | 6 votes |
@Test public void shouldTalkToPluginToGetPackageConfiguration() throws Exception { String expectedRequestBody = null; String expectedResponseBody = "{" + "\"key-one\":{}," + "\"key-two\":{\"default-value\":\"two\",\"part-of-identity\":true,\"secure\":true,\"required\":true,\"display-name\":\"display-two\",\"display-order\":\"1\"}," + "\"key-three\":{\"default-value\":\"three\",\"part-of-identity\":false,\"secure\":false,\"required\":false,\"display-name\":\"display-three\",\"display-order\":\"2\"}" + "}"; when(pluginManager.isPluginOfType(PACKAGE_MATERIAL_EXTENSION, PLUGIN_ID)).thenReturn(true); when(pluginManager.submitTo(eq(PLUGIN_ID), eq(PACKAGE_MATERIAL_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(expectedResponseBody)); com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration packageConfiguration = extension.getPackageConfiguration(PLUGIN_ID); assertRequest(requestArgumentCaptor.getValue(), PACKAGE_MATERIAL_EXTENSION, "1.0", PackageRepositoryExtension.REQUEST_PACKAGE_CONFIGURATION, expectedRequestBody); assertPropertyConfiguration((PackageMaterialProperty) packageConfiguration.get("key-one"), "key-one", "", true, true, false, "", 0); assertPropertyConfiguration((PackageMaterialProperty) packageConfiguration.get("key-two"), "key-two", "two", true, true, true, "display-two", 1); assertPropertyConfiguration((PackageMaterialProperty) packageConfiguration.get("key-three"), "key-three", "three", false, false, false, "display-three", 2); }
Example #4
Source File: ElasticAgentExtensionV4Test.java From gocd with Apache License 2.0 | 6 votes |
@Test public void shouldMakeJobCompletionCall() { final String elasticAgentId = "ea1"; final JobIdentifier jobIdentifier = new JobIdentifier("up42", 2, "Test", "up42_stage", "10", "up42_job"); when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ELASTIC_AGENT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(null)); extensionV4.jobCompletion(PLUGIN_ID, elasticAgentId, jobIdentifier, Collections.EMPTY_MAP, Collections.EMPTY_MAP); String expectedRequestBody = "{\n" + " \"elastic_agent_id\": \"ea1\",\n" + " \"job_identifier\": {\n" + " \"pipeline_name\": \"up42\",\n" + " \"pipeline_label\": \"Test\",\n" + " \"pipeline_counter\": 2,\n" + " \"stage_name\": \"up42_stage\",\n" + " \"stage_counter\": \"10\",\n" + " \"job_name\": \"up42_job\",\n" + " \"job_id\": -1\n" + " }\n" + "}"; assertExtensionRequest("4.0", REQUEST_JOB_COMPLETION, expectedRequestBody); }
Example #5
Source File: ArtifactExtensionTestBase.java From gocd with Apache License 2.0 | 6 votes |
@Test public void shouldValidateFetchArtifactConfig() { String responseBody = "[{\"message\":\"Filename must not be blank.\",\"key\":\"Filename\"}]"; when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody)); ValidationResult validationResult = artifactExtension.validateFetchArtifactConfig(PLUGIN_ID, Collections.singletonMap("Filename", "")); final GoPluginApiRequest request = requestArgumentCaptor.getValue(); assertThat(request.extension(), is(ARTIFACT_EXTENSION)); assertThat(request.requestName(), is(REQUEST_FETCH_ARTIFACT_VALIDATE)); assertThat(request.requestBody(), is("{\"Filename\":\"\"}")); assertThat(validationResult.isSuccessful(), is(false)); assertThat(validationResult.getErrors(), containsInAnyOrder( new ValidationError("Filename", "Filename must not be blank.") )); }
Example #6
Source File: TaskExtensionTest.java From gocd with Apache License 2.0 | 6 votes |
@Test public void shouldTalkToPluginToGetPluginSettingsView() throws Exception { extension.registerHandler("1.0", pluginSettingsJSONMessageHandler); extension.messageHandlerMap.put("1.0", jsonMessageHandler); String responseBody = "expected-response"; String deserializedResponse = ""; when(pluginSettingsJSONMessageHandler.responseMessageForPluginSettingsView(responseBody)).thenReturn(deserializedResponse); when(pluginManager.isPluginOfType(PLUGGABLE_TASK_EXTENSION, pluginId)).thenReturn(true); when(pluginManager.submitTo(eq(pluginId), eq(PLUGGABLE_TASK_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody)); String response = extension.getPluginSettingsView(pluginId); assertRequest(requestArgumentCaptor.getValue(), PLUGGABLE_TASK_EXTENSION, "1.0", PluginSettingsConstants.REQUEST_PLUGIN_SETTINGS_VIEW, null); verify(pluginSettingsJSONMessageHandler).responseMessageForPluginSettingsView(responseBody); assertSame(response, deserializedResponse); }
Example #7
Source File: S3PackageMaterialPoller.java From gocd-s3-artifacts with Apache License 2.0 | 6 votes |
private GoPluginApiResponse handleLatestRevisionSince(GoPluginApiRequest goPluginApiRequest) { final Map<String, String> repositoryKeyValuePairs = keyValuePairs(goPluginApiRequest, REQUEST_REPOSITORY_CONFIGURATION); final Map<String, String> packageKeyValuePairs = keyValuePairs(goPluginApiRequest, REQUEST_PACKAGE_CONFIGURATION); Map<String, Object> previousRevisionMap = getMapFor(goPluginApiRequest, "previous-revision"); String previousRevision = (String) previousRevisionMap.get("revision"); String s3Bucket = repositoryKeyValuePairs.get(S3_BUCKET); S3ArtifactStore artifactStore = s3ArtifactStore(s3Bucket); try { RevisionStatus revision = artifactStore.getLatest(artifact(packageKeyValuePairs)); if(new Revision(revision.revision.getRevision()).compareTo(new Revision(previousRevision)) > 0) { return createResponse(DefaultGoPluginApiResponse.SUCCESS_RESPONSE_CODE, revision.toMap()); } return createResponse(DefaultGoPluginApiResponse.SUCCESS_RESPONSE_CODE, null); } catch (Exception e) { logger.error(e.getMessage(), e); return createResponse(DefaultGoPluginApiResponse.INTERNAL_ERROR, null); } }
Example #8
Source File: AuthorizationExtensionTest.java From gocd with Apache License 2.0 | 6 votes |
@Test void shouldTalkToPlugin_To_GetAuthorizationServerUrl() { String requestBody = "{\n" + " \"auth_configs\": [\n" + " {\n" + " \"id\": \"github\",\n" + " \"configuration\": {\n" + " \"url\": \"some-url\"\n" + " }\n" + " }\n" + " ],\n" + " \"authorization_server_callback_url\": \"http://go.site.url/go/plugin/plugin-id/authenticate\"\n" + "}"; String responseBody = "{\"authorization_server_url\":\"url_to_authorization_server\"}"; SecurityAuthConfig authConfig = new SecurityAuthConfig("github", "cd.go.github", create("url", false, "some-url")); when(pluginManager.submitTo(eq(PLUGIN_ID), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody)); String authorizationServerRedirectUrl = authorizationExtension.getAuthorizationServerUrl(PLUGIN_ID, Collections.singletonList(authConfig), "http://go.site.url"); assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "1.0", REQUEST_AUTHORIZATION_SERVER_URL, requestBody); assertThat(authorizationServerRedirectUrl).isEqualTo("url_to_authorization_server"); }
Example #9
Source File: PackageRepositoryExtensionTest.java From gocd with Apache License 2.0 | 6 votes |
@Test public void shouldTalkToPluginToCheckIfPackageConfigurationIsValid() throws Exception { String expectedRequestBody = "{\"repository-configuration\":{\"key-one\":{\"value\":\"value-one\"},\"key-two\":{\"value\":\"value-two\"}}," + "\"package-configuration\":{\"key-three\":{\"value\":\"value-three\"},\"key-four\":{\"value\":\"value-four\"}}}"; String expectedResponseBody = "[{\"key\":\"key-one\",\"message\":\"incorrect value\"},{\"message\":\"general error\"}]"; when(pluginManager.isPluginOfType(PACKAGE_MATERIAL_EXTENSION, PLUGIN_ID)).thenReturn(true); when(pluginManager.submitTo(eq(PLUGIN_ID), eq(PACKAGE_MATERIAL_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(expectedResponseBody)); ValidationResult validationResult = extension.isPackageConfigurationValid(PLUGIN_ID, packageConfiguration, repositoryConfiguration); assertRequest(requestArgumentCaptor.getValue(), PACKAGE_MATERIAL_EXTENSION, "1.0", PackageRepositoryExtension.REQUEST_VALIDATE_PACKAGE_CONFIGURATION, expectedRequestBody); assertValidationError(validationResult.getErrors().get(0), "key-one", "incorrect value"); assertValidationError(validationResult.getErrors().get(1), "", "general error"); }
Example #10
Source File: ClusterStatusReportExecutor.java From docker-swarm-elastic-agent-plugin with Apache License 2.0 | 6 votes |
public GoPluginApiResponse execute() { try { LOG.debug("[status-report] Generating cluster status report."); final DockerClient dockerClient = dockerClientFactory.docker(clusterStatusReportRequest.getClusterProfile()); final SwarmCluster swarmCluster = new SwarmCluster(dockerClient); final Template template = viewBuilder.getTemplate("status-report.template.ftlh"); final String statusReportView = viewBuilder.build(template, swarmCluster); JsonObject responseJSON = new JsonObject(); responseJSON.addProperty("view", statusReportView); return DefaultGoPluginApiResponse.success(responseJSON.toString()); } catch (Exception e) { return StatusReportGenerationErrorHandler.handle(viewBuilder, e); } }
Example #11
Source File: Plugin1.java From go-plugins with Apache License 2.0 | 6 votes |
@Override public GoPluginApiResponse handle(GoPluginApiRequest goPluginApiRequest) throws UnhandledRequestTypeException { if ("configuration".equals(goPluginApiRequest.requestName())) { HashMap<String, Object> config = new HashMap<>(); HashMap<String, Object> url = new HashMap<>(); url.put("display-order", "0"); url.put("display-name", "Url"); url.put("required", true); config.put("Url", url); return DefaultGoPluginApiResponse.success(new GsonBuilder().create().toJson(config)); } else if ("view".equals(goPluginApiRequest.requestName())) { return getViewRequest(); } throw new UnhandledRequestTypeException(goPluginApiRequest.requestName()); }
Example #12
Source File: AgentStatusReportExecutor.java From docker-swarm-elastic-agent-plugin with Apache License 2.0 | 6 votes |
public GoPluginApiResponse execute() { String elasticAgentId = request.getElasticAgentId(); JobIdentifier jobIdentifier = request.getJobIdentifier(); LOG.info(String.format("[status-report] Generating status report for agent: %s with job: %s", elasticAgentId, jobIdentifier)); try { final DockerClient dockerClient = dockerClientFactory.docker(request.getClusterProfileProperties()); Service dockerService = findService(elasticAgentId, jobIdentifier, dockerClient); DockerServiceElasticAgent elasticAgent = DockerServiceElasticAgent.fromService(dockerService, dockerClient); final String statusReportView = builder.build(builder.getTemplate("agent-status-report.template.ftlh"), elasticAgent); JsonObject responseJSON = new JsonObject(); responseJSON.addProperty("view", statusReportView); return DefaultGoPluginApiResponse.success(responseJSON.toString()); } catch (Exception e) { return StatusReportGenerationErrorHandler.handle(builder, e); } }
Example #13
Source File: JobCompletionRequestExecutor.java From docker-swarm-elastic-agent-plugin with Apache License 2.0 | 6 votes |
@Override public GoPluginApiResponse execute() throws Exception { ClusterProfileProperties pluginSettings = jobCompletionRequest.getClusterProfileProperties(); String elasticAgentId = jobCompletionRequest.getElasticAgentId(); Agent agent = new Agent(); agent.elasticAgentId(elasticAgentId); LOG.info(format("[Job Completion] Terminating elastic agent with id {0} on job completion {1}.", agent.elasticAgentId(), jobCompletionRequest.jobIdentifier())); List<Agent> agents = Collections.singletonList(agent); pluginRequest.disableAgents(agents); agentInstances.terminate(agent.elasticAgentId(), pluginSettings); pluginRequest.deleteAgents(agents); return DefaultGoPluginApiResponse.success(""); }
Example #14
Source File: CreateAgentRequestExecutor.java From docker-elastic-agents-plugin with Apache License 2.0 | 6 votes |
@Override public GoPluginApiResponse execute() throws Exception { ConsoleLogAppender consoleLogAppender = text -> { final String message = String.format("%s %s\n", LocalTime.now().toString(MESSAGE_PREFIX_FORMATTER), text); pluginRequest.appendToConsoleLog(request.jobIdentifier(), message); }; consoleLogAppender.accept(String.format("Received request to create a container of %s at %s", request.dockerImage(), new DateTime().toString("yyyy-MM-dd HH:mm:ss ZZ"))); try { agentInstances.create(request, pluginRequest, consoleLogAppender); } catch (Exception e) { consoleLogAppender.accept(String.format("Failed while creating container: %s", e.getMessage())); throw e; } return new DefaultGoPluginApiResponse(200); }
Example #15
Source File: AuthorizationExtensionTest.java From gocd with Apache License 2.0 | 6 votes |
@Test void shouldTalkToPlugin_To_GetPluginConfigurationMetadata() { String responseBody = "[{\"key\":\"username\",\"metadata\":{\"required\":true,\"secure\":false}},{\"key\":\"password\",\"metadata\":{\"required\":true,\"secure\":true}}]"; when(pluginManager.submitTo(eq(PLUGIN_ID), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody)); List<PluginConfiguration> authConfigMetadata = authorizationExtension.getAuthConfigMetadata(PLUGIN_ID); assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "1.0", REQUEST_GET_AUTH_CONFIG_METADATA, null); assertThat(authConfigMetadata.size()).isEqualTo(2); assertThat(authConfigMetadata).hasSize(2) .contains( new PluginConfiguration("username", new Metadata(true, false)), new PluginConfiguration("password", new Metadata(true, true)) ); }
Example #16
Source File: JobCompletionRequestExecutor.java From kubernetes-elastic-agents with Apache License 2.0 | 6 votes |
@Override public GoPluginApiResponse execute() throws Exception { ClusterProfileProperties clusterProfileProperties = jobCompletionRequest.clusterProfileProperties(); String elasticAgentId = jobCompletionRequest.getElasticAgentId(); Agent agent = new Agent(); agent.setElasticAgentId(elasticAgentId); LOG.info(format("[Job Completion] Terminating elastic agent with id {0} on job completion {1}.", agent.elasticAgentId(), jobCompletionRequest.jobIdentifier())); List<Agent> agents = Arrays.asList(agent); pluginRequest.disableAgents(agents); agentInstances.terminate(agent.elasticAgentId(), clusterProfileProperties); pluginRequest.deleteAgents(agents); return DefaultGoPluginApiResponse.success(""); }
Example #17
Source File: AuthorizationExtensionTest.java From gocd with Apache License 2.0 | 6 votes |
@Test void shouldTalkToPlugin_To_SearchUsers() { String requestBody = "{\n" + " \"search_term\": \"bob\",\n" + " \"auth_configs\": [\n" + " {\n" + " \"id\": \"ldap\",\n" + " \"configuration\": {\n" + " \"foo\": \"bar\"\n" + " }\n" + " }\n" + " ]\n" + "}"; String responseBody = "[{\"username\":\"bob\",\"display_name\":\"Bob\",\"email\":\"[email protected]\"}]"; when(pluginManager.submitTo(eq(PLUGIN_ID), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody)); List<User> users = authorizationExtension.searchUsers(PLUGIN_ID, "bob", Collections.singletonList(new SecurityAuthConfig("ldap", "cd.go.ldap", create("foo", false, "bar")))); assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "1.0", REQUEST_SEARCH_USERS, requestBody); assertThat(users).hasSize(1) .contains(new User("bob", "Bob", "[email protected]")); }
Example #18
Source File: RoleConfigValidateRequestExecutor.java From github-oauth-authorization-plugin with Apache License 2.0 | 6 votes |
@Override public GoPluginApiResponse execute() throws Exception { final ValidationResult validationResult = new MetadataValidator().validate(request.gitHubRoleConfiguration()); if (!request.gitHubRoleConfiguration().hasConfiguration()) { validationResult.addError("Organizations", "At least one of the fields(organizations,teams or users) should be specified."); validationResult.addError("Teams", "At least one of the fields(organizations,teams or users) should be specified."); validationResult.addError("Users", "At least one of the fields(organizations,teams or users) should be specified."); } try { request.gitHubRoleConfiguration().teams(); } catch (RuntimeException e) { validationResult.addError("Teams", e.getMessage()); } return DefaultGoPluginApiResponse.success(validationResult.toJSON()); }
Example #19
Source File: ArtifactExtensionTestBase.java From gocd with Apache License 2.0 | 6 votes |
@Test public void shouldValidateArtifactStoreConfig() { String responseBody = "[{\"message\":\"ACCESS_KEY must not be blank.\",\"key\":\"ACCESS_KEY\"}]"; when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody)); ValidationResult validationResult = artifactExtension.validateArtifactStoreConfig(PLUGIN_ID, Collections.singletonMap("ACCESS_KEY", "")); final GoPluginApiRequest request = requestArgumentCaptor.getValue(); assertThat(request.extension(), is(ARTIFACT_EXTENSION)); assertThat(request.requestName(), is(REQUEST_STORE_CONFIG_VALIDATE)); assertThat(request.requestBody(), is("{\"ACCESS_KEY\":\"\"}")); assertThat(validationResult.isSuccessful(), is(false)); assertThat(validationResult.getErrors(), containsInAnyOrder( new ValidationError("ACCESS_KEY", "ACCESS_KEY must not be blank.") )); }
Example #20
Source File: ClusterStatusReportExecutor.java From kubernetes-elastic-agents with Apache License 2.0 | 6 votes |
public GoPluginApiResponse execute() { try { LOG.info("[status-report] Generating status report."); KubernetesClient client = factory.client(request.clusterProfileProperties()); final KubernetesCluster kubernetesCluster = new KubernetesCluster(client); final Template template = statusReportViewBuilder.getTemplate("status-report.template.ftlh"); final String statusReportView = statusReportViewBuilder.build(template, kubernetesCluster); final JsonObject responseJSON = new JsonObject(); responseJSON.addProperty("view", statusReportView); return DefaultGoPluginApiResponse.success(responseJSON.toString()); } catch (Exception e) { return StatusReportGenerationErrorHandler.handle(statusReportViewBuilder, e); } }
Example #21
Source File: IsValidUserRequestExecutor.java From gocd-filebased-authentication-plugin with Apache License 2.0 | 6 votes |
@Override public GoPluginApiResponse execute() throws Exception { JsonObject jsonObject = GSON.fromJson(request.requestBody(), JsonObject.class); Type type = new TypeToken<AuthConfig>() {}.getType(); String username = jsonObject.get("username").getAsString(); AuthConfig authConfig = GSON.fromJson(jsonObject.get("auth_config").toString(), type); final User found = find(username, authConfig); if (found != null) { return new DefaultGoPluginApiResponse(200); } return new DefaultGoPluginApiResponse(404); }
Example #22
Source File: PackageRepositoryExtensionTest.java From gocd with Apache License 2.0 | 6 votes |
@Test public void shouldTalkToPluginToGetRepositoryConfiguration() throws Exception { String expectedRequestBody = null; String expectedResponseBody = "{" + "\"key-one\":{}," + "\"key-two\":{\"default-value\":\"two\",\"part-of-identity\":true,\"secure\":true,\"required\":true,\"display-name\":\"display-two\",\"display-order\":\"1\"}," + "\"key-three\":{\"default-value\":\"three\",\"part-of-identity\":false,\"secure\":false,\"required\":false,\"display-name\":\"display-three\",\"display-order\":\"2\"}" + "}"; when(pluginManager.isPluginOfType(PACKAGE_MATERIAL_EXTENSION, PLUGIN_ID)).thenReturn(true); when(pluginManager.submitTo(eq(PLUGIN_ID), eq(PACKAGE_MATERIAL_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(expectedResponseBody)); RepositoryConfiguration repositoryConfiguration = extension.getRepositoryConfiguration(PLUGIN_ID); assertRequest(requestArgumentCaptor.getValue(), PACKAGE_MATERIAL_EXTENSION, "1.0", PackageRepositoryExtension.REQUEST_REPOSITORY_CONFIGURATION, expectedRequestBody); assertPropertyConfiguration((PackageMaterialProperty) repositoryConfiguration.get("key-one"), "key-one", "", true, true, false, "", 0); assertPropertyConfiguration((PackageMaterialProperty) repositoryConfiguration.get("key-two"), "key-two", "two", true, true, true, "display-two", 1); assertPropertyConfiguration((PackageMaterialProperty) repositoryConfiguration.get("key-three"), "key-three", "three", false, false, false, "display-three", 2); }
Example #23
Source File: AuthorizationExtensionTest.java From gocd with Apache License 2.0 | 5 votes |
@Test void shouldTalkToPlugin_To_GetAuthConfigView() { String responseBody = "{ \"template\": \"<div>This is view snippet</div>\" }"; when(pluginManager.submitTo(eq(PLUGIN_ID), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody)); String pluginConfigurationView = authorizationExtension.getAuthConfigView(PLUGIN_ID); assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "1.0", REQUEST_GET_AUTH_CONFIG_VIEW, null); assertThat(pluginConfigurationView).isEqualTo("<div>This is view snippet</div>"); }
Example #24
Source File: YamlConfigPlugin.java From gocd-yaml-config-plugin with Apache License 2.0 | 5 votes |
@Override public GoPluginApiResponse handle(GoPluginApiRequest request) throws UnhandledRequestTypeException { String requestName = request.requestName(); switch (requestName) { case REQ_PLUGIN_SETTINGS_GET_CONFIGURATION: return handleGetPluginSettingsConfiguration(); case REQ_CONFIG_FILES: return handleGetConfigFiles(request); case REQ_PLUGIN_SETTINGS_GET_VIEW: try { return handleGetPluginSettingsView(); } catch (IOException e) { return error(gson.toJson(format("Failed to find template: %s", e.getMessage()))); } case REQ_PLUGIN_SETTINGS_VALIDATE_CONFIGURATION: return handleValidatePluginSettingsConfiguration(); case REQ_PARSE_CONTENT: return handleParseContentRequest(request); case REQ_PARSE_DIRECTORY: ensureConfigured(); return handleParseDirectoryRequest(request); case REQ_PIPELINE_EXPORT: return handlePipelineExportRequest(request); case REQ_GET_CAPABILITIES: return success(gson.toJson(new Capabilities())); case REQ_PLUGIN_SETTINGS_CHANGED: configurePlugin(PluginSettings.fromJson(request.requestBody())); return new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, ""); case REQ_GET_ICON: return handleGetIconRequest(); default: throw new UnhandledRequestTypeException(requestName); } }
Example #25
Source File: ArtifactExtensionTestBase.java From gocd with Apache License 2.0 | 5 votes |
@Test public void shouldSubmitPublishArtifactRequest() { final String responseBody = "{\n" + " \"metadata\": {\n" + " \"artifact-version\": \"10.12.0\"\n" + " }\n" + "}"; when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody)); ArtifactPlan artifactPlan = new ArtifactPlan("{\"id\":\"installer\",\"storeId\":\"docker\"}"); ArtifactStore artifactStore = new ArtifactStore("docker", "cd.go.docker"); EnvironmentVariableContext env = new EnvironmentVariableContext("foo", "bar"); final PublishArtifactResponse response = artifactExtension.publishArtifact(PLUGIN_ID, artifactPlan, artifactStore, "/temp", env); final GoPluginApiRequest request = requestArgumentCaptor.getValue(); assertThat(request.extension(), is(ARTIFACT_EXTENSION)); assertThat(request.requestName(), is(REQUEST_PUBLISH_ARTIFACT)); final String expectedJSON = "{" + " \"artifact_plan\": {" + " \"id\": \"installer\"," + " \"storeId\": \"docker\"" + " }," + " \"artifact_store\": {" + " \"configuration\": {}," + " \"id\": \"docker\"" + " }," + " \"environment_variables\": {" + " \"foo\": \"bar\"" + " }," + " \"agent_working_directory\": \"/temp\"" + "}"; assertThatJson(expectedJSON).isEqualTo(request.requestBody()); assertThat(response.getMetadata().size(), is(1)); assertThat(response.getMetadata(), hasEntry("artifact-version", "10.12.0")); }
Example #26
Source File: PublishTask.java From gocd-s3-artifacts with Apache License 2.0 | 5 votes |
private GoPluginApiResponse handleTaskView() { int responseCode = DefaultGoPluginApiResponse.SUCCESS_RESPONSE_CODE; Map view = new HashMap(); view.put("displayValue", "Publish To S3"); try { view.put("template", IOUtils.toString(getClass().getResourceAsStream("/views/task.template.html"), "UTF-8")); } catch (Exception e) { responseCode = DefaultGoPluginApiResponse.INTERNAL_ERROR; String errorMessage = "Failed to find template: " + e.getMessage(); view.put("exception", errorMessage); logger.error(errorMessage, e); } return createResponse(responseCode, view); }
Example #27
Source File: ElasticAgentExtensionV5Test.java From gocd with Apache License 2.0 | 5 votes |
@Test public void shouldGetAgentStatusReport() { final String responseBody = "{\"view\":\"<div>This is a status report snippet.</div>\"}"; final JobIdentifier jobIdentifier = new JobIdentifier("up42", 2, "Test", "up42_stage", "10", "up42_job"); when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ELASTIC_AGENT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody)); Map<String, String> clusterProfile = Collections.singletonMap("go-server-url", "server-url-value"); extensionV5.getAgentStatusReport(PLUGIN_ID, jobIdentifier, "GoCD193659b3b930480287b898eeef0ade37", clusterProfile); final String requestBody = "{\n" + " \"job_identifier\": {\n" + " \"pipeline_name\": \"up42\",\n" + " \"pipeline_label\": \"Test\",\n" + " \"pipeline_counter\": 2,\n" + " \"stage_name\": \"up42_stage\",\n" + " \"stage_counter\": \"10\",\n" + " \"job_name\": \"up42_job\",\n" + " \"job_id\": -1\n" + " },\n" + " \"cluster_profile_properties\":{" + " \"go-server-url\":\"server-url-value\"" + " }," + " \"elastic_agent_id\": \"GoCD193659b3b930480287b898eeef0ade37\"\n" + "}"; assertExtensionRequest("5.0", REQUEST_AGENT_STATUS_REPORT, requestBody); }
Example #28
Source File: AuthorizationExtensionTest.java From gocd with Apache License 2.0 | 5 votes |
@Test void shouldTalkToPlugin_To_GetCapabilities() { String responseBody = "{\"supported_auth_type\":\"password\",\"can_search\":true}"; when(pluginManager.submitTo(eq(PLUGIN_ID), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody)); com.thoughtworks.go.plugin.domain.authorization.Capabilities capabilities = authorizationExtension.getCapabilities(PLUGIN_ID); assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "1.0", REQUEST_GET_CAPABILITIES, null); assertThat(capabilities.getSupportedAuthType().toString()).isEqualTo(SupportedAuthType.Password.toString()); assertThat(capabilities.canSearch()).isEqualTo(true); }
Example #29
Source File: YamlConfigPluginIntegrationTest.java From gocd-yaml-config-plugin with Apache License 2.0 | 5 votes |
@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 #30
Source File: ElasticAgentExtensionV5Test.java From gocd with Apache License 2.0 | 5 votes |
@Test public void shouldGetPluginIcon() { when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ELASTIC_AGENT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success("{\"content_type\":\"image/png\",\"data\":\"Zm9vYmEK\"}")); final Image icon = extensionV5.getIcon(PLUGIN_ID); assertThat(icon.getContentType(), is("image/png")); assertThat(icon.getData(), is("Zm9vYmEK")); assertExtensionRequest("5.0", REQUEST_GET_PLUGIN_SETTINGS_ICON, null); }