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

Commit

Permalink
Define the Hudson.Data.View class and start deserializing it off of t…
Browse files Browse the repository at this point in the history
…he Root API call
  • Loading branch information
R. Tyler Ballance committed Sep 6, 2009
1 parent a14949e commit 967ac4e
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Sources/Data/Root.cs
Expand Up @@ -13,6 +13,7 @@ public class Root
protected string nodeDescription = null;
protected int numExecutors = 0;
protected string description = null;
protected List<View> views = null;
#endregion

#region "Public Properties"
Expand Down Expand Up @@ -45,6 +46,12 @@ public string Description
get { return this.description; }
set { this.description = value; }
}

public List<View> Views
{
get { return this.views; }
set { this.views = value; }
}
#endregion
}
}
43 changes: 43 additions & 0 deletions Sources/Data/View.cs
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;

namespace Hudson.Data
{
[Serializable]
public class View
{
#region "Member Variables"
protected string description = null;
protected List<Project> jobs = null;
protected string name = null;
protected string url = null;
#endregion

#region "Public Properties"
public string Description
{
get { return this.description; }
set { this.description = value; }
}

public List<Project> Jobs
{
get { return this.jobs; }
set { this.jobs = value; }
}

public string Name
{
get { return this.name; }
set { this.name = value; }
}

public string Url
{
get { return this.url; }
set { this.url = value; }
}
#endregion
}
}
1 change: 0 additions & 1 deletion Tests/Data/RootTest.cs
@@ -1,5 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;

Expand Down
53 changes: 53 additions & 0 deletions Tests/Data/ViewTest.cs
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;

using NUnit.Framework;

using Hudson.Data;

namespace Hudson.Tests.ViewTests
{
[TestFixture]
public class ViewTest : Hudson.Tests.TestBase
{
protected readonly string sampleRootData = "{\"name\":\"All\",\"url\":\"http://localhost:8080/\"}";
protected readonly string sampleViewDetailData = "{\"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/\"}";

[Test]
public void BasicSimpleDeserialization()
{
View view = this.json.Deserialize<View>(this.sampleRootData);
Assert.IsNotNull(view, "Deserialized View object is null");
}

[Test]
public void BasicDetailedDeserialization()
{
View view = this.json.Deserialize<View>(this.sampleViewDetailData);
Assert.IsNotNull(view, "Deserialized (detailed) View object is null");
}

[Test]
public void VerifySimpleMembers()
{
View view = this.json.Deserialize<View>(this.sampleRootData);

Assert.AreEqual("All", view.Name, "Simple View.Name should be \"All\"");
Assert.AreEqual("http://localhost:8080/", view.Url, "Simple View.Url is wrong");

Assert.IsNull(view.Description, "View.Description should be null for simple data");
}

[Test]
public void VerifyDetailedMembers()
{
View view = this.json.Deserialize<View>(this.sampleViewDetailData);

Assert.AreEqual("TestView", view.Name);
Assert.AreEqual("This is a secondary view", view.Description);
Assert.AreEqual(2, view.Jobs.Count);
Assert.AreEqual("http://localhost:8080/view/TestView/", view.Url);
}
}
}

0 comments on commit 967ac4e

Please sign in to comment.