Commit 8c9e8211 authored by Matija Obreza's avatar Matija Obreza
Browse files

Tests refactored

parent 8e68c40c
package org.genesys2.tests.resttests;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.io.IOException;
import java.util.ArrayList;
......@@ -13,6 +15,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.model.BasicUser.AccountType;
import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyException;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Team;
......@@ -50,12 +53,7 @@ public class PermissionControllerTest extends AbstractRestTest {
public void setUp() throws UserException, IOException, PasswordPolicyException {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
user = new User();
user.setEmail("salexandrbasov@gmail.com");
user.setPassword("Alexandr19011990");
user.setFullName("SYS_ADMIN");
userService.addUser(user);
user = userService.createUser("salexandrbasov@gmail.com", "SYS_ADMIN", "Alexandr19011990", AccountType.LOCAL);
faoInstitute = new FaoInstitute();
faoInstitute.setFullName("This is name of institute");
......
package org.genesys2.tests.resttests;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -14,6 +16,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.model.BasicUser.AccountType;
import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyException;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.model.genesys.Method;
......@@ -58,12 +61,7 @@ public class TraitsControllerTest extends AbstractRestTest {
public void setUp() throws JsonProcessingException, UserException, PasswordPolicyException {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
user = new User();
user.setEmail("salexandrbasov@gmail.com");
user.setPassword("Alexandr19011990");
user.setFullName("SYS_ADMIN");
userService.addUser(user);
user = userService.createUser("salexandrbasov@gmail.com", "SYS_ADMIN", "Alexandr19011990", AccountType.LOCAL);
ObjectMapper objectMapper = new ObjectMapper();
......
package org.genesys2.tests.resttests;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -14,10 +17,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.model.BasicUser.AccountType;
import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyException;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Team;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.servlet.controller.rest.UserController;
import org.junit.After;
......@@ -47,7 +50,6 @@ public class UserControllerTest extends AbstractRestTest {
private User user = new User();
private FaoInstitute faoInstitute;
private Team team;
private List<FaoInstitute> institutes = new ArrayList<>();
@Before
......@@ -66,16 +68,7 @@ public class UserControllerTest extends AbstractRestTest {
faoInstitute.setUniqueAcceNumbs(true);
faoInstitute.setCode("Code");
user = new User();
user.setEmail("salexandrbasov@gmail.com");
user.setPassword("Alexandr19011990");
user.setFullName("SYS_ADMIN");
team = new Team();
team.setName("name of team");
team.setVersion(1);
userService.addUser(user);
user = userService.createUser("salexandrbasov@gmail.com", "SYS_ADMIN", "Alexandr19011990", AccountType.LOCAL);
institutes.add(faoInstitute);
instituteService.update(institutes);
......@@ -97,7 +90,7 @@ public class UserControllerTest extends AbstractRestTest {
SecurityContextHolder.getContext().setAuthentication(authToken);
teamService.addTeam(team.getName());
teamService.addTeam("name");
}
@After
......
......@@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.model.BasicUser.AccountType;
import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyException;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.model.impl.FaoInstitute;
......@@ -73,16 +74,7 @@ public class UsersControllerTest extends AbstractRestTest {
faoInstitute.setUniqueAcceNumbs(true);
faoInstitute.setCode("Code");
user = new User();
user.setEmail("salexandrbasov@gmail.com");
user.setPassword("Alexandr19011990");
user.setFullName("SYS_ADMIN");
team = new Team();
team.setName("name of team");
team.setVersion(1);
userService.addUser(user);
user = userService.createUser("salexandrbasov@gmail.com", "SYS_ADMIN", "Alexandr19011990", AccountType.LOCAL);
institutes.add(faoInstitute);
instituteService.update(institutes);
......@@ -104,7 +96,7 @@ public class UsersControllerTest extends AbstractRestTest {
SecurityContextHolder.getContext().setAuthentication(authToken);
teamService.addTeam(team.getName());
teamService.addTeam("name of team");
}
@After
......
......@@ -15,11 +15,12 @@
**/
package org.genesys2.tests.unit;
import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.model.BasicUser.AccountType;
import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyException;
import org.genesys2.server.model.impl.User;
import org.junit.Ignore;
......@@ -37,13 +38,8 @@ public class AuthUserDetailsServiceTest extends AbstractServicesTest {
public void loadUserByUsernameTest() throws PasswordPolicyException {
LOG.info("Start test-method loadUserByUsernameTest");
User user = new User();
user.setEmail("email@mail.com");
user.setFullName("UserName");
user.setPassword("User1Password!");
try {
userService.addUser(user);
User user = userService.createUser("email@mail.com", "UserName", "User1Password!", AccountType.LOCAL);
UserDetails userDetails = userDetailsService.loadUserByUsername(user.getEmail());
assertTrue(userDetails != null);
assertTrue(userDetails.getPassword().equals(user.getPassword()));
......
......@@ -25,6 +25,7 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.model.BasicUser.AccountType;
import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyException;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.model.impl.User;
......@@ -64,13 +65,7 @@ public class EmailVerificationServiceTest extends AbstractServicesTest {
LOG.info("set up");
try {
User user = new User();
user.setFullName("Name 1");
user.setPassword("password of u1!ser");
user.setEmail("salexandrbasov@gmail.com");
user.setUuid("Uuid");
userService.addUser(user);
userService.createUser("salexandrbasov@gmail.com", "Name 1", "password of u1!ser", AccountType.LOCAL);
contentService.createGlobalArticle("smtp.email-verification", contentService.getDefaultLocale(), "title for oneArticle", "<h1>Tho BOdy of oneArticle</h1>", null, true);
......
......@@ -25,6 +25,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys.blocks.security.SecurityContextUtil;
import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.model.BasicUser.AccountType;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Team;
......@@ -45,8 +46,6 @@ import org.springframework.security.core.context.SecurityContextHolder;
public class TeamServiceTest extends AbstractServicesTest {
public static final Log LOG = LogFactory.getLog(TeamServiceTest.class);
private Team team;
private String teamName;
private FaoInstitute faoInstitute;
......@@ -68,15 +67,7 @@ public class TeamServiceTest extends AbstractServicesTest {
faoInstitute.setUniqueAcceNumbs(true);
faoInstitute.setCode("Code");
user = new User();
user.setFullName("User's name");
user.setPassword("User's password");
user.setEmail("email@test.com");
team = new Team();
team.setName(teamName);
userService.addUser(user);
userService.createUser("email@test.com", "User's name", "password of u1!ser", AccountType.LOCAL);
List<FaoInstitute> institutes = new ArrayList<>();
institutes.add(faoInstitute);
instituteService.update(institutes);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment