Skip to content

Commit

Permalink
Added Bellatrix.Plugins.Jira.Zephyr
Browse files Browse the repository at this point in the history
  • Loading branch information
MiriamKyoseva committed May 31, 2024
1 parent b02cd0f commit 1e8db5f
Show file tree
Hide file tree
Showing 15 changed files with 654 additions and 0 deletions.
35 changes: 35 additions & 0 deletions BellatrixTestFramework.sln
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bellatrix.Playwright", "src
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bellatrix.Playwright.GettingStarted", "templates\Bellatrix.Playwright.GettingStarted\Bellatrix.Playwright.GettingStarted.csproj", "{EACDDFC5-A313-4981-9FFB-F41639713BB1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bellatrix.Plugins.Jira.Zephyr", "src\Bellatrix.Plugins.Jira.Zephyr\Bellatrix.Plugins.Jira.Zephyr.csproj", "{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
DEBUG|Any CPU = DEBUG|Any CPU
Expand Down Expand Up @@ -1166,6 +1168,38 @@ Global
{EACDDFC5-A313-4981-9FFB-F41639713BB1}.STAGE|x64.Build.0 = Debug|Any CPU
{EACDDFC5-A313-4981-9FFB-F41639713BB1}.STAGE|x86.ActiveCfg = Debug|Any CPU
{EACDDFC5-A313-4981-9FFB-F41639713BB1}.STAGE|x86.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.DEBUG|Any CPU.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.DEBUG|Any CPU.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.DEBUG|ARM.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.DEBUG|ARM.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.DEBUG|x64.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.DEBUG|x64.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.DEBUG|x86.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.DEBUG|x86.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.QA|Any CPU.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.QA|Any CPU.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.QA|ARM.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.QA|ARM.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.QA|x64.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.QA|x64.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.QA|x86.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.QA|x86.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.Release|Any CPU.Build.0 = Release|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.Release|ARM.ActiveCfg = Release|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.Release|ARM.Build.0 = Release|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.Release|x64.ActiveCfg = Release|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.Release|x64.Build.0 = Release|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.Release|x86.ActiveCfg = Release|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.Release|x86.Build.0 = Release|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|Any CPU.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|Any CPU.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|ARM.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|ARM.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|x64.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|x64.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|x86.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|x86.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1205,6 +1239,7 @@ Global
{1AFF3507-F2C7-4240-A9D4-B166BEAC9B6F} = {E8AA67CB-09C6-4E4B-AFF1-0D5875903C34}
{08D46A7C-4BCC-4813-B20F-C7A9039621C9} = {1DF0F472-E4CA-4EFD-9459-F5B90E2E8E67}
{EACDDFC5-A313-4981-9FFB-F41639713BB1} = {74747D87-4B09-479B-B2FC-63F2CCAC4201}
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB} = {1DF0F472-E4CA-4EFD-9459-F5B90E2E8E67}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5CA92FF2-B2AC-41BA-ADDD-1F259867B5F4}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="RestSharp" Version="110.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Bellatrix.Core\Bellatrix.Core.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>

</Project>
135 changes: 135 additions & 0 deletions src/Bellatrix.Plugins.Jira.Zephyr/ZephyrPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// <copyright file="ZephyrPlugin.cs" company="Automate The Planet Ltd.">
// Copyright 2024 Automate The Planet Ltd.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// <author>Miriam Kyoseva</author>
// <site>https://bellatrix.solutions/</site>

using System.Reflection;
using Bellatrix.Plugins.Jira.Zephyr.Attributes;
using Bellatrix.Plugins.Jira.Zephyr.Data;
using Bellatrix.Plugins.Jira.Zephyr.Eventargs;
using Bellatrix.Plugins.Jira.Zephyr.Services;
using Plugins.Jira.Zephyr.Services;

namespace Bellatrix.Plugins.Jira.Zephyr;

public class ZephyrPlugin : Plugin
{
internal static ZephyrSettings Settings => ConfigurationService.GetSection<ZephyrSettings>();

internal static ZephyrLocalData Data = new ZephyrLocalData();

private readonly ZephyrPluginProvider _zephyrPluginProvider = new ZephyrPluginProvider();
private static bool IsEnabled => Settings.IsEnabled;

protected override void PostTestsArrange(object sender, PluginEventArgs e)
{
if (IsEnabled)
{
var testCycleName = $"{DateTimeUtilities.GetUtcNow()} {Settings.TestCycleName}";

var testCycle = new ZephyrTestCycle(Settings.DefaultProjectKey, testCycleName, "In Progress");

Check warning on line 39 in src/Bellatrix.Plugins.Jira.Zephyr/ZephyrPlugin.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'projectKey' in 'ZephyrTestCycle.ZephyrTestCycle(string projectKey, string name, string statusName)'.

Check warning on line 39 in src/Bellatrix.Plugins.Jira.Zephyr/ZephyrPlugin.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'projectKey' in 'ZephyrTestCycle.ZephyrTestCycle(string projectKey, string name, string statusName)'.
testCycle.PlannedStartDate = DateTimeUtilities.GetUtcNow();
Data.TestCycle = testCycle;

Data.TestCycleResponse = ZephyrApiService.CreateTestCycle(Data);

e.Container.RegisterInstance(Data);

_zephyrPluginProvider.ZephyrCycleCreated(e, Data.TestCycle);
}

base.PostTestsArrange(sender, e);
}

protected override void PostTestCleanup(object sender, PluginEventArgs e)
{
if (IsEnabled)
{
var data = e.Container.Resolve<ZephyrLocalData>();
var testCase = new ZephyrTestCase(GetProjectId(e.TestMethodMemberInfo), data.TestCycleResponse.key, GetExecutionId(e.TestMethodMemberInfo), GetTestStatus(e.TestOutcome));

if (string.IsNullOrEmpty(testCase.TestCaseId) || string.IsNullOrEmpty(testCase.Status) || string.IsNullOrEmpty(testCase.ProjectId))
{
_zephyrPluginProvider.ZephyrTestCaseExecutionFailed(e, testCase);
}
else
{
var response = ZephyrApiService.ExecuteTestCase(testCase);

if (!response.IsSuccessful)
_zephyrPluginProvider.ZephyrTestCaseExecutionFailed(e, testCase);
else
_zephyrPluginProvider.ZephyrTestCaseExecuted(e, testCase);
}
}

base.PostTestCleanup(sender, e);
}

protected override void PostTestsCleanup(object sender, PluginEventArgs e)
{
if (IsEnabled)
{
var data = e.Container.Resolve<ZephyrLocalData>();

data.TestCycle.PlannedEndDate = DateTimeUtilities.GetUtcNow();
var response = ZephyrApiService.MarkTestCycleDone(data);

if (!response.IsSuccessful)
{
_zephyrPluginProvider.ZephyrCycleStatusUpdateFailed(e, data.TestCycle);
}
}

base.PostTestsCleanup(sender, e);
}

internal class ZephyrLocalData
{
internal ZephyrTestCycleResponse TestCycleResponse { get; set; }
internal ZephyrTestCycle TestCycle { get; set; }
}

private string GetExecutionId(MemberInfo memberInfo)
{
var zephyrTestCaseAttribute = memberInfo.GetCustomAttribute<ZephyrTestCaseAttribute>();
return zephyrTestCaseAttribute != null ? zephyrTestCaseAttribute.Id : string.Empty;
}

private string GetProjectId(MemberInfo memberInfo)
{
var zephyrProjectAttribute = memberInfo.DeclaringType.GetCustomAttribute<ZephyrProjectAttribute>();

Check warning on line 110 in src/Bellatrix.Plugins.Jira.Zephyr/ZephyrPlugin.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'element' in 'ZephyrProjectAttribute? CustomAttributeExtensions.GetCustomAttribute<ZephyrProjectAttribute>(MemberInfo element)'.
if (zephyrProjectAttribute != null)
{
return zephyrProjectAttribute.Id;
}
else
{
return Settings.DefaultProjectKey != null ? Settings.DefaultProjectKey : string.Empty;
}
}

private string GetTestStatus(TestOutcome testOutcome)
{
switch(testOutcome)
{
case TestOutcome.Failed:
case TestOutcome.Aborted:
case TestOutcome.Error:
return "Fail";
case TestOutcome.Passed:
return "Pass";
default:
return "In Progress";
}
}
}
23 changes: 23 additions & 0 deletions src/Bellatrix.Plugins.Jira.Zephyr/ZephyrPluginConfigure.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// <copyright file="ZephyrPluginConfigure.cs" company="Automate The Planet Ltd.">
// Copyright 2024 Automate The Planet Ltd.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// <author>Miriam Kyoseva</author>
// <site>https://bellatrix.solutions/</site>

namespace Bellatrix.Plugins.Jira.Zephyr;

public static class ZephyrPluginConfigure
{
public static void Add()
{
ServicesCollection.Current.RegisterType<Plugin, ZephyrPlugin>(Guid.NewGuid().ToString());
}
}
11 changes: 11 additions & 0 deletions src/Bellatrix.Plugins.Jira.Zephyr/ZephyrSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Bellatrix.Plugins.Jira.Zephyr;

public class ZephyrSettings
{
public bool IsEnabled { get; set; }
public string? ApiUrl { get; set; }
public string? Token { get; set; }
public string? DefaultProjectKey { get; set; }
public string TestCycleName { get; set; } = "BELLATRIX TEST RUN";
public string? CycleFinalStatus { get; set; } = "Done";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// <copyright file="ZephyrProjectAttribute.cs" company="Automate The Planet Ltd.">
// Copyright 2024 Automate The Planet Ltd.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// <author>Miriam Kyoseva</author>
// <site>https://bellatrix.solutions/</site>

namespace Bellatrix.Plugins.Jira.Zephyr.Attributes;

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public sealed class ZephyrProjectAttribute : Attribute
{
public string Id { get; }

public ZephyrProjectAttribute(string id)
{
Id = id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// <copyright file="ZephyrTestCaseAttribute.cs" company="Automate The Planet Ltd.">
// Copyright 2024 Automate The Planet Ltd.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// <author>Miriam Kyoseva</author>
// <site>https://bellatrix.solutions/</site>

namespace Bellatrix.Plugins.Jira.Zephyr.Attributes;

[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public sealed class ZephyrTestCaseAttribute : Attribute
{
public string Id { get; }

public ZephyrTestCaseAttribute(string id)
{
Id = id;
}
}
32 changes: 32 additions & 0 deletions src/Bellatrix.Plugins.Jira.Zephyr/data/ZephyrTestCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// <copyright file="ZephyrTestCase.cs" company="Automate The Planet Ltd.">
// Copyright 2024 Automate The Planet Ltd.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// <author>Miriam Kyoseva</author>
// <site>https://bellatrix.solutions/</site>

namespace Bellatrix.Plugins.Jira.Zephyr.Data;

public class ZephyrTestCase
{
public ZephyrTestCase(string projectId, string testCycleId, string testCaseId, string status)
{
this.ProjectId = projectId;
this.TestCycleId = testCycleId;
this.TestCaseId = testCaseId;
this.Status = status;
}

public string ProjectId { get; set; }
public string TestCycleId { get; set; }
public string TestCaseId { get; set; }
public string Status { get; set; }
public double Duration { get; set; }
}
31 changes: 31 additions & 0 deletions src/Bellatrix.Plugins.Jira.Zephyr/data/ZephyrTestCycle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// <copyright file="ZephyrTestCycle.cs" company="Automate The Planet Ltd.">
// Copyright 2024 Automate The Planet Ltd.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// <author>Miriam Kyoseva</author>
// <site>https://bellatrix.solutions/</site>

namespace Bellatrix.Plugins.Jira.Zephyr.Data;

public class ZephyrTestCycle
{
public ZephyrTestCycle(string projectKey, string name, string statusName)
{
this.ProjectKey = projectKey;
this.Name = name;
this.StatusName = statusName;
}

public string ProjectKey { get; set; }
public string Name { get; set; }
public string StatusName { get; set; }
public string? PlannedStartDate { get; set; }
public string? PlannedEndDate { get; set; }
}
20 changes: 20 additions & 0 deletions src/Bellatrix.Plugins.Jira.Zephyr/data/ZephyrTestCycleResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// <copyright file="ZephyrTestCycleResponse.cs" company="Automate The Planet Ltd.">
// Copyright 2024 Automate The Planet Ltd.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// <author>Miriam Kyoseva</author>
// <site>https://bellatrix.solutions/</site>

namespace Bellatrix.Plugins.Jira.Zephyr.Data;
public struct ZephyrTestCycleResponse
{
public string id;
public string key;
}
Loading

0 comments on commit 1e8db5f

Please sign in to comment.