public async Task PostSavesConfigurationInJson() { // Given await this.TestClient.DeleteAsync("admin/it"); RestApiConfiguration configuration = new RestApiConfiguration { Service = "Palantir.HostedRedmine", Projects = new List <string>() { "test-credit-system" }, Token = "token", }; string json = JsonConvert.SerializeObject(configuration); StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); // When await this.TestClient.PostAsync("admin/it", stringContent); // Then HttpResponseMessage response = await this.TestClient.GetAsync("admin/it"); string jsonResponse = await response.Content.ReadAsStringAsync(); string expectedJson = "{\"WidgetType\":\"it\",\"ServiceName\":\"Palantir.HostedRedmine.RestApiService, Palantir.HostedRedmine\",\"RestApiUrls\":[\"http://www.hostedredmine.com/projects/test-credit-system/issues.json?status_id=8&limit=100\"],\"RestApiHeader\":{\"AuthorizationToken\":\"token\",\"UserAgent\":\"\",\"ApiVersion\":\"\"}}"; Assert.Equal(expectedJson, jsonResponse); }
public async Task UpdateConfiguration(RestApiConfiguration configuration, string path) { string result = await IOHelper.ReadFile(path); List <WidgetConfiguration> currentConfigList = JsonConvert.DeserializeObject <List <WidgetConfiguration> >(result); if (currentConfigList != null && currentConfigList.Any(item => item.WidgetType == "iframe")) { List <WidgetConfiguration> updatedConfigList = new List <WidgetConfiguration>(); WidgetConfiguration config = new WidgetConfiguration() { WidgetType = "iframe", ServiceName = configuration.Html, }; updatedConfigList.Add(config); if (currentConfigList != null) { foreach (WidgetConfiguration item in currentConfigList) { if (item.WidgetType != "iframe") { updatedConfigList.Add(item); } } } string configJson = JsonConvert.SerializeObject(updatedConfigList); await IOHelper.WriteFile(path, configJson); } }
public async Task PutDoesNotUpdateConfigurationInJsonIfThereIsNotPreviousConfiguration() { // Given await this.TestClient.DeleteAsync("admin/it"); // When RestApiConfiguration configuration = new RestApiConfiguration { Service = "Palantir.HostedRedmine", Projects = new List <string>() { "test-credit-system" }, Token = "token", }; string json = JsonConvert.SerializeObject(configuration); StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); await this.TestClient.PutAsync("admin/it", stringContent); // Then HttpResponseMessage response = await this.TestClient.GetAsync("admin/it"); string jsonResponse = await response.Content.ReadAsStringAsync(); string expectedJson = string.Empty; Assert.Equal(expectedJson, jsonResponse); }
public async Task <IActionResult> Put(RestApiConfiguration configuration) { IframeConfigurationWriter configurationWriter = new IframeConfigurationWriter(); await configurationWriter.UpdateConfiguration(configuration, this.configFilePath); return(this.Ok()); }
public async Task DeleteRemovesConfigurationInJson() { // Given RestApiConfiguration configuration = new RestApiConfiguration { Projects = new List <string>() { "8722522" }, Service = "Palantir.TravisCI", Token = "token", }; string json = JsonConvert.SerializeObject(configuration); StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); await this.TestClient.PostAsync("admin/bs", stringContent); // When await this.TestClient.DeleteAsync("admin/bs"); // Then HttpResponseMessage response = await this.TestClient.GetAsync("admin/bs"); string jsonResponse = await response.Content.ReadAsStringAsync(); string expectedJson = string.Empty; Assert.Equal(expectedJson, jsonResponse); }
public async Task BSReturnsExpectedTravisCIBuildsResponse() { // Given await this.TestClient.DeleteAsync("admin/bs"); RestApiConfiguration configuration = new RestApiConfiguration { Service = "Palantir.TravisCI", Projects = new List <string>() { "8722522" }, Token = "o5EDKkh872Ws00tnILXAjg", }; string json = JsonConvert.SerializeObject(configuration); StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); await this.TestClient.PostAsync("admin/bs", stringContent); // When HttpResponseMessage response = await this.TestClient.GetAsync("view/bs"); // Then string expectedJson = "[{\"id\":631066056,\"url\":\"https://travis-ci.org/gonzalocozzi/aydoo-2016-e4/builds/631066056\",\"number\":\"297\",\"state\":\"errored\",\"repository\":\"aydoo-2016-e4\",\"branch\":\"master\",\"commit\":\"Bump mustache from 2.1.3 to 3.2.1 in /archivos de ejemplo/plantilla\\n\\nBumps [mustache](https://github.com/janl/mustache.js) from 2.1.3 to 3.2.1.\\n- [Release notes](https://github.com/janl/mustache.js/releases)\\n- [Changelog](https://github.com/janl/mustache.js/blob/master/CHANGELOG.md)\\n- [Commits](https://github.com/janl/mustache.js/compare/v2.1.3...v3.2.1)\\n\\nSigned-off-by: dependabot[bot] <*****@*****.**>\",\"startedOn\":\"2019-12-30T20:23:06+00:00\",\"finishedOn\":\"2019-12-30T20:23:23+00:00\"},{\"id\":631065999,\"url\":\"https://travis-ci.org/gonzalocozzi/aydoo-2016-e4/builds/631065999\",\"number\":\"296\",\"state\":\"errored\",\"repository\":\"aydoo-2016-e4\",\"branch\":\"dependabot/npm_and_yarn/archivos-de-ejemplo/plantilla/mustache-3.2.1\",\"commit\":\"Bump mustache from 2.1.3 to 3.2.1 in /archivos de ejemplo/plantilla\\n\\nBumps [mustache](https://github.com/janl/mustache.js) from 2.1.3 to 3.2.1.\\n- [Release notes](https://github.com/janl/mustache.js/releases)\\n- [Changelog](https://github.com/janl/mustache.js/blob/master/CHANGELOG.md)\\n- [Commits](https://github.com/janl/mustache.js/compare/v2.1.3...v3.2.1)\\n\\nSigned-off-by: dependabot[bot] <*****@*****.**>\",\"startedOn\":\"2019-12-30T20:23:01+00:00\",\"finishedOn\":\"2019-12-30T20:23:19+00:00\"},{\"id\":138963890,\"url\":\"https://travis-ci.org/gonzalocozzi/aydoo-2016-e4/builds/138963890\",\"number\":\"295\",\"state\":\"passed\",\"repository\":\"aydoo-2016-e4\",\"branch\":\"v2\",\"commit\":\"se hizo un cambio chiquito de redaccion en el Readme\",\"startedOn\":\"2016-06-20T17:06:09+00:00\",\"finishedOn\":\"2016-06-20T17:07:19+00:00\"}]"; string jsonResponse = await response.Content.ReadAsStringAsync(); Assert.Equal(expectedJson, jsonResponse); }
public async Task PostSavesConfigurationInJson() { // Given await this.TestClient.DeleteAsync("admin/bs"); RestApiConfiguration configuration = new RestApiConfiguration { Projects = new List <string>() { "8722522" }, Service = "Palantir.TravisCI", Token = "token", }; string json = JsonConvert.SerializeObject(configuration); StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); // When await this.TestClient.PostAsync("admin/bs", stringContent); // Then HttpResponseMessage response = await this.TestClient.GetAsync("admin/bs"); string jsonResponse = await response.Content.ReadAsStringAsync(); string expectedJson = "{\"WidgetType\":\"bs\",\"ServiceName\":\"Palantir.TravisCI.RestApiService, Palantir.TravisCI\",\"RestApiUrls\":[\"https://api.travis-ci.org/repo/8722522/builds\"],\"RestApiHeader\":{\"AuthorizationToken\":\"token\",\"UserAgent\":\"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41\",\"ApiVersion\":\"3\"}}"; Assert.Equal(expectedJson, jsonResponse); }
public async Task ITReturnsExpectedHostedRedmineIssuesResponse() { // Given await this.TestClient.DeleteAsync("admin/it"); RestApiConfiguration configuration = new RestApiConfiguration { Service = "Palantir.HostedRedmine", Projects = new List <string>() { "test-credit-system" }, Token = "0c93671c0f32595a533d91ad4001206f08cb9f7a", }; string json = JsonConvert.SerializeObject(configuration); StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); await this.TestClient.PostAsync("admin/it", stringContent); // When HttpResponseMessage response = await this.TestClient.GetAsync("view/it"); // Then string jsonResponse = await response.Content.ReadAsStringAsync(); string expectedJson = "[{\"id\":851196,\"url\":\"http://www.hostedredmine.com/issues/851196\",\"project\":\"TestCreditSystem\",\"title\":\"[Front][Back] Export Data table\",\"state\":\"In Progress\",\"authorName\":\"Eric Chau\",\"assignedTo\":\"surendra k\",\"createdOn\":\"2019-12-05T17:59:24+00:00\",\"updatedOn\":\"2019-12-11T20:09:08+00:00\"},{\"id\":833318,\"url\":\"http://www.hostedredmine.com/issues/833318\",\"project\":\"TestCreditSystem\",\"title\":\"Angleški logo\",\"state\":\"In Progress\",\"authorName\":\"Klemen Urbančnik\",\"assignedTo\":\"Klemen Urbančnik\",\"createdOn\":\"2019-08-29T07:21:25+00:00\",\"updatedOn\":\"2019-09-09T20:51:53+00:00\"},{\"id\":680102,\"url\":\"http://www.hostedredmine.com/issues/680102\",\"project\":\"TestCreditSystem\",\"title\":\"Dlaczego my?\",\"state\":\"In Progress\",\"authorName\":\"Rafał Hejnowicz\",\"assignedTo\":\"Mateusz Zabój\",\"createdOn\":\"2017-06-29T23:31:06+00:00\",\"updatedOn\":\"2017-07-27T19:53:37+00:00\"},{\"id\":678528,\"url\":\"http://www.hostedredmine.com/issues/678528\",\"project\":\"TestCreditSystem\",\"title\":\"abonnement bevriezen\",\"state\":\"In Progress\",\"authorName\":\"Ritchie Peperkoorn\",\"assignedTo\":\"Ritchie Peperkoorn\",\"createdOn\":\"2017-06-21T06:18:52+00:00\",\"updatedOn\":\"2017-07-06T09:52:41+00:00\"},{\"id\":635939,\"url\":\"http://www.hostedredmine.com/issues/635939\",\"project\":\"TestCreditSystem\",\"title\":\"GoGo JAPAN Tier 2 flyer\",\"state\":\"In Progress\",\"authorName\":\"Joyce Gorsuch\",\"assignedTo\":\"Geraldine Matias\",\"createdOn\":\"2017-02-10T03:54:45+00:00\",\"updatedOn\":\"2017-02-14T19:37:01+00:00\"},{\"id\":612685,\"url\":\"http://www.hostedredmine.com/issues/612685\",\"project\":\"TestCreditSystem\",\"title\":\"学习git\",\"state\":\"In Progress\",\"authorName\":\"浩然 白\",\"assignedTo\":\"no one\",\"createdOn\":\"2016-11-18T11:23:43+00:00\",\"updatedOn\":\"2016-11-21T01:39:44+00:00\"},{\"id\":568419,\"url\":\"http://www.hostedredmine.com/issues/568419\",\"project\":\"TestCreditSystem\",\"title\":\"Licentie capability inbouwen\",\"state\":\"In Progress\",\"authorName\":\"Hans de Bue\",\"assignedTo\":\"no one\",\"createdOn\":\"2016-06-22T05:45:40+00:00\",\"updatedOn\":\"2016-12-05T20:55:45+00:00\"}]"; Assert.Equal(expectedJson, jsonResponse); }
public async Task PostSavesConfigurationInJson() { // Given await this.TestClient.DeleteAsync("admin/scm"); RestApiConfiguration configuration = new RestApiConfiguration { Service = "Palantir.GitLab", Projects = new List <string>() { "15722380" }, User = string.Empty, Token = "token", }; string json = JsonConvert.SerializeObject(configuration); StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); // When await this.TestClient.PostAsync("admin/scm", stringContent); // Then HttpResponseMessage response = await this.TestClient.GetAsync("admin/scm"); string jsonResponse = await response.Content.ReadAsStringAsync(); string expectedJson = "{\"WidgetType\":\"scm\",\"ServiceName\":\"Palantir.GitLab.RestApiService, Palantir.GitLab\",\"RestApiUrls\":[\"https://gitlab.com/api/v4/projects/15722380/merge_requests\"],\"RestApiHeader\":{\"AuthorizationToken\":\"token\",\"UserAgent\":\"\",\"ApiVersion\":\"\"}}"; Assert.Equal(expectedJson, jsonResponse); }
public async Task ScmReturnsExpectedGitLabMergeRequestResponse() { // Given await this.TestClient.DeleteAsync("admin/scm"); RestApiConfiguration configuration = new RestApiConfiguration { Service = "Palantir.GitLab", Projects = new List <string>() { "15722380" }, Token = "qAxa6BEzME7miLNQzmKD", }; string json = JsonConvert.SerializeObject(configuration); StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); await this.TestClient.PostAsync("admin/scm", stringContent); // When HttpResponseMessage response = await this.TestClient.GetAsync("view/scm"); // Then string jsonResponse = await response.Content.ReadAsStringAsync(); string expectedJson = "[{\"id\":44126460,\"title\":\"Readme updated\",\"authorName\":\"nicopaez\",\"creationDate\":\"2019-12-06T12:55:01.316+00:00\",\"lastUpdate\":\"2019-12-06T12:55:01.316+00:00\",\"state\":\"opened\",\"url\":\"https://gitlab.com/untref-ingsoft/tfi-cozzi/sample-repo1/-/merge_requests/1\"}]"; Assert.Equal(expectedJson, jsonResponse); }
public async Task ScmReturnsExpectedGitHubPullRequestResponse() { // Given await this.TestClient.DeleteAsync("admin/scm"); RestApiConfiguration configuration = new RestApiConfiguration { Service = "Palantir.GitHub", User = "******", Projects = new List <string>() { "rest-api-test" }, Token = "86a48616a377f0a29df4f086f085451afb044b53", }; string json = JsonConvert.SerializeObject(configuration); StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); await this.TestClient.PostAsync("admin/scm", stringContent); // When HttpResponseMessage response = await this.TestClient.GetAsync("view/scm"); // Then string jsonResponse = await response.Content.ReadAsStringAsync(); string expectedJson = "[{\"id\":315229289,\"title\":\"Test\",\"authorName\":\"gonzalocozzi\",\"creationDate\":\"2019-09-07T22:26:59+00:00\",\"lastUpdate\":\"2019-09-23T23:46:10+00:00\",\"state\":\"open\",\"url\":\"https://github.com/gonzalocozzi/rest-api-test/pull/1\"}]"; Assert.Equal(expectedJson, jsonResponse); }
public async Task UpdateConfiguration(RestApiConfiguration configuration, string path) { string fullQualifiedName = $"{configuration.Service}.WidgetConfigurationAdapter, {configuration.Service}"; IWidgetConfigurationAdapter widgetConfigurationAdapter = (IWidgetConfigurationAdapter)Activator.CreateInstance(Type.GetType(fullQualifiedName), configuration); widgetConfigurationAdapter.ValidateWidgetConfiguration(configuration); string result = await IOHelper.ReadFile(path); List <WidgetConfiguration> currentConfigList = JsonConvert.DeserializeObject <List <WidgetConfiguration> >(result); if (currentConfigList != null && currentConfigList.Any(item => item.WidgetType == "scm")) { this.widgetConfiguration = widgetConfigurationAdapter.GetWidgetConfiguration(); List <WidgetConfiguration> updatedConfigList = new List <WidgetConfiguration> { this.widgetConfiguration, }; if (currentConfigList != null) { foreach (WidgetConfiguration item in currentConfigList) { if (item.WidgetType != "scm") { updatedConfigList.Add(item); } } } string configJson = JsonConvert.SerializeObject(updatedConfigList); await IOHelper.WriteFile(path, configJson); } }
public void ValidateWidgetConfiguration(RestApiConfiguration adaptee) { if (string.IsNullOrEmpty(adaptee.Token)) { throw new Palantir.Exceptions.MissingTokenException(); } if (adaptee.Projects == null || !adaptee.Projects.Any() || adaptee.Projects.Contains(string.Empty)) { throw new Palantir.Exceptions.InvalidFieldException("El nombre de proyecto de HostedRedmine es obligatorio"); } }
public void ValidateWidgetConfiguration(RestApiConfiguration adaptee) { if (string.IsNullOrEmpty(adaptee.Token)) { throw new MissingTokenException(); } if (adaptee.Projects == null || !adaptee.Projects.Any() || adaptee.Projects.Contains(string.Empty)) { throw new InvalidFieldException("El nombre o ID de proyecto de Travis CI es obligatorio"); } }
public WidgetConfigurationAdapterTests() { // Given this.adaptee = new RestApiConfiguration() { Projects = new List <string>() { "test-credit-system" }, Token = "token", }; this.adapter = new WidgetConfigurationAdapter(this.adaptee); }
public WidgetConfigurationAdapterTests() { // Given this.adaptee = new RestApiConfiguration { Projects = new List <string>() { "0123456789" }, Token = "token", }; this.adapter = new WidgetConfigurationAdapter(this.adaptee); }
public WidgetConfigurationAdapterTests() { // Given this.adaptee = new RestApiConfiguration { User = "******", Projects = new List <string>() { "project" }, Token = "token", }; this.adapter = new WidgetConfigurationAdapter(this.adaptee); }
/// <summary> /// Initializes the RestClient based on the API Name in RestApiConfiguration.json /// And Initializes the client with given AgentBaseUrl /// </summary> /// <param name="baseUrl">API Name in the RestApiConfiguration.json</param> public RestClientFactory(string ApiName, string AgentBaseUrl) { try { this.configuration = RestApiConfigurationManager.Instance.Configurations; this.apiConfiguration = this.configuration.RestApis.FirstOrDefault(api => api.Name == ApiName); client = new RestClient(AgentBaseUrl); } catch (Exception ex) { //errHandler(); #region Text Logging #endregion Text Logging } }
/// <summary> /// Initializes the RestClient Authenticator with provided username and password. /// </summary> /// <param name="baseUrl">API Name in the RestApiConfiguration.json</param> /// <param name="username"></param> /// <param name="password"></param> public RestClientFactory(string ApiName, string username, string password) { try { this.configuration = RestApiConfigurationManager.Instance.Configurations; this.apiConfiguration = this.configuration.RestApis.FirstOrDefault(api => api.Name == ApiName); client = new RestClient(this.apiConfiguration.BaseUrl); client.Authenticator = new HttpBasicAuthenticator(username, password); } catch (Exception ex) { //errHandler(); #region Text Logging #endregion Text Logging } }
public async Task PutReturnsBadRequestWhenServiceNameIsInvalidOrUnexistent() { // Given RestApiConfiguration configuration = new RestApiConfiguration { Service = "invalid", }; string json = JsonConvert.SerializeObject(configuration); StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); // When HttpResponseMessage response = await this.TestClient.PutAsync("admin/bs", stringContent); // Then HttpResponseMessage expectedResponse = new HttpResponseMessage(HttpStatusCode.BadRequest); Assert.Equal(expectedResponse.StatusCode, response.StatusCode); }
public async Task PutReturnsBadRequestWhenTravisCIProjectIsNull() { // Given RestApiConfiguration configuration = new RestApiConfiguration { Service = "Palantir.TravisCI", Token = "token", }; string json = JsonConvert.SerializeObject(configuration); StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); // WhenGitHub HttpResponseMessage response = await this.TestClient.PutAsync("admin/bs", stringContent); // Then HttpResponseMessage expectedResponse = new HttpResponseMessage(HttpStatusCode.BadRequest); Assert.Equal(expectedResponse.StatusCode, response.StatusCode); }
public void ValidateWidgetConfiguration(RestApiConfiguration adaptee) { if (string.IsNullOrEmpty(adaptee.Token)) { throw new MissingTokenException(); } if (adaptee.Projects == null || !adaptee.Projects.Any() || adaptee.Projects.Contains(string.Empty)) { throw new InvalidFieldException("El ID de proyecto de GitLab es obligatorio"); } foreach (string item in adaptee.Projects) { if (!Regex.IsMatch(item, @"^\d+$")) { throw new InvalidFieldException("El ID de proyecto de GitLab debe componerse únicamente de caracteres numéricos"); } } }
public async Task PutReturnsBadRequestWhenGitHubProjectIsNull() { // Given RestApiConfiguration configuration = new RestApiConfiguration { Service = "Palantir.GitHub", User = "******", Token = "86a48616a377f0a29df4f086f085451afb044b53", }; string json = JsonConvert.SerializeObject(configuration); StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); // When HttpResponseMessage response = await this.TestClient.PutAsync("admin/scm", stringContent); // Then HttpResponseMessage expectedResponse = new HttpResponseMessage(HttpStatusCode.BadRequest); Assert.Equal(expectedResponse.StatusCode, response.StatusCode); }
public async Task <IActionResult> Put(RestApiConfiguration configuration) { SourceControlManagerConfigurationWriter configurationWriter = new SourceControlManagerConfigurationWriter(); try { await configurationWriter.UpdateConfiguration(configuration, this.configFilePath); } catch (Exception exception) { if (exception is TargetInvocationException || exception is ArgumentNullException || exception is InvalidServiceNameException || exception is InvalidFieldException) { return(this.BadRequest(exception.Message)); } else if (exception is MissingTokenException) { return(this.Unauthorized(exception.Message)); } } return(this.Ok()); }
public async Task PutReturnsUnauthorizedWhenGitLabProjectIsNotNumeric() { // Given RestApiConfiguration configuration = new RestApiConfiguration { Service = "Palantir.GitLab", Projects = new List <string>() { "15722w380" }, }; string json = JsonConvert.SerializeObject(configuration); StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); // When HttpResponseMessage response = await this.TestClient.PutAsync("admin/scm", stringContent); // Then HttpResponseMessage expectedResponse = new HttpResponseMessage(HttpStatusCode.Unauthorized); Assert.Equal(expectedResponse.StatusCode, response.StatusCode); }
public async Task PostReturnsUnauthorizedWhenHostedRedmineTokenIsNull() { // Given RestApiConfiguration configuration = new RestApiConfiguration { Service = "Palantir.HostedRedmine", Projects = new List <string>() { "test-credit-system" }, }; string json = JsonConvert.SerializeObject(configuration); StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); // When HttpResponseMessage response = await this.TestClient.PostAsync("admin/it", stringContent); // Then HttpResponseMessage expectedResponse = new HttpResponseMessage(HttpStatusCode.Unauthorized); Assert.Equal(expectedResponse.StatusCode, response.StatusCode); }
public async Task PutReturnsUnauthorizedWhenTravisCITokenIsNull() { // Given RestApiConfiguration configuration = new RestApiConfiguration { Projects = new List <string>() { "8722522" }, Service = "Palantir.TravisCI", }; string json = JsonConvert.SerializeObject(configuration); StringContent stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); // When HttpResponseMessage response = await this.TestClient.PutAsync("admin/bs", stringContent); // Then HttpResponseMessage expectedResponse = new HttpResponseMessage(HttpStatusCode.Unauthorized); Assert.Equal(expectedResponse.StatusCode, response.StatusCode); }
public void Dispose() { this.adaptee = null; }
public WidgetConfigurationAdapter(RestApiConfiguration adaptee) { this.adaptee = adaptee; }