Skip to content
This repository has been archived by the owner on Mar 8, 2018. It is now read-only.

Commit

Permalink
Add the Api.FetchView() and .FetchViews() API calls with tests to fet…
Browse files Browse the repository at this point in the history
…ch view data from Hudson
  • Loading branch information
R. Tyler Ballance committed Sep 6, 2009
1 parent 967ac4e commit 0511791
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Sources/Hudson.cs
Expand Up @@ -98,6 +98,28 @@ public Hudson.Data.Job FetchJob(string jobName)
string endpoint = String.Format("/job/{0}/api/json", jobName);
return this.requestProxy.Execute<Hudson.Data.Job>(endpoint);
}

public Hudson.Data.View FetchView(string viewName)
{
if (String.IsNullOrEmpty(viewName))
{
return null;
}
string endpoint = String.Format("/view/{0}/api/json", viewName);
return this.requestProxy.Execute<Hudson.Data.View>(endpoint);

}

public List<Hudson.Data.View> FetchViews()
{
Hudson.Data.Root root = this.FetchRootData();

if (root == null)
{
return null;
}
return root.Views;
}
#endregion
}

Expand Down
33 changes: 33 additions & 0 deletions Tests/Api.cs
Expand Up @@ -133,4 +133,37 @@ public void SynchronousFetchWithEmptyJobName()
Assert.IsNull(job, "FetchJob() should have returned null");
}
}

[TestFixture]
public class FetchViewTests : ApiBase
{
[SetUp]
public virtual void SetUp()
{
Dictionary<string, string> testData = new Dictionary<string, string>();
testData.Add("/api/json", "{\"assignedLabels\":[{}],\"mode\":\"NORMAL\",\"nodeDescription\":\"the master Hudson node\",\"nodeName\":\"\",\"numExecutors\":2,\"description\":null,\"jobs\":[{\"name\":\"Downstream\",\"url\":\"http://localhost:8080/job/Downstream/\",\"color\":\"blue\"},{\"name\":\"Hudson.NET\",\"url\":\"http://localhost:8080/job/Hudson.NET/\",\"color\":\"blue\"},{\"name\":\"Sleeper\",\"url\":\"http://localhost:8080/job/Sleeper/\",\"color\":\"blue\"}],\"primaryView\":{\"name\":\"All\",\"url\":\"http://localhost:8080/\"},\"slaveAgentPort\":0,\"useCrumbs\":false,\"useSecurity\":false,\"views\":[{\"name\":\"All\",\"url\":\"http://localhost:8080/\"},{\"name\":\"TestView\",\"url\":\"http://localhost:8080/view/TestView/\"}]}");
testData.Add("/view/TestView/api/json", "{\"description\":\"This is a secondary view\",\"jobs\":[{\"name\":\"Downstream\",\"url\":\"http://localhost:8080/job/Downstream/\",\"color\":\"blue\"},{\"name\":\"Sleeper\",\"url\":\"http://localhost:8080/job/Sleeper/\",\"color\":\"blue\"}],\"name\":\"TestView\",\"url\":\"http://localhost:8080/view/TestView/\"}");

this.requestProxy = new Hudson.Tests.MockRequestProxy(testData);
this.api = new Api(this.requestProxy);
}

[Test]
public void SynchronousFetchView()
{
View view = this.api.FetchView("TestView");

Assert.IsNotNull(view);
Assert.IsNotNull(view.Description);
}

[Test]
public void SynchronousFetchViews()
{
List<View> views = this.api.FetchViews();

Assert.IsNotNull(views);
Assert.AreEqual(2, views.Count);
}
}
}

0 comments on commit 0511791

Please sign in to comment.