NIHVIVO-2299 Convert tests to use UserAccount instead of User.
This commit is contained in:
parent
4dfbf6920b
commit
95d26b9ffb
2 changed files with 75 additions and 68 deletions
|
@ -3,12 +3,18 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.filtering.filters;
|
package edu.cornell.mannlib.vitro.webapp.dao.filtering.filters;
|
||||||
|
|
||||||
import static edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSource.INTERNAL;
|
import static edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSource.INTERNAL;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionSetsLoader.URI_CURATOR;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionSetsLoader.URI_DBA;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionSetsLoader.URI_EDITOR;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionSetsLoader.URI_SELF_EDITOR;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -21,7 +27,7 @@ import org.junit.runners.Parameterized.Parameters;
|
||||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDaoStub;
|
import stubs.edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDaoStub;
|
||||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.IndividualDaoStub;
|
import stubs.edu.cornell.mannlib.vitro.webapp.dao.IndividualDaoStub;
|
||||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDaoStub;
|
import stubs.edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDaoStub;
|
||||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.UserDaoStub;
|
import stubs.edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDaoStub;
|
||||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
|
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSource;
|
import edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSource;
|
||||||
|
@ -35,7 +41,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.User;
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,35 +100,32 @@ public class HiddenFromDisplayBelowRoleLevelFilterTest extends
|
||||||
|
|
||||||
private static final String NS = "http://someDomain/individual/";
|
private static final String NS = "http://someDomain/individual/";
|
||||||
|
|
||||||
private static final String ROLE_NON_EDITOR = "1";
|
private static final UserAccount USER_SELF = userAccount("userSelf",
|
||||||
private static final String ROLE_EDITOR = "4";
|
"self_editor", URI_SELF_EDITOR);
|
||||||
private static final String ROLE_CURATOR = "5";
|
private static final UserAccount USER_EDITOR = userAccount("userEditor",
|
||||||
private static final String ROLE_DBA = "50";
|
"editor", URI_EDITOR);
|
||||||
|
private static final UserAccount USER_CURATOR = userAccount("userCurator",
|
||||||
private static final User USER_SELF = user("userSelf", "self_editor",
|
"curator", URI_CURATOR);
|
||||||
ROLE_NON_EDITOR);
|
private static final UserAccount USER_DBA = userAccount(NS + "userDba",
|
||||||
private static final User USER_EDITOR = user("userEditor", "editor",
|
"dba", URI_DBA);
|
||||||
ROLE_EDITOR);
|
|
||||||
private static final User USER_CURATOR = user("userCurator", "curator",
|
|
||||||
ROLE_CURATOR);
|
|
||||||
private static final User USER_DBA = user(NS + "userDba", "dba", ROLE_DBA);
|
|
||||||
|
|
||||||
/** Create a User */
|
/** Create a User */
|
||||||
private static User user(String uri, String username, String roleUri) {
|
private static UserAccount userAccount(String uri, String emailAddress,
|
||||||
User user = new User();
|
String roleUri) {
|
||||||
user.setURI(NS + uri);
|
UserAccount user = new UserAccount();
|
||||||
user.setUsername(username);
|
user.setUri(NS + uri);
|
||||||
user.setRoleURI(roleUri);
|
user.setEmailAddress(emailAddress);
|
||||||
|
user.setPermissionSetUris(Collections.singleton(roleUri));
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final UserDaoStub DAO_USER = userDao(USER_SELF, USER_EDITOR,
|
private static final UserAccountsDaoStub DAO_USER_ACCOUNT = userAccountsDao(USER_SELF, USER_EDITOR,
|
||||||
USER_CURATOR, USER_DBA);
|
USER_CURATOR, USER_DBA);
|
||||||
|
|
||||||
/** Create the UserDao */
|
/** Create the UserAccountsDao */
|
||||||
private static UserDaoStub userDao(User... users) {
|
private static UserAccountsDaoStub userAccountsDao(UserAccount... users) {
|
||||||
UserDaoStub dao = new UserDaoStub();
|
UserAccountsDaoStub dao = new UserAccountsDaoStub();
|
||||||
for (User user : users) {
|
for (UserAccount user : users) {
|
||||||
dao.addUser(user);
|
dao.addUser(user);
|
||||||
}
|
}
|
||||||
return dao;
|
return dao;
|
||||||
|
@ -138,6 +141,11 @@ public class HiddenFromDisplayBelowRoleLevelFilterTest extends
|
||||||
private static final LoginStatusBean LOGIN_DBA = loginStatusBean(USER_DBA,
|
private static final LoginStatusBean LOGIN_DBA = loginStatusBean(USER_DBA,
|
||||||
INTERNAL);
|
INTERNAL);
|
||||||
|
|
||||||
|
private static LoginStatusBean loginStatusBean(UserAccount user,
|
||||||
|
AuthenticationSource auth) {
|
||||||
|
return new LoginStatusBean(user.getUri(), auth);
|
||||||
|
}
|
||||||
|
|
||||||
private static final LoginStatusBean[] LOGINS = new LoginStatusBean[] {
|
private static final LoginStatusBean[] LOGINS = new LoginStatusBean[] {
|
||||||
LOGIN_NONE, LOGIN_SELF, LOGIN_EDITOR, LOGIN_CURATOR, LOGIN_DBA };
|
LOGIN_NONE, LOGIN_SELF, LOGIN_EDITOR, LOGIN_CURATOR, LOGIN_DBA };
|
||||||
|
|
||||||
|
@ -168,11 +176,6 @@ public class HiddenFromDisplayBelowRoleLevelFilterTest extends
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static LoginStatusBean loginStatusBean(User user,
|
|
||||||
AuthenticationSource auth) {
|
|
||||||
return new LoginStatusBean(user.getURI(), auth);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final VClass PUBLIC_VCLASS = vClass("PUBLIC_vclass",
|
private static final VClass PUBLIC_VCLASS = vClass("PUBLIC_vclass",
|
||||||
RoleLevel.PUBLIC);
|
RoleLevel.PUBLIC);
|
||||||
private static final VClass SELF_VCLASS = vClass("SELF_vclass",
|
private static final VClass SELF_VCLASS = vClass("SELF_vclass",
|
||||||
|
@ -786,20 +789,20 @@ public class HiddenFromDisplayBelowRoleLevelFilterTest extends
|
||||||
return RoleLevel.PUBLIC;
|
return RoleLevel.PUBLIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
User user = DAO_USER.getUserByURI(userUri);
|
UserAccount user = DAO_USER_ACCOUNT.getUserAccountByUri(userUri);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return RoleLevel.PUBLIC;
|
return RoleLevel.PUBLIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
String roleURI = user.getRoleURI();
|
Set<String> roleUris = user.getPermissionSetUris();
|
||||||
if ("1".equals(roleURI)) {
|
if (roleUris.contains(URI_DBA)) {
|
||||||
return RoleLevel.SELF;
|
|
||||||
} else if ("4".equals(roleURI)) {
|
|
||||||
return RoleLevel.EDITOR;
|
|
||||||
} else if ("5".equals(roleURI)) {
|
|
||||||
return RoleLevel.CURATOR;
|
|
||||||
} else if ("50".equals(roleURI)) {
|
|
||||||
return RoleLevel.DB_ADMIN;
|
return RoleLevel.DB_ADMIN;
|
||||||
|
} else if (roleUris.contains(URI_CURATOR)) {
|
||||||
|
return RoleLevel.CURATOR;
|
||||||
|
} else if (roleUris.contains(URI_EDITOR)) {
|
||||||
|
return RoleLevel.EDITOR;
|
||||||
|
} else if (roleUris.contains(URI_SELF_EDITOR)) {
|
||||||
|
return RoleLevel.SELF;
|
||||||
} else {
|
} else {
|
||||||
return RoleLevel.PUBLIC;
|
return RoleLevel.PUBLIC;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,19 +3,23 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
|
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.User;
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.UserDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
|
||||||
|
@ -32,34 +36,33 @@ public class OntModelSegementationTest {
|
||||||
wadf = new WebappDaoFactoryJena(new SimpleOntModelSelector());
|
wadf = new WebappDaoFactoryJena(new SimpleOntModelSelector());
|
||||||
}
|
}
|
||||||
|
|
||||||
@org.junit.Test
|
@Test
|
||||||
public void testUserAccountModel() {
|
public void testUserAccountModel() {
|
||||||
|
|
||||||
UserDao udao = wadf.getUserDao();
|
UserAccountsDao uadao = wadf.getUserAccountsDao();
|
||||||
OntModelSelector oms = wadf.getOntModelSelector();
|
OntModelSelector oms = wadf.getOntModelSelector();
|
||||||
|
|
||||||
User user = new User();
|
UserAccount user = new UserAccount();
|
||||||
user.setFirstName("Chuck");
|
user.setFirstName("Chuck");
|
||||||
user.setLastName("Roast");
|
user.setLastName("Roast");
|
||||||
user.setUsername("chuckroast");
|
user.setExternalAuthId("chuckroast");
|
||||||
|
|
||||||
String userURI = udao.insertUser(user);
|
uadao.insertUserAccount(user);
|
||||||
user.setURI(userURI);
|
|
||||||
Assert.assertTrue(oms.getUserAccountsModel().size() > 0);
|
Assert.assertTrue(oms.getUserAccountsModel().size() > 0);
|
||||||
Assert.assertTrue(oms.getFullModel().size() == 0);
|
Assert.assertTrue(oms.getFullModel().size() == 0);
|
||||||
Assert.assertTrue(oms.getABoxModel().size() == 0);
|
Assert.assertTrue(oms.getABoxModel().size() == 0);
|
||||||
Assert.assertTrue(oms.getTBoxModel().size() == 0);
|
Assert.assertTrue(oms.getTBoxModel().size() == 0);
|
||||||
Assert.assertTrue(oms.getApplicationMetadataModel().size() == 0);
|
Assert.assertTrue(oms.getApplicationMetadataModel().size() == 0);
|
||||||
|
|
||||||
user.setUsername("todd");
|
user.setEmailAddress("todd@somewhere");
|
||||||
udao.updateUser(user);
|
uadao.updateUserAccount(user);
|
||||||
Assert.assertTrue(oms.getUserAccountsModel().size() > 0);
|
Assert.assertTrue(oms.getUserAccountsModel().size() > 0);
|
||||||
Assert.assertTrue(oms.getFullModel().size() == 0);
|
Assert.assertTrue(oms.getFullModel().size() == 0);
|
||||||
Assert.assertTrue(oms.getABoxModel().size() == 0);
|
Assert.assertTrue(oms.getABoxModel().size() == 0);
|
||||||
Assert.assertTrue(oms.getTBoxModel().size() == 0);
|
Assert.assertTrue(oms.getTBoxModel().size() == 0);
|
||||||
Assert.assertTrue(oms.getApplicationMetadataModel().size() == 0);
|
Assert.assertTrue(oms.getApplicationMetadataModel().size() == 0);
|
||||||
|
|
||||||
udao.deleteUser(user);
|
uadao.deleteUserAccount(user.getUri());
|
||||||
Assert.assertTrue(oms.getUserAccountsModel().size() == 0);
|
Assert.assertTrue(oms.getUserAccountsModel().size() == 0);
|
||||||
Assert.assertTrue(oms.getFullModel().size() == 0);
|
Assert.assertTrue(oms.getFullModel().size() == 0);
|
||||||
Assert.assertTrue(oms.getABoxModel().size() == 0);
|
Assert.assertTrue(oms.getABoxModel().size() == 0);
|
||||||
|
@ -69,7 +72,7 @@ public class OntModelSegementationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@org.junit.Test
|
@Test
|
||||||
public void testApplicationMetadataModel() throws InsertException {
|
public void testApplicationMetadataModel() throws InsertException {
|
||||||
|
|
||||||
PortalDao pdao = wadf.getPortalDao();
|
PortalDao pdao = wadf.getPortalDao();
|
||||||
|
@ -134,7 +137,7 @@ public class OntModelSegementationTest {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@org.junit.Test
|
@Test
|
||||||
public void testTBoxModel() throws InsertException {
|
public void testTBoxModel() throws InsertException {
|
||||||
|
|
||||||
OntModelSelector oms = wadf.getOntModelSelector();
|
OntModelSelector oms = wadf.getOntModelSelector();
|
||||||
|
@ -189,7 +192,7 @@ public class OntModelSegementationTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@org.junit.Test
|
@Test
|
||||||
public void testAboxModel() throws InsertException {
|
public void testAboxModel() throws InsertException {
|
||||||
|
|
||||||
OntModelSelector oms = wadf.getOntModelSelector();
|
OntModelSelector oms = wadf.getOntModelSelector();
|
||||||
|
@ -242,20 +245,21 @@ public class OntModelSegementationTest {
|
||||||
Assert.assertTrue(oms.getUserAccountsModel().size() == 0);
|
Assert.assertTrue(oms.getUserAccountsModel().size() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@org.junit.Test
|
@Ignore
|
||||||
|
@Test
|
||||||
public void testConcurrency() throws InsertException {
|
public void testConcurrency() throws InsertException {
|
||||||
// (new Thread(new ClassLister(wadf))).start();
|
(new Thread(new ClassLister(wadf))).start();
|
||||||
// (new Thread(new ClassLister(wadf))).start();
|
(new Thread(new ClassLister(wadf))).start();
|
||||||
// VClass v = null;
|
VClass v = null;
|
||||||
// for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; i++) {
|
||||||
// v = new VClass();
|
v = new VClass();
|
||||||
// v.setURI("http://example.org/vclass" + i);
|
v.setURI("http://example.org/vclass" + i);
|
||||||
// wadf.getVClassDao().insertNewVClass(v);
|
wadf.getVClassDao().insertNewVClass(v);
|
||||||
// }
|
}
|
||||||
// for (int i = 0; i < 500; i++) {
|
for (int i = 0; i < 500; i++) {
|
||||||
// v.setName("blah " + i);
|
v.setName("blah " + i);
|
||||||
// wadf.getVClassDao().updateVClass(v);
|
wadf.getVClassDao().updateVClass(v);
|
||||||
// }
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue