diff --git a/2020-2021/.gitignore b/2020-2021/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/2020-2021/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/2020-2021/TD1.ucls b/2020-2021/TD1.ucls new file mode 100644 index 0000000..ccb3c6e --- /dev/null +++ b/2020-2021/TD1.ucls @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2020-2021/src/TD1/Admin.java b/2020-2021/src/TD1/Admin.java new file mode 100644 index 0000000..ac203db --- /dev/null +++ b/2020-2021/src/TD1/Admin.java @@ -0,0 +1,29 @@ +package TD1; + +public class Admin { + + private String nom; + + public Admin() { + this(null); + } + + public Admin(String n) { + this.nom = n; + } + + // Operations + + public void knowMembers() { + //TODO + } + + + public String getForum() { + return this.nom; + } + + public void setForum(String n) { + this.nom = n; + } +} diff --git a/2020-2021/src/TD1/Forum.java b/2020-2021/src/TD1/Forum.java new file mode 100644 index 0000000..d6523f0 --- /dev/null +++ b/2020-2021/src/TD1/Forum.java @@ -0,0 +1,70 @@ +package TD1; + +import java.util.ArrayList; +import java.util.List; + +public class Forum { + private String nom; + private Admin admin; + private MessageManager messageManager; + private List member = new ArrayList(); + + public Forum() { + this(null, null, null, null); + } + + public Forum(String n) { + this(n, null, null, null); + } + + public Forum(String n,Admin a, MessageManager mg, List m) { + this.setNom(n); + this.admin=a; + this.messageManager=mg; + this.member=m; + } + + public void createMessage() { + // TODO + } + + public void createMessageManager() { + // TODO + } + + public void createUser() { + // TODO + } + + public void addMember(Member m) { + this.getMembers().add(m); + } + + + public List getMembers() { + return this.member; + } + + public Admin getAdmin() { + return this.admin; + } + + public void setAdmin(Admin admin) { + this.admin = admin; + } + + public MessageManager getMessageManager() { + return this.messageManager; + } + + // Operations + + public String getNom() { + return nom; + } + + public void setNom(String nom) { + this.nom = nom; + } + +} diff --git a/2020-2021/src/TD1/Member.java b/2020-2021/src/TD1/Member.java new file mode 100644 index 0000000..c411010 --- /dev/null +++ b/2020-2021/src/TD1/Member.java @@ -0,0 +1,53 @@ +package TD1; + +import java.util.ArrayList; +import java.util.List; + +public class Member { + + private String nom; + private List msg = new ArrayList(); + + public Member() { + this(null, null); + } + + public Member(String n) { + this(n, null); + } + + public Member(String n, List m) { + this.nom = n; + this.msg = m; + } + + // Operations + + public void envoyerMessage() { + // TODO + } + + public void effacerMessage() { + // TODO + } + + public void lireMessage() { + // TODO + } + + public String getNom() { + return this.nom; + } + + public void setNom(String nom) { + this.nom = nom; + } + + public List getMsg() { + return msg; + } + + public void setMsg(List msg) { + this.msg = msg; + } +} diff --git a/2020-2021/src/TD1/Message.java b/2020-2021/src/TD1/Message.java new file mode 100644 index 0000000..23d249d --- /dev/null +++ b/2020-2021/src/TD1/Message.java @@ -0,0 +1,49 @@ +package TD1; + +import java.time.Instant; +import java.util.Date; + +public class Message { + + private String content; + private Member destinator; + private Date creationDate; + + public Message() { + this(null); + } + + public Message(String c) { + this(c, null); + } + + public Message(String c, Member d) { + this.content = c; + this.setDestinator(d); + this.creationDate = Date.from(Instant.now()); + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public Date getCreationDate() { + return this.creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public Member getDestinator() { + return destinator; + } + + public void setDestinator(Member destinator) { + this.destinator = destinator; + } +} diff --git a/2020-2021/src/TD1/MessageManager.java b/2020-2021/src/TD1/MessageManager.java new file mode 100644 index 0000000..5b5b02a --- /dev/null +++ b/2020-2021/src/TD1/MessageManager.java @@ -0,0 +1,22 @@ +package TD1; + +public class MessageManager { + + public MessageManager() { + + } + + // Operations + public void createMessage() { + //TODO + } + + public void deleteMessage() { + //TODO + } + + public void posterMessage() { + //TODO + } + +} diff --git a/2020-2021/tests/TD1/ForumTest.java b/2020-2021/tests/TD1/ForumTest.java new file mode 100644 index 0000000..e5c05c5 --- /dev/null +++ b/2020-2021/tests/TD1/ForumTest.java @@ -0,0 +1,89 @@ +package TD1; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Date; +import java.util.List; + +import org.junit.jupiter.api.Test; + +import fr.uca.iut.info.coo.td1.Forum; +import fr.uca.iut.info.coo.td1.Member; +import fr.uca.iut.info.coo.td1.Message; + +class ForumTest { + + @Test + void testMainScenario() throws InterruptedException { + //L'agence “oogle-stade” (Administrateur) crée un forum “OGCN”. + Forum ogcn = new Forum("OGCN"); + + //Initialisation du Forum avec les membres + Member mario = new Member("Mario"); + Member walter = new Member("Walter"); + Member alban = new Member("Alban"); + ogcn.addMember(mario); + ogcn.addMember(walter); + ogcn.addMember(alban); + List members = ogcn.getMembers(); + assertEquals(3, members.size()); + + //Mario (Membre) poste un message WaitAndSee: “a quoi cela sert de courir?” sur le forum “OGCN”. + Message wait = new Message("a quoi cela sert de courir?", mario); + ogcn.addMessage(wait); + assertEquals(1, ogcn.getAllMessages().size()); + + //Walter (Membre) demande s'il y a de nouvelles informations sur le forum et obtient le message WaitAndSee. + //Il pose la même question un peu plus tard, et le système lui répond qu'il n'y a pas de nouveaux messages. + //Walter demande à lire tous les messages. + //Walter poste un message Yes : “Tout à fait d'accord!”. + List messages = ogcn.getNewMessages(walter); + assertTrue(messages.contains(wait)); + messages = ogcn.getNewMessages(walter); + assertEquals(0,messages.size()); + assertEquals(1, ogcn.getAllMessages().size()); + Message yes = new Message( "Tout à fait d'accord!", walter); + ogcn.addMessage(yes); + + + //Alban (Membre) demande s'il y a de nouveaux messages et obtient les messages WaitAndSee and Yes. + messages = ogcn.getNewMessages(alban); + assertTrue(messages.contains(wait)); + assertTrue(messages.contains(yes)); + + //Youcef s'inscrit sur le forum puis poste un message PFFF : “Vous rigolez?”. + Member youcef = new Member("Youcef"); + ogcn.addMember(youcef); + Message pfff = new Message( "Vous rigolez?", youcef); + ogcn.addMessage(pfff); + messages = ogcn.getNewMessages(youcef); + assertEquals(3, messages.size()); + messages = ogcn.getNewMessages(youcef); + assertEquals(0, messages.size()); + + //Walter demande à lire les nouveaux messages. + messages = ogcn.getNewMessages(walter); + assertEquals(2, messages.size()); + + //Walter demande à effacer le message réalisé par Youcef, il n'a pas le droit, cela ne fait rien. + messages = ogcn.getAllMessages(); + int numberOfMessages = messages.size(); + + boolean removed = ogcn.remove(pfff, walter); + assertFalse(removed); + messages = ogcn.getAllMessages(); + assertEquals(numberOfMessages,messages.size()); + + //Youcef efface son message + removed = ogcn.remove(pfff, youcef); + assertTrue(removed); + messages = ogcn.getAllMessages(); + assertEquals(numberOfMessages-1,messages.size(),"le message a bien été effacé"); + + assertFalse(pfff.isOutOfDate(2)); + Thread.sleep(2001); + assertTrue(pfff.isOutOfDate(2)); + //Les messages postés il y a plus de 10mn (adapté la durée pour les tests) sont détruits par “oogle-stade”. + } + +}