Commit f3d62373 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

login is unique and not null

parent f987da70
......@@ -19,6 +19,7 @@ public class User implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(unique = true, nullable = false)
private String login;
@Column(nullable = false)
......
package lcsb.mapviewer.persist.dao.user;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import java.util.ArrayList;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.PropertyValueException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.exception.ConstraintViolationException;
import org.junit.*;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.security.Privilege;
import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.AnnotatorParamDefinition;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.model.user.UserAnnotationSchema;
import lcsb.mapviewer.model.user.UserClassAnnotators;
import lcsb.mapviewer.model.user.UserClassRequiredAnnotations;
import lcsb.mapviewer.model.user.UserClassValidAnnotations;
import lcsb.mapviewer.model.user.UserGuiPreference;
import lcsb.mapviewer.model.user.*;
import lcsb.mapviewer.model.user.annotator.AnnotatorConfigParameter;
import lcsb.mapviewer.model.user.annotator.AnnotatorData;
import lcsb.mapviewer.persist.PersistTestFunctions;
......@@ -95,6 +85,39 @@ public class UserDaoTest extends PersistTestFunctions {
}
}
@Test(expected = PropertyValueException.class)
public void testTryUserWithNullLogin() {
try {
User user = new User();
user.setCryptedPassword("ZX");
userDao.add(user);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test(expected = ConstraintViolationException.class)
public void testTryUserWithExistingLogin() {
try {
User user = new User();
user.setLogin(testLogin);
user.setCryptedPassword("");
userDao.add(user);
User user2 = new User();
user2.setLogin(testLogin);
user2.setCryptedPassword("");
userDao.add(user2);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAddDeleteAdd() {
try {
......@@ -189,6 +212,7 @@ public class UserDaoTest extends PersistTestFunctions {
public void testUserWithAnnotatorSchema() throws Exception {
try {
User user = new User();
user.setLogin(testLogin);
user.setCryptedPassword("");
UserAnnotationSchema uas = new UserAnnotationSchema();
uas.setValidateMiriamTypes(true);
......@@ -231,6 +255,7 @@ public class UserDaoTest extends PersistTestFunctions {
public void testUserWithAnnotatorSchemaGuiPreferences() throws Exception {
try {
User user = new User();
user.setLogin(testLogin);
user.setCryptedPassword("");
UserAnnotationSchema uas = new UserAnnotationSchema();
user.setAnnotationSchema(uas);
......@@ -257,6 +282,7 @@ public class UserDaoTest extends PersistTestFunctions {
public void testUserWithAnnotatorSchemaRequiredAnnotations() throws Exception {
try {
User user = new User();
user.setLogin(testLogin);
user.setCryptedPassword("");
UserAnnotationSchema uas = new UserAnnotationSchema();
user.setAnnotationSchema(uas);
......@@ -281,6 +307,7 @@ public class UserDaoTest extends PersistTestFunctions {
public void testUserWithAnnotatorParams() throws Exception {
try {
User user = new User();
user.setLogin(testLogin);
user.setCryptedPassword("");
UserAnnotationSchema uas = new UserAnnotationSchema();
user.setAnnotationSchema(uas);
......
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