我的应用程序中有一个方法,可以使用Microsoft Graph REST API在Azure AD B2C上创建用户,我想模拟GraphServiceClient
来进行一些测试。
创建用户的Java方法:
public User createUser(User user) throws ClientException {
final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId(clientId)
.clientSecret(clientSecret)
.tenantId(tenantId)
.build();
final TokenCredentialAuthProvider tokenCredentialAuthProvider = new TokenCredentialAuthProvider(Arrays.asList(scope), clientSecretCredential);
GraphServiceClient graphClient = GraphServiceClient.builder()
.authenticationProvider(tokenCredentialAuthProvider)
.buildClient();
user.passwordPolicies = "DisablePasswordExpiration"; // optional
PasswordProfile passwordProfile = new PasswordProfile();
passwordProfile.forceChangePasswordNextSignIn = true; // false if the user does not need to change password
passwordProfile.password = "xWwvJ]6NMw+bWH-d";
user.passwordProfile = passwordProfile;
return graphClient.users()
.buildRequest()
.post(user);
}
字符串
我如何模拟返回一个用户,就像我们使用RestTemplate
和MockRestServiceServer
一样
1条答案
按热度按时间tquggr8v1#
模拟GraphServiceClient的最佳方法应该是定义一种方法来覆盖通过调用另一个方法来获取
GraphServiceClient
所返回的bean字符串
然后,您应该能够使用Powermock和您最喜欢的模拟工具(easymock / mockito)和测试框架(junit / testng)模拟此方法。