You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by "gzhao9 (via GitHub)" <gi...@apache.org> on 2023/10/24 17:18:49 UTC

[PR] refactor MockNetworkVO [cloudstack]

gzhao9 opened a new pull request, #8137:
URL: https://github.com/apache/cloudstack/pull/8137

   ### 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.**
   
   <!-- When "Fixes: #<id>" is specified, the issue/PR will automatically be closed when this PR gets merged -->
   **Fixes: Similar Issue to #8087**


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] refactor MockNetworkVO [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland closed pull request #8137: refactor MockNetworkVO
URL: https://github.com/apache/cloudstack/pull/8137


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] refactor MockNetworkVO [cloudstack]

Posted by "soreana (via GitHub)" <gi...@apache.org>.
soreana commented on code in PR #8137:
URL: https://github.com/apache/cloudstack/pull/8137#discussion_r1378610749


##########
plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/InstanceIpModelTest.java:
##########
@@ -56,14 +56,7 @@ public void testCreateInstanceIp() throws IOException {
         when(controller.getManager()).thenReturn(contrailMgr);
 
         // Create Virtual-Network (VN)
-        NetworkVO network = mock(NetworkVO.class);
-        when(network.getName()).thenReturn("testnetwork");
-        when(network.getState()).thenReturn(Network.State.Implemented);
-        when(network.getGateway()).thenReturn("10.1.1.1");
-        when(network.getCidr()).thenReturn("10.1.1.0/24");
-        when(network.getPhysicalNetworkId()).thenReturn(42L);
-        when(network.getDomainId()).thenReturn(10L);
-        when(network.getAccountId()).thenReturn(42L);
+        NetworkVO network =  new MockNetworkVO(Network.State.Implemented).getNetwork();

Review Comment:
   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.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] refactor MockNetworkVO [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on code in PR #8137:
URL: https://github.com/apache/cloudstack/pull/8137#discussion_r1371388631


##########
plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VirtualNetworkModelTest.java:
##########
@@ -26,6 +26,7 @@
 import java.util.List;
 import java.util.UUID;
 
+import com.cloud.network.Network;

Review Comment:
   ```suggestion
   ```
   I missed this one. An unused import (reported by checkstyle)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] refactor MockNetworkVO [cloudstack]

Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud merged PR #8137:
URL: https://github.com/apache/cloudstack/pull/8137


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] refactor MockNetworkVO [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #8137:
URL: https://github.com/apache/cloudstack/pull/8137#issuecomment-1779457846

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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] refactor MockNetworkVO [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on PR #8137:
URL: https://github.com/apache/cloudstack/pull/8137#issuecomment-1779454408

   @blueorangutan package


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] refactor MockNetworkVO [cloudstack]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #8137:
URL: https://github.com/apache/cloudstack/pull/8137#issuecomment-1778459306

   ## [Codecov](https://app.codecov.io/gh/apache/cloudstack/pull/8137?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   > Merging [#8137](https://app.codecov.io/gh/apache/cloudstack/pull/8137?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (4cb6c4f) into [main](https://app.codecov.io/gh/apache/cloudstack/commit/543c54c7189937fe15e2c74db2277795e13a7a1c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (543c54c) will **decrease** coverage by `23.37%`.
   > The diff coverage is `n/a`.
   
   ```diff
   @@             Coverage Diff              @@
   ##               main   #8137       +/-   ##
   ============================================
   - Coverage     28.15%   4.79%   -23.37%     
   ============================================
     Files          5111     345     -4766     
     Lines        360669   26102   -334567     
     Branches      52700    4493    -48207     
   ============================================
   - Hits         101562    1252   -100310     
   + Misses       245113   24715   -220398     
   + Partials      13994     135    -13859     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/cloudstack/pull/8137/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [simulator-marvin-tests](https://app.codecov.io/gh/apache/cloudstack/pull/8137/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [uitests](https://app.codecov.io/gh/apache/cloudstack/pull/8137/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `4.79% <ø> (ø)` | |
   | [unit-tests](https://app.codecov.io/gh/apache/cloudstack/pull/8137/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   [see 4766 files with indirect coverage changes](https://app.codecov.io/gh/apache/cloudstack/pull/8137/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] refactor MockNetworkVO [cloudstack]

Posted by "gzhao9 (via GitHub)" <gi...@apache.org>.
gzhao9 commented on code in PR #8137:
URL: https://github.com/apache/cloudstack/pull/8137#discussion_r1379324087


##########
plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/InstanceIpModelTest.java:
##########
@@ -56,14 +56,7 @@ public void testCreateInstanceIp() throws IOException {
         when(controller.getManager()).thenReturn(contrailMgr);
 
         // Create Virtual-Network (VN)
-        NetworkVO network = mock(NetworkVO.class);
-        when(network.getName()).thenReturn("testnetwork");
-        when(network.getState()).thenReturn(Network.State.Implemented);
-        when(network.getGateway()).thenReturn("10.1.1.1");
-        when(network.getCidr()).thenReturn("10.1.1.0/24");
-        when(network.getPhysicalNetworkId()).thenReturn(42L);
-        when(network.getDomainId()).thenReturn(10L);
-        when(network.getAccountId()).thenReturn(42L);
+        NetworkVO network =  new MockNetworkVO(Network.State.Implemented).getNetwork();

Review Comment:
   Thanks for the advice, I used the first method.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] refactor MockNetworkVO [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on PR #8137:
URL: https://github.com/apache/cloudstack/pull/8137#issuecomment-1779468653

   lot of failed checks


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] refactor MockNetworkVO [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #8137:
URL: https://github.com/apache/cloudstack/pull/8137#issuecomment-1779579595

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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org