-
Notifications
You must be signed in to change notification settings - Fork 29
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
add spring-trpc junit #36
Merged
wardseptember
merged 6 commits into
trpc-group:master
from
chenhao26-nineteen:feat/add-spring-support-junit-test
May 27, 2024
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5e4840e
add spring-trpc junit
chenhao26-nineteen 77b1351
fix code style and adjust private method call
chenhao26-nineteen 31c817c
remove no use code
chenhao26-nineteen 0c47ac4
remove no use code and change constant
chenhao26-nineteen 3704ad9
remove new instance code
chenhao26-nineteen abd95f9
adjust testConstructorWithNullEmpty
chenhao26-nineteen 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
135 changes: 135 additions & 0 deletions
135
...m/tencent/trpc/spring/context/configuration/AddFilterTRpcConfigManagerCustomizerTest.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,135 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making tRPC available. | ||
* | ||
* Copyright (C) 2023 THL A29 Limited, a Tencent company. | ||
* All rights reserved. | ||
* | ||
* If you have downloaded a copy of the tRPC source code from Tencent, | ||
* please note that tRPC source code is licensed under the Apache 2.0 License, | ||
* A copy of the Apache 2.0 License can be found in the LICENSE file. | ||
*/ | ||
|
||
package com.tencent.trpc.spring.context.configuration; | ||
|
||
import com.tencent.trpc.core.common.ConfigManager; | ||
import com.tencent.trpc.core.common.config.BackendConfig; | ||
import com.tencent.trpc.core.common.config.ClientConfig; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class AddFilterTRpcConfigManagerCustomizerTest { | ||
|
||
private static final String FILTER_ONE = "filter1"; | ||
|
||
private static final String FILTER_TWO = "filter2"; | ||
|
||
private static final String FILTER_THREE = "filter3"; | ||
|
||
private static final String FILTER_FOUR = "filter4"; | ||
|
||
private static final String BACKEND_MAP_KEY = "backend"; | ||
|
||
private static final Integer ORDER_VALUE = 1024; | ||
|
||
private static AddFilterTRpcConfigManagerCustomizer addFilterTRpcConfigManagerCustomizer; | ||
|
||
@Before | ||
public void setUp() { | ||
addFilterTRpcConfigManagerCustomizer = new AddFilterTRpcConfigManagerCustomizer(); | ||
} | ||
|
||
@Test | ||
public void testConstructor() { | ||
Assert.assertNotNull(addFilterTRpcConfigManagerCustomizer); | ||
} | ||
|
||
@Test | ||
public void testAddClientFilters() { | ||
AddFilterTRpcConfigManagerCustomizer customizer = addFilterTRpcConfigManagerCustomizer.addClientFilters( | ||
FILTER_ONE, FILTER_TWO); | ||
Assert.assertEquals(addFilterTRpcConfigManagerCustomizer, customizer); | ||
} | ||
|
||
@Test | ||
public void testAddServerFilters() { | ||
AddFilterTRpcConfigManagerCustomizer customizer = addFilterTRpcConfigManagerCustomizer.addServerFilters( | ||
FILTER_ONE, FILTER_TWO); | ||
Assert.assertEquals(addFilterTRpcConfigManagerCustomizer, customizer); | ||
} | ||
|
||
@Test | ||
public void testCustomize() { | ||
ConfigManager instance = ConfigManager.getInstance(); | ||
ClientConfig clientConfig = new ClientConfig(); | ||
List<String> list = Arrays.asList(FILTER_ONE, FILTER_TWO); | ||
clientConfig.setFilters(list); | ||
instance.setClientConfig(clientConfig); | ||
addFilterTRpcConfigManagerCustomizer.customize(instance); | ||
List<String> filters = instance.getClientConfig().getFilters(); | ||
|
||
Assert.assertEquals(filters.size(), list.size()); | ||
Assert.assertEquals(list, instance.getClientConfig().getFilters()); | ||
} | ||
|
||
@Test | ||
public void testGetOrder() { | ||
Assert.assertEquals(Integer.MAX_VALUE, addFilterTRpcConfigManagerCustomizer.getOrder()); | ||
addFilterTRpcConfigManagerCustomizer = new TestAddFilterTRpcConfigManagerCustomizer(); | ||
Assert.assertEquals((long) ORDER_VALUE, addFilterTRpcConfigManagerCustomizer.getOrder()); | ||
} | ||
|
||
static final class TestAddFilterTRpcConfigManagerCustomizer extends AddFilterTRpcConfigManagerCustomizer { | ||
|
||
@Override | ||
public int getOrder() { | ||
return ORDER_VALUE; | ||
} | ||
} | ||
|
||
@Test | ||
public void testConstructorWithNullEmpty() { | ||
addFilterTRpcConfigManagerCustomizer.addClientFilters(FILTER_ONE, FILTER_TWO); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这一行可以移动到L95行之后 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
addFilterTRpcConfigManagerCustomizer = new AddFilterTRpcConfigManagerCustomizer(null, null); | ||
|
||
ClientConfig clientConfig = new ClientConfig(); | ||
BackendConfig backendConfig = new BackendConfig(); | ||
|
||
backendConfig.setFilters(Arrays.asList(FILTER_THREE, FILTER_FOUR)); | ||
clientConfig.getBackendConfigMap().put(BACKEND_MAP_KEY, backendConfig); | ||
|
||
ConfigManager configManager = ConfigManager.getInstance(); | ||
configManager.setClientConfig(clientConfig); | ||
|
||
addFilterTRpcConfigManagerCustomizer.customize(configManager); | ||
List<String> expected = Arrays.asList(FILTER_THREE, FILTER_FOUR); | ||
Assert.assertEquals(expected.size(), backendConfig.getFilters().size()); | ||
Assert.assertEquals(expected, backendConfig.getFilters()); | ||
} | ||
|
||
@Test | ||
public void testMerge() { | ||
// add client filter | ||
addFilterTRpcConfigManagerCustomizer.addClientFilters(FILTER_ONE, FILTER_TWO); | ||
|
||
ClientConfig clientConfig = new ClientConfig(); | ||
BackendConfig backendConfig = new BackendConfig(); | ||
|
||
backendConfig.setFilters(Arrays.asList(FILTER_THREE, FILTER_FOUR)); | ||
clientConfig.getBackendConfigMap().put(BACKEND_MAP_KEY, backendConfig); | ||
|
||
ConfigManager configManager = ConfigManager.getInstance(); | ||
configManager.setClientConfig(clientConfig); | ||
|
||
// call customize method | ||
addFilterTRpcConfigManagerCustomizer.customize(configManager); | ||
|
||
List<String> expected = Arrays.asList(FILTER_ONE, FILTER_TWO, FILTER_THREE, FILTER_FOUR); | ||
Assert.assertEquals(expected, backendConfig.getFilters()); | ||
|
||
expected = Arrays.asList(FILTER_ONE, FILTER_TWO, FILTER_THREE); | ||
Assert.assertNotEquals(expected, backendConfig.getFilters()); | ||
} | ||
} |
Oops, something went wrong.
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.
这个函数是测emptyIfNull,可以在new AddFilterTRpcConfigManagerCustomizer(null, null);后,向clientFilters和serverFilters添加插件,然后断言
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.
done