"fin séance 09-09"

This commit is contained in:
JunkJumper 2020-09-09 15:40:29 +02:00
parent e35a3b07d5
commit ff85fa4e79
8 changed files with 400 additions and 0 deletions

1
2020-2021/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/bin/

87
2020-2021/TD1.ucls Normal file
View File

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.2.4" icons="true" always-add-relationships="false" generalizations="true" realizations="true"
associations="true" dependencies="false" nesting-relationships="true" router="FAN">
<class id="1" language="java" name="TD1.Forum" project="M315" file="/M315/src/TD1/Forum.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="490" y="149"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="2" language="java" name="TD1.Admin" project="M315" file="/M315/src/TD1/Admin.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="242" y="421"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="3" language="java" name="TD1.Member" project="M315" file="/M315/src/TD1/Member.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="801" y="403"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="4" language="java" name="TD1.Message" project="M315" file="/M315/src/TD1/Message.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="504" y="471"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="5" language="java" name="TD1.MessageManager" project="M315" file="/M315/src/TD1/MessageManager.java"
binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="791" y="122"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<association id="6">
<end type="SOURCE" refId="3" navigable="false">
<attribute id="7" name="msg"/>
<multiplicity id="8" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="4" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="9">
<end type="SOURCE" refId="1" navigable="false">
<attribute id="10" name="admin"/>
<multiplicity id="11" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="12">
<end type="SOURCE" refId="1" navigable="false">
<attribute id="13" name="messageManager"/>
<multiplicity id="14" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="5" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="15">
<end type="SOURCE" refId="1" navigable="false">
<attribute id="16" name="member"/>
<multiplicity id="17" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="3" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</classifier-display>
<association-display labels="true" multiplicity="true"/>
</class-diagram>

View File

@ -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;
}
}

View File

@ -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> member = new ArrayList<Member>();
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<Member> 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<Member> 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;
}
}

View File

@ -0,0 +1,53 @@
package TD1;
import java.util.ArrayList;
import java.util.List;
public class Member {
private String nom;
private List<Message> msg = new ArrayList<Message>();
public Member() {
this(null, null);
}
public Member(String n) {
this(n, null);
}
public Member(String n, List<Message> 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<Message> getMsg() {
return msg;
}
public void setMsg(List<Message> msg) {
this.msg = msg;
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,22 @@
package TD1;
public class MessageManager {
public MessageManager() {
}
// Operations
public void createMessage() {
//TODO
}
public void deleteMessage() {
//TODO
}
public void posterMessage() {
//TODO
}
}

View File

@ -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<Member> 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<Message> 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.
}
}