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