Skip to content

Commit 1f6c862

Browse files
author
sam.gerene
committed
[Add] RestClient that implements the various GET requests specified in the OMG SysML v2 REST/HTTP PSM
[Add] partial implementation of the login component
1 parent 7a7a8f5 commit 1f6c862

File tree

17 files changed

+1408
-5
lines changed

17 files changed

+1408
-5
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
// -------------------------------------------------------------------------------------------------
2+
// <copyright file="RestClientTestFixture.cs" company="RHEA System S.A.">
3+
//
4+
// Copyright 2022 RHEA System S.A.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// </copyright>
19+
// ------------------------------------------------------------------------------------------------
20+
21+
namespace SySML2.NET.REST.Tests
22+
{
23+
using System;
24+
using System.Linq;
25+
using System.Net.Http;
26+
using System.Threading;
27+
using System.Threading.Tasks;
28+
29+
using SysML2.NET.Serializer.Json;
30+
31+
using NUnit.Framework;
32+
33+
/// <summary>
34+
/// Suite of tests for the <see cref="RestClient"/> class
35+
/// </summary>
36+
public class RestClientTestFixture
37+
{
38+
private string baseUri;
39+
40+
private CancellationTokenSource cancellationTokenSource;
41+
42+
private IRestClient restClient;
43+
44+
private Guid projectId;
45+
46+
private Guid branchId;
47+
48+
private Guid commitId;
49+
50+
private Guid tagId;
51+
52+
private Guid elementId;
53+
54+
[SetUp]
55+
public void Setup()
56+
{
57+
this.baseUri = "http://sysml2-sst.intercax.com:9000";
58+
59+
this.cancellationTokenSource = new CancellationTokenSource();
60+
61+
var httpClient = new HttpClient();
62+
var deserializer = new DeSerializer();
63+
var serializer = new Serializer();
64+
65+
this.projectId = Guid.Parse("2e912d1b-a31c-4f93-b082-2c0aff296ea0");
66+
this.branchId = Guid.Parse("047c94c7-e8dc-420a-a0fb-0b19fc57c998");
67+
this.commitId = Guid.Parse("c5c5f0a2-5cce-4a2c-a083-97f39a576b53");
68+
this.tagId = Guid.Parse("79722f63-0592-40e8-941f-cbf60c14243e");
69+
this.elementId = Guid.Parse("00730052-0ac7-4344-8a90-a3d70da21ccb");
70+
71+
this.restClient = new RestClient(httpClient, deserializer, serializer);
72+
}
73+
74+
[Test]
75+
public async Task Verify_that_RestClient_can_be_opened_and_that_projects_are_returned()
76+
{
77+
var projects = await this.restClient.Open("john", "doe", this.baseUri, this.cancellationTokenSource.Token);
78+
79+
Assert.That(projects, Is.Not.Empty);
80+
}
81+
82+
[Test]
83+
public async Task Verify_that_projects_can_be_requested()
84+
{
85+
Assert.DoesNotThrowAsync(async () => await this.restClient.Open("john", "doe", this.baseUri, this.cancellationTokenSource.Token));
86+
87+
var projects = await this.restClient.RequestProjects(null, null, this.cancellationTokenSource.Token);
88+
89+
Assert.That(projects, Is.Not.Empty);
90+
91+
projects = await this.restClient.RequestProjects(this.projectId, null, this.cancellationTokenSource.Token);
92+
93+
var project = projects.Single();
94+
95+
Assert.That(project.Name, Is.EqualTo("Spacecraft project with branches and tags - 2022-08-12 16:03:49.344073"));
96+
}
97+
98+
[Test]
99+
public async Task Verify_that_branches_in_a_project_can_be_requested()
100+
{
101+
Assert.DoesNotThrowAsync(async () => await this.restClient.Open("john", "doe", this.baseUri, this.cancellationTokenSource.Token));
102+
103+
var branches = await this.restClient.RequestBranches(this.projectId, null, null, this.cancellationTokenSource.Token);
104+
105+
Assert.That(branches, Is.Not.Empty);
106+
107+
branches = await this.restClient.RequestBranches(this.projectId, this.branchId, null, this.cancellationTokenSource.Token);
108+
109+
var branch = branches.Single();
110+
111+
Assert.That(branch.Name, Is.EqualTo("main"));
112+
Assert.That(branch.Head, Is.EqualTo(Guid.Parse("7aaae0dd-63f2-445f-b494-43e3305d3394")));
113+
Assert.That(branch.OwningProject, Is.EqualTo(this.projectId));
114+
}
115+
116+
[Test]
117+
public async Task Verify_that_commits_in_a_project_can_be_requested()
118+
{
119+
Assert.DoesNotThrowAsync(async () => await this.restClient.Open("john", "doe", this.baseUri, this.cancellationTokenSource.Token));
120+
121+
var commits = await this.restClient.RequestCommits(this.projectId, null, null, this.cancellationTokenSource.Token);
122+
123+
Assert.That(commits, Is.Not.Empty);
124+
125+
Assert.Warn("deserializer is too strict for the pilot implementation response");
126+
127+
return;
128+
129+
commits = await this.restClient.RequestCommits(this.projectId, this.commitId, null, this.cancellationTokenSource.Token);
130+
131+
var commit = commits.Single();
132+
133+
Assert.That(commit.PreviousCommit, Is.EqualTo(Guid.Parse("7aaae0dd-63f2-445f-b494-43e3305d3394")));
134+
Assert.That(commit.OwningProject, Is.EqualTo(this.projectId));
135+
}
136+
137+
[Test]
138+
public async Task Verify_that_tags_in_a_project_can_be_requested()
139+
{
140+
Assert.DoesNotThrowAsync(async () => await this.restClient.Open("john", "doe", this.baseUri, this.cancellationTokenSource.Token));
141+
142+
var tags = await this.restClient.RequestTags(this.projectId, null, null, this.cancellationTokenSource.Token);
143+
144+
Assert.That(tags, Is.Not.Empty);
145+
146+
tags = await this.restClient.RequestTags(this.projectId, this.tagId, null, this.cancellationTokenSource.Token);
147+
148+
var tag = tags.Single();
149+
150+
Assert.That(tag.Name, Is.EqualTo("Spacecraft Internal Release 0.2 build 1"));
151+
Assert.That(tag.OwningProject, Is.EqualTo(this.projectId));
152+
}
153+
154+
[Test]
155+
public async Task Verify_that_elements_in_a_project_commit_can_be_requested()
156+
{
157+
Assert.DoesNotThrowAsync(async () => await this.restClient.Open("john", "doe", this.baseUri, this.cancellationTokenSource.Token));
158+
159+
Assert.Warn("deserializer is too strict for the pilot implementation response");
160+
161+
return;
162+
163+
var elements = await this.restClient.RequestElements(this.projectId, this.commitId, null,null, this.cancellationTokenSource.Token);
164+
165+
Assert.That(elements, Is.Not.Empty);
166+
167+
elements = await this.restClient.RequestElements(this.projectId, this.commitId, this.elementId, null, this.cancellationTokenSource.Token);
168+
169+
var element = elements.Single();
170+
171+
Assert.That(element.Name, Is.EqualTo("Propulsion System"));
172+
}
173+
}
174+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Company>RHEA System S.A.</Company>
6+
<Authors>Sam Gerene</Authors>
7+
<Description>Nunit test suite for the SysML2.NET.REST project</Description>
8+
<Copyright>Copyright 2022 RHEA System S.A.</Copyright>
9+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
10+
<RepositoryUrl>https://github.com/RHEAGROUP/SysML2.NET.git</RepositoryUrl>
11+
<RepositoryType>Git</RepositoryType>
12+
<ImplicitUsings>false</ImplicitUsings>
13+
<Nullable>disable</Nullable>
14+
<IsPackable>false</IsPackable>
15+
<PreserveCompilationContext>true</PreserveCompilationContext>
16+
</PropertyGroup>
17+
18+
<ItemGroup>
19+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
20+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
21+
<PackageReference Include="NUnit" Version="3.13.3" />
22+
<PackageReference Include="NUnit.Console" Version="3.15.2" />
23+
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
24+
25+
<PackageReference Include="coverlet.collector" Version="3.1.2">
26+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
27+
<PrivateAssets>all</PrivateAssets>
28+
</PackageReference>
29+
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
30+
<PrivateAssets>all</PrivateAssets>
31+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
32+
</PackageReference>
33+
</ItemGroup>
34+
35+
<ItemGroup>
36+
<ProjectReference Include="..\SySML2.NET.REST\SySML2.NET.REST.csproj" />
37+
</ItemGroup>
38+
39+
</Project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// -------------------------------------------------------------------------------------------------
2+
// <copyright file="AuthenticationStatusKind.cs" company="RHEA System S.A.">
3+
//
4+
// Copyright 2022 RHEA System S.A.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// </copyright>
19+
// ------------------------------------------------------------------------------------------------
20+
21+
namespace SySML2.NET.REST
22+
{
23+
/// <summary>
24+
/// Enumeration that defines possible status for the authentication process
25+
/// </summary>
26+
public enum AuthenticationStatusKind
27+
{
28+
/// <summary>
29+
/// Defaut status, when no authentication process has been performed
30+
/// </summary>
31+
None,
32+
33+
/// <summary>
34+
/// Status when the authentication process is in progress
35+
/// </summary>
36+
Authenticating,
37+
38+
/// <summary>
39+
/// Status when the authentication process ends succesfully
40+
/// </summary>
41+
Success,
42+
43+
/// <summary>
44+
/// Status when the authentication process failed
45+
/// </summary>
46+
Fail
47+
}
48+
}

0 commit comments

Comments
 (0)