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 @@

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 @@
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 @@
{
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 @@
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 @@
xOutputTemplateTab.Text = string.Format("Output Values Template ({0})", mApplicationAPIModel.ReturnValues.Count);
}

private async void UpdateWireMockTemplateTabHeader()

Check warning on line 201 in Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs#L201

Return 'Task' instead.
{
int count = await WireMockTemplateTabCount();
xWireMockTemplateTab.Text = string.Format("WireMock Mapping ({0})", count);
}

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
private void FillTargetAppsComboBox()
{
//get key object
Expand Down Expand Up @@ -987,5 +1014,30 @@

_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 @@
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 Down Expand Up @@ -56,6 +57,8 @@

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 +119,11 @@
}
}

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

Check notice on line 124 in Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelWizard/AddAPIModelWizard.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelWizard/AddAPIModelWizard.cs#L124

Remove the unnecessary Boolean literal(s).
}

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

private void CreateWireMockMappingsAsync(ObservableList<ApplicationAPIModel> SelectedAAMList)
{

foreach (ApplicationAPIModel appmodel in SelectedAAMList)
{
WireMockMappingGenerator.CreateWireMockMapping(appmodel);
}
}
AmanPrasad43 marked this conversation as resolved.
Show resolved Hide resolved

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