Skip to content

WireMock Defects Fixed#4116

Merged
Maheshkale447 merged 5 commits into
Releases/Official-Releasefrom
BugFix/WireMock
Feb 20, 2025
Merged

WireMock Defects Fixed#4116
Maheshkale447 merged 5 commits into
Releases/Official-Releasefrom
BugFix/WireMock

Conversation

@AmanPrasad43

@AmanPrasad43 AmanPrasad43 commented Feb 20, 2025

Copy link
Copy Markdown
Contributor

Thank you for your contribution.
Before submitting this PR, please make sure:

  • PR description and commit message should describe the changes done in this PR
  • Verify the PR is pointing to correct branch i.e. Release or Beta branch if the code fix is for specific release , else point it to master
  • Latest Code from master or specific release branch is merged to your branch
  • No unwanted\commented\junk code is included
  • No new warning upon build solution
  • Code Summary\Comments are added to my code which explains what my code is doing
  • Existing unit test cases are passed
  • New Unit tests are added for your development
  • Sanity Tests are successfully executed for New and Existing Functionality
  • Verify that changes are compatible with all relevant browsers and platforms.
  • After creating pull request there should not be any conflicts
  • Resolve all Codacy comments
  • Builds and checks are passed before PR is sent for review
  • Resolve code review comments
  • Update the Help Library document to match any feature changes

Summary by CodeRabbit

  • New Features

    • The UI now dynamically updates mapping counts, ensuring that changes are immediately visible.
    • Event notifications have been added to refresh information when a new mapping is created.
    • Live API connectivity is now enabled by default.
  • Refactor

    • Mapping functionality has been streamlined for consistent behavior.
    • URL configuration and error handling have been simplified for more robust connections.
  • Minor Improvements

    • The toolbar’s tooltip text has been updated for clearer guidance on mapping deletion.
    • Radio button state management has been transitioned to an event-driven model for improved efficiency.

@coderabbitai

coderabbitai Bot commented Feb 20, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This set of changes updates several components related to WireMock integration and mapping management. The modifications include replacing a radio button state method with an asynchronous grid update event handler in the API model, unifying mapping types from Mapping to WireMockMapping, adding new event delegates for mapping creation, and adjusting URL handling in both configuration and HTTP client utilities. Additionally, tooltip text for mapping deletion was updated, and error handling as well as logging have seen minor adjustments, ensuring more streamlined and consistent behavior across the affected modules.

Changes

File(s) Change Summary
Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs Removed CheckMockAPIRadioButton; added async event handler WireMockTemplatePage_GridUpdated that updates the WireMock tab header on grid updates.
Ginger/Ginger/ApplicationModelsLib/WireMockAPIModels/WireMockTemplatePage.xaml.cs Added event handler OnMappingCreated, introduced delegate GridUpdatedEventHandler and event GridUpdated; updated method signatures and variable types from Mapping to WireMockMapping to ensure type consistency.
Ginger/Ginger/GeneralWindows/WireMockMappingPage.xaml.cs Updated tooltip text from "Delete All selected mapping" to "Delete All Mappings" in the toolbar tool configuration.
Ginger/Ginger/UserControlsLib/UCTreeView/TreeViewItemGenericBase.cs Introduced new delegate MappingCreatedEventHandler, static event MappingCreated, and method OnMappingCreated to support event-driven mapping creation.
Ginger/GingerCoreCommon/External/Configurations/WireMockConfiguration.cs Modified WireMockUrl setter to assign value directly; removed normalization logic and the NormalizeUrl method.
Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs Initialized mUseLiveAPI field to true to set a default state for live API usage.
Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs Applied ValueExpression.PasswordCalculation to mockConfiguration.WireMockUrl; introduced try-catch for URI construction and adjusted trailing slash handling in Client.BaseAddress.
Ginger/GingerCoreNET/External/WireMock/WireMockAPI.cs Introduced a new public method NormalizeUrl and updated various asynchronous methods to use normalized URLs.
Ginger/GingerCoreNET/External/WireMock/WireMockMappingGenerator.cs Removed unused variables (mockConfiguration, baseurl); adjusted error handling in RemovingURLPathQuery by changing logging levels and adding a catch for general exceptions.
Ginger/Ginger/SolutionWindows/TreeViewItems/ApplicationModelsTreeItems/AppApiModelsFolderTreeItem.cs Replaced direct method calls for radio button checks with event handler calls for UseMockedAPIURL and UseRealAPIURL methods.

Sequence Diagram(s)

sequenceDiagram
    participant UI as UI Component
    participant AP as APIModelPage
    participant TMP as WireMockTemplatePage
    participant TV as TreeViewItemGenericBase
    participant API as WireMockAPI

    UI->>TV: Request WireMock mapping creation
    TV-->>TV: Execute CreateWireMockMappingHandler
    TV->>TV: Trigger OnMappingCreated (raise MappingCreated event)
    TV->>TMP: Notify mapping created (MappingCreated event)
    TMP->>AP: Raise GridUpdated event on grid change
    AP->>AP: Execute WireMockTemplatePage_GridUpdated (updates tab header)
Loading

Possibly related PRs

Suggested reviewers

  • Maheshkale447

Poem

In fields of code I hop with glee,
Mapping changes set my spirit free.
New events and flows now take the stage,
A smoother journey in this updated page.
🐇 Coding with carrots and bits so bright,
I celebrate these commits deep into the night!
Hop on, the code's a delight!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a063234 and 3987bae.

📒 Files selected for processing (9)
  • Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs (2 hunks)
  • Ginger/Ginger/ApplicationModelsLib/WireMockAPIModels/WireMockTemplatePage.xaml.cs (13 hunks)
  • Ginger/Ginger/GeneralWindows/WireMockMappingPage.xaml.cs (1 hunks)
  • Ginger/Ginger/UserControlsLib/UCTreeView/TreeViewItemGenericBase.cs (2 hunks)
  • Ginger/GingerCoreCommon/External/Configurations/WireMockConfiguration.cs (1 hunks)
  • Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs (1 hunks)
  • Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs (1 hunks)
  • Ginger/GingerCoreNET/External/WireMock/WireMockAPI.cs (10 hunks)
  • Ginger/GingerCoreNET/External/WireMock/WireMockMappingGenerator.cs (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
Ginger/GingerCoreCommon/External/Configurations/WireMockConfiguration.cs (1)
Learnt from: AmanPrasad43
PR: Ginger-Automation/Ginger#4100
File: Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs:353-364
Timestamp: 2025-02-14T06:06:06.322Z
Learning: WireMockConfiguration always stores URLs with __admin suffix through URL normalization, so additional checks for __admin presence are not needed when using WireMockUrl.
Ginger/GingerCoreNET/External/WireMock/WireMockAPI.cs (1)
Learnt from: AmanPrasad43
PR: Ginger-Automation/Ginger#4100
File: Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs:353-364
Timestamp: 2025-02-14T06:06:06.322Z
Learning: WireMockConfiguration always stores URLs with __admin suffix through URL normalization, so additional checks for __admin presence are not needed when using WireMockUrl.
Ginger/GingerCoreNET/External/WireMock/WireMockMappingGenerator.cs (1)
Learnt from: AmanPrasad43
PR: Ginger-Automation/Ginger#4100
File: Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelWizard/AddAPIModelWizard.cs:151-157
Timestamp: 2025-02-14T05:46:45.210Z
Learning: WireMock server configuration validation is handled internally by WireMockMappingGenerator when creating mappings, which includes URL validation and error handling.
🔇 Additional comments (12)
Ginger/GingerCoreNET/External/WireMock/WireMockMappingGenerator.cs (2)

1-1: No notable concerns on the updated import.


132-136: Reevaluate the exception handling strategy for malformed URLs.

Logging a UriFormatException at INFO level may obscure legitimate failures, as it implies a routine scenario rather than an error. Returning the original URL might inadvertently propagate a malformed URL downstream. Additionally, silently returning string.Empty on a general exception can mask issues. Consider logging potential invalid URL issues more prominently and validating whether the fallback behaviors are desired.

Ginger/GingerCoreNET/External/WireMock/WireMockAPI.cs (1)

32-32: Commend the consistent use of NormalizeUrl in HTTP requests.

All these lines properly call NormalizeUrl, reducing the risk of missing the __admin suffix. Confirm that any preexisting URLs (e.g., uppercase “__ADMIN”) do not cause duplication or unexpected failures when appended.

Also applies to: 51-51, 72-72, 91-91, 116-116, 136-136, 157-157, 177-177, 196-196

Ginger/Ginger/ApplicationModelsLib/WireMockAPIModels/WireMockTemplatePage.xaml.cs (3)

21-21: LGTM! Type alias improves code clarity.

The using alias for WireMockMapping makes the code more specific and easier to understand.


43-51: LGTM! Event handling for mapping creation.

The event handler properly refreshes the grid and notifies listeners when a mapping is created. The async/await pattern is correctly used.


145-153: LGTM! Event handling for grid updates.

The event handling implementation follows best practices:

  • Proper delegate and event declaration
  • Protected virtual method for raising the event
  • Null-conditional operator for safe event invocation
Ginger/Ginger/UserControlsLib/UCTreeView/TreeViewItemGenericBase.cs (2)

211-221: LGTM! Event handling for mapping creation.

The event handling implementation follows best practices:

  • Clear delegate and event naming
  • Protected virtual method for raising the event
  • Null-conditional operator for safe event invocation

229-230: LGTM! Event raising after successful mapping creation.

The event is raised at the correct point - after successful creation of the WireMock mapping.

Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs (1)

1051-1054: LGTM! Event handler for grid updates.

The event handler correctly updates the WireMock template tab header asynchronously when the grid is updated.

Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs (2)

356-356: Verify the password calculation logic.

The change introduces password calculation for the WireMock URL. This could indicate that the URL might contain sensitive information.

Please ensure that:

  1. The URL doesn't expose sensitive information in logs or error messages
  2. The password calculation is necessary for this URL

359-371: Improved error handling for malformed URLs.

The added try-catch block provides a fallback mechanism when the URL format is invalid, making the code more robust.

Good improvements:

  1. Proper handling of URI format exceptions
  2. Fallback to direct URL concatenation
  3. Consistent handling of trailing slashes
Ginger/Ginger/GeneralWindows/WireMockMappingPage.xaml.cs (1)

61-61: Improved tooltip accuracy.

The tooltip text now correctly reflects that the action deletes all mappings, not just selected ones, which aligns with the actual functionality in DeleteAllButton_Click.

Comment thread Ginger/GingerCoreNET/External/WireMock/WireMockAPI.cs Outdated
AmanPrasad43 and others added 2 commits February 20, 2025 13:44
…lLib/ApplicationAPIModel.cs

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3987bae and cb51039.

📒 Files selected for processing (4)
  • Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs (2 hunks)
  • Ginger/Ginger/SolutionWindows/TreeViewItems/ApplicationModelsTreeItems/AppApiModelsFolderTreeItem.cs (2 hunks)
  • Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs (1 hunks)
  • Ginger/GingerCoreNET/External/WireMock/WireMockAPI.cs (10 hunks)
🧰 Additional context used
🧠 Learnings (1)
Ginger/GingerCoreNET/External/WireMock/WireMockAPI.cs (2)
Learnt from: AmanPrasad43
PR: Ginger-Automation/Ginger#4116
File: Ginger/GingerCoreCommon/External/Configurations/WireMockConfiguration.cs:34-34
Timestamp: 2025-02-20T08:13:43.184Z
Learning: URL normalization for WireMock endpoints (adding `__admin`, removing trailing slashes) is handled in the API communication layer (WireMockAPI.cs) rather than in the configuration class (WireMockConfiguration.cs) to keep the configuration simple and normalize URLs closer to where they're used.
Learnt from: AmanPrasad43
PR: Ginger-Automation/Ginger#4100
File: Ginger/GingerCoreNET/Drivers/WebServicesDriver/HttpWebClientUtils.cs:353-364
Timestamp: 2025-02-14T06:06:06.322Z
Learning: WireMockConfiguration always stores URLs with __admin suffix through URL normalization, so additional checks for __admin presence are not needed when using WireMockUrl.
🔇 Additional comments (7)
Ginger/GingerCoreNET/External/WireMock/WireMockAPI.cs (2)

32-32: Good approach with NormalizeUrl(...) usage.

Leveraging the NormalizeUrl() method across all API calls ensures consistent handling of trailing slashes and __admin. This is a neat way to standardize endpoint URLs, and the case-insensitive check for __admin is a nice touch.

Also applies to: 51-51, 72-72, 91-91, 116-116, 136-136, 157-157, 177-177, 196-196


208-228: Helper method for URL normalization.

This method effectively cleans up trailing slashes and ensures the __admin suffix. The case-insensitive approach to appending __admin prevents duplicates. Overall, it's straightforward and well-structured.

Ginger/Ginger/SolutionWindows/TreeViewItems/ApplicationModelsTreeItems/AppApiModelsFolderTreeItem.cs (2)

174-174: Event-based approach for mocking API usage.

Switching from a direct function call to invoking the xMockAPIRadioButton_Checked event handler is a clean approach that aligns with the UI event model. This maintains consistency and clarity in the code.


185-185: Event-based approach for real API usage.

Invoking the xRealAPIRadioButton_Checked event handler similarly keeps the logic centralized and consistent with the updated event-driven design for API selection.

Ginger/GingerCoreCommon/Repository/ApplicationModelLib/APIModelLib/ApplicationAPIModel.cs (1)

41-45: Useful documentation for defaulting to live API.

Declaring and explaining mUseLiveAPI = true clarifies why the application defaults to the live API. This explicit choice reinforces discoverability and helps avoid confusion regarding the initial API usage mode.

Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs (2)

71-71: LGTM!

The event subscription is correctly placed after the instance creation and uses the appropriate async event handler.


1047-1050: LGTM!

The event handler follows the correct async pattern for WPF event handlers and properly awaits the async call.

Comment thread Ginger/Ginger/ApplicationModelsLib/APIModels/APIModelPage.xaml.cs
@Maheshkale447
Maheshkale447 merged commit f4d37f2 into Releases/Official-Release Feb 20, 2025
@Maheshkale447
Maheshkale447 deleted the BugFix/WireMock branch February 20, 2025 10:26
@coderabbitai coderabbitai Bot mentioned this pull request Jul 21, 2025
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants