Modifications des tests

Seuls les tests ayant un rapport avec les roles ne passent pas.
This commit is contained in:
2008-01-21 16:53:30 +00:00
parent 3beb363650
commit e7e9a5367e
3 changed files with 158 additions and 68 deletions

View File

@@ -1,17 +1,17 @@
package org.yacos.tests.core; package org.yacos.tests.core;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.naming.NamingException; import javax.naming.NamingException;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.yacos.core.article.Article; import org.yacos.core.article.Article;
import org.yacos.core.article.IArticleManager; import org.yacos.core.article.IArticleManager;
import org.yacos.core.conferences.Conference; import org.yacos.core.conferences.Conference;
@@ -22,12 +22,13 @@ import org.yacos.core.users.User;
public class ArticleManagerTest { public class ArticleManagerTest {
static IArticleManager am; private static IArticleManager am;
static IConferenceManager cm; private static IConferenceManager cm;
static IUserManager um; private static IUserManager um;
User author; private User author;
Conference conf; private Conference conf;
static int articleId; private Article article;
private int articleId;
@BeforeClass @BeforeClass
public static void setUpManager() throws NamingException, PKAlreadyUsedException { 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"); author = um.addUser("max","pw","maxime","dagn","ipint", "e@e.fr");
} }
//ajout d'une conf //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 //ajout d'un article
//Article article = am.addArticle("title", "topic", "url_article", author, new ArrayList<String>(), 1, conf); article = am.addArticle(
//articleId = article.getId(); "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 @Test
public void addArticleTest(){ public void addArticleTest(){
List<String> secondaryAuthors = new ArrayList<String>(); assertNotNull(am.getArticle(articleId));
Article article = am.addArticle("title", "topic", "url_article", author, secondaryAuthors, 1, conf); assertEquals("title", am.getArticle(articleId).getTitle());
assertEquals(article.getTitle(), am.getArticle(article.getId()).getTitle());
articleId = article.getId();
} }
@Test @Test
public void updateArticleTest(){ public void updateArticleTest(){
Article article = am.getArticle(articleId);
article.setTitle("titre2"); article.setTitle("titre2");
am.updateArticle(article); am.updateArticle(article);
article = am.getArticle(articleId); article = am.getArticle(articleId);
assertNotNull(article);
assertEquals("titre2", article.getTitle()); assertEquals("titre2", article.getTitle());
assertEquals(articleId, article.getId());
} }
@Test @Test
public void removeArticleTest(){ public void removeArticleTest(){
am.removeArticle(am.getArticle(articleId)); am.removeArticle(articleId);
assertNull(am.getArticle(articleId)); assertFalse(am.existsArticle(articleId));
} }
@Test @Test
public void getArticlesOfConfTest(){ public void getArticlesOfConfTest() throws Exception{
//ajout d'un article //ajout d'un article
List<String> secondaryAuthors = new ArrayList<String>(); 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); Integer numberOfArticles = am.getArticles(conf.getId()).size();
assertFalse("tableau vide", list.isEmpty());
assertEquals("title", list.get(list.size()-1).getTitle()); 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 @Test
public void getArticleOfConfAndAuthor(){ public void getArticleOfConfAndAuthor(){
} }
@After
public void cleanup(){
if(am.existsArticle(articleId)){
am.removeArticle(articleId);
}
cm.remove(conf.getId());
}
} }

View File

@@ -9,6 +9,8 @@ import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.naming.NamingException; import javax.naming.NamingException;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.yacos.core.conferences.Conference; import org.yacos.core.conferences.Conference;
@@ -20,31 +22,34 @@ import org.yacos.core.users.User;
public class ConferenceManagerTest { public class ConferenceManagerTest {
static IConferenceManager cm; private static IConferenceManager cm;
static IUserManager um; private static IUserManager um;
static int id; private int id;
static Conference conf; private Conference conf;
@BeforeClass @BeforeClass
public static void setUpManager() throws NamingException, PKAlreadyUsedException { public static void setUpManager() throws NamingException, PKAlreadyUsedException {
Context context = new InitialContext(); Context context = new InitialContext();
cm = (IConferenceManager) context.lookup("ConferenceManagerBean/remote"); cm = (IConferenceManager) context.lookup("ConferenceManagerBean/remote");
um = (IUserManager) context.lookup("UserManagerBean/remote"); um = (IUserManager) context.lookup("UserManagerBean/remote");
}
@Before
public void setUp() throws Exception {
if(!um.exists("max")){ if(!um.exists("max")){
um.addUser("max","pw","maxime","dagn","ipint", "e@e.fr"); 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()); conf = cm.addConference("titre","desc conf","info en plus",new Date(),new Date(),new Date(),new Date(),new Date());
id = conf.getId(); id = conf.getId();
} }
@Test @Test
public void addConferenceTest(){ public void addConferenceTest(){
conf = cm.addConference("titi","desc conf","info en plus",new Date(),new Date(),new Date(),new Date(),new Date()); 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()); assertEquals("titi", cm.getConference(conf.getId()).getTitle());
cm.remove(conf); cm.remove(conf.getId());
} }
@@ -65,7 +70,7 @@ public class ConferenceManagerTest {
public void removeConferenceTest(){ public void removeConferenceTest(){
conf = cm.getConference(id); 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()); 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()); conf = cm.addConference("titre2","desc conf","info en plus",new Date(),new Date(),new Date(),new Date(),new Date());
List<Conference> list = cm.getConferences(); List<Conference> list = cm.getConferences();
assertFalse("liste vide",list.isEmpty()); assertFalse("liste vide",list.isEmpty());
cm.remove(conf); cm.remove(conf.getId());
} }
@Test @Test
public void addRoleForUserTest(){ public void addRoleForUserTest(){
User user = um.getUser("max"); cm.addRole(Role.RoleType.AUTHOR, "max" , id);
conf = cm.getConference(id);
cm.addRole(Role.RoleType.AUTHOR, user , conf);
} }
@Test @Test
public void getRolesForConfTest(){ public void getRolesForConfTest(){
User user = um.getUser("max"); User user = um.getUser("max");
List<Role> list = cm.getRoles(user,conf); List<Role> list = cm.getRoles(user,conf);
assertFalse("liste vide",list.isEmpty()); assertTrue("liste vide",list.isEmpty());
Role role = list.get(0); cm.addRole(Role.RoleType.AUTHOR, "max" , id);
assertNotNull(role);
} }
@Test @Test
@@ -101,7 +103,7 @@ public class ConferenceManagerTest {
User user2 = um.addUser("max2","pw","maxime","dagn","ipint", "e@e.fr"); User user2 = um.addUser("max2","pw","maxime","dagn","ipint", "e@e.fr");
list = cm.getConferences(user2); list = cm.getConferences(user2);
assertTrue(list.isEmpty()); assertTrue(list.isEmpty());
um.removeUser(user2); um.removeUser(user2.getLogin());
} }
@Test @Test
@@ -112,4 +114,27 @@ public class ConferenceManagerTest {
Role role = list.get(0); Role role = list.get(0);
assertNotNull(role); 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);
}
}
} }

View File

@@ -1,32 +1,44 @@
package org.yacos.tests.core; package org.yacos.tests.core;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.util.Date;
import java.util.List;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.yacos.core.conferences.Conference; 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.IUserManager;
import org.yacos.core.users.Role;
import org.yacos.core.users.User; import org.yacos.core.users.User;
import org.yacos.core.users.Role.RoleType;
public class UserTest { public class UserTest {
private IUserManager manager; private IUserManager manager;
private IConferenceManager confManager;
private Conference conference;
User user; User user;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
Context context = new InitialContext(); Context context = new InitialContext();
manager = (IUserManager) context.lookup("UserManagerBean/remote"); manager = (IUserManager) context.lookup("UserManagerBean/remote");
confManager = (IConferenceManager) context.lookup("ConferenceManagerBean/remote");
if(manager.exists("toto")){ user = manager.addUser("testUser1","mp","bruno","dupont","ipint","e@e.fr");
manager.removeUser(manager.getUser("toto"));
}
manager.addUser("toto","mp","bruno","dupont","ipint","e@e.fr"); Date dateArticles = new Date();
user = manager.getUser("toto"); conference = confManager.addConference("A Conference",
"Test symposium 2008",
"Some infos",
dateArticles,
dateArticles,
dateArticles,
dateArticles,
dateArticles);
} }
@Test @Test
@@ -35,39 +47,53 @@ public class UserTest {
} }
@Test @Test
public void testUserWritingReading(){ public void testUserWritingReading() throws Exception{
user = manager.addUser("testUser",
User user = manager.getUser("toto"); "aPassword",
"Bob", "Smith",
"MIT", "bob.smith@yacos.mit.org");
assertNotNull(user); assertNotNull(user);
assertEquals("toto", user.getLogin());
assertEquals("dupont", user.getLastName()); user = manager.getUser("testUser");
assertEquals("bruno", user.getFirstName());
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 @Test
public void testUpdateUser(){ public void testUpdateUser(){
//on change l'email //on change l'email
user.setEmail("a@a.fr"); user.setEmail("a@a.fr");
manager.UpdateUser(user); manager.UpdateUser(user);
user = manager.getUser("toto"); user = manager.getUser("testUser1");
assertEquals("a@a.fr", user.getEmail()); assertEquals("a@a.fr", user.getEmail());
} }
@Test @Test
public void testRemoveUser(){ public void testRemoveUser(){
manager.removeUser(user.getLogin());
manager.removeUser(user); user = manager.getUser("testUser1");
user = manager.getUser("toto");
assertNull(user); assertNull(user);
} }
@Test @Test
public void testAddRole(Role role){ public void testAddRole(){
int count = user.getRoles().size(); 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()); assertTrue(count+1 == user.getRoles().size());
} }
@@ -77,4 +103,21 @@ public class UserTest {
//assertNotNull(list); //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());
}
}
} }