本文整理汇总了Java中com.thoughtworks.go.plugin.api.response.GoPluginApiResponse类的典型用法代码示例。如果您正苦于以下问题:Java GoPluginApiResponse类的具体用法?Java GoPluginApiResponse怎么用?Java GoPluginApiResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GoPluginApiResponse类属于com.thoughtworks.go.plugin.api.response包,在下文中一共展示了GoPluginApiResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldReturnSuccessResponseOnSuccessfulVerification
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; //导入依赖的package包/类
@Test
public void shouldReturnSuccessResponseOnSuccessfulVerification() throws Exception {
final GitHubConfiguration gitHubConfiguration = mock(GitHubConfiguration.class);
when(request.githubConfiguration()).thenReturn(gitHubConfiguration);
GoPluginApiResponse response = executor.execute();
String expectedJSON = "{\n" +
" \"message\": \"Connection ok\",\n" +
" \"status\": \"success\"\n" +
"}";
assertThat(response.responseCode(), is(200));
JSONAssert.assertEquals(expectedJSON, response.responseBody(), JSONCompareMode.NON_EXTENSIBLE);
}
开发者ID:gocd-contrib,项目名称:github-oauth-authorization-plugin,代码行数:17,代码来源:VerifyConnectionRequestExecutorTest.java
示例2: shouldValidateEmptyRoleConfig
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; //导入依赖的package包/类
@Test
public void shouldValidateEmptyRoleConfig() throws Exception {
when(request.requestBody()).thenReturn(new Gson().toJson(Collections.emptyMap()));
GoPluginApiResponse response = RoleConfigValidateRequest.from(request).execute();
String json = response.responseBody();
String expectedJSON = "[\n" +
" {\n" +
" \"key\": \"Users\",\n" +
" \"message\": \"At least one of the fields(organizations,teams or users) should be specified.\"\n" +
" },\n" +
" {\n" +
" \"key\": \"Teams\",\n" +
" \"message\": \"At least one of the fields(organizations,teams or users) should be specified.\"\n" +
" },\n" +
" {\n" +
" \"key\": \"Organizations\",\n" +
" \"message\": \"At least one of the fields(organizations,teams or users) should be specified.\"\n" +
" }\n" +
"]";
JSONAssert.assertEquals(expectedJSON, json, JSONCompareMode.NON_EXTENSIBLE);
}
开发者ID:gocd-contrib,项目名称:github-oauth-authorization-plugin,代码行数:25,代码来源:RoleConfigValidateRequestExecutorTest.java
示例3: shouldBuildStatusReportView
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; //导入依赖的package包/类
@Test
public void shouldBuildStatusReportView() throws Exception {
NodeOperationsImpl nodes = mock(NodeOperationsImpl.class);
PodOperationsImpl pods = mock(PodOperationsImpl.class);
when(nodes.list()).thenReturn(new NodeList());
when(kubernetesClient.nodes()).thenReturn(nodes);
when(pods.inNamespace(Constants.KUBERNETES_NAMESPACE_KEY)).thenReturn(pods);
when(pods.withLabel(Constants.CREATED_BY_LABEL_KEY, Constants.PLUGIN_ID)).thenReturn(pods);
when(pods.list()).thenReturn(new PodList());
when(kubernetesClient.pods()).thenReturn(pods);
final PluginStatusReportViewBuilder builder = mock(PluginStatusReportViewBuilder.class);
final Template template = mock(Template.class);
when(builder.getTemplate("status-report.template.ftlh")).thenReturn(template);
when(builder.build(eq(template), any(KubernetesCluster.class))).thenReturn("status-report");
final GoPluginApiResponse response = new StatusReportExecutor(pluginRequest, kubernetesClientFactory, builder).execute();
assertThat(response.responseCode(), is(200));
assertThat(response.responseBody(), is("{\"view\":\"status-report\"}"));
}
示例4: execute
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; //导入依赖的package包/类
public GoPluginApiResponse execute() throws Exception {
if (request.authConfigs() == null || request.authConfigs().isEmpty()) {
throw new NoAuthorizationConfigurationException("[Get Access Token] No authorization configuration found.");
}
if (!request.requestParameters().containsKey("code")) {
throw new IllegalArgumentException("Get Access Token] Expecting `code` in request params, but not received.");
}
final AuthConfig authConfig = request.authConfigs().get(0);
final GitHubConfiguration gitHubConfiguration = authConfig.gitHubConfiguration();
String fetchAccessTokenUrl = fetchAccessTokenUrl(gitHubConfiguration);
final Request fetchAccessTokenRequest = fetchAccessTokenRequest(fetchAccessTokenUrl);
final Response response = httpClient.newCall(fetchAccessTokenRequest).execute();
if (response.isSuccessful()) {
LOG.info("[Get Access Token] Access token fetched successfully.");
final TokenInfo tokenInfo = TokenInfo.fromJSON(response.body().string());
return DefaultGoPluginApiResponse.success(tokenInfo.toJSON());
}
throw new AuthenticationException(format("[Get Access Token] {0}", response.message()));
}
开发者ID:gocd-contrib,项目名称:github-oauth-authorization-plugin,代码行数:25,代码来源:FetchAccessTokenRequestExecutor.java
示例5: shouldValidateABadConfiguration
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; //导入依赖的package包/类
@Test
public void shouldValidateABadConfiguration() throws Exception {
ValidatePluginSettings settings = new ValidatePluginSettings();
GoPluginApiResponse response = new ValidateConfigurationExecutor(settings, pluginRequest).execute();
assertThat(response.responseCode(), is(200));
JSONAssert.assertEquals("[\n" +
" {\n" +
" \"message\": \"Agent auto-register Timeout (in minutes) must be a positive integer.\",\n" +
" \"key\": \"auto_register_timeout\"\n" +
" },\n" +
" {\n" +
" \"message\": \"Maximum Pending Kuberneted Pods Count must be a positive integer.\",\n" +
" \"key\": \"pending_pods_count\"\n" +
" },\n" +
" {\n" +
" \"message\": \"Kubernetes Cluster URL must not be blank.\",\n" +
" \"key\": \"kubernetes_cluster_url\"\n" +
" }\n" +
"]", response.responseBody(), true);
}
示例6: shouldValidateGoServerHTTPSUrlFormat
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; //导入依赖的package包/类
@Test
public void shouldValidateGoServerHTTPSUrlFormat() throws Exception {
ValidatePluginSettings settings = new ValidatePluginSettings();
settings.put("go_server_url", "foo.com/go(");
settings.put("kubernetes_cluster_url", "https://cluster.example.com");
settings.put("auto_register_timeout", "10");
settings.put("pending_pods_count", "10");
GoPluginApiResponse response = new ValidateConfigurationExecutor(settings, pluginRequest).execute();
assertThat(response.responseCode(), is(200));
JSONAssert.assertEquals("[" +
" {\n" +
" \"message\": \"Go Server URL must be a valid HTTPs URL (https://example.com).\",\n" +
" \"key\": \"go_server_url\"\n" +
" }\n" +
"]", response.responseBody(), true);
}
示例7: shouldValidateGitHubEnterpriseUrl
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; //导入依赖的package包/类
@Test
public void shouldValidateGitHubEnterpriseUrl() throws Exception {
when(request.requestBody()).thenReturn("{\n" +
" \"ClientId\": \"client-id\",\n" +
" \"AllowedOrganizations\": \"example-1,example-2\",\n" +
" \"AuthenticateWith\": \"GitHubEnterprise\",\n" +
" \"ClientSecret\": \"client-secret\",\n" +
" \"AuthorizeUsing\": \"UserAccessToken\"\n" +
"}");
GoPluginApiResponse response = AuthConfigValidateRequest.from(request).execute();
String expectedJSON = "[\n" +
" {\n" +
" \"key\": \"GitHubEnterpriseUrl\",\n" +
" \"message\": \"GitHubEnterpriseUrl must not be blank.\"\n" +
" }\n" +
"]";
JSONAssert.assertEquals(expectedJSON, response.responseBody(), JSONCompareMode.NON_EXTENSIBLE);
}
开发者ID:gocd-contrib,项目名称:github-oauth-authorization-plugin,代码行数:22,代码来源:AuthConfigValidateRequestExecutorTest.java
示例8: shouldAuthenticate
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; //导入依赖的package包/类
@Test
public void shouldAuthenticate() throws Exception {
final TokenInfo tokenInfo = new TokenInfo("31239032-xycs.xddasdasdasda", 7200, "foo-type", "refresh-xysaddasdjlascdas");
when(request.authConfigs()).thenReturn(Collections.singletonList(authConfig));
when(request.tokenInfo()).thenReturn(tokenInfo);
when(googleApiClient.userProfile(tokenInfo)).thenReturn(new GoogleUser("[email protected]", "Foo Bar"));
final GoPluginApiResponse response = executor.execute();
String expectedJSON = "{\n" +
" \"roles\": [],\n" +
" \"user\": {\n" +
" \"username\": \"[email protected]\",\n" +
" \"display_name\": \"Foo Bar\",\n" +
" \"email\": \"[email protected]\"\n" +
" }\n" +
"}";
assertThat(response.responseCode(), is(200));
JSONAssert.assertEquals(expectedJSON, response.responseBody(), true);
}
开发者ID:gocd-contrib,项目名称:google-oauth-authorization-plugin,代码行数:23,代码来源:UserAuthenticationRequestExecutorTest.java
示例9: execute
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; //导入依赖的package包/类
@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());
}
开发者ID:gocd-contrib,项目名称:github-oauth-authorization-plugin,代码行数:19,代码来源:RoleConfigValidateRequestExecutor.java
示例10: shouldFetchAccessToken
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; //导入依赖的package包/类
@Test
public void shouldFetchAccessToken() throws Exception {
final TokenInfo tokenInfo = new TokenInfo("31239032-xycs.xddasdasdasda", 7200, "foo-type", "refresh-xysaddasdjlascdas");
when(request.authConfigs()).thenReturn(Collections.singletonList(authConfig));
when(request.requestParameters()).thenReturn(Collections.singletonMap("code", "code-received-in-previous-step"));
when(googleApiClient.fetchAccessToken(request.requestParameters())).thenReturn(tokenInfo);
final GoPluginApiResponse response = executor.execute();
final String expectedJSON = "{\n" +
" \"access_token\": \"31239032-xycs.xddasdasdasda\",\n" +
" \"expires_in\": 7200,\n" +
" \"token_type\": \"foo-type\",\n" +
" \"refresh_token\": \"refresh-xysaddasdjlascdas\"\n" +
"}";
assertThat(response.responseCode(), is(200));
JSONAssert.assertEquals(expectedJSON, response.responseBody(), true);
}
开发者ID:gocd-contrib,项目名称:google-oauth-authorization-plugin,代码行数:22,代码来源:FetchAccessTokenRequestExecutorTest.java
示例11: execute
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; //导入依赖的package包/类
@Override
public GoPluginApiResponse execute() throws Exception {
PluginSettings pluginSettings = pluginRequest.getPluginSettings();
Agents allAgents = pluginRequest.listAgents();
Agents missingAgents = new Agents();
for (Agent agent : allAgents.agents()) {
if (agentInstances.find(agent.elasticAgentId()) == null) {
MarathonPlugin.LOG.warn("Was expecting a container with name " + agent.elasticAgentId() + ", but it was missing!");
missingAgents.add(agent);
}
}
Agents agentsToDisable = agentInstances.instancesCreatedAfterTimeout(pluginSettings, allAgents);
agentsToDisable.addAll(missingAgents);
disableIdleAgents(agentsToDisable);
allAgents = pluginRequest.listAgents();
terminateDisabledAgents(allAgents, pluginSettings);
agentInstances.terminateUnregisteredInstances(pluginSettings, allAgents);
return DefaultGoPluginApiResponse.success("");
}
示例12: shouldFetchAccessToken
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; //导入依赖的package包/类
@Test
public void shouldFetchAccessToken() throws Exception {
mockWebServer.enqueue(new MockResponse()
.setResponseCode(200)
.setBody(new TokenInfo("token-444248275346-5758603453985735", "bearer", "user:email,read:org").toJSON()));
when(fetchAccessTokenRequest.authConfigs()).thenReturn(Collections.singletonList(authConfig));
when(fetchAccessTokenRequest.requestParameters()).thenReturn(Collections.singletonMap("code", "code-received-in-previous-step"));
when(gitHubConfiguration.apiUrl()).thenReturn(mockWebServer.url("/").toString());
final GoPluginApiResponse response = executor.execute();
String expectedJSON = "{\n" +
" \"access_token\": \"token-444248275346-5758603453985735\",\n" +
" \"token_type\": \"bearer\",\n" +
" \"scope\": \"user:email,read:org\"\n" +
"}";
assertThat(response.responseCode(), is(200));
JSONAssert.assertEquals(expectedJSON, response.responseBody(), true);
}
开发者ID:gocd-contrib,项目名称:github-oauth-authorization-plugin,代码行数:22,代码来源:FetchAccessTokenRequestExecutorTest.java
示例13: execute
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; //导入依赖的package包/类
@Override
public GoPluginApiResponse execute() throws Exception {
Credentials credentials = Credentials.fromJSON(request.requestBody());
final List<AuthConfig> authConfigs = AuthConfig.fromJSONList(request.requestBody());
Map<String, Object> userMap = new HashMap<>();
try {
final User user = authenticator.authenticate(credentials, authConfigs);
userMap.put("user", user);
userMap.put("roles", Collections.emptyList());
return new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, GSON.toJson(userMap));
} catch (AuthenticationException e) {
LOG.error(String.format("[Authenticate] Failed to authenticate user: `%s`", credentials.getUsername()), e);
return new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, GSON.toJson(userMap));
}
}
示例14: handleShouldReturnErrorResponseInCaseOfUnknownException
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; //导入依赖的package包/类
@Test
public void handleShouldReturnErrorResponseInCaseOfUnknownException() throws Exception {
when(requestHandlerFactory.create(anyString())).thenThrow(Exception.class);
GoPluginApiRequest request = new DefaultGoPluginApiRequest("scm", "1.0", RequestHandlerFactory.SCM_CONFIGURATION);
GoPluginApiResponse response = plugin.handle(request);
assertThat(response.responseCode(), equalTo(DefaultGoPluginApiResponse.INTERNAL_ERROR));
}
示例15: handleShouldReturnErrorResponseGivenInvalidJson
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; //导入依赖的package包/类
@Test
public void handleShouldReturnErrorResponseGivenInvalidJson() {
DefaultGoPluginApiRequest request = validRequest;
request.setRequestBody("Invalid JSON");
GoPluginApiResponse response = handler.handle(request);
assertThat(response.responseCode(), equalTo(DefaultGoPluginApiResponse.INTERNAL_ERROR));
}