-
Notifications
You must be signed in to change notification settings - Fork 11.7k
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
[ISSUE #8417]add some test cases for org.apache.rocketmq.common.AclConfig #8418
Merged
RongtongJin
merged 2 commits into
apache:develop
from
TeFuirnever:tongyi_testcase_coverage
Jul 23, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
common/src/test/java/org/apache/rocketmq/common/AclConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.rocketmq.common; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class AclConfigTest { | ||
|
||
/** | ||
* Test to verify that getGlobalWhiteAddrs returns null when no addresses have been set. | ||
* | ||
*/ | ||
@Test | ||
public void testGetGlobalWhiteAddrsWhenNull() { | ||
AclConfig aclConfig = new AclConfig(); | ||
Assert.assertNull("The globalWhiteAddrs should return null", aclConfig.getGlobalWhiteAddrs()); | ||
} | ||
|
||
/** | ||
* Test to verify that getGlobalWhiteAddrs returns an empty list when an empty list is set. | ||
*/ | ||
@Test | ||
public void testGetGlobalWhiteAddrsWhenEmpty() { | ||
AclConfig aclConfig = new AclConfig(); | ||
List<String> globalWhiteAddrs = new ArrayList<>(); | ||
aclConfig.setGlobalWhiteAddrs(globalWhiteAddrs); | ||
assertNotNull("The globalWhiteAddrs should never return null", aclConfig.getGlobalWhiteAddrs()); | ||
assertEquals("The globalWhiteAddrs list should be empty", 0, aclConfig.getGlobalWhiteAddrs().size()); | ||
} | ||
|
||
/** | ||
* Test to verify that getGlobalWhiteAddrs correctly returns a list of set global white addresses. | ||
*/ | ||
@Test | ||
public void testGetGlobalWhiteAddrs() { | ||
AclConfig aclConfig = new AclConfig(); | ||
List<String> expected = Arrays.asList("192.168.1.1", "192.168.1.2"); | ||
aclConfig.setGlobalWhiteAddrs(expected); | ||
assertEquals("Global white addresses should match", expected, aclConfig.getGlobalWhiteAddrs()); | ||
assertEquals("The globalWhiteAddrs list should be equal to 2", 2, aclConfig.getGlobalWhiteAddrs().size()); | ||
} | ||
|
||
/** | ||
* Test to verify that getPlainAccessConfigs returns null when no configurations have been set. | ||
*/ | ||
@Test | ||
public void testGetPlainAccessConfigsWhenNull() { | ||
AclConfig aclConfig = new AclConfig(); | ||
Assert.assertNull("The plainAccessConfigs should return null", aclConfig.getPlainAccessConfigs()); | ||
} | ||
|
||
/** | ||
* Test to verify that getPlainAccessConfigs returns an empty list when an empty list is set. | ||
*/ | ||
@Test | ||
public void testGetPlainAccessConfigsWhenEmpty() { | ||
AclConfig aclConfig = new AclConfig(); | ||
List<PlainAccessConfig> plainAccessConfigs = new ArrayList<>(); | ||
aclConfig.setPlainAccessConfigs(plainAccessConfigs); | ||
assertNotNull("The plainAccessConfigs should never return null", aclConfig.getPlainAccessConfigs()); | ||
assertEquals("The plainAccessConfigs list should be empty", 0, aclConfig.getPlainAccessConfigs().size()); | ||
} | ||
|
||
/** | ||
* Test to verify that getPlainAccessConfigs correctly returns a list of set plain access configurations. | ||
*/ | ||
@Test | ||
public void testGetPlainAccessConfigs() { | ||
AclConfig aclConfig = new AclConfig(); | ||
List<PlainAccessConfig> expected = Arrays.asList(new PlainAccessConfig(), new PlainAccessConfig()); | ||
aclConfig.setPlainAccessConfigs(expected); | ||
assertEquals("Plain access configs should match", expected, aclConfig.getPlainAccessConfigs()); | ||
assertEquals("The plainAccessConfigs list should be equal to 2", 2, aclConfig.getPlainAccessConfigs().size()); | ||
} | ||
|
||
/** | ||
* Test the toString method when global white addresses and plain access configurations are null. | ||
*/ | ||
@Test | ||
public void testToStringWithNullValues() { | ||
AclConfig aclConfig = new AclConfig(); | ||
String result = aclConfig.toString(); | ||
assertNotNull("toString should not be null", result); | ||
assertEquals("toString should match", "AclConfig{globalWhiteAddrs=null, plainAccessConfigs=null}", result); | ||
} | ||
|
||
@Test | ||
public void testToStringWithEmptyGlobalWhiteAddrsAndPlainAccessConfigs() { | ||
AclConfig aclConfig = new AclConfig(); | ||
aclConfig.setGlobalWhiteAddrs(Collections.emptyList()); | ||
aclConfig.setPlainAccessConfigs(Collections.emptyList()); | ||
String expected = "AclConfig{globalWhiteAddrs=[], plainAccessConfigs=[]}"; | ||
assertEquals(expected, aclConfig.toString()); | ||
} | ||
|
||
/** | ||
* Test the toString method to ensure it correctly represents the state of the AclConfig instance. | ||
*/ | ||
@Test | ||
public void testToStringWithNonEmptyGlobalWhiteAddrsAndPlainAccessConfigs() { | ||
AclConfig aclConfig = new AclConfig(); | ||
List<String> globalWhiteAddrs = Collections.singletonList("192.168.1.1"); | ||
aclConfig.setGlobalWhiteAddrs(globalWhiteAddrs); | ||
PlainAccessConfig plainAccessConfig = new PlainAccessConfig(); | ||
List<PlainAccessConfig> plainAccessConfigs = Collections.singletonList(plainAccessConfig); | ||
aclConfig.setPlainAccessConfigs(plainAccessConfigs); | ||
String expected = "AclConfig{globalWhiteAddrs=[192.168.1.1], plainAccessConfigs=[" + plainAccessConfig + "]}"; | ||
assertEquals("toString should match", expected, aclConfig.toString()); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test classes do not require method comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it to remove all method level comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's not necessary in test class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, why does my check item show "7 workflows awaiting approval"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, it's first contribution, need the approval of the committer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much, I've modified it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to bother you again, is codecov-commenter triggered automatically or do you need to trigger it manually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ci automatically triggered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much