Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WireMock Related Changes #4100

Merged
16 changes: 15 additions & 1 deletion Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid Name="APIConfigurationsTab" Background="{StaticResource $BackgroundColor_White}">
<Grid.RowDefinitions>
<RowDefinition Height="400*"/>
<RowDefinition Height="500*"/>
<RowDefinition Height="350*"/>
<RowDefinition/>
</Grid.RowDefinitions>
Expand All @@ -60,6 +60,11 @@
<Label Style="{StaticResource @InputFieldLabelStyle}" Margin="0,0,10,0">API Type:</Label>
<UserControlsLib:UCComboBox x:Name="xAPITypeComboBox" Width="120"></UserControlsLib:UCComboBox>
</StackPanel>
<StackPanel Orientation="Horizontal" >
<Label Style="{StaticResource @InputFieldLabelStyle}" Margin="0,0,10,0">Use :</Label>
<RadioButton x:Name="xRealAPIRadioButton" Content="Real API" Margin="0,0,10,0" VerticalAlignment="Center" IsChecked="True" Checked="xRealAPIRadioButton_Checked" Style="{StaticResource @InputRadioButtonStyle}"/>
AmanPrasad43 marked this conversation as resolved.
Show resolved Hide resolved
<RadioButton x:Name="xMockAPIRadioButton" Content="Mock API" VerticalAlignment="Center" IsChecked="False" Checked="xMockAPIRadioButton_Checked" Style="{StaticResource @InputRadioButtonStyle}"/>
</StackPanel>
<StackPanel VerticalAlignment="Top" Margin="0,0,0,0">
<Label Style="{StaticResource @InputFieldLabelStyle}" Margin="0,0,10,0">End Point URL:</Label>
<TextBox x:Name="EndPointURLTextBox"></TextBox>
Expand Down Expand Up @@ -266,6 +271,15 @@
</TabItem.Header>
<Frame x:Name="xOutputTemplateFrame" HorizontalAlignment="Stretch"/>
</TabItem>
<TabItem Style="{StaticResource $RoundedTab}">
<TabItem.Header>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" >
<Image Source="/Images/WireMock_Logo.png" Height="20" Width="20"/>
<TextBlock x:Name="xWireMockTemplateTab" Margin="5,0,0,0" VerticalAlignment="Center" Foreground="{StaticResource $PrimaryColor_Black}" FontWeight="Bold" />
</StackPanel>
</TabItem.Header>
<Frame x:Name="xWireMockTemplateFrame" HorizontalAlignment="Stretch"/>
</TabItem>
</TabControl>

</Grid>
Expand Down
52 changes: 52 additions & 0 deletions Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ limitations under the License.

using amdocs.ginger.GingerCoreNET;
using Amdocs.Ginger.Common;
using Amdocs.Ginger.CoreNET.External.WireMock;
using Amdocs.Ginger.Repository;
using Ginger;
using Ginger.ApplicationModelsLib.WireMockAPIModels;
using Ginger.UserControls;
using Ginger.UserControlsLib;
using GingerCore.GeneralLib;
Expand All @@ -29,6 +31,7 @@ limitations under the License.
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand All @@ -38,10 +41,13 @@ namespace GingerWPF.ApplicationModelsLib.APIModels
{
public partial class APIModelPage : GingerUIPage
{
WireMockMappingController wmController;
AmanPrasad43 marked this conversation as resolved.
Show resolved Hide resolved

ApplicationAPIModel mApplicationAPIModel;
ModelParamsPage modelParamsPage;
private bool saveWasDone = false;
General.eRIPageViewMode mPageViewMode;
public WireMockAPI MockAPI;
public APIModelPage(ApplicationAPIModel applicationAPIModelBase, General.eRIPageViewMode viewMode = General.eRIPageViewMode.Standalone)
{
mApplicationAPIModel = applicationAPIModelBase;
Expand All @@ -61,11 +67,15 @@ public APIModelPage(ApplicationAPIModel applicationAPIModelBase, General.eRIPage
OutputTemplatePage outputTemplatePage = new OutputTemplatePage(mApplicationAPIModel, viewMode);
xOutputTemplateFrame.ClearAndSetContent(outputTemplatePage);

WireMockTemplatePage wiremockTemplatePage = new WireMockTemplatePage(mApplicationAPIModel, viewMode);
xWireMockTemplateFrame.ClearAndSetContent(wiremockTemplatePage);

AmanPrasad43 marked this conversation as resolved.
Show resolved Hide resolved
mApplicationAPIModel.AppModelParameters.CollectionChanged += AppModelParameters_CollectionChanged;
mApplicationAPIModel.GlobalAppModelParameters.CollectionChanged += AppModelParameters_CollectionChanged;
UpdateModelParametersTabHeader();
mApplicationAPIModel.ReturnValues.CollectionChanged += ReturnValues_CollectionChanged;
UpdateOutputTemplateTabHeader();
UpdateWireMockTemplateTabHeader();
AmanPrasad43 marked this conversation as resolved.
Show resolved Hide resolved

mPageViewMode = viewMode;

Expand Down Expand Up @@ -188,6 +198,23 @@ private void UpdateOutputTemplateTabHeader()
xOutputTemplateTab.Text = string.Format("Output Values Template ({0})", mApplicationAPIModel.ReturnValues.Count);
}

private async Task UpdateWireMockTemplateTabHeader()
{
int count = await WireMockTemplateTabCount();
xWireMockTemplateTab.Text = string.Format("WireMock Mapping ({0})", count);
}
AmanPrasad43 marked this conversation as resolved.
Show resolved Hide resolved

public async Task<int> WireMockTemplateTabCount()
{
wmController = new();
var mappings = await wmController.DeserializeWireMockResponseAsync();

string ApiName = mApplicationAPIModel.Name;

// Filter the mappings based on the Name
int filteredMappings = mappings.Where(mapping => mapping.Name == ApiName).Count();
return filteredMappings;
}
AmanPrasad43 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Verify alignment with naming and concurrency guidelines.

UpdateWireMockTemplateTabHeader and WireMockTemplateTabCount are async methods that can throw exceptions or cause delays. If used frequently, ensure the UI remains responsive and any concurrency is handled correctly.

private void FillTargetAppsComboBox()
{
//get key object
Expand Down Expand Up @@ -987,5 +1014,30 @@ private void UndoChangesAndClose()

_pageGenericWin.Close();
}

public void xRealAPIRadioButton_Checked(object sender, RoutedEventArgs e)
{
mApplicationAPIModel.UseRealAPI = true;
}

public async void xMockAPIRadioButton_Checked(object sender, RoutedEventArgs e)
{
mApplicationAPIModel.UseRealAPI = false;
}

public void CheckRealAPIRadioButton()
{
xMockAPIRadioButton.IsChecked = false;
xRealAPIRadioButton.IsChecked = true;
xRealAPIRadioButton_Checked(xRealAPIRadioButton, null);
}

public void CheckMockAPIRadioButton()
{
xRealAPIRadioButton.IsChecked = false;
xMockAPIRadioButton.IsChecked = true;
xMockAPIRadioButton_Checked(xMockAPIRadioButton, null);
}
AmanPrasad43 marked this conversation as resolved.
Show resolved Hide resolved
AmanPrasad43 marked this conversation as resolved.
Show resolved Hide resolved

}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
<Page x:Class="GingerWPF.ApplicationModelsLib.APIModels.APIModelWizard.AddAPIModelExtraConfigsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Ginger="clr-namespace:Ginger"
xmlns:usercontrolslib="clr-namespace:Ginger.UserControlsLib"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="AddAPIModelExtraConfigsPage">
<Page x:Class="GingerWPF.ApplicationModelsLib.APIModels.APIModelWizard.AddAPIModelExtraConfigsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Ginger="clr-namespace:Ginger"
xmlns:usercontrolslib="clr-namespace:Ginger.UserControlsLib"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="AddAPIModelExtraConfigsPage">

<Grid Background="{StaticResource $BackgroundColor_White}">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
<Label x:Name="xTAlabel" Style="{StaticResource @InputFieldLabelStyle}" Content="" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<usercontrolslib:UCComboBox x:Name="xTargetApplicationComboBox" Width="250" HorizontalAlignment="Left" VerticalAlignment="Center"></usercontrolslib:UCComboBox>
</StackPanel>
<Ginger:ucTagsViewer x:Name="xTagsViewer" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" />
</Grid>
</Page>
<Grid Background="{StaticResource $BackgroundColor_White}">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
<Label x:Name="xTAlabel" Style="{StaticResource @InputFieldLabelStyle}" Content="" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<usercontrolslib:UCComboBox x:Name="xTargetApplicationComboBox" Width="250" HorizontalAlignment="Left" VerticalAlignment="Center"></usercontrolslib:UCComboBox>
</StackPanel>

<Ginger:ucTagsViewer x:Name="xTagsViewer" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" />

<StackPanel Grid.Row="2" Grid.Column="0" Orientation="Horizontal">
<Label Content="Do You want to Create WireMock Mapping ? " HorizontalAlignment="Left" VerticalAlignment="Center"/>
AmanPrasad43 marked this conversation as resolved.
Show resolved Hide resolved
<CheckBox x:Name="xWireMockMappingToggle" IsEnabled="True" Width="50" Checked="xWireMockMappingToggle_Checked" HorizontalAlignment="Left" VerticalAlignment="Center"/>
</StackPanel>
</Grid>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.

using amdocs.ginger.GingerCoreNET;
using Amdocs.Ginger.Common;
using Amdocs.Ginger.Common.External.Configurations;
using Amdocs.Ginger.Repository;
using GingerCore;
using GingerCoreNET.SolutionRepositoryLib.RepositoryObjectsLib.PlatformsLib;
Expand Down Expand Up @@ -80,5 +81,22 @@ public void WizardEvent(WizardEventArgs WizardEventArgs)
// AddAPIModelWizard.NextEnabled = false;
//}
}

private void xWireMockMappingToggle_Checked(object sender, RoutedEventArgs e)
{
WireMockConfiguration mockConfiguration;
mockConfiguration = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems<WireMockConfiguration>().Count == 0 ? new WireMockConfiguration() : WorkSpace.Instance.SolutionRepository.GetFirstRepositoryItem<WireMockConfiguration>();
if (string.IsNullOrEmpty(mockConfiguration.WireMockUrl))
{

Reporter.ToUser(eUserMsgKey.WireMockConnectionFail);

}
else
{
AddAPIModelWizard.toCreateWireMock = true;
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License.
using Amdocs.Ginger.Common;
using Amdocs.Ginger.Common.Repository.ApplicationModelLib;
using Amdocs.Ginger.CoreNET.Application_Models;
using Amdocs.Ginger.CoreNET.External.WireMock;
using Amdocs.Ginger.Repository;
using Ginger.ApplicationModelsLib.APIModels.APIModelWizard;
using Ginger.ApplicationModelsLib.ModelOptionalValue;
Expand All @@ -29,11 +30,13 @@ limitations under the License.
using GingerWPF.WizardLib;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace GingerWPF.ApplicationModelsLib.APIModels.APIModelWizard
{
public class AddAPIModelWizard : WizardBase
{
public WireMockMappingGenerator mockMappingGenerator;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Consider using a property with XML documentation.
Like in other classes, a public field may reduce clarity. Converting it to a property with doc comments better aligns with C# norms.

public enum eAPIType
{
[EnumValueDescription("WSDL")]
Expand All @@ -56,6 +59,8 @@ public enum eAPITypeTemp

public RepositoryFolder<ApplicationAPIModel> APIModelFolder;

public bool toCreateWireMock;
AmanPrasad43 marked this conversation as resolved.
Show resolved Hide resolved

public string URL { get; set; }

public string InfoTitle { get; set; }
Expand Down Expand Up @@ -116,6 +121,11 @@ public override void Finish()
}
}

if (toCreateWireMock)
{
CreateWireMockMappingsAsync(General.ConvertListToObservableList(LearnedAPIModelsList.Where(x => x.IsSelected).ToList()));
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve code reusability and async handling.

The code has the following issues:

  1. The LINQ query LearnedAPIModelsList.Where(x => x.IsSelected) is duplicated.
  2. The method name suggests async operation but is called synchronously.

Apply this diff to improve code reusability and async handling:

+            var selectedModels = General.ConvertListToObservableList(LearnedAPIModelsList.Where(x => x.IsSelected).ToList());
             if (toCreateWireMock)
             {
-                CreateWireMockMappingsAsync(General.ConvertListToObservableList(LearnedAPIModelsList.Where(x => x.IsSelected).ToList()));
+                await CreateWireMockMappingsAsync(selectedModels);
             }
-            ImportAPIModels(General.ConvertListToObservableList(LearnedAPIModelsList.Where(x => x.IsSelected == true).ToList()));
+            ImportAPIModels(selectedModels);

Also update the method signature to be async:

-        public override void Finish()
+        public override async Task Finish()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (toCreateWireMock)
{
CreateWireMockMappingsAsync(General.ConvertListToObservableList(LearnedAPIModelsList.Where(x => x.IsSelected).ToList()));
}
public override async Task Finish()
{
var selectedModels = General.ConvertListToObservableList(LearnedAPIModelsList.Where(x => x.IsSelected).ToList());
if (toCreateWireMock)
{
await CreateWireMockMappingsAsync(selectedModels);
}
ImportAPIModels(selectedModels);
// ... (rest of the method if applicable)
}

ImportAPIModels(General.ConvertListToObservableList(LearnedAPIModelsList.Where(x => x.IsSelected == true).ToList()));
}
private GlobalAppModelParameter AddGlobalParam(string customurl, string placehold)
Expand All @@ -135,6 +145,15 @@ private GlobalAppModelParameter AddGlobalParam(string customurl, string placehol
return newModelGlobalParam;
}

private async Task CreateWireMockMappingsAsync(ObservableList<ApplicationAPIModel> SelectedAAMList)
{
mockMappingGenerator = new();
foreach (ApplicationAPIModel appmodel in SelectedAAMList)
{
await mockMappingGenerator.CreateWireMockMapping(appmodel);
}
}

private void ImportAPIModels(ObservableList<ApplicationAPIModel> SelectedAAMList)
{
GlobalAppModelParameter itemtoadd = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<Page x:Class="Ginger.ApplicationModelsLib.WireMockAPIModels.WireMockTemplatePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Ginger.ApplicationModelsLib.WireMockAPIModels" xmlns:Ginger="clr-namespace:Ginger"
mc:Ignorable="d"
d:DesignHeight="550" d:DesignWidth="900"
Title="WireMockTemplatePage">

<Grid x:Name="xWMMappingTemplatePage" Background="{StaticResource $BackgroundColor_White}">
<Grid.Resources>
<Thickness
x:Key="@ActionButtonPadding"
Left="4"
Top="2"
Right="4"
Bottom="2" />
<DataTemplate
AmanPrasad43 marked this conversation as resolved.
Show resolved Hide resolved
x:Key="xMappingOperationTab">
<StackPanel
Orientation="Horizontal">
<Button
x:Name="xViewMappingBtn"
Click="xViewMappingbtn_Click"
ToolTip="View Mapping"
Style="{StaticResource @InputImageGridCellButtonStyle}"
Padding="{StaticResource @ActionButtonPadding}">
<Image
Source="{StaticResource @View_16x16}"
Height="16"
Width="16" />
</Button>
<Button
x:Name="xEditMappingBtn"
Click="xEditMappingbtn_Click"
ToolTip="Edit Mapping"
Style="{StaticResource @InputImageGridCellButtonStyle}"
Padding="{StaticResource @ActionButtonPadding}"
Tag="{Binding .}">
<Image
Source="{StaticResource @Edit_16x16}"
Height="16"
Width="16" />
</Button>
<Button
x:Name="xDeleteMappingBtn"
Click="xDeleteMappingBtn_Click"
ToolTip="Deleting Mapping"
Style="{StaticResource @InputImageGridCellButtonStyle}"
Padding="{StaticResource @ActionButtonPadding}"
Tag="{Binding .}">
<Image
Source="{StaticResource @Delete_32x32}"
Height="16"
Width="16" />
AmanPrasad43 marked this conversation as resolved.
Show resolved Hide resolved
</Button>
</StackPanel>
AmanPrasad43 marked this conversation as resolved.
Show resolved Hide resolved
</DataTemplate>
</Grid.Resources>
<DockPanel>
<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto" >
<Ginger:ucGrid x:Name="xGridMappingOutput" ShowAdd="Visible" ShowCopy="Visible" ShowPaste="Visible" IsReadOnly="True" ShowClearAll="Visible" ShowDelete="Collapsed" ShowEdit="Collapsed" ShowUndo="Collapsed" ShowRefresh="Collapsed" ShowUpDown="Collapsed" ShowTagsFilter="Collapsed" ShowTitle="Collapsed">
</Ginger:ucGrid>
</ScrollViewer>
</DockPanel>
</Grid>
</Page>
Loading
Loading