This is an automated email from the ASF dual-hosted git repository. solomax pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/openmeetings.git
The following commit(s) were added to refs/heads/master by this push: new d703849 [OPENMEETINGS-1970] test is added d703849 is described below commit d703849f45459cfb8913da78047893bd5aeb97ef Author: Maxim Solodovnik <solomax...@gmail.com> AuthorDate: Wed Dec 12 18:59:03 2018 +0700 [OPENMEETINGS-1970] test is added --- openmeetings-web/pom.xml | 5 ++ .../apache/openmeetings/web/app/UserManager.java | 2 +- .../web/app/TestUserManagerMocked.java | 93 ++++++++++++++++++++++ pom.xml | 6 ++ 4 files changed, 105 insertions(+), 1 deletion(-) diff --git a/openmeetings-web/pom.xml b/openmeetings-web/pom.xml index 6185131..94092e4 100644 --- a/openmeetings-web/pom.xml +++ b/openmeetings-web/pom.xml @@ -733,5 +733,10 @@ </exclusions> <scope>test</scope> </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/UserManager.java b/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/UserManager.java index 5a4c651..1d306dc 100644 --- a/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/UserManager.java +++ b/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/UserManager.java @@ -254,7 +254,7 @@ public class UserManager implements IUserManager { fUser.getGroupUsers().add(new GroupUser(groupDao.get(getDefaultGroup()), fUser)); for (Map.Entry<String, String> entry : user.getUserData().entrySet()) { final String expression = entry.getKey(); - PropertyResolver.setValue(expression, fUser, entry.getKey(), new PropertyResolverConverter(null, null) { + PropertyResolver.setValue(expression, fUser, entry.getValue(), new PropertyResolverConverter(null, null) { private static final long serialVersionUID = 1L; @SuppressWarnings("unchecked") diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/web/app/TestUserManagerMocked.java b/openmeetings-web/src/test/java/org/apache/openmeetings/web/app/TestUserManagerMocked.java new file mode 100644 index 0000000..6722d3f --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/web/app/TestUserManagerMocked.java @@ -0,0 +1,93 @@ +/* + * 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.openmeetings.web.app; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.nullable; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.security.NoSuchAlgorithmException; + +import org.apache.openmeetings.core.remote.ScopeApplicationAdapter; +import org.apache.openmeetings.db.dao.server.SessiondataDao; +import org.apache.openmeetings.db.dao.user.GroupDao; +import org.apache.openmeetings.db.dao.user.UserDao; +import org.apache.openmeetings.db.dto.user.OAuthUser; +import org.apache.openmeetings.db.entity.server.OAuthServer; +import org.apache.openmeetings.db.entity.user.User; +import org.apache.openmeetings.db.entity.user.User.Type; +import org.apache.openmeetings.db.manager.IClientManager; +import org.apache.openmeetings.db.manager.IStreamClientManager; +import org.apache.openmeetings.service.mail.EmailManager; +import org.apache.openmeetings.util.OpenmeetingsVariables; +import org.apache.openmeetings.util.crypt.SCryptImplementation; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; + +@RunWith(MockitoJUnitRunner.class) +public class TestUserManagerMocked { + @Mock + private SessiondataDao sessionDao; + @Mock + private GroupDao groupDao; + @Mock + private UserDao userDao; + @Mock + private EmailManager emailManager; + @Mock + private ScopeApplicationAdapter scopeAdapter; + @Mock + private IStreamClientManager streamClientManager; + @Mock + private IClientManager cm; + @InjectMocks + private UserManager userManager; + + @Test + public void oauthTest() throws NoSuchAlgorithmException, IOException { + OpenmeetingsVariables.setCryptClassName(SCryptImplementation.class.getCanonicalName()); + when(userDao.validLogin(anyString())).thenReturn(true); + when(userDao.checkEmail(anyString(), eq(Type.oauth), any(Long.class), nullable(Long.class))).thenReturn(true); + when(userDao.update(any(User.class), nullable(String.class), any(Long.class))).then(new Answer<User>() { + @Override + public User answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + return (User)args[0]; + } + }); + final String json = "{\"email\":\"openmeeti...@pod.land\",\"email_verified\":true,\"id\":78207,\"nationalcode_verified\":false,\"phone_number_verified\":false,\"preferred_username\":\"openmeetings\",\"sub\":\"78207\",\"user_metadata\":\"{\\\"mail.auto-forward\\\":true,\\\"email\\\":{\\\"auto_forward\\\":true}}\"}"; + OAuthUser user = new OAuthUser(json, new OAuthServer() + .addMapping(OAuthUser.PARAM_LOGIN, "preferred_username") + .addMapping(OAuthUser.PARAM_EMAIL, "email")); + User u = userManager.loginOAuth(user, 1); + assertNotNull("Valid user should be created", u); + assertEquals("User should have valid login", "openmeetings", u.getLogin()); + assertEquals("User should have valid email", "openmeeti...@pod.land", u.getAddress().getEmail()); + } +} diff --git a/pom.xml b/pom.xml index 04368d4..f920b68 100644 --- a/pom.xml +++ b/pom.xml @@ -636,6 +636,12 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>2.23.4</version> + <scope>test</scope> + </dependency> </dependencies> </dependencyManagement> <dependencies>