Skip to content

refactor MockNetworkVO#8137

Merged
yadvr merged 3 commits intoapache:mainfrom
gzhao9:refactor-136-ContrailManagerImpl-across
Nov 3, 2023
Merged

refactor MockNetworkVO#8137
yadvr merged 3 commits intoapache:mainfrom
gzhao9:refactor-136-ContrailManagerImpl-across

Conversation

@gzhao9
Copy link
Contributor

@gzhao9 gzhao9 commented Oct 24, 2023

Description

This PR addresses a problem similar to the one mentioned in Issue #8087 by adopting the same solution approach used in PR #8098. Specifically, it refactors the mock object creation for NetworkVO across test suites of four classes: InstanceIpModelTest.java, VirtualMachineModelTest.java, VirtualNetworkModelTest.java, and the testCreateVMInterface method in another class. The central concern is the repetitive mock object creations for NetworkVO.

Proposed Changes

Following the methodology from PR #8098, I've introduced a new and reusable MockNetworkVO class. This class is designated for creating NetworkVO mock objects with consistent behavior, aiming to eliminate redundancy.

Benefits of the Proposed Refactoring:

  • This refactoring leads to a cleaner codebase, streamlining the test cases and enhancing maintainability.
  • Should there arise a need to modify the NetworkVO mock creation process in the future, adjustments will only be necessary within the MockNetworkVO class. This centralizes modifications instead of scattering them across multiple test classes.

Fixes: Similar Issue to #8087

@codecov
Copy link

codecov bot commented Oct 25, 2023

Codecov Report

Merging #8137 (a166824) into main (543c54c) will increase coverage by 1.05%.
Report is 23 commits behind head on main.
The diff coverage is n/a.

@@             Coverage Diff              @@
##               main    #8137      +/-   ##
============================================
+ Coverage     28.15%   29.20%   +1.05%     
- Complexity    29181    31016    +1835     
============================================
  Files          5111     5181      +70     
  Lines        360669   365099    +4430     
  Branches      52700    53420     +720     
============================================
+ Hits         101562   106644    +5082     
+ Misses       245113   243839    -1274     
- Partials      13994    14616     +622     
Flag Coverage Δ
simulator-marvin-tests 25.17% <ø> (+1.30%) ⬆️
uitests 4.50% <ø> (-0.30%) ⬇️
unit-tests 14.80% <ø> (+0.28%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 444 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

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

clgtm

Co-authored-by: dahn <daan.hoogland@gmail.com>
@DaanHoogland
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@DaanHoogland
Copy link
Contributor

lot of failed checks

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 7512

when(network.getPhysicalNetworkId()).thenReturn(42L);
when(network.getDomainId()).thenReturn(10L);
when(network.getAccountId()).thenReturn(42L);
NetworkVO network = new MockNetworkVO(Network.State.Implemented).getNetwork();
Copy link
Member

Choose a reason for hiding this comment

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

This usage of new followed by invoking a method is considered a poor coding convention. Could you kindly consider modifying it?

I have two suggestions feel free to apply any of them or use any other approach.

  1. Consider adding a static method to the MockNetworkVO class that generates a MockNetworkVO rather than using new everytime.
  2. Employ the builder design pattern to generate the MockNetworkVO. Begin by implementing a builder class called MockNetworkVOBuilder. Within this class, introduce a method that constructs a MockNetworkVO using specified parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the advice, I used the first method.

adding a static method to the MockNetworkVO class that generates a MockNetworkVO rather than using new everytime.
@gzhao9 gzhao9 requested a review from soreana November 2, 2023 16:00
@yadvr yadvr merged commit 2f97e3b into apache:main Nov 3, 2023
dhslove pushed a commit to ablecloud-team/ablestack-cloud that referenced this pull request Nov 8, 2023
* refactor MockNetworkVO

* Apply suggestions from code review

Co-authored-by: dahn <daan.hoogland@gmail.com>

* adding static

adding a static method to the MockNetworkVO class that generates a MockNetworkVO rather than using new everytime.

---------

Co-authored-by: dahn <daan.hoogland@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants