Modifications des tests
Seuls les tests ayant un rapport avec les roles ne passent pas.
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
package org.yacos.tests.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.yacos.core.article.Article;
|
||||
import org.yacos.core.article.IArticleManager;
|
||||
import org.yacos.core.conferences.Conference;
|
||||
@@ -21,13 +21,14 @@ import org.yacos.core.users.IUserManager;
|
||||
import org.yacos.core.users.User;
|
||||
|
||||
public class ArticleManagerTest {
|
||||
|
||||
static IArticleManager am;
|
||||
static IConferenceManager cm;
|
||||
static IUserManager um;
|
||||
User author;
|
||||
Conference conf;
|
||||
static int articleId;
|
||||
|
||||
private static IArticleManager am;
|
||||
private static IConferenceManager cm;
|
||||
private static IUserManager um;
|
||||
private User author;
|
||||
private Conference conf;
|
||||
private Article article;
|
||||
private int articleId;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpManager() throws NamingException, PKAlreadyUsedException {
|
||||
@@ -46,11 +47,19 @@ public class ArticleManagerTest {
|
||||
author = um.addUser("max","pw","maxime","dagn","ipint", "e@e.fr");
|
||||
}
|
||||
//ajout d'une conf
|
||||
conf = cm.getConference(1);
|
||||
conf = cm.addConference("titi","desc conf","info en plus",new Date(),new Date(),new Date(),new Date(),new Date());
|
||||
assertEquals("titi", cm.getConference(conf.getId()).getTitle());;
|
||||
|
||||
//ajout d'un article
|
||||
//Article article = am.addArticle("title", "topic", "url_article", author, new ArrayList<String>(), 1, conf);
|
||||
//articleId = article.getId();
|
||||
article = am.addArticle(
|
||||
"title",
|
||||
"topic",
|
||||
"url_article",
|
||||
author.getLogin(),
|
||||
new ArrayList<String>(),
|
||||
Article.State.SUMMARY,
|
||||
conf.getId());
|
||||
articleId = article.getId();
|
||||
}
|
||||
|
||||
|
||||
@@ -58,43 +67,56 @@ public class ArticleManagerTest {
|
||||
|
||||
@Test
|
||||
public void addArticleTest(){
|
||||
List<String> secondaryAuthors = new ArrayList<String>();
|
||||
Article article = am.addArticle("title", "topic", "url_article", author, secondaryAuthors, 1, conf);
|
||||
assertEquals(article.getTitle(), am.getArticle(article.getId()).getTitle());
|
||||
articleId = article.getId();
|
||||
assertNotNull(am.getArticle(articleId));
|
||||
assertEquals("title", am.getArticle(articleId).getTitle());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateArticleTest(){
|
||||
Article article = am.getArticle(articleId);
|
||||
article.setTitle("titre2");
|
||||
am.updateArticle(article);
|
||||
article = am.getArticle(articleId);
|
||||
assertNotNull(article);
|
||||
assertEquals("titre2", article.getTitle());
|
||||
assertEquals(articleId, article.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeArticleTest(){
|
||||
am.removeArticle(am.getArticle(articleId));
|
||||
assertNull(am.getArticle(articleId));
|
||||
am.removeArticle(articleId);
|
||||
assertFalse(am.existsArticle(articleId));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getArticlesOfConfTest(){
|
||||
public void getArticlesOfConfTest() throws Exception{
|
||||
|
||||
//ajout d'un article
|
||||
List<String> secondaryAuthors = new ArrayList<String>();
|
||||
Article article = am.addArticle("title", "topic", "url_article", author, secondaryAuthors, 1, conf);
|
||||
articleId = article.getId();
|
||||
|
||||
List<Article> list = am.getArticles(conf);
|
||||
assertFalse("tableau vide", list.isEmpty());
|
||||
assertEquals("title", list.get(list.size()-1).getTitle());
|
||||
Integer numberOfArticles = am.getArticles(conf.getId()).size();
|
||||
|
||||
Article newArticle = am.addArticle("newTitle", "newTopic", "url_article", author.getLogin(), secondaryAuthors, Article.State.SUMMARY, conf.getId());
|
||||
Integer newArticleId = newArticle.getId();
|
||||
|
||||
List<Article> list = am.getArticles(conf.getId());
|
||||
assertEquals(numberOfArticles+1, list.size());
|
||||
assertFalse("list not empty", list.isEmpty());
|
||||
//assertTrue(list.contains(article));
|
||||
assertEquals("title", article.getTitle());
|
||||
am.removeArticle(newArticleId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getArticleOfConfAndAuthor(){
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup(){
|
||||
if(am.existsArticle(articleId)){
|
||||
am.removeArticle(articleId);
|
||||
}
|
||||
cm.remove(conf.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.yacos.core.conferences.Conference;
|
||||
@@ -20,31 +22,34 @@ import org.yacos.core.users.User;
|
||||
|
||||
|
||||
public class ConferenceManagerTest {
|
||||
static IConferenceManager cm;
|
||||
static IUserManager um;
|
||||
static int id;
|
||||
static Conference conf;
|
||||
private static IConferenceManager cm;
|
||||
private static IUserManager um;
|
||||
private int id;
|
||||
private Conference conf;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpManager() throws NamingException, PKAlreadyUsedException {
|
||||
Context context = new InitialContext();
|
||||
cm = (IConferenceManager) context.lookup("ConferenceManagerBean/remote");
|
||||
um = (IUserManager) context.lookup("UserManagerBean/remote");
|
||||
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if(!um.exists("max")){
|
||||
um.addUser("max","pw","maxime","dagn","ipint", "e@e.fr");
|
||||
} else {
|
||||
um.getUser("max");
|
||||
}
|
||||
conf = cm.addConference("titre","desc conf","info en plus",new Date(),new Date(),new Date(),new Date(),new Date());
|
||||
id = conf.getId();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void addConferenceTest(){
|
||||
conf = cm.addConference("titi","desc conf","info en plus",new Date(),new Date(),new Date(),new Date(),new Date());
|
||||
assertEquals("titi", cm.getConference(conf.getId()).getTitle());
|
||||
cm.remove(conf);
|
||||
cm.remove(conf.getId());
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +70,7 @@ public class ConferenceManagerTest {
|
||||
|
||||
public void removeConferenceTest(){
|
||||
conf = cm.getConference(id);
|
||||
cm.remove(conf);
|
||||
cm.remove(conf.getId());
|
||||
cm.addConference("titre","desc conf","info en plus",new Date(),new Date(),new Date(),new Date(),new Date());
|
||||
}
|
||||
|
||||
@@ -74,23 +79,20 @@ public class ConferenceManagerTest {
|
||||
conf = cm.addConference("titre2","desc conf","info en plus",new Date(),new Date(),new Date(),new Date(),new Date());
|
||||
List<Conference> list = cm.getConferences();
|
||||
assertFalse("liste vide",list.isEmpty());
|
||||
cm.remove(conf);
|
||||
cm.remove(conf.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addRoleForUserTest(){
|
||||
User user = um.getUser("max");
|
||||
conf = cm.getConference(id);
|
||||
cm.addRole(Role.RoleType.AUTHOR, user , conf);
|
||||
cm.addRole(Role.RoleType.AUTHOR, "max" , id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRolesForConfTest(){
|
||||
User user = um.getUser("max");
|
||||
List<Role> list = cm.getRoles(user,conf);
|
||||
assertFalse("liste vide",list.isEmpty());
|
||||
Role role = list.get(0);
|
||||
assertNotNull(role);
|
||||
assertTrue("liste vide",list.isEmpty());
|
||||
cm.addRole(Role.RoleType.AUTHOR, "max" , id);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,7 +103,7 @@ public class ConferenceManagerTest {
|
||||
User user2 = um.addUser("max2","pw","maxime","dagn","ipint", "e@e.fr");
|
||||
list = cm.getConferences(user2);
|
||||
assertTrue(list.isEmpty());
|
||||
um.removeUser(user2);
|
||||
um.removeUser(user2.getLogin());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,5 +113,28 @@ public class ConferenceManagerTest {
|
||||
assertFalse("liste vide",list.isEmpty());
|
||||
Role role = list.get(0);
|
||||
assertNotNull(role);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConferenceExists(){
|
||||
assertTrue(cm.exists(id));
|
||||
cm.remove(id);
|
||||
assertFalse(cm.exists(id));
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup(){
|
||||
User user = um.getUser("max");
|
||||
|
||||
if(um.exists("max")){
|
||||
for(Role role : user.getRoles() ){
|
||||
um.removeRole("max", role.getType(), role.getConference().getId());
|
||||
}
|
||||
um.removeUser("max");
|
||||
}
|
||||
|
||||
if(cm.exists(id)){
|
||||
cm.remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,44 @@
|
||||
package org.yacos.tests.core;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import java.util.Date;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.yacos.core.conferences.Conference;
|
||||
import org.yacos.core.conferences.IConferenceManager;
|
||||
import org.yacos.core.exceptions.PKAlreadyUsedException;
|
||||
import org.yacos.core.users.IUserManager;
|
||||
import org.yacos.core.users.Role;
|
||||
import org.yacos.core.users.User;
|
||||
import org.yacos.core.users.Role.RoleType;
|
||||
|
||||
public class UserTest {
|
||||
private IUserManager manager;
|
||||
private IConferenceManager confManager;
|
||||
private Conference conference;
|
||||
|
||||
User user;
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Context context = new InitialContext();
|
||||
manager = (IUserManager) context.lookup("UserManagerBean/remote");
|
||||
confManager = (IConferenceManager) context.lookup("ConferenceManagerBean/remote");
|
||||
|
||||
if(manager.exists("toto")){
|
||||
manager.removeUser(manager.getUser("toto"));
|
||||
}
|
||||
manager.addUser("toto","mp","bruno","dupont","ipint","e@e.fr");
|
||||
user = manager.getUser("toto");
|
||||
user = manager.addUser("testUser1","mp","bruno","dupont","ipint","e@e.fr");
|
||||
|
||||
|
||||
Date dateArticles = new Date();
|
||||
conference = confManager.addConference("A Conference",
|
||||
"Test symposium 2008",
|
||||
"Some infos",
|
||||
dateArticles,
|
||||
dateArticles,
|
||||
dateArticles,
|
||||
dateArticles,
|
||||
dateArticles);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -35,39 +47,53 @@ public class UserTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserWritingReading(){
|
||||
|
||||
User user = manager.getUser("toto");
|
||||
public void testUserWritingReading() throws Exception{
|
||||
user = manager.addUser("testUser",
|
||||
"aPassword",
|
||||
"Bob", "Smith",
|
||||
"MIT", "bob.smith@yacos.mit.org");
|
||||
assertNotNull(user);
|
||||
assertEquals("toto", user.getLogin());
|
||||
assertEquals("dupont", user.getLastName());
|
||||
assertEquals("bruno", user.getFirstName());
|
||||
|
||||
user = manager.getUser("testUser");
|
||||
|
||||
assertNotNull(user);
|
||||
assertEquals("testUser", user.getLogin());
|
||||
assertEquals("Smith", user.getLastName());
|
||||
assertEquals("Bob", user.getFirstName());
|
||||
assertEquals("MIT", user.getOrganization());
|
||||
assertEquals("bob.smith@yacos.mit.org", user.getEmail());
|
||||
assertEquals("aPassword", user.getPassword());
|
||||
|
||||
try{
|
||||
manager.addUser("testUser", "", "", "", "", "");
|
||||
fail("Duplicate user created");
|
||||
} catch(PKAlreadyUsedException e){
|
||||
}
|
||||
|
||||
manager.removeUser(user.getLogin());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateUser(){
|
||||
|
||||
|
||||
//on change l'email
|
||||
user.setEmail("a@a.fr");
|
||||
manager.UpdateUser(user);
|
||||
user = manager.getUser("toto");
|
||||
user = manager.getUser("testUser1");
|
||||
assertEquals("a@a.fr", user.getEmail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveUser(){
|
||||
|
||||
manager.removeUser(user);
|
||||
user = manager.getUser("toto");
|
||||
manager.removeUser(user.getLogin());
|
||||
user = manager.getUser("testUser1");
|
||||
assertNull(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddRole(Role role){
|
||||
|
||||
public void testAddRole(){
|
||||
int count = user.getRoles().size();
|
||||
user.addRole(role);
|
||||
assertFalse(user.hasRoleForConference(RoleType.AUTHOR, conference));
|
||||
manager.addRoleForConference(user.getLogin(),RoleType.AUTHOR,conference.getId());
|
||||
assertTrue(count+1 == user.getRoles().size());
|
||||
}
|
||||
|
||||
@@ -77,4 +103,21 @@ public class UserTest {
|
||||
//assertNotNull(list);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserExists(){
|
||||
assertTrue(manager.exists("testUser1"));
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup(){
|
||||
user = manager.getUser("testUser1");
|
||||
if(user != null){
|
||||
manager.removeUser("testUser1");
|
||||
}
|
||||
|
||||
if(conference != null){
|
||||
confManager.remove(conference.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user