You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2018/12/12 11:59:15 UTC

[openmeetings] branch 4.0.x updated: [OPENMEETINGS-1970] test is added

This is an automated email from the ASF dual-hosted git repository.

solomax pushed a commit to branch 4.0.x
in repository https://gitbox.apache.org/repos/asf/openmeetings.git


The following commit(s) were added to refs/heads/4.0.x by this push:
     new 07bf969  [OPENMEETINGS-1970] test is added
07bf969 is described below

commit 07bf96946ea16db3c71de5cc7832465378a05fec
Author: Maxim Solodovnik <so...@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 5b739a3..9b99310 100644
--- a/openmeetings-web/pom.xml
+++ b/openmeetings-web/pom.xml
@@ -766,5 +766,10 @@
 			<artifactId>tomcat-embed-jasper</artifactId>
 			<version>${tomcat.version}</version>
 		</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 df38e9c..d1f2c8b 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
@@ -310,7 +310,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\":\"openmeetings@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", "openmeetings@pod.land", u.getAddress().getEmail());
+	}
+}
diff --git a/pom.xml b/pom.xml
index aca1298..1d5c95f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -634,6 +634,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>