diff --git a/.gitignore b/.gitignore index 466e24805a90b649c3cecf85f68be30227c1121a..5b5f22e29972177086674fa3eeb362af00b2dbd2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -out/ \ No newline at end of file + out\ \ No newline at end of file diff --git a/out/production/infrastructureLogicielleClient/exceptions/BadEntryException.class b/out/production/infrastructureLogicielleClient/exceptions/BadEntryException.class new file mode 100644 index 0000000000000000000000000000000000000000..9e1597d70d863c1026ac6fd7f098aa4f6fed1180 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/exceptions/BadEntryException.class differ diff --git a/out/production/infrastructureLogicielleClient/exceptions/ItemBookAlreadyExistsException.class b/out/production/infrastructureLogicielleClient/exceptions/ItemBookAlreadyExistsException.class new file mode 100644 index 0000000000000000000000000000000000000000..aadaa794c08eae1e9afb9ca07f9c7f7f84c0d8f6 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/exceptions/ItemBookAlreadyExistsException.class differ diff --git a/out/production/infrastructureLogicielleClient/exceptions/ItemFilmAlreadyExistsException.class b/out/production/infrastructureLogicielleClient/exceptions/ItemFilmAlreadyExistsException.class new file mode 100644 index 0000000000000000000000000000000000000000..c36a4c17b3f2122ff5049cc9531240a51f87d5f3 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/exceptions/ItemFilmAlreadyExistsException.class differ diff --git a/out/production/infrastructureLogicielleClient/exceptions/MemberAlreadyExistsException.class b/out/production/infrastructureLogicielleClient/exceptions/MemberAlreadyExistsException.class new file mode 100644 index 0000000000000000000000000000000000000000..dab3f0504f8f6a9308c151e9feddddbf30178a56 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/exceptions/MemberAlreadyExistsException.class differ diff --git a/out/production/infrastructureLogicielleClient/exceptions/NotItemException.class b/out/production/infrastructureLogicielleClient/exceptions/NotItemException.class new file mode 100644 index 0000000000000000000000000000000000000000..9e2d3d38569bb5d372323fcde7708461328c2a54 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/exceptions/NotItemException.class differ diff --git a/out/production/infrastructureLogicielleClient/exceptions/NotMemberException.class b/out/production/infrastructureLogicielleClient/exceptions/NotMemberException.class new file mode 100644 index 0000000000000000000000000000000000000000..e8038fb4eb960762c9623967f68fa09762ac2d45 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/exceptions/NotMemberException.class differ diff --git a/out/production/infrastructureLogicielleClient/exceptions/NotTestReportException.class b/out/production/infrastructureLogicielleClient/exceptions/NotTestReportException.class new file mode 100644 index 0000000000000000000000000000000000000000..32d700047f84d594cc4c11a35b3117919948f601 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/exceptions/NotTestReportException.class differ diff --git a/out/production/infrastructureLogicielleClient/hmi/InputJPanel$InputListener.class b/out/production/infrastructureLogicielleClient/hmi/InputJPanel$InputListener.class new file mode 100644 index 0000000000000000000000000000000000000000..e19329c80a57653c0a02adecf2cb13649d7de92a Binary files /dev/null and b/out/production/infrastructureLogicielleClient/hmi/InputJPanel$InputListener.class differ diff --git a/out/production/infrastructureLogicielleClient/hmi/InputJPanel.class b/out/production/infrastructureLogicielleClient/hmi/InputJPanel.class new file mode 100644 index 0000000000000000000000000000000000000000..a4f0904e144973ce3c62e78ac210cc0243f4fc50 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/hmi/InputJPanel.class differ diff --git a/out/production/infrastructureLogicielleClient/hmi/PasswordJPanel$PasswordActionListener.class b/out/production/infrastructureLogicielleClient/hmi/PasswordJPanel$PasswordActionListener.class new file mode 100644 index 0000000000000000000000000000000000000000..979d1935442cf72cc390a0d36f1c20c13317d406 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/hmi/PasswordJPanel$PasswordActionListener.class differ diff --git a/out/production/infrastructureLogicielleClient/hmi/PasswordJPanel.class b/out/production/infrastructureLogicielleClient/hmi/PasswordJPanel.class new file mode 100644 index 0000000000000000000000000000000000000000..9438baa751339cb4b6fbd0e0e9ed8a259707c5cb Binary files /dev/null and b/out/production/infrastructureLogicielleClient/hmi/PasswordJPanel.class differ diff --git a/out/production/infrastructureLogicielleClient/hmi/TextJScrollPane.class b/out/production/infrastructureLogicielleClient/hmi/TextJScrollPane.class new file mode 100644 index 0000000000000000000000000000000000000000..092a93fc233db791437652eae08da5a553be4dca Binary files /dev/null and b/out/production/infrastructureLogicielleClient/hmi/TextJScrollPane.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/Book.class b/out/production/infrastructureLogicielleClient/opinion/Book.class new file mode 100644 index 0000000000000000000000000000000000000000..8dfdf984bf75a2ed66860015a00782fa24b141a7 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/Book.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/HMI$AddItemBook$AddItemBookAction.class b/out/production/infrastructureLogicielleClient/opinion/HMI$AddItemBook$AddItemBookAction.class new file mode 100644 index 0000000000000000000000000000000000000000..5811c8e15ab6368237fe351ab4cde70675f00d0d Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/HMI$AddItemBook$AddItemBookAction.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/HMI$AddItemBook.class b/out/production/infrastructureLogicielleClient/opinion/HMI$AddItemBook.class new file mode 100644 index 0000000000000000000000000000000000000000..c10889fd6dfe92ace7f3176f4fecf14478940d16 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/HMI$AddItemBook.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/HMI$AddItemFilm$AddItemFilmAction.class b/out/production/infrastructureLogicielleClient/opinion/HMI$AddItemFilm$AddItemFilmAction.class new file mode 100644 index 0000000000000000000000000000000000000000..5faaa65c5de9a64b6943404ab9c6178d40584a0d Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/HMI$AddItemFilm$AddItemFilmAction.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/HMI$AddItemFilm.class b/out/production/infrastructureLogicielleClient/opinion/HMI$AddItemFilm.class new file mode 100644 index 0000000000000000000000000000000000000000..a9dbccc96dbe773319d4ee4fac20b6ffab641238 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/HMI$AddItemFilm.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/HMI$AddMember$AddMemberAction.class b/out/production/infrastructureLogicielleClient/opinion/HMI$AddMember$AddMemberAction.class new file mode 100644 index 0000000000000000000000000000000000000000..1d470c6107d04cb6a196fa296b5a6a9defe8208a Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/HMI$AddMember$AddMemberAction.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/HMI$AddMember.class b/out/production/infrastructureLogicielleClient/opinion/HMI$AddMember.class new file mode 100644 index 0000000000000000000000000000000000000000..a147cc59ad277d6304f91aceea0be86783feea14 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/HMI$AddMember.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/HMI$ConsultItem$ConsultItemAction.class b/out/production/infrastructureLogicielleClient/opinion/HMI$ConsultItem$ConsultItemAction.class new file mode 100644 index 0000000000000000000000000000000000000000..3d2d75cebbb94ef171434e9b41b8d76ada83a2fb Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/HMI$ConsultItem$ConsultItemAction.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/HMI$ConsultItem.class b/out/production/infrastructureLogicielleClient/opinion/HMI$ConsultItem.class new file mode 100644 index 0000000000000000000000000000000000000000..3314219a8edc0fec191d27f7ca9a01b0acaf74d7 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/HMI$ConsultItem.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/HMI$ReviewItem$ReviewItemAction.class b/out/production/infrastructureLogicielleClient/opinion/HMI$ReviewItem$ReviewItemAction.class new file mode 100644 index 0000000000000000000000000000000000000000..e92981992e0135e71ec2194bf0dfb4991d395485 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/HMI$ReviewItem$ReviewItemAction.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/HMI$ReviewItem.class b/out/production/infrastructureLogicielleClient/opinion/HMI$ReviewItem.class new file mode 100644 index 0000000000000000000000000000000000000000..841b4ad63459a3acd42d2f4c41f4e8654208f632 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/HMI$ReviewItem.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/HMI$ShowNetwork.class b/out/production/infrastructureLogicielleClient/opinion/HMI$ShowNetwork.class new file mode 100644 index 0000000000000000000000000000000000000000..2a1a3e024395d81c04c028a26977152557a7f96a Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/HMI$ShowNetwork.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/HMI.class b/out/production/infrastructureLogicielleClient/opinion/HMI.class new file mode 100644 index 0000000000000000000000000000000000000000..11eb9a2be6552c6d3afdfd27c096009dbc8696a1 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/HMI.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/ISocialNetwork.class b/out/production/infrastructureLogicielleClient/opinion/ISocialNetwork.class new file mode 100644 index 0000000000000000000000000000000000000000..18e1d82bf6330e3270e48996bb4882beb6ff55fb Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/ISocialNetwork.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/Member.class b/out/production/infrastructureLogicielleClient/opinion/Member.class new file mode 100644 index 0000000000000000000000000000000000000000..561d96632d636c74be1cd2ec6a51a3b754764361 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/Member.class differ diff --git a/out/production/infrastructureLogicielleClient/opinion/SocialNetwork.class b/out/production/infrastructureLogicielleClient/opinion/SocialNetwork.class new file mode 100644 index 0000000000000000000000000000000000000000..63caec3114c6cff4ec8a5d44055e4672e8b70dec Binary files /dev/null and b/out/production/infrastructureLogicielleClient/opinion/SocialNetwork.class differ diff --git a/out/production/infrastructureLogicielleClient/tests/AddItemBookTest.class b/out/production/infrastructureLogicielleClient/tests/AddItemBookTest.class new file mode 100644 index 0000000000000000000000000000000000000000..3aa5982a27f78f513d95d096aabb05cc89434868 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/tests/AddItemBookTest.class differ diff --git a/out/production/infrastructureLogicielleClient/tests/AddMemberTest.class b/out/production/infrastructureLogicielleClient/tests/AddMemberTest.class new file mode 100644 index 0000000000000000000000000000000000000000..428db0695063dcca3c3a0991857b6b6341ad027e Binary files /dev/null and b/out/production/infrastructureLogicielleClient/tests/AddMemberTest.class differ diff --git a/out/production/infrastructureLogicielleClient/tests/InitTest.class b/out/production/infrastructureLogicielleClient/tests/InitTest.class new file mode 100644 index 0000000000000000000000000000000000000000..c0afc5c3d16d922a630f928a013f5546bf6359fe Binary files /dev/null and b/out/production/infrastructureLogicielleClient/tests/InitTest.class differ diff --git a/out/production/infrastructureLogicielleClient/tests/SocialNetworkTest.class b/out/production/infrastructureLogicielleClient/tests/SocialNetworkTest.class new file mode 100644 index 0000000000000000000000000000000000000000..43008bf72d0e27b0536d8e0706d97b7ef8fbd6d8 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/tests/SocialNetworkTest.class differ diff --git a/out/production/infrastructureLogicielleClient/tests/TestReport.class b/out/production/infrastructureLogicielleClient/tests/TestReport.class new file mode 100644 index 0000000000000000000000000000000000000000..cdc162f70617cbc7881faec27436fe36d4450860 Binary files /dev/null and b/out/production/infrastructureLogicielleClient/tests/TestReport.class differ diff --git a/src/opinion/Book.java b/src/opinion/Book.java index e9e4890405d41c141e97599543e68ad3cd1f0ae9..e2b8f614fd08a75639f3b5c6bca1b79be9d674a4 100644 --- a/src/opinion/Book.java +++ b/src/opinion/Book.java @@ -1,7 +1,5 @@ package opinion; -import java.util.LinkedList; - /** * This class allows us to create books and to register new books */ @@ -10,16 +8,14 @@ public class Book { //Declaration of private class variables private String title, kind, author, comment; private int nbPages; - private float mark; - - /** - * Initialization of private class variables by the constructor - * @param title - * @param kind - * @param author - * @param nbPages + * Initialization of private variables with constructor + * + * @param title The title of the book + * @param kind The type of the book + * @param author The author of the book + * @param nbPages The number of pages of the book */ public Book(String title, String kind, String author, int nbPages) { this.title = title; @@ -28,64 +24,60 @@ public class Book { this.nbPages = nbPages; } - /** - * String function to retrieve the book's title - * @return + * Return the title of the book + * + * @return book's title */ public String getTitle() { return this.title; } - /** - * String function to retrieve the book's kind - * @return the kind of the book + * Return the kind of the book + * + * @return book's kind */ public String getKind() { return this.kind; } - /** - * String function to retrieve the book's author - * @return the author + * Retrieve the author of the book + * + * @return book's author */ public String getAuthor() { return this.author; } - /** - * Integer function to retrieve the book's number of pages - * @return the number of pages + * Return the number of pages of the book + * + * @return book's page number */ public int getNbPages() { return this.nbPages; } - - /** - * Boolean function to know if the book is already present in the database - * @param title - * @return true or false + * Identify if the current book's title is similar as another book + * + * @param title2 other's book's title + * @return true if same, false if different */ - public boolean isCalled(String title) { - String titleUpperCase = this.title.toUpperCase().trim(); - if(titleUpperCase.equals(title.toUpperCase().trim())) { - return true; - } - return false; + public boolean compareTitle(String title2) { + String formattedTitle = this.title.toUpperCase().trim(); + String formattedTitle2 = title2.toUpperCase().trim(); + return formattedTitle.equals(formattedTitle2); } - - /** - * String function to didsplay the values of a book - * @return the values + * String function to display the details of a book + * + * @return the book's details */ public String toString() { - return "Book : "+getTitle()+"\nKind : "+getKind()+"\nAuthor : "+getAuthor()+"\nNumber of pages : "+getNbPages(); + return "Book : " + getTitle() + "\nKind : " + getKind() + "\nAuthor : " + getAuthor() + "\nNumber of pages : " + getNbPages(); } } diff --git a/src/opinion/HMI.java b/src/opinion/HMI.java index 6be31ce21dc786f04f937866fb8813b99b5eef6e..032fa90f6c5dccb6d192af82bc371a65f08d5dc4 100644 --- a/src/opinion/HMI.java +++ b/src/opinion/HMI.java @@ -8,8 +8,6 @@ import hmi.TextJScrollPane; import javax.swing.*; - - import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -17,612 +15,593 @@ import java.util.LinkedList; /** * The <i>HMI</i> class allows the interactive use of a <i>SocialNetwork</i>. - * @author B. Prou + * + * @author B. Prou * @author E. Cousin (English translation) */ public class HMI { - - - - /** - * @uml.property name="sn" - * @uml.associationEnd - */ - private ISocialNetwork sn = null; - - - - private int windowWidth = 600; - - private String memberLogin = ""; - private String memberPassword = ""; - private String memberProfile = ""; - - String bookTitle; - String bookKind; - String bookAuthor; - String bookNbPages; - - String filmTitle; - String filmKind; - String filmDirector; - String filmScenarist; - String filmDuration; - - String comment; - String mark; - - private JFrame interactionWindow; - private JMenuBar menuBar; - private JMenu memberMenu; - private JMenu visitorMenu; - - private JFrame outputWindow; - /** - * @uml.property name="outputWindowJScrollPane" - * @uml.associationEnd - */ - private TextJScrollPane outputWindowJScrollPane; - - private JFrame itemOutputWindow; - /** - * @uml.property name="itemOutputJScrollPane" - * @uml.associationEnd - */ - private TextJScrollPane itemOutputJScrollPane; - - - public HMI() { - // Outputs for the user are given in french - - JMenuItem jMenuItem; - interactionWindow = new JFrame("IHM de SocialNetwork : "); - interactionWindow.setSize(windowWidth + 100, 100); - interactionWindow.setVisible(true); - //Font f = fenetreInteraction.getFont().deriveFont(Font.ITALIC + Font.BOLD); - interactionWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - menuBar = new JMenuBar(); - outputWindow = null; - - - memberMenu = new JMenu("membre"); // member - jMenuItem = new JMenuItem("afficher le réseau social"); // print content of the social network - jMenuItem.addActionListener(new ShowNetwork()); - memberMenu.add(jMenuItem); - jMenuItem = new JMenuItem("consulter un item"); // consult an item - jMenuItem.addActionListener(new ConsultItem()); - memberMenu.add(jMenuItem); - jMenuItem = new JMenuItem("ajouter un profil"); // add a member - jMenuItem.addActionListener(new AddMember()); - memberMenu.add(jMenuItem); - jMenuItem = new JMenuItem("ajouter un item livre"); // add a book - jMenuItem.addActionListener(new AddItemBook()); - memberMenu.add(jMenuItem); - jMenuItem = new JMenuItem("ajouter un item film"); // add a film - jMenuItem.addActionListener(new AddItemFilm()); - memberMenu.add(jMenuItem); - jMenuItem = new JMenuItem("donner un avis sur un item livre"); // rate an item - jMenuItem.addActionListener(new ReviewItem("livre")); // book - memberMenu.add(jMenuItem); - jMenuItem = new JMenuItem("donner un avis sur un item film"); // rate a film - jMenuItem.addActionListener(new ReviewItem("film")); // film - memberMenu.add(jMenuItem); - - - visitorMenu = new JMenu("visiteur"); // anonymous user - jMenuItem = new JMenuItem("consulter un item"); // consult an item - jMenuItem.addActionListener(new ConsultItem()); - visitorMenu.add(jMenuItem); - jMenuItem = new JMenuItem("ajouter un profil"); // add a member - jMenuItem.addActionListener(new AddMember()); - visitorMenu.add(jMenuItem); - - menuBar.add(memberMenu); - menuBar.add(visitorMenu); - - interactionWindow.setJMenuBar(menuBar); - interactionWindow.setVisible(true); - } - - - - - /** - * Setter of the property <tt>topic</tt> - * @param topic The topic to set. - * @uml.property name="topic" - */ - public void setTopic(ISocialNetwork topic) { - this.sn = topic; - } - - - - private class ShowNetwork implements ActionListener { - public void actionPerformed(ActionEvent e) { - if (outputWindow == null) { - outputWindow = new JFrame(); - outputWindow.setLocation(60,60); - outputWindowJScrollPane = new TextJScrollPane(" Social Network ", "", false, windowWidth); - outputWindowJScrollPane.setText(sn.toString()); - outputWindow.getContentPane().removeAll(); - outputWindow.repaint(); - outputWindow.setSize(windowWidth + 100, 350); - outputWindow.getContentPane().add(outputWindowJScrollPane); - outputWindowJScrollPane.setVisible(true); - outputWindow.setVisible(true); - outputWindow.repaint(); - } else { - outputWindowJScrollPane.setText(sn.toString()); - outputWindow.setVisible(true); - outputWindow.repaint(); - } - } - - } - - - - /** - * @author prou - */ - private class ConsultItem implements ActionListener { - /** - * @uml.property name="jPanelNameItem" - * @uml.associationEnd - */ - InputJPanel itemTitleJPanel; - public void actionPerformed(ActionEvent e) { - JPanel consultItem = new JPanel(); - consultItem.setLayout(new GridLayout(2,1, 4, 4)); - itemTitleJPanel = new InputJPanel(" nom de l'item ? ", "", windowWidth); // item's title - consultItem.add(itemTitleJPanel); - JButton confirm = new JButton("valider la demande consultation "); // confirm action - confirm.setPreferredSize(new Dimension(windowWidth-20, 25)); - confirm.addActionListener(new ConsultItemAction()); - consultItem.add(confirm); - consultItem.setVisible(false); - interactionWindow.getContentPane().removeAll(); - interactionWindow.repaint(); - interactionWindow.setSize(windowWidth + 100, 120); - interactionWindow.getContentPane().add(consultItem); - consultItem.setVisible(true); - interactionWindow.repaint(); - } - class ConsultItemAction implements ActionListener { - public void actionPerformed(ActionEvent e) { - try { - LinkedList <String> items = sn.consultItems(itemTitleJPanel.getEntree()); - String s = "\n"; - for (String item : items) { - s += item + "\n"; - } - if (itemOutputWindow == null) { - itemOutputWindow = new JFrame(); - itemOutputWindow.setLocation(30,30); - itemOutputJScrollPane = new TextJScrollPane(" items ", s, false, windowWidth); - itemOutputWindow.getContentPane().removeAll(); - itemOutputWindow.repaint(); - itemOutputWindow.setSize(windowWidth + 100, 350); - itemOutputWindow.getContentPane().add(itemOutputJScrollPane); - itemOutputJScrollPane.setVisible(true); - itemOutputWindow.setVisible(true); - itemOutputWindow.repaint(); - } else { - itemOutputJScrollPane.setText(s); - itemOutputWindow.setVisible(true); - itemOutputWindow.repaint(); - } - - } - catch (Exception exception) { - JOptionPane.showMessageDialog(interactionWindow, "Exception dans consultItems : " + exception); - } - } - } - - } - - - - /** - * @author prou - */ - private class AddMember implements ActionListener { - /** - * @uml.property name="pseudoJPanel" - * @uml.associationEnd - */ - InputJPanel pseudoJPanel; - /** - * @uml.property name="passwordJPanel" - * @uml.associationEnd - */ - InputJPanel passwordJPanel; - /** - * @uml.property name="jScrollPaneProfil" - * @uml.associationEnd - */ - TextJScrollPane profileJScrollPane; - public void actionPerformed(ActionEvent e) { - JPanel addMemberJPanel = new JPanel(); - profileJScrollPane = new TextJScrollPane(" profil du membre ? ", memberProfile, true, windowWidth); // member's profile ? - addMemberJPanel.add(profileJScrollPane); - JPanel loginAndPwdJPanel = new JPanel(); - loginAndPwdJPanel.setLayout(new GridLayout(3,1, 4, 4)); - pseudoJPanel = new InputJPanel(" pseudo ? ", memberLogin, windowWidth); // member's login - loginAndPwdJPanel.add(pseudoJPanel); - passwordJPanel = new InputJPanel(" mot de passe ? ", memberPassword, windowWidth); // member's password ? - loginAndPwdJPanel.add(passwordJPanel); - JButton confirm = new JButton("valider son inscription "); // confirm member's creation - confirm.setPreferredSize(new Dimension(windowWidth-20, 25)); - confirm.addActionListener(new AddMemberAction()); - loginAndPwdJPanel.add(confirm); - loginAndPwdJPanel.setVisible(true); - addMemberJPanel.add(loginAndPwdJPanel); - addMemberJPanel.setVisible(false); - interactionWindow.getContentPane().removeAll(); - interactionWindow.repaint(); - interactionWindow.setSize(windowWidth + 100, 410); - interactionWindow.getContentPane().add(addMemberJPanel); - addMemberJPanel.setVisible(true); - interactionWindow.repaint(); - } - - class AddMemberAction implements ActionListener { - public void actionPerformed(ActionEvent e) { - try { - memberLogin = pseudoJPanel.getEntree(); - memberPassword = passwordJPanel.getEntree(); - memberProfile = profileJScrollPane.getText(); - sn.addMember(memberLogin, memberPassword, memberProfile); - } - catch (Exception exception) { - JOptionPane.showMessageDialog(interactionWindow, "Exception dans addMember : " + exception); - } - } - } - } - - - - - /** - * @author prou - */ - private class AddItemBook implements ActionListener { - /** - * @uml.property name="loginJPanel" - * @uml.associationEnd - */ - InputJPanel loginJPanel; - /** - * @uml.property name="passwordJPanel" - * @uml.associationEnd - */ - PasswordJPanel passwordJPanel; - /** - * @uml.property name="titleJPanel" - * @uml.associationEnd - */ - InputJPanel titleJPanel; - /** - * @uml.property name="kindJPanel" - * @uml.associationEnd - */ - InputJPanel kindJPanel; - /** - * @uml.property name="authorJPanel" - * @uml.associationEnd - */ - InputJPanel authorJPanel; - /** - * @uml.property name="nbPagesJPanel" - * @uml.associationEnd - */ - InputJPanel nbPagesJPanel; - - public void actionPerformed(ActionEvent e) { - JPanel addBookJP = new JPanel(); - addBookJP.setLayout(new GridLayout(7,1, 4, 4)); - loginJPanel = new InputJPanel(" pseudo membre ? ", memberLogin, windowWidth); // member's login ? - addBookJP.add(loginJPanel); - passwordJPanel = new PasswordJPanel(" password membre ? ", memberPassword, windowWidth); // member's password ? - addBookJP.add(passwordJPanel); - titleJPanel = new InputJPanel(" titre ? ", bookTitle, windowWidth); // book's title ? - addBookJP.add(titleJPanel); - kindJPanel = new InputJPanel(" genre ? ", bookKind, windowWidth); // book's kind ? - addBookJP.add(kindJPanel); - authorJPanel = new InputJPanel(" auteur ? ", bookAuthor, windowWidth); // book's author ? - addBookJP.add(authorJPanel); - nbPagesJPanel = new InputJPanel(" nb pages ? ", bookNbPages, windowWidth); // book's nb of pages - addBookJP.add(nbPagesJPanel); - JButton confirm = new JButton("Valider ajouter item livre"); // confirm add a book - confirm.setPreferredSize(new Dimension(windowWidth-20, 25)); - confirm.addActionListener(new AddItemBookAction()); - addBookJP.add(confirm); - addBookJP.setVisible(false); - interactionWindow.getContentPane().removeAll(); - interactionWindow.repaint(); - interactionWindow.setSize(windowWidth + 100, 320); - interactionWindow.getContentPane().add(addBookJP); - addBookJP.setVisible(true); - interactionWindow.setVisible(true); - interactionWindow.repaint(); - } - - class AddItemBookAction implements ActionListener { - public void actionPerformed(ActionEvent e) { - try { - memberLogin = loginJPanel.getEntree(); - memberPassword = passwordJPanel.getPassword(); - bookTitle = titleJPanel.getEntree(); - bookKind = kindJPanel.getEntree(); - bookAuthor = authorJPanel.getEntree(); - bookNbPages = nbPagesJPanel.getEntree(); - sn.addItemBook(memberLogin, memberPassword, bookTitle, bookKind, bookAuthor, new Integer(bookNbPages)); - } - catch (Exception exception) { - JOptionPane.showMessageDialog(interactionWindow, "Exception dans addItemBook : " + exception); - } - } - } - } - - - - private class AddItemFilm implements ActionListener { - /** - * @uml.property name="loginJPanel" - * @uml.associationEnd - */ - InputJPanel loginJPanel; - /** - * @uml.property name="passwordJPanel" - * @uml.associationEnd - */ - PasswordJPanel passwordJPanel; - /** - * @uml.property name="titleJPanel" - * @uml.associationEnd - */ - InputJPanel titleJPanel; - /** - * @uml.property name="kindJPanel" - * @uml.associationEnd - */ - InputJPanel kindJPanel; - /** - * @uml.property name="directorJPanel" - * @uml.associationEnd - */ - InputJPanel directorJPanel; - /** - * @uml.property name="scenaristJPanel" - * @uml.associationEnd - */ - InputJPanel scenaristJPanel; - /** - * @uml.property name="nbPagesJPanel" - * @uml.associationEnd - */ - InputJPanel nbPagesJPanel; - - public void actionPerformed(ActionEvent e) { - JPanel addFilmJP = new JPanel(); - addFilmJP.setLayout(new GridLayout(7,1, 4, 4)); - loginJPanel = new InputJPanel(" pseudo membre ? ", memberLogin, windowWidth); - addFilmJP.add(loginJPanel); - passwordJPanel = new PasswordJPanel(" password membre ? ", memberPassword, windowWidth); - addFilmJP.add(passwordJPanel); - titleJPanel = new InputJPanel(" titre ? ", filmTitle, windowWidth); - addFilmJP.add(titleJPanel); - kindJPanel = new InputJPanel(" genre ? ", filmKind, windowWidth); - addFilmJP.add(kindJPanel); - directorJPanel = new InputJPanel(" réalisateur ? ", filmDirector, windowWidth); - addFilmJP.add(directorJPanel); - scenaristJPanel = new InputJPanel(" scénariste ? ", filmScenarist, windowWidth); - addFilmJP.add(scenaristJPanel); - nbPagesJPanel = new InputJPanel(" durée ? ", filmDuration, windowWidth); - addFilmJP.add(nbPagesJPanel); - JButton confirm = new JButton("Valider ajouter item film"); - confirm.setPreferredSize(new Dimension(windowWidth-20, 25)); - confirm.addActionListener(new AddItemFilmAction()); - addFilmJP.add(confirm); - addFilmJP.setVisible(false); - interactionWindow.getContentPane().removeAll(); - interactionWindow.repaint(); - interactionWindow.setSize(windowWidth + 100, 320); - interactionWindow.getContentPane().add(addFilmJP); - addFilmJP.setVisible(true); - interactionWindow.setVisible(true); - interactionWindow.repaint(); - } - - class AddItemFilmAction implements ActionListener { - public void actionPerformed(ActionEvent e) { - try { - memberLogin = loginJPanel.getEntree(); - memberPassword = passwordJPanel.getPassword(); - filmTitle = titleJPanel.getEntree(); - filmKind = kindJPanel.getEntree(); - filmDirector = directorJPanel.getEntree(); - filmScenarist = scenaristJPanel.getEntree(); - filmDuration = nbPagesJPanel.getEntree(); - sn.addItemFilm(memberLogin, memberPassword, filmTitle, filmKind, filmDirector, filmScenarist, new Integer(filmDuration)); - } - catch (Exception exception) { - JOptionPane.showMessageDialog(interactionWindow, "Exception dans addItemFilm : " + exception); - } - } - } - } - - - - - private class ReviewItem implements ActionListener { - /** - * @uml.property name="pseudoJPanel" - * @uml.associationEnd - */ - InputJPanel pseudoJPanel; - /** - * @uml.property name="passwordJPanel" - * @uml.associationEnd - */ - PasswordJPanel passwordJPanel; - /** - * @uml.property name="titleJPanel" - * @uml.associationEnd - */ - InputJPanel titleJPanel; - /** - * @uml.property name="noteJPanel" - * @uml.associationEnd - */ - InputJPanel noteJPanel; - /** - * @uml.property name="commentJScrollPane" - * @uml.associationEnd - */ - TextJScrollPane commentJScrollPane; - - String type; - - public ReviewItem (String type) { - this.type = type; - } - public void actionPerformed(ActionEvent e) { - JPanel reviewerJP = new JPanel(); - commentJScrollPane = new TextJScrollPane(" commentaire ? ", comment, true, windowWidth); // comment ? - reviewerJP.add(commentJScrollPane); - JPanel loginPwdAndTitleJPanel = new JPanel(); - loginPwdAndTitleJPanel.setLayout(new GridLayout(5,1, 4, 4)); - pseudoJPanel = new InputJPanel(" pseudo membre ? ", memberLogin, windowWidth); // member's login ? - loginPwdAndTitleJPanel.add(pseudoJPanel); - passwordJPanel = new PasswordJPanel(" password membre ? ", memberPassword, windowWidth); // member's password ? - loginPwdAndTitleJPanel.add(passwordJPanel); - titleJPanel = new InputJPanel(" titre ? ", bookTitle, windowWidth); // title ? - loginPwdAndTitleJPanel.add(titleJPanel); - noteJPanel = new InputJPanel(" note ? ", mark, windowWidth); // mark ? - loginPwdAndTitleJPanel.add(noteJPanel); - JButton valider = new JButton("Valider reviewer item " + type); // confirm review item ? - valider.setPreferredSize(new Dimension(windowWidth-20, 25)); - valider.addActionListener(new ReviewItemAction()); - loginPwdAndTitleJPanel.add(valider); - reviewerJP.add(loginPwdAndTitleJPanel); - reviewerJP.setVisible(false); - interactionWindow.getContentPane().removeAll(); - interactionWindow.repaint(); - interactionWindow.setSize(windowWidth + 100, 470); - interactionWindow.getContentPane().add(reviewerJP); - reviewerJP.setVisible(true); - interactionWindow.setVisible(true); - interactionWindow.repaint(); - } - - class ReviewItemAction implements ActionListener { - public void actionPerformed(ActionEvent e) { - try { - memberLogin = pseudoJPanel.getEntree(); - memberPassword = passwordJPanel.getPassword(); - bookTitle = titleJPanel.getEntree(); - mark = noteJPanel.getEntree(); - comment = commentJScrollPane.getText(); - if (type.equals("livre")) //book - sn.reviewItemBook(memberLogin, memberPassword, bookTitle, new Float(mark), comment); - if (type.equals("film")) // film - sn.reviewItemFilm(memberLogin, memberPassword, bookTitle, new Float(mark), comment); - - } - catch (Exception exception) { - if (type.equals("livre")) // book - JOptionPane.showMessageDialog(interactionWindow, "Exception dans reviewItemBook : " + exception); - if (type.equals("film")) // film - JOptionPane.showMessageDialog(interactionWindow, "Exception dans reviewItemFilm : " + exception); - } - } - } - } - - - - - - - - /** - * Creates a new <i>SocialNetwork</i> with <ul> - * <li>3 users (login/pwd) : Paul/paul, Antoine/antoine, Alice/alice</li> - * <li>3 books (title) : "Lignes de faille","La peste", "Guerre et Paix", "Le train sifflera trois fois"</li> - * <li>4 films (title) : "Le train sifflera trois fois", "Avant l'aube", "Le discours d'un roi", "Black Swan", "Guerre et Paix"</li> - * </ul> - * and some opinions :<ul> - * <li>Book "La Peste" : Antoine (1.5),Alice (2.5)</li> - * <li>Book "Lignes de faille" : Alice (1.5)</li> - * <li>Book "Guerre et paix" : Alice (2.0), Antoine (4.5)</li> - * <li>Film "Black Swan" : Paul (2.5)</li> - * <li>Film "Avant l'aube" : Antoine (3.0), Paul (2.5)</li> - * <li>Film "Guerre et paix" : Alice (4.2), Paul (4.4)</li> - * </ul> - * Then add an opinion by a member who already gave one for the same item : Book "La Peste" / Antoine (3.8)</br> - * And finally launches an interactive HMI that gives access to the main actions on this <i>SocialNetwork</i>. - * @param args not used - */ - public static void main (String [] args) { - - try { - ISocialNetwork sn = new SocialNetwork(); // the SocialNetwork to interact with - - HMI ihm = new HMI(); - ihm.setTopic(sn); - - // add 3 members - sn.addMember("Paul", "paul", "lecteur impulsif"); - sn.addMember("Antoine", "antoine", "grand amoureux de littérature"); - sn.addMember("Alice", "alice", "23 ans, sexy"); - - - // add 3 books and 4 films - sn.addItemBook("Alice", "alice", "Lignes de faille", "roman", "Nancy Huston", 220); - sn.addItemFilm("Alice", "alice", "Le train sifflera trois fois", "western 1952", "Fred Zinnemann", "Carl Foreman", 85); - sn.addItemBook("Paul", "paul", "La peste", "roman", " Albert Camus", 336); - sn.addItemFilm("Paul", "paul", "Avant l'aube", "thriller 2011", "Raphael Jacoulot", "Lise Macheboeuf et Raphael Jacoulot", 104); - sn.addItemBook("Antoine", "antoine", "Guerre et Paix", "roman", "Leon Tosltoi", 1247); - sn.addItemFilm("Antoine", "antoine", "Le discours d'un roi", "drame historique 2010", "Tom Hooper", "David Seidler", 118); - sn.addItemFilm("Alice", "alice", "Black Swan", "drame 2010", "Darren Aronofsky", "John McLaughlin et Mark Heyman et Andres Heinz", 103); - sn.addItemBook("Alice", "alice", "Le train sifflera trois fois", "roman", " J. W. Cunningham", 257); - sn.addItemFilm("Paul", "paul", "Guerre et Paix", "aventure historique", "King Vidor", "Bridget Boland, Robert Westbery", 200); - - - - // review some books and films - sn.reviewItemBook("Antoine", "antoine", "La Peste", 1.5f, "un peu daté"); - sn.reviewItemFilm("Paul", "paul", "Black Swan", 2.5f, "pour la performance..."); - sn.reviewItemFilm("Antoine", "antoine", "Avant l'aube", 3.0f, "tout le monde fume..."); - sn.reviewItemBook("Alice", "alice", "Lignes de faille", 1.5f, "famille attachante"); - // review a film and a book that were already reviewed by somebody else - sn.reviewItemFilm("Paul", "paul", "Avant l'aube", 2.5f, "mitigé"); - sn.reviewItemBook("Alice", "alice", "La Peste", 2.5f, " "); - // several reviews of a film and a book with the same title - sn.reviewItemBook("Alice", "alice", "Guerre et Paix", 2.0f, "un peu long"); - sn.reviewItemFilm("Alice", "alice", "Guerre et Paix", 4.2f, "on ne voit pas le temps passer"); - sn.reviewItemBook("Antoine", "antoine", "Guerre et Paix", 4.5f, "parfait pour une semaine pluvieuse"); - sn.reviewItemFilm("Paul", "paul", "Guerre et Paix", 4.4f, "choisir une salle confortable"); - // review a book that was already reviewed by the same member - sn.reviewItemBook("Antoine", "antoine", "La Peste", 3.8f, "bien meilleur à la relecture"); - - System.out.println(sn); - } - catch (Exception e) { - System.out.println("Exception inattendue : " + e); - e.printStackTrace(); - } - - } + /** + * @uml.property name="sn" + * @uml.associationEnd + */ + private ISocialNetwork sn = null; + + + private int windowWidth = 600; + + private String memberLogin = ""; + private String memberPassword = ""; + private String memberProfile = ""; + + String bookTitle; + String bookKind; + String bookAuthor; + String bookNbPages; + + String filmTitle; + String filmKind; + String filmDirector; + String filmScenarist; + String filmDuration; + + String comment; + String mark; + + private JFrame interactionWindow; + private JMenuBar menuBar; + private JMenu memberMenu; + private JMenu visitorMenu; + + private JFrame outputWindow; + /** + * @uml.property name="outputWindowJScrollPane" + * @uml.associationEnd + */ + private TextJScrollPane outputWindowJScrollPane; + + private JFrame itemOutputWindow; + /** + * @uml.property name="itemOutputJScrollPane" + * @uml.associationEnd + */ + private TextJScrollPane itemOutputJScrollPane; + + + public HMI() { + // Outputs for the user are given in french + + JMenuItem jMenuItem; + interactionWindow = new JFrame("IHM de SocialNetwork : "); + interactionWindow.setSize(windowWidth + 100, 100); + interactionWindow.setVisible(true); + //Font f = fenetreInteraction.getFont().deriveFont(Font.ITALIC + Font.BOLD); + interactionWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + menuBar = new JMenuBar(); + outputWindow = null; + + + memberMenu = new JMenu("membre"); // member + jMenuItem = new JMenuItem("afficher le réseau social"); // print content of the social network + jMenuItem.addActionListener(new ShowNetwork()); + memberMenu.add(jMenuItem); + jMenuItem = new JMenuItem("consulter un item"); // consult an item + jMenuItem.addActionListener(new ConsultItem()); + memberMenu.add(jMenuItem); + jMenuItem = new JMenuItem("ajouter un profil"); // add a member + jMenuItem.addActionListener(new AddMember()); + memberMenu.add(jMenuItem); + jMenuItem = new JMenuItem("ajouter un item livre"); // add a book + jMenuItem.addActionListener(new AddItemBook()); + memberMenu.add(jMenuItem); + jMenuItem = new JMenuItem("ajouter un item film"); // add a film + jMenuItem.addActionListener(new AddItemFilm()); + memberMenu.add(jMenuItem); + jMenuItem = new JMenuItem("donner un avis sur un item livre"); // rate an item + jMenuItem.addActionListener(new ReviewItem("livre")); // book + memberMenu.add(jMenuItem); + jMenuItem = new JMenuItem("donner un avis sur un item film"); // rate a film + jMenuItem.addActionListener(new ReviewItem("film")); // film + memberMenu.add(jMenuItem); + + + visitorMenu = new JMenu("visiteur"); // anonymous user + jMenuItem = new JMenuItem("consulter un item"); // consult an item + jMenuItem.addActionListener(new ConsultItem()); + visitorMenu.add(jMenuItem); + jMenuItem = new JMenuItem("ajouter un profil"); // add a member + jMenuItem.addActionListener(new AddMember()); + visitorMenu.add(jMenuItem); + + menuBar.add(memberMenu); + menuBar.add(visitorMenu); + + interactionWindow.setJMenuBar(menuBar); + interactionWindow.setVisible(true); + } + + + /** + * Setter of the property <tt>topic</tt> + * + * @param topic The topic to set. + * @uml.property name="topic" + */ + public void setTopic(ISocialNetwork topic) { + this.sn = topic; + } + + + private class ShowNetwork implements ActionListener { + public void actionPerformed(ActionEvent e) { + if (outputWindow == null) { + outputWindow = new JFrame(); + outputWindow.setLocation(60, 60); + outputWindowJScrollPane = new TextJScrollPane(" Social Network ", "", false, windowWidth); + outputWindowJScrollPane.setText(sn.toString()); + outputWindow.getContentPane().removeAll(); + outputWindow.repaint(); + outputWindow.setSize(windowWidth + 100, 350); + outputWindow.getContentPane().add(outputWindowJScrollPane); + outputWindowJScrollPane.setVisible(true); + outputWindow.setVisible(true); + outputWindow.repaint(); + } else { + outputWindowJScrollPane.setText(sn.toString()); + outputWindow.setVisible(true); + outputWindow.repaint(); + } + } + + } + + + /** + * @author prou + */ + private class ConsultItem implements ActionListener { + /** + * @uml.property name="jPanelNameItem" + * @uml.associationEnd + */ + InputJPanel itemTitleJPanel; + + public void actionPerformed(ActionEvent e) { + JPanel consultItem = new JPanel(); + consultItem.setLayout(new GridLayout(2, 1, 4, 4)); + itemTitleJPanel = new InputJPanel(" nom de l'item ? ", "", windowWidth); // item's title + consultItem.add(itemTitleJPanel); + JButton confirm = new JButton("valider la demande consultation "); // confirm action + confirm.setPreferredSize(new Dimension(windowWidth - 20, 25)); + confirm.addActionListener(new ConsultItemAction()); + consultItem.add(confirm); + consultItem.setVisible(false); + interactionWindow.getContentPane().removeAll(); + interactionWindow.repaint(); + interactionWindow.setSize(windowWidth + 100, 120); + interactionWindow.getContentPane().add(consultItem); + consultItem.setVisible(true); + interactionWindow.repaint(); + } + + class ConsultItemAction implements ActionListener { + public void actionPerformed(ActionEvent e) { + try { + LinkedList<String> items = sn.consultItems(itemTitleJPanel.getEntree()); + String s = "\n"; + for (String item : items) { + s += item + "\n"; + } + if (itemOutputWindow == null) { + itemOutputWindow = new JFrame(); + itemOutputWindow.setLocation(30, 30); + itemOutputJScrollPane = new TextJScrollPane(" items ", s, false, windowWidth); + itemOutputWindow.getContentPane().removeAll(); + itemOutputWindow.repaint(); + itemOutputWindow.setSize(windowWidth + 100, 350); + itemOutputWindow.getContentPane().add(itemOutputJScrollPane); + itemOutputJScrollPane.setVisible(true); + itemOutputWindow.setVisible(true); + itemOutputWindow.repaint(); + } else { + itemOutputJScrollPane.setText(s); + itemOutputWindow.setVisible(true); + itemOutputWindow.repaint(); + } + + } catch (Exception exception) { + JOptionPane.showMessageDialog(interactionWindow, "Exception dans consultItems : " + exception); + } + } + } + + } + + + /** + * @author prou + */ + private class AddMember implements ActionListener { + /** + * @uml.property name="pseudoJPanel" + * @uml.associationEnd + */ + InputJPanel pseudoJPanel; + /** + * @uml.property name="passwordJPanel" + * @uml.associationEnd + */ + InputJPanel passwordJPanel; + /** + * @uml.property name="jScrollPaneProfil" + * @uml.associationEnd + */ + TextJScrollPane profileJScrollPane; + + public void actionPerformed(ActionEvent e) { + JPanel addMemberJPanel = new JPanel(); + profileJScrollPane = new TextJScrollPane(" profil du membre ? ", memberProfile, true, windowWidth); // member's profile ? + addMemberJPanel.add(profileJScrollPane); + JPanel loginAndPwdJPanel = new JPanel(); + loginAndPwdJPanel.setLayout(new GridLayout(3, 1, 4, 4)); + pseudoJPanel = new InputJPanel(" pseudo ? ", memberLogin, windowWidth); // member's login + loginAndPwdJPanel.add(pseudoJPanel); + passwordJPanel = new InputJPanel(" mot de passe ? ", memberPassword, windowWidth); // member's password ? + loginAndPwdJPanel.add(passwordJPanel); + JButton confirm = new JButton("valider son inscription "); // confirm member's creation + confirm.setPreferredSize(new Dimension(windowWidth - 20, 25)); + confirm.addActionListener(new AddMemberAction()); + loginAndPwdJPanel.add(confirm); + loginAndPwdJPanel.setVisible(true); + addMemberJPanel.add(loginAndPwdJPanel); + addMemberJPanel.setVisible(false); + interactionWindow.getContentPane().removeAll(); + interactionWindow.repaint(); + interactionWindow.setSize(windowWidth + 100, 410); + interactionWindow.getContentPane().add(addMemberJPanel); + addMemberJPanel.setVisible(true); + interactionWindow.repaint(); + } + + class AddMemberAction implements ActionListener { + public void actionPerformed(ActionEvent e) { + try { + memberLogin = pseudoJPanel.getEntree(); + memberPassword = passwordJPanel.getEntree(); + memberProfile = profileJScrollPane.getText(); + sn.addMember(memberLogin, memberPassword, memberProfile); + } catch (Exception exception) { + JOptionPane.showMessageDialog(interactionWindow, "Exception dans addMember : " + exception); + } + } + } + } + + + /** + * @author prou + */ + private class AddItemBook implements ActionListener { + /** + * @uml.property name="loginJPanel" + * @uml.associationEnd + */ + InputJPanel loginJPanel; + /** + * @uml.property name="passwordJPanel" + * @uml.associationEnd + */ + PasswordJPanel passwordJPanel; + /** + * @uml.property name="titleJPanel" + * @uml.associationEnd + */ + InputJPanel titleJPanel; + /** + * @uml.property name="kindJPanel" + * @uml.associationEnd + */ + InputJPanel kindJPanel; + /** + * @uml.property name="authorJPanel" + * @uml.associationEnd + */ + InputJPanel authorJPanel; + /** + * @uml.property name="nbPagesJPanel" + * @uml.associationEnd + */ + InputJPanel nbPagesJPanel; + + public void actionPerformed(ActionEvent e) { + JPanel addBookJP = new JPanel(); + addBookJP.setLayout(new GridLayout(7, 1, 4, 4)); + loginJPanel = new InputJPanel(" pseudo membre ? ", memberLogin, windowWidth); // member's login ? + addBookJP.add(loginJPanel); + passwordJPanel = new PasswordJPanel(" password membre ? ", memberPassword, windowWidth); // member's password ? + addBookJP.add(passwordJPanel); + titleJPanel = new InputJPanel(" titre ? ", bookTitle, windowWidth); // book's title ? + addBookJP.add(titleJPanel); + kindJPanel = new InputJPanel(" genre ? ", bookKind, windowWidth); // book's kind ? + addBookJP.add(kindJPanel); + authorJPanel = new InputJPanel(" auteur ? ", bookAuthor, windowWidth); // book's author ? + addBookJP.add(authorJPanel); + nbPagesJPanel = new InputJPanel(" nb pages ? ", bookNbPages, windowWidth); // book's nb of pages + addBookJP.add(nbPagesJPanel); + JButton confirm = new JButton("Valider ajouter item livre"); // confirm add a book + confirm.setPreferredSize(new Dimension(windowWidth - 20, 25)); + confirm.addActionListener(new AddItemBookAction()); + addBookJP.add(confirm); + addBookJP.setVisible(false); + interactionWindow.getContentPane().removeAll(); + interactionWindow.repaint(); + interactionWindow.setSize(windowWidth + 100, 320); + interactionWindow.getContentPane().add(addBookJP); + addBookJP.setVisible(true); + interactionWindow.setVisible(true); + interactionWindow.repaint(); + } + + class AddItemBookAction implements ActionListener { + public void actionPerformed(ActionEvent e) { + try { + memberLogin = loginJPanel.getEntree(); + memberPassword = passwordJPanel.getPassword(); + bookTitle = titleJPanel.getEntree(); + bookKind = kindJPanel.getEntree(); + bookAuthor = authorJPanel.getEntree(); + bookNbPages = nbPagesJPanel.getEntree(); + sn.addItemBook(memberLogin, memberPassword, bookTitle, bookKind, bookAuthor, new Integer(bookNbPages)); + } catch (Exception exception) { + JOptionPane.showMessageDialog(interactionWindow, "Exception dans addItemBook : " + exception); + } + } + } + } + + + private class AddItemFilm implements ActionListener { + /** + * @uml.property name="loginJPanel" + * @uml.associationEnd + */ + InputJPanel loginJPanel; + /** + * @uml.property name="passwordJPanel" + * @uml.associationEnd + */ + PasswordJPanel passwordJPanel; + /** + * @uml.property name="titleJPanel" + * @uml.associationEnd + */ + InputJPanel titleJPanel; + /** + * @uml.property name="kindJPanel" + * @uml.associationEnd + */ + InputJPanel kindJPanel; + /** + * @uml.property name="directorJPanel" + * @uml.associationEnd + */ + InputJPanel directorJPanel; + /** + * @uml.property name="scenaristJPanel" + * @uml.associationEnd + */ + InputJPanel scenaristJPanel; + /** + * @uml.property name="nbPagesJPanel" + * @uml.associationEnd + */ + InputJPanel nbPagesJPanel; + + public void actionPerformed(ActionEvent e) { + JPanel addFilmJP = new JPanel(); + addFilmJP.setLayout(new GridLayout(7, 1, 4, 4)); + loginJPanel = new InputJPanel(" pseudo membre ? ", memberLogin, windowWidth); + addFilmJP.add(loginJPanel); + passwordJPanel = new PasswordJPanel(" password membre ? ", memberPassword, windowWidth); + addFilmJP.add(passwordJPanel); + titleJPanel = new InputJPanel(" titre ? ", filmTitle, windowWidth); + addFilmJP.add(titleJPanel); + kindJPanel = new InputJPanel(" genre ? ", filmKind, windowWidth); + addFilmJP.add(kindJPanel); + directorJPanel = new InputJPanel(" réalisateur ? ", filmDirector, windowWidth); + addFilmJP.add(directorJPanel); + scenaristJPanel = new InputJPanel(" scénariste ? ", filmScenarist, windowWidth); + addFilmJP.add(scenaristJPanel); + nbPagesJPanel = new InputJPanel(" durée ? ", filmDuration, windowWidth); + addFilmJP.add(nbPagesJPanel); + JButton confirm = new JButton("Valider ajouter item film"); + confirm.setPreferredSize(new Dimension(windowWidth - 20, 25)); + confirm.addActionListener(new AddItemFilmAction()); + addFilmJP.add(confirm); + addFilmJP.setVisible(false); + interactionWindow.getContentPane().removeAll(); + interactionWindow.repaint(); + interactionWindow.setSize(windowWidth + 100, 320); + interactionWindow.getContentPane().add(addFilmJP); + addFilmJP.setVisible(true); + interactionWindow.setVisible(true); + interactionWindow.repaint(); + } + + class AddItemFilmAction implements ActionListener { + public void actionPerformed(ActionEvent e) { + try { + memberLogin = loginJPanel.getEntree(); + memberPassword = passwordJPanel.getPassword(); + filmTitle = titleJPanel.getEntree(); + filmKind = kindJPanel.getEntree(); + filmDirector = directorJPanel.getEntree(); + filmScenarist = scenaristJPanel.getEntree(); + filmDuration = nbPagesJPanel.getEntree(); + sn.addItemFilm(memberLogin, memberPassword, filmTitle, filmKind, filmDirector, filmScenarist, new Integer(filmDuration)); + } catch (Exception exception) { + JOptionPane.showMessageDialog(interactionWindow, "Exception dans addItemFilm : " + exception); + } + } + } + } + + + private class ReviewItem implements ActionListener { + /** + * @uml.property name="pseudoJPanel" + * @uml.associationEnd + */ + InputJPanel pseudoJPanel; + /** + * @uml.property name="passwordJPanel" + * @uml.associationEnd + */ + PasswordJPanel passwordJPanel; + /** + * @uml.property name="titleJPanel" + * @uml.associationEnd + */ + InputJPanel titleJPanel; + /** + * @uml.property name="noteJPanel" + * @uml.associationEnd + */ + InputJPanel noteJPanel; + /** + * @uml.property name="commentJScrollPane" + * @uml.associationEnd + */ + TextJScrollPane commentJScrollPane; + + String type; + + public ReviewItem(String type) { + this.type = type; + } + + public void actionPerformed(ActionEvent e) { + JPanel reviewerJP = new JPanel(); + commentJScrollPane = new TextJScrollPane(" commentaire ? ", comment, true, windowWidth); // comment ? + reviewerJP.add(commentJScrollPane); + JPanel loginPwdAndTitleJPanel = new JPanel(); + loginPwdAndTitleJPanel.setLayout(new GridLayout(5, 1, 4, 4)); + pseudoJPanel = new InputJPanel(" pseudo membre ? ", memberLogin, windowWidth); // member's login ? + loginPwdAndTitleJPanel.add(pseudoJPanel); + passwordJPanel = new PasswordJPanel(" password membre ? ", memberPassword, windowWidth); // member's password ? + loginPwdAndTitleJPanel.add(passwordJPanel); + titleJPanel = new InputJPanel(" titre ? ", bookTitle, windowWidth); // title ? + loginPwdAndTitleJPanel.add(titleJPanel); + noteJPanel = new InputJPanel(" note ? ", mark, windowWidth); // mark ? + loginPwdAndTitleJPanel.add(noteJPanel); + JButton valider = new JButton("Valider reviewer item " + type); // confirm review item ? + valider.setPreferredSize(new Dimension(windowWidth - 20, 25)); + valider.addActionListener(new ReviewItemAction()); + loginPwdAndTitleJPanel.add(valider); + reviewerJP.add(loginPwdAndTitleJPanel); + reviewerJP.setVisible(false); + interactionWindow.getContentPane().removeAll(); + interactionWindow.repaint(); + interactionWindow.setSize(windowWidth + 100, 470); + interactionWindow.getContentPane().add(reviewerJP); + reviewerJP.setVisible(true); + interactionWindow.setVisible(true); + interactionWindow.repaint(); + } + + class ReviewItemAction implements ActionListener { + public void actionPerformed(ActionEvent e) { + try { + memberLogin = pseudoJPanel.getEntree(); + memberPassword = passwordJPanel.getPassword(); + bookTitle = titleJPanel.getEntree(); + mark = noteJPanel.getEntree(); + comment = commentJScrollPane.getText(); + if (type.equals("livre")) //book + sn.reviewItemBook(memberLogin, memberPassword, bookTitle, new Float(mark), comment); + if (type.equals("film")) // film + sn.reviewItemFilm(memberLogin, memberPassword, bookTitle, new Float(mark), comment); + + } catch (Exception exception) { + if (type.equals("livre")) // book + JOptionPane.showMessageDialog(interactionWindow, "Exception dans reviewItemBook : " + exception); + if (type.equals("film")) // film + JOptionPane.showMessageDialog(interactionWindow, "Exception dans reviewItemFilm : " + exception); + } + } + } + } + + + /** + * Creates a new <i>SocialNetwork</i> with <ul> + * <li>3 users (login/pwd) : Paul/paul, Antoine/antoine, Alice/alice</li> + * <li>3 books (title) : "Lignes de faille","La peste", "Guerre et Paix", "Le train sifflera trois fois"</li> + * <li>4 films (title) : "Le train sifflera trois fois", "Avant l'aube", "Le discours d'un roi", "Black Swan", "Guerre et Paix"</li> + * </ul> + * and some opinions :<ul> + * <li>Book "La Peste" : Antoine (1.5),Alice (2.5)</li> + * <li>Book "Lignes de faille" : Alice (1.5)</li> + * <li>Book "Guerre et paix" : Alice (2.0), Antoine (4.5)</li> + * <li>Film "Black Swan" : Paul (2.5)</li> + * <li>Film "Avant l'aube" : Antoine (3.0), Paul (2.5)</li> + * <li>Film "Guerre et paix" : Alice (4.2), Paul (4.4)</li> + * </ul> + * Then add an opinion by a member who already gave one for the same item : Book "La Peste" / Antoine (3.8)</br> + * And finally launches an interactive HMI that gives access to the main actions on this <i>SocialNetwork</i>. + * + * @param args not used + */ + public static void main(String[] args) { + + try { + ISocialNetwork sn = new SocialNetwork(); // the SocialNetwork to interact with + + HMI ihm = new HMI(); + ihm.setTopic(sn); + + // add 3 members + sn.addMember("Paul", "paul", "lecteur impulsif"); + sn.addMember("Antoine", "antoine", "grand amoureux de littérature"); + sn.addMember("Alice", "alice", "23 ans, sexy"); + + + // add 3 books and 4 films + sn.addItemBook("Alice", "alice", "Lignes de faille", "roman", "Nancy Huston", 220); + sn.addItemFilm("Alice", "alice", "Le train sifflera trois fois", "western 1952", "Fred Zinnemann", "Carl Foreman", 85); + sn.addItemBook("Paul", "paul", "La peste", "roman", " Albert Camus", 336); + sn.addItemFilm("Paul", "paul", "Avant l'aube", "thriller 2011", "Raphael Jacoulot", "Lise Macheboeuf et Raphael Jacoulot", 104); + sn.addItemBook("Antoine", "antoine", "Guerre et Paix", "roman", "Leon Tosltoi", 1247); + sn.addItemFilm("Antoine", "antoine", "Le discours d'un roi", "drame historique 2010", "Tom Hooper", "David Seidler", 118); + sn.addItemFilm("Alice", "alice", "Black Swan", "drame 2010", "Darren Aronofsky", "John McLaughlin et Mark Heyman et Andres Heinz", 103); + sn.addItemBook("Alice", "alice", "Le train sifflera trois fois", "roman", " J. W. Cunningham", 257); + sn.addItemFilm("Paul", "paul", "Guerre et Paix", "aventure historique", "King Vidor", "Bridget Boland, Robert Westbery", 200); + + + // review some books and films + sn.reviewItemBook("Antoine", "antoine", "La Peste", 1.5f, "un peu daté"); + sn.reviewItemFilm("Paul", "paul", "Black Swan", 2.5f, "pour la performance..."); + sn.reviewItemFilm("Antoine", "antoine", "Avant l'aube", 3.0f, "tout le monde fume..."); + sn.reviewItemBook("Alice", "alice", "Lignes de faille", 1.5f, "famille attachante"); + // review a film and a book that were already reviewed by somebody else + sn.reviewItemFilm("Paul", "paul", "Avant l'aube", 2.5f, "mitigé"); + sn.reviewItemBook("Alice", "alice", "La Peste", 2.5f, " "); + // several reviews of a film and a book with the same title + sn.reviewItemBook("Alice", "alice", "Guerre et Paix", 2.0f, "un peu long"); + sn.reviewItemFilm("Alice", "alice", "Guerre et Paix", 4.2f, "on ne voit pas le temps passer"); + sn.reviewItemBook("Antoine", "antoine", "Guerre et Paix", 4.5f, "parfait pour une semaine pluvieuse"); + sn.reviewItemFilm("Paul", "paul", "Guerre et Paix", 4.4f, "choisir une salle confortable"); + // review a book that was already reviewed by the same member + sn.reviewItemBook("Antoine", "antoine", "La Peste", 3.8f, "bien meilleur à la relecture"); + + System.out.println(sn); + } catch (Exception e) { + System.out.println("Exception inattendue : " + e); + e.printStackTrace(); + } + + } } diff --git a/src/opinion/ISocialNetwork.java b/src/opinion/ISocialNetwork.java index 3ea81d21be83d95cde85246e3107624dd1272f76..fdce081f4d40eb14ff609961dd6f927e6020894d 100644 --- a/src/opinion/ISocialNetwork.java +++ b/src/opinion/ISocialNetwork.java @@ -9,7 +9,7 @@ import exceptions.MemberAlreadyExistsException; import exceptions.NotItemException; import exceptions.NotMemberException; -/** +/** * @author - A. Beugnard * @author - E. Cousin * @author - G. Ouvradou @@ -31,266 +31,266 @@ import exceptions.NotMemberException; * raise both, there is no way to predict which of the two will actually be * thrown. * </p> - * + * */ public interface ISocialNetwork { - /** - * Get the number of members registered in the <i>SocialNetwork</i> - * - * @return number of members - */ - public int nbMembers(); + /** + * Get the number of members registered in the <i>SocialNetwork</i> + * + * @return number of members + */ + public int nbMembers(); - /** - * Get the number of films registered in the <i>SocialNetwork</i> - * - * @return number of films - */ - public int nbFilms(); + /** + * Get the number of films registered in the <i>SocialNetwork</i> + * + * @return number of films + */ + public int nbFilms(); - /** - * Get the number of books registered in the <i>SocialNetwork</i> - * - * @return number of books - */ - public int nbBooks(); + /** + * Get the number of books registered in the <i>SocialNetwork</i> + * + * @return number of books + */ + public int nbBooks(); - /** - * Add a new member to the <i>SocialNetwork</i> - * - * @param login - * the new member's login - * @param password - * the new member's password - * @param profile - * a free String describing the new member's profile - * - * @throws BadEntryException - * <ul> - * <li>if login is not instantiated or contains less than one - * non-space character</li> - * <li>if password is not instantiated or contains less than - * four characters (not taking into account leading or trailing - * blanks)</li> - * <li>if profile is not instantiated</li> - * </ul> - * <br> - * - * @throws MemberAlreadyExistsException - * if a member with the same login is already registered in the - * <i>SocialNetwork</i> (same login : not case-sensitive and - * leadings/trailings blanks are not taken into account) - * - */ - public void addMember(String login, String password, String profile) - throws BadEntryException, MemberAlreadyExistsException; + /** + * Add a new member to the <i>SocialNetwork</i> + * + * @param login + * the new member's login + * @param password + * the new member's password + * @param profile + * a free String describing the new member's profile + * + * @throws BadEntryException + * <ul> + * <li>if login is not instantiated or contains less than one + * non-space character</li> + * <li>if password is not instantiated or contains less than + * four characters (not taking into account leading or trailing + * blanks)</li> + * <li>if profile is not instantiated</li> + * </ul> + * <br> + * + * @throws MemberAlreadyExistsException + * if a member with the same login is already registered in the + * <i>SocialNetwork</i> (same login : not case-sensitive and + * leadings/trailings blanks are not taken into account) + * + */ + public void addMember(String login, String password, String profile) + throws BadEntryException, MemberAlreadyExistsException; - /** - * Add a new film to the <i>SocialNetwork</i> - * - * @param login - * login of the member adding the film - * @param password - * password of the member adding the film - * @param title - * the new film's title - * @param kind - * the new film's kind (adventure, thriller, etc.) - * @param director - * the new film's director - * @param scenarist - * the new film's scenarist - * @param duration - * the new film's duration (in minutes) - * - * @throws BadEntryException - * <ul> - * <li>if login is not instantiated or contains less than one - * non-space character</li> - * <li>if password is not instantiated or contains less than - * four characters (not taking into account leading or trailing - * blanks)</li> - * <li>if title is not instantiated or contains less than one - * non-space character</li> - * <li>if kind is not instanciated</li> - * <li>if director is not instanciated</li> - * <li>if scenarist is not instanciated</li> - * <li>if duration is not stricly positive - * </ul> - * <br> - * @throws NotMemberException - * if login does not match with the login of a registered member - * in <i>SocialNetwork</i> or if password does not correspond to - * his registered password. - * @throws ItemFilmAlreadyExistsException - * : a film with the same title is already registered in the - * <i>SocialNetwork</i> (same title : not case-sensitive and - * leadings/trailings blanks are not taken into account) - * - */ - public void addItemFilm(String login, String password, String title, - String kind, String director, String scenarist, int duration) - throws BadEntryException, NotMemberException, - ItemFilmAlreadyExistsException; + /** + * Add a new film to the <i>SocialNetwork</i> + * + * @param login + * login of the member adding the film + * @param password + * password of the member adding the film + * @param title + * the new film's title + * @param kind + * the new film's kind (adventure, thriller, etc.) + * @param director + * the new film's director + * @param scenarist + * the new film's scenarist + * @param duration + * the new film's duration (in minutes) + * + * @throws BadEntryException + * <ul> + * <li>if login is not instantiated or contains less than one + * non-space character</li> + * <li>if password is not instantiated or contains less than + * four characters (not taking into account leading or trailing + * blanks)</li> + * <li>if title is not instantiated or contains less than one + * non-space character</li> + * <li>if kind is not instanciated</li> + * <li>if director is not instanciated</li> + * <li>if scenarist is not instanciated</li> + * <li>if duration is not stricly positive + * </ul> + * <br> + * @throws NotMemberException + * if login does not match with the login of a registered member + * in <i>SocialNetwork</i> or if password does not correspond to + * his registered password. + * @throws ItemFilmAlreadyExistsException + * : a film with the same title is already registered in the + * <i>SocialNetwork</i> (same title : not case-sensitive and + * leadings/trailings blanks are not taken into account) + * + */ + public void addItemFilm(String login, String password, String title, + String kind, String director, String scenarist, int duration) + throws BadEntryException, NotMemberException, + ItemFilmAlreadyExistsException; - /** - * Add a new book to the <i>SocialNetwork</i> - * - * @param login - * login of the member adding the book - * @param password - * password of the member adding the book - * @param title - * the new book's title - * @param kind - * the new book's kind (adventure, thriller, etc.) - * @param author - * the new book's author - * @param nbPages - * number of pages of the new book's - * - * @throws BadEntryException - * <ul> - * <li>if login is not instantiated or contains less than one - * non-space character</li> - * <li>if password is not instantiated or contains less than - * four characters (not taking into account leading or trailing - * blanks)</li> - * <li>if title is not instantiated or contains less than one - * non-space character</li> - * <li>if kind is not instanciated</li> - * <li>if author is not instanciated</li> - * <li>if nbPages is not stricly positive - * </ul> - * <br> - * @throws NotMemberException - * if login does not match with the login of a registered member - * in <i>SocialNetwork</i> or if password does not correspond to - * his registered password. - * @throws ItemBookAlreadyExistsException - * a book with the same title is already registered in the - * <i>SocialNetwork</i> (same title : not case-sensitive and - * leadings/trailings blanks are not taken into account) - * - */ - public void addItemBook(String login, String password, String title, - String kind, String author, int nbPages) throws BadEntryException, - NotMemberException, ItemBookAlreadyExistsException; + /** + * Add a new book to the <i>SocialNetwork</i> + * + * @param login + * login of the member adding the book + * @param password + * password of the member adding the book + * @param title + * the new book's title + * @param kind + * the new book's kind (adventure, thriller, etc.) + * @param author + * the new book's author + * @param nbPages + * number of pages of the new book's + * + * @throws BadEntryException + * <ul> + * <li>if login is not instantiated or contains less than one + * non-space character</li> + * <li>if password is not instantiated or contains less than + * four characters (not taking into account leading or trailing + * blanks)</li> + * <li>if title is not instantiated or contains less than one + * non-space character</li> + * <li>if kind is not instanciated</li> + * <li>if author is not instanciated</li> + * <li>if nbPages is not stricly positive + * </ul> + * <br> + * @throws NotMemberException + * if login does not match with the login of a registered member + * in <i>SocialNetwork</i> or if password does not correspond to + * his registered password. + * @throws ItemBookAlreadyExistsException + * a book with the same title is already registered in the + * <i>SocialNetwork</i> (same title : not case-sensitive and + * leadings/trailings blanks are not taken into account) + * + */ + public void addItemBook(String login, String password, String title, + String kind, String author, int nbPages) throws BadEntryException, + NotMemberException, ItemBookAlreadyExistsException; - /** - * Add in the <i>SocialNetwork</i> a new review for a film on behalf of a - * specific member.</br> If this member has already given a review for this - * same film before, the new review replaces the previous one. - * - * @param login - * login of the member adding the review - * @param password - * password of the member adding the review - * @param title - * the reviewed film's title - * @param mark - * the mark given by the member for this film - * @param comment - * the comment given by the member for this film - * - * @throws BadEntryException - * <ul> - * <li>if login is not instantiated or contains less than one - * non-space character</li> - * <li>if password is not instantiated or contains less than - * four characters (not taking into account leading or trailing - * blanks)</li> - * <li>if title is not instantiated or contains less than one - * non-space character</li> - * <li>if mark is not greater or equals to 0.0 and lesser or - * equals to 5.0.</li> - * <li>if comment is not instantiated</li> - * </ul> - * <br> - * @throws NotMemberException - * if login does not match with the login of a registered member - * in <i>SocialNetwork</i> or if password does not correspond to - * his registered password. - * @throws NotItemException - * if title is not registered as a film's title in the - * <i>SocialNetwork</i> - * - * @return mean of the marks for this film - */ - public float reviewItemFilm(String login, String password, String title, - float mark, String comment) throws BadEntryException, - NotMemberException, NotItemException; + /** + * Add in the <i>SocialNetwork</i> a new review for a film on behalf of a + * specific member.</br> If this member has already given a review for this + * same film before, the new review replaces the previous one. + * + * @param login + * login of the member adding the review + * @param password + * password of the member adding the review + * @param title + * the reviewed film's title + * @param mark + * the mark given by the member for this film + * @param comment + * the comment given by the member for this film + * + * @throws BadEntryException + * <ul> + * <li>if login is not instantiated or contains less than one + * non-space character</li> + * <li>if password is not instantiated or contains less than + * four characters (not taking into account leading or trailing + * blanks)</li> + * <li>if title is not instantiated or contains less than one + * non-space character</li> + * <li>if mark is not greater or equals to 0.0 and lesser or + * equals to 5.0.</li> + * <li>if comment is not instantiated</li> + * </ul> + * <br> + * @throws NotMemberException + * if login does not match with the login of a registered member + * in <i>SocialNetwork</i> or if password does not correspond to + * his registered password. + * @throws NotItemException + * if title is not registered as a film's title in the + * <i>SocialNetwork</i> + * + * @return mean of the marks for this film + */ + public float reviewItemFilm(String login, String password, String title, + float mark, String comment) throws BadEntryException, + NotMemberException, NotItemException; - /** - * Add in the <i>SocialNetwork</i> a new review for a book on behalf of a - * specific member.</br> If this member has already given a review for this - * same book before, the new review replaces the previous one. - * - * @param login - * login of the member adding the review - * @param password - * password of the member adding the review - * @param title - * the reviewed book's title - * @param mark - * the mark given by the member for this book - * @param comment - * the comment given by the member for this book - * - * @throws BadEntryException - * <ul> - * <li>if login is not instantiated or contains less than one - * non-space character</li> - * <li>if password is not instantiated or contains less than - * four characters (not taking into account leading or trailing - * blanks)</li> - * <li>if title is not instantiated or contains less than one - * non-space character</li> - * <li>if mark is not greater or equals to 0.0 and lesser or - * equals to 5.0.</li> - * <li>if comment is not instantiated</li> - * </ul> - * <br> - * @throws NotMemberException - * if login does not match with the login of a registered member - * in <i>SocialNetwork</i> or if password does not correspond to - * his registered password. - * @throws NotItemException - * if title is not registered as a book's title in the - * <i>SocialNetwork</i> - * - * @return mean of the marks for this book - */ - public float reviewItemBook(String login, String password, String title, - float mark, String comment) throws BadEntryException, - NotMemberException, NotItemException; + /** + * Add in the <i>SocialNetwork</i> a new review for a book on behalf of a + * specific member.</br> If this member has already given a review for this + * same book before, the new review replaces the previous one. + * + * @param login + * login of the member adding the review + * @param password + * password of the member adding the review + * @param title + * the reviewed book's title + * @param mark + * the mark given by the member for this book + * @param comment + * the comment given by the member for this book + * + * @throws BadEntryException + * <ul> + * <li>if login is not instantiated or contains less than one + * non-space character</li> + * <li>if password is not instantiated or contains less than + * four characters (not taking into account leading or trailing + * blanks)</li> + * <li>if title is not instantiated or contains less than one + * non-space character</li> + * <li>if mark is not greater or equals to 0.0 and lesser or + * equals to 5.0.</li> + * <li>if comment is not instantiated</li> + * </ul> + * <br> + * @throws NotMemberException + * if login does not match with the login of a registered member + * in <i>SocialNetwork</i> or if password does not correspond to + * his registered password. + * @throws NotItemException + * if title is not registered as a book's title in the + * <i>SocialNetwork</i> + * + * @return mean of the marks for this book + */ + public float reviewItemBook(String login, String password, String title, + float mark, String comment) throws BadEntryException, + NotMemberException, NotItemException; - /** - * Search for items in the <i>SocialNetwork</i>. - * - * @param title - * title of searched item(s) - * - * @throws BadEntryException - * if title is not instantiated or contains less than one - * non-space character - * - * @return LinkedList <String> a list of String representing all items (book - * and/or film) matching the searched name.</br> Each String will - * contain at least the score of the corresponding item. - */ - public LinkedList<String> consultItems(String title) - throws BadEntryException; + /** + * Search for items in the <i>SocialNetwork</i>. + * + * @param title + * title of searched item(s) + * + * @throws BadEntryException + * if title is not instantiated or contains less than one + * non-space character + * + * @return LinkedList <String> a list of String representing all items (book + * and/or film) matching the searched name.</br> Each String will + * contain at least the score of the corresponding item. + */ + public LinkedList<String> consultItems(String title) + throws BadEntryException; - /** - * A <i>SocialNetwork</i> is described at least by member's names, book's - * titles/scores and film's titles/scores. - * - * @return a String representing the <i>SocialNetwork</i>, with at least - * member's names, book's titles/scores and film's titles/scores. - */ - public String toString(); + /** + * A <i>SocialNetwork</i> is described at least by member's names, book's + * titles/scores and film's titles/scores. + * + * @return a String representing the <i>SocialNetwork</i>, with at least + * member's names, book's titles/scores and film's titles/scores. + */ + public String toString(); } diff --git a/src/opinion/Member.java b/src/opinion/Member.java index 3aefbc6383cd7b464c312bb98c291bce6259c007..76fd06354008ef4adcac7f14c4273351d97c75a8 100644 --- a/src/opinion/Member.java +++ b/src/opinion/Member.java @@ -4,12 +4,13 @@ package opinion; /** * This class allows us to create and register new members * A member has a login, a password and a profile that he has to register before connecting to the site + * * @author Maryam TENGKU * @author Neva MASSY * @version 1.0 * @since 1.0 */ -public class Member{ +public class Member { /** * Declaration of member's login, password and profile. @@ -18,9 +19,10 @@ public class Member{ /** * Construct new Member with specified login, password and profile. - * @param login member's login + * + * @param login member's login * @param password member's password - * @param profile member's profile + * @param profile member's profile */ Member(String login, String password, String profile) { this.login = login; @@ -30,31 +32,36 @@ public class Member{ /** * Returns member's login + * * @return login */ - public String getLogin(){ + public String getLogin() { return login; } /** * Returns member's password + * * @return password */ - public String getPassword(){ + public String getPassword() { return password; } /** * Returns member's profile + * * @return profile */ - public String getProfile(){ + public String getProfile() { return profile; } + /** * String function to display details of a member (login and profile) + * * @return string of details of a member */ public String toString() { diff --git a/src/opinion/SocialNetwork.java b/src/opinion/SocialNetwork.java index bd05cc594e7602bab51e72a3d702c26769f11b5f..3a0fd692baf7c37d462bd30faba8f1c34ea5e554 100644 --- a/src/opinion/SocialNetwork.java +++ b/src/opinion/SocialNetwork.java @@ -14,194 +14,241 @@ import exceptions.NotMemberException; * * @author Tengku Maryam BINTI * @author Neva MASSY - * * @version 1.0 */ public class SocialNetwork implements ISocialNetwork { - private LinkedList<Member> listMember; - private Member member; - private int nbmembers, nbbooks; - private LinkedList<Book> listBook; - private Book book; - - - /** - * Constructs new SocialNetwork instance with empty member list. - */ - public SocialNetwork() { - listMember = new LinkedList<Member>(); - nbmembers=0; - nbbooks=0; - - } - - /** - * Returns number of registered members. - * @return number of members - */ - @Override - public int nbMembers() { - // TODO Auto-generated method stub - return nbmembers; - } - - /** - * Returns number of films. - */ - @Override - public int nbFilms() { - // TODO Auto-generated method stub - return 0; - } - - /** - * Returns number of books. - */ - @Override - public int nbBooks() { - // TODO Auto-generated method stub - return 0; - } - - /** - * Checks whether a member already exists. - * @param login the login to check - * @return true if login exists, else return false - */ - public boolean memberRegister(String login) { - for(Member m : listMember) { - if(m.getLogin().toUpperCase().trim().equals(login.toUpperCase().trim())) { - - if (m.getPassword().toUpperCase().trim().equals(login.toUpperCase().trim())) { - return true; - } - } - }return false; - } - - public boolean validateuser(String login, String password) throws BadEntryException{ - boolean result = false; - if(login==null || login.length()<=1 ){ - throw new BadEntryException("login is null or empty"); - } - if(password==null || password.length()<=1 ){ - throw new BadEntryException("password is null or empty"); - } - - - else - return true; - } - - public boolean validatebook(String title) throws BadEntryException { - boolean result = false; - if(title==null || title.length()<=1 ){ - throw new BadEntryException("title is null or empty"); - } - for(Book b : listBook) { - if(title.toUpperCase().trim().equals(book.getTitle().toUpperCase().trim())) { - result = true; - } - } - return result; - } - - /** - * Adds a new member to the social network. - * @param login the new member's login - * @param password the new member's password - * @param profile a free String describing the new member's profile - * @throws BadEntryException if parameter is null or too short - * @throws MemberAlreadyExistsException if login already exists - */ - @Override - public void addMember(String login, String password, String profile) throws BadEntryException, MemberAlreadyExistsException{ - if (profile==null){ - throw new BadEntryException("profile is null or empty"); - } - if (memberRegister(login)) { - throw new MemberAlreadyExistsException(); - } - if(validateuser(login, password) ){ - member = new Member(login, password, profile); - listMember.add(member); - nbmembers++; - } - - if(validateuser(login, password) ){ - member = new Member(login, password, profile); - listMember.add(member); - nbmembers++; - } - - - - - } - - @Override - public void addItemBook(String login, String password, String title, - String kind, String author, int nbPages) throws BadEntryException, - NotMemberException, ItemBookAlreadyExistsException { - if (validateuser(login,password)){ - if (!memberRegister(login)) { - throw new NotMemberException("This user does not exist"); - - } - if (validatebook(title)) { - throw new ItemBookAlreadyExistsException(); - } - else{ - book = new Book(title, kind, author, nbPages); - listBook.add(book); - } - } - } - - @Override - public void addItemFilm(String login, String password, String title, String kind, String director, String scriptwriter, int duration) - throws BadEntryException, NotMemberException, ItemFilmAlreadyExistsException { - } - - @Override - public float reviewItemFilm(String login, String password, String title, - float mark, String comment) throws BadEntryException, NotMemberException, NotItemException { - // TODO Auto-generated method stub - return 0; - } - - public String toString(){ - String ret = ""; - for (Member m : listMember) { - ret += m.toString() + "\n"; - } - return ret; - //return (listMember.toString()); - - } - - @Override - public float reviewItemBook(String login, String password, String title, - float mark, String comment) throws BadEntryException, - NotMemberException, NotItemException { - // TODO Auto-generated method stub - return 0; - } - - @Override - public LinkedList<String> consultItems(String title) - throws BadEntryException { - return new LinkedList<String>(); - } - - /** - * @param args - */ - public static void main(String[] args) { - // TODO Auto-generated method stub - - } - -} + private LinkedList<Member> listMember; + private Member member; + private int nbmembers, nbbooks; + private LinkedList<Book> listBook; + private Book book; + + + /** + * Constructs new SocialNetwork instance with empty member list. + */ + public SocialNetwork() { + listMember = new LinkedList<Member>(); + listBook = new LinkedList<Book>(); + nbmembers = 0; + nbbooks = 0; + } + + /** + * Returns number of registered members. + * + * @return number of members + */ + @Override + public int nbMembers() { + // TODO Auto-generated method stub + return nbmembers; + } + + /** + * Returns number of films. + * + * @return 0 + */ + @Override + public int nbFilms() { + // TODO Auto-generated method stub + return 0; + } + + /** + * Returns number of books. + * + * @return number of books + */ + @Override + public int nbBooks() { + // TODO Auto-generated method stub + return listBook.size(); + } + + /** + * Checks whether a member already exists. + * + * @param login the login to be checked + * @return true if login exists, else return false + */ + public boolean memberRegister(String login) { + for (Member m : listMember) { + if (m.getLogin().trim().equalsIgnoreCase(login.trim())) { + return true; + } + } + return false; + } + + /** + * Validates the format of a user's login and password (not empty or too short) + * + * @param login the login to be validated + * @param password the password to be validated + * @return true if login and password are valid + * @throws BadEntryException if either login or password is invalid + */ + public boolean validateuser(String login, String password) throws BadEntryException { + boolean result = false; + if (login == null || login.length() <= 1) { + throw new BadEntryException("login is null or empty"); + } + if (password == null || password.length() < 4) { + throw new BadEntryException("password is null or empty"); + } + return true; + } + + /** + * Authenticates a user's login and password + * + * @param login the login of the user + * @param password the password of the user + * @return true if password corresponds to registered login, false if wrong password + */ + private boolean authenticateUser(String login, String password) { + for (Member m : listMember) { + if (m.getLogin().trim().equalsIgnoreCase(login.trim()) && + m.getPassword().trim().equals(password.trim())) { + return true; + } + } + return false; + } + + /** + * Checks if a book title is valid (not empty or too short) and if the book already exists + * + * @param title the title of the book to be validated + * @return true if book does not exist yet in system, false if already exists + * @throws BadEntryException if title is empty or too short + */ + public boolean validatebook(String title) throws BadEntryException { + boolean result = false; + if (title == null || title.length() <= 1) { + throw new BadEntryException("title is null or empty"); + } + for (Book b : listBook) { + if (b.compareTitle(title)) { + return true; + } + } + return false; + } + + /** + * Adds a new member to the social network. + * + * @param login the new member's login + * @param password the new member's password + * @param profile a free String describing the new member's profile + * @throws BadEntryException if parameter is null or too short + * @throws MemberAlreadyExistsException if login already exists + */ + @Override + public void addMember(String login, String password, String profile) throws BadEntryException, MemberAlreadyExistsException { + if (profile == null) { + throw new BadEntryException("profile is null or empty"); + } + validateuser(login, password); + if (memberRegister(login)) { + throw new MemberAlreadyExistsException(); + } + member = new Member(login.trim(), password.trim(), profile.trim()); + listMember.add(member); + nbmembers++; + } + + /** + * Adds a new book to the social network. + * + * @param login login of the member adding the book + * @param password password of the member adding the book + * @param title the new book's title + * @param kind the new book's kind + * @param author the new book's author + * @param nbPages number of pages of the new book's + * @throws BadEntryException if any input is invalid (empty or number pages equal or less than 0) + * @throws NotMemberException if login or password is wrong + * @throws ItemBookAlreadyExistsException if book already exists in system + */ + @Override + public void addItemBook(String login, String password, String title, String kind, String author, int nbPages) throws BadEntryException, NotMemberException, ItemBookAlreadyExistsException { + validateuser(login, password); + if (title == null || title.trim().isEmpty()) + throw new BadEntryException("Error: Invalid title."); + if (kind == null || kind.trim().isEmpty()) + throw new BadEntryException("Error: Invalid kind."); + if (author == null || author.trim().isEmpty()) + throw new BadEntryException("Error: Invalid author."); + if (nbPages <= 0) + throw new BadEntryException("Error: Invalid number of pages."); + if (!authenticateUser(login, password)) + throw new NotMemberException("Error: User doesn't exist"); + for (Book b : listBook) { + if (b.compareTitle(title)) { + throw new ItemBookAlreadyExistsException(); + } + } + book = new Book(title.trim(), kind.trim(), author.trim(), nbPages); + listBook.add(book); + nbbooks++; + } + + @Override + public void addItemFilm(String login, String password, String title, String kind, String director, String scriptwriter, int duration) + throws BadEntryException, NotMemberException, ItemFilmAlreadyExistsException { + } + + @Override + public float reviewItemFilm(String login, String password, String title, + float mark, String comment) throws BadEntryException, NotMemberException, NotItemException { + // TODO Auto-generated method stub + return 0; + } + + /** + * Displays a whole list of registered members + * + * @return list of registered members + */ + public String toString() { + if (listMember.isEmpty()) { + return "There are currently no registered members :("; + } + String ret = "\nRegistered members:\n"; + int counter = 1; + for (Member m : listMember) { + ret += counter + ". " + m.toString() + "\n"; + counter++; + } + return ret.trim(); + } + + @Override + public float reviewItemBook(String login, String password, String title, + float mark, String comment) throws BadEntryException, + NotMemberException, NotItemException { + // TODO Auto-generated method stub + return 0; + } + + @Override + public LinkedList<String> consultItems(String title) + throws BadEntryException { + return new LinkedList<String>(); + } + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} \ No newline at end of file diff --git a/src/opinion/package-info.java b/src/opinion/package-info.java index ebd7bee0cb423b7f877883c61c9f2c05bb476528..4899300120fa560f0f605e7c1b49f3e2d101f75d 100644 --- a/src/opinion/package-info.java +++ b/src/opinion/package-info.java @@ -1,4 +1,4 @@ /** - * Main package for SocialNetwork + * Main package for SocialNetwork */ package opinion; \ No newline at end of file diff --git a/src/tests/AddItemBookTest.java b/src/tests/AddItemBookTest.java index 282be8f2f39e5c4b93173fa70c7ce054d1d73162..07dc4b9c15e3d872b6cc30a4e119164352c8f3f5 100644 --- a/src/tests/AddItemBookTest.java +++ b/src/tests/AddItemBookTest.java @@ -1,373 +1,152 @@ package tests; + +import opinion.ISocialNetwork; +import opinion.SocialNetwork; import exceptions.BadEntryException; +import exceptions.MemberAlreadyExistsException; +import exceptions.NotMemberException; import exceptions.ItemBookAlreadyExistsException; import exceptions.NotTestReportException; -import exceptions.NotMemberException; -import opinion.ISocialNetwork; -import opinion.SocialNetwork; +/** + * Tests for the SocialNetwork.<i>addItemBook()</i> method. + */ public class AddItemBookTest { /** - * Function to test if we catch correctly bad entries - * @param sn - * @param login - * @param pwd - * @param title - * @param kind - * @param author - * @param nbPages - * @param testId - * @param errorMessage - * @return - */ - private static int addItemBookBadEntryTest(ISocialNetwork sn, String login, - String pwd, String title, String kind, String author, int nbPages, String testId, String errorMessage) { - - int nbBooks = sn.nbBooks(); // Number of books when starting to - // run this method - try { - sn.addItemBook(login, pwd, title, kind, author, nbPages); // Try to add this book - // Reaching this point means that no exception was thrown by - // addItemBook() - System.out.println("Err " + testId + " : " + errorMessage); // display - // the - // error - // message - return 1; // and return the "error" value - } catch (BadEntryException e) { // BadEntry exception was thrown by - // addItemBook() : this is a good start! - // Let's now check if 'sn' was not - // impacted - if (sn.nbBooks() != nbBooks) { // The number of members has - // changed : this is an error - // case. - System.out - .println("Err " - + testId - + " : BadEntry was thrown but the number of books was changed"); // Display - // a - // specific - // error - // message - return 1; // return "error" value - } else - // The number of books hasn't changed, which is considered a - // good indicator that 'sn' was not modified - return 0; // return success value : everything seems OK, nothing - // to display - } catch (Exception e) { // An exception was thrown by addItemBook(), but - // it was not the expected exception BadEntry - System.out.println("Err " + testId + " : unexpected exception. " - + e); // Display a specific error message - e.printStackTrace(); // Display contextual info about what happened - return 1; // return error value - } - } - - /** - * Function to test if the method send a error when the book already exist - * @param sn - * @param login - * @param pwd - * @param title - * @param kind - * @param author - * @param nbPages - * @param testId - * @param errorMessage - * @return + * Check that the method addItemBook throws BadEntryException or NotMemberException correctly. + * If OK, the method just returns 0. If not OK, displays an error message and returns 1. + * + * @param sn the <i>ISocialNetwork</i> + * @param login the login of the member + * @param password the password of the member + * @param title the title of the book + * @param kind the kind of the book + * @param author the author of the book + * @param nbPages the page number of the book + * @param expectedException the expected exception class + * @param testId the test ID + * @return 0 if test is OK, 1 if not OK */ - private static int addItemBookAlreadyExistsTest(ISocialNetwork sn, - String login, String pwd, String title, String kind, String author, int nbPages, String testId, - String errorMessage) { - int nbBooks = sn.nbBooks(); // Number of members when starting to - // process this method + private static int checkAddItemBookException(ISocialNetwork sn, String login, String password, String title, String kind, String author, int nbPages, Class<?> expectedException, String testId) { try { - sn.addItemBook(login, pwd, title, kind, author, nbPages); // Try to add this book - // Reaching this point means that no exception was thrown by - // addItemBook() - System.out.println("Err " + testId + " : " + errorMessage); // display - // the - // error - // message - return 1; // and return the "error" value - } catch ( ItemBookAlreadyExistsException e) {// AlreadyExists exception was - // thrown by addItemBook() : - // this is a good start! - // Let's now check if 'sn' - // was not impacted - if (sn.nbBooks() != nbBooks) { - System.out - .println("Err " - + testId - + " : ItemBookAlreadyExists was thrown, but the number of books was changed"); // Display - // a - // specific - // error - // message - return 1;// and return the "error" value - } else - return 0; // return success value : everything is OK, nothing to - // display - } catch (Exception e) { // An exception was thrown by addMember(), but - // it was not the expected exception - // AlreadyExists - System.out.println("Err " + testId + " : unexpected exception. " - + e); // Display a specific error message - e.printStackTrace(); // Display contextual info about what happened - return 1; // return error value + sn.addItemBook(login, password, title, kind, author, nbPages); + System.out.println("Err " + testId + " : Expected exception " + expectedException.getSimpleName() + " was not thrown"); + return 1; + } catch (Exception e) { + if (e.getClass().equals(expectedException)) { + return 0; + } else { + System.out.println("Err " + testId + " : Unexpected exception " + e); + e.printStackTrace(); + return 1; + } } - } /** - * Function to test if the method work correctly - * @param sn - * @param login - * @param pwd - * @param title - * @param kind - * @param author - * @param nbPages - * @param testId - * @return + * Check that the method addItemBook succeeds. + * If OK, the method just returns 0. If not OK, displays an error message and returns 1. + * + * @param sn the <i>ISocialNetwork</i> + * @param login the login of the member + * @param password the password of the member + * @param title the title of the book + * @param kind the kind of the book + * @param author the author of the book + * @param nbPages the number of pages of the book + * @param testId the test's ID + * @return 0 if test is OK, 1 if not OK */ - private static int addItemBookOKTest(ISocialNetwork sn, String login, - String pwd, String title, String kind, String author, int nbPages, String testId) { - int nbBooks = sn.nbBooks(); // Number of books when starting to - // process this method + private static int checkAddItemBookSuccess(ISocialNetwork sn, String login, String password, String title, String kind, String author, int nbPages, String testId) { try { - sn.addItemBook(login, pwd, title, kind, author, nbPages); // Try to add this book - // No exception was thrown. That's a good start ! - if (sn.nbBooks() != nbBooks + 1) { // But the number of books - // hasn't changed - // accordingly - System.out.println("Err " + testId - + " : the number of books (" + nbBooks - + ") was not incremented"); // Error message displayed - return 1; // return error code - } else - return 0; // return success code : everything is OK, nothing to - // display - } catch (Exception e) {// An exception was thrown by addMember() : this - // is an error case - System.out - .println("Err " + testId + " : unexpected exception " + e); // Error - // message - // displayed - e.printStackTrace(); // Display contextual info about what happened - return 1; // return error code + sn.addItemBook(login, password, title, kind, author, nbPages); + return 0; + } catch (Exception e) { + System.out.println("Err " + testId + " : Unexpected exception " + e); + e.printStackTrace(); + return 1; } } /** - * Function to test if the method send a error the member is not registerd - * @param sn - * @param login - * @param pwd - * @param title - * @param kind - * @param author - * @param nbPages - * @param testId - * @param errorMessage - * @return + * Main test for addItemBook: + * Checks if the method throws BadEntryException or NotMemberException in non-nominal conditions + * Checks if the method works correctly in nominal conditions + * + * @return a summary of the performed tests */ - private static int NotMemberTest(ISocialNetwork sn, - String login, String pwd, String title, String kind, String author, int nbPages, String testId, - String errorMessage) { - int nbBooks = sn.nbBooks(); // Number of members when starting to - // process this method - try { - sn.addItemBook(login, pwd, title, kind, author, nbPages); // Try to add this book - // Reaching this point means that no exception was thrown by - // addItemBook() - System.out.println("Err " + testId + " : " + errorMessage); // display - // the - // error - // message - return 1; // and return the "error" value - } catch ( NotMemberException e) {// AlreadyExists exception was - // thrown by addItemBook() : - // this is a good start! - // Let's now check if 'sn' - // was not impacted - if (sn.nbBooks() != nbBooks) { - System.out - .println("Err " - + testId - + " : NotMember was thrown, but the number of books was changed"); // Display - // a - // specific - // error - // message - return 1;// and return the "error" value - } else - return 0; // return success value : everything is OK, nothing to - // display - } catch (Exception e) { // An exception was thrown by addMember(), but - // it was not the expected exception - // AlreadyExists - System.out.println("Err " + testId + " : unexpected exception. " - + e); // Display a specific error message - e.printStackTrace(); // Display contextual info about what happened - return 1; // return error value - } + public static TestReport test() { - } - - /** - * Function to test if the method add some members correctly - * @param sn - * @param login - * @param pwd - * @param profile - * @param testId - * @return - */ - private static int addMemberOKTest(ISocialNetwork sn, String login, - String pwd, String profile, String testId) { - int nbMembers = sn.nbMembers(); // Number of members when starting to - // process this method + ISocialNetwork sn = new SocialNetwork(); try { - sn.addMember(login, pwd, profile); // Try to add this member - // No exception was thrown. That's a good start ! - if (sn.nbMembers() != nbMembers + 1) { // But the number of members - // hasn't changed - // accordingly - System.out.println("Err " + testId - + " : the number of members (" + nbMembers - + ") was not incremented"); // Error message displayed - return 1; // return error code - } else - return 0; // return success code : everything is OK, nothing to - // display - } catch (Exception e) {// An exception was thrown by addMember() : this - // is an error case - System.out - .println("Err " + testId + " : unexpected exception " + e); // Error - // message - // displayed - e.printStackTrace(); // Display contextual info about what happened - return 1; // return error code + sn.addMember("usertest", "passwordtest1", "profile1"); + } catch (BadEntryException | MemberAlreadyExistsException e) { + System.out.println("Err : Unexpected exception " + e); + e.printStackTrace(); } - } - - - public static TestReport test(){ - - ISocialNetwork sn = new SocialNetwork(); - - int nbBooks = sn.nbBooks(); // number of books in 'sn' (should be 0 - - int nbTests = 0; // total number of performed tests - int nbErrors = 0; // total number of failed tests + int nbTests = 0; + int nbErrors = 0; System.out.println("Testing addItemBook()"); - // <=> test n°1 - - // check if incorrect parameters cause addItemBook() to throw BadEntry - // exception - //populate 'sn' with 3 members - nbErrors += addMemberOKTest(sn,"Paul","paul","","1.0a"); - nbErrors += addMemberOKTest(sn,"Antoine","antoine","", "1.0b"); - nbErrors += addMemberOKTest(sn,"Alice", "alice","", "1.0c"); + // Non-nominal scenarios - - nbTests++; - nbErrors += addItemBookBadEntryTest(sn, null, "password1.1", "test1.1","drame","eleve",10, "1.1", - "addItemBook() doesn't reject null logins"); - nbTests++; - nbErrors += addItemBookBadEntryTest(sn," ","password1.2","test1.2","drame","eleve",10,"1.2", - "addItemBook() doesn't reject logins that don't contain at least one character other than space"); - nbTests++; - nbErrors += addItemBookBadEntryTest(sn, "B", null,"test1.3","drame","eleve",10, "1.3", - "addItemBook() doesn't reject null passwords"); - nbTests++; - nbErrors += addItemBookBadEntryTest(sn,"B"," qwd ","test1.4","drame","eleve",10,"1.4", - "addItemBook() doesn't reject passwords that don't contain at least 4 characters (not taking into account leading or trailing blanks)"); + // Test 2.1 : Invalid login (empty) nbTests++; - nbErrors += addItemBookBadEntryTest(sn,"BB", "password1.5", null,"drame","eleve",10, "1.5", - "addItemBook() doesn't reject null title"); - nbTests++; - nbErrors += addItemBookBadEntryTest(sn,"A","password1.6"," ","drame","eleve",10,"1.6", - "addItemBook() doesn't reject title that don't contain at least one character other than space"); - nbTests++; - nbErrors += addItemBookBadEntryTest(sn, "AA", "password1.7", "test1.7",null,"eleve",10, "1.7", - "addItemBook() doesn't reject null kind"); - nbTests++; - nbErrors += addItemBookBadEntryTest(sn, "AAA", "password1.8", "test1.8","drame",null,10, "1.8", - "addItemBook() doesn't reject null author"); - nbTests++; - nbErrors += addItemBookBadEntryTest(sn, "AAA", "password1.8", "test1.8","drame","eleve",-10, "1.8", - "addItemBook() doesn't reject negative number of pages"); - - // <=> test n°2 - - + nbErrors += checkAddItemBookException(sn, "", "passwordtest1", "New Book", "Comedy", "Juan Perez", 300, BadEntryException.class, "2.1"); - // populate 'sn' with 3 books - - nbTests++; - nbErrors += addItemBookOKTest(sn,"Paul","paul","Germinal","Roman","Emile Zola",462,"2.1a"); + // Test 2.2 : Invalid password(less than 8 characters) nbTests++; - nbErrors += addItemBookOKTest(sn,"Antoine","antoine","Les miserables","Roman","Victor Hugo",2598, "2.1b"); - nbTests++; - nbErrors += addItemBookOKTest(sn,"Alice", "alice","Les fleurs du mal","Poesie","Charles Baudelaire",151, "2.1c"); - - // try to add already registered books + nbErrors += checkAddItemBookException(sn, "usertest", "abc", "New Book", "Comedy", "Juan Perez", 300, BadEntryException.class, "2.2"); + // Test 2.3 : Invalid title (empty) nbTests++; - nbErrors += addItemBookAlreadyExistsTest(sn, "Paul","paul",new String("Germinal"),"Roman", "Emile Zola",462, "2.2", - "The first book with the same title's name was accepted as a new book "); + nbErrors += checkAddItemBookException(sn, "usertest", "passwordtest1", "", "Comedy", "Juan Perez", 300, BadEntryException.class, "2.3"); + // Test 2.4 : Uninstantiated kind nbTests++; - nbErrors += addItemBookAlreadyExistsTest(sn, "Alice", "alice",new String("Les fleurs du mal"),"Poesie","Charles Baudelaire",151, "2.3", - "The last book was accepted as a new book"); + nbErrors += checkAddItemBookException(sn, "usertest", "passwordtest1", "New Book", null, "Juan Perez", 300, BadEntryException.class, "2.4"); + // Test 2.5 : Uninstantiated author nbTests++; - nbErrors += addItemBookAlreadyExistsTest(sn,"Antoine","antoine",new String("lEs miSerabLes"),"Roman","Victor Hugo",2598,"2.4", - "An already registered book, but with different case, was accepted as login for a new member"); - nbTests++; - nbErrors += addItemBookAlreadyExistsTest(sn,"Antoine","antoine",new String(" Les miserables "),"Roman","Victor Hugo",2598,"2.5", - "An already registered book title, surrounded by leading/trailing blanks, was accepted as title for a new book"); + nbErrors += checkAddItemBookException(sn, "usertest", "passwordtest1", "New Book", "Comedy", null, 300, BadEntryException.class, "2.5"); + // Test 2.6 : Invalid number of pages (not strictly positive) + nbTests++; + nbErrors += checkAddItemBookException(sn, "usertest", "passwordtest1", "New Book", "Comedy", "Juan Perez", 0, BadEntryException.class, "2.6"); - //try to enter a book with no register login + // Test 2.7 : Non-existent member nbTests++; - nbErrors += NotMemberTest(sn, new String("Clementine"),"bloblo","Le Cygne","Poesie","Charles Baudelaire", 374,"3.1","The login used is not registered"); + nbErrors += checkAddItemBookException(sn, "nonExistentUser", "passwordtest1", "New Book", "Comedy", "Juan Perez", 300, NotMemberException.class, "2.7"); - //try to enter wrong password + // Test 2.8 : Invalid password(null) nbTests++; - nbErrors += NotMemberTest(sn,"Paul",new String("blublu"),"Jamais Plus","Roman", "Colleen Hoover", 445,"3.2","You're password is incorrect"); + nbErrors += checkAddItemBookException(sn, "usertest", "", "New Book", "Comedy", "Juan Perez", 300, BadEntryException.class, "2.8"); + + // Nominal scenarios - //try to enter a new book with a good login + // Test 2.9 : Valid book addition nbTests++; - nbErrors += addItemBookOKTest(sn,"Alice","alice","Le Cygne","Poesie","Charles Baudelaire", 374,"3.3"); + nbErrors += checkAddItemBookSuccess(sn, "usertest", "passwordtest1", "Effective Java", "Programming", "Joshua Bloch", 416, "2.9"); - // Display final state of 'sn' - System.out.println("Final state of the social network : " + sn); + // Test 2.10 : Add an existing book + nbTests++; + nbErrors += checkAddItemBookException(sn, "usertest", "passwordtest1", "Effective Java", "Programming", "Jose Pablo", 416, ItemBookAlreadyExistsException.class, "2.10"); // Print a summary of the tests and return test results - try{ + try { TestReport tr = new TestReport(nbTests, nbErrors); System.out.println("AddItemBookTest : " + tr); return tr; - } - catch (NotTestReportException e){ //This shouldn't happen - System.out.println("Unexpected error in AddMemberTest test code - Can't return valuable test results"); + } catch (NotTestReportException e) { + System.out.println("Unexpected error in AddItemBookTest test code - Can't return valuable test results"); return null; } - } public static void main(String[] args) { test(); - } - } - diff --git a/src/tests/InitTest.java b/src/tests/InitTest.java index 9d6ce394d8e571d857a6840f7b5294ca3b197ad6..bd6ac053a7ad01e824d852dd8997fd90d7f09415 100644 --- a/src/tests/InitTest.java +++ b/src/tests/InitTest.java @@ -5,8 +5,9 @@ import opinion.ISocialNetwork; import opinion.SocialNetwork; -/** +/** * Tests for the <i>SocialNetwork()</i> constructor. + * * @author B. Prou, E Cousin, GO * @version V2.0 - 2011-2018 */ @@ -14,70 +15,68 @@ import opinion.SocialNetwork; public class InitTest { + /** + * Main test for the <i>SocialNetwork()</i> constructor. + * + * @return a summary of the performed tests + */ + public static TestReport test() { + int nbTests = 0; // total number of performed tests + int nbErrors = 0; // total number of failed tests + + + System.out.println("Testing brand new Social Networks... "); + + + try { + + // a fresh SocialNetwork should not contain any member, book or film + ISocialNetwork sn = new SocialNetwork(); + nbTests++; + if (sn.nbMembers() != 0) { + nbErrors++; + System.out.println("Err 0.1 : non-zero number of members in a newly instanciated Social Network"); + } + nbTests++; + if (sn.nbBooks() != 0) { + nbErrors++; + System.out.println("Err 0.2 : non-zero number of books in a newly instanciated Social Network"); + } + nbTests++; + if (sn.nbFilms() != 0) { + nbErrors++; + System.out.println("Err 0.3 : non-zero number of films in a newly instanciated Social Network"); + } + + + // Show the Social Network, just in case the tester could detect a problem + System.out.println("Here is the newly created SocialNetwork :"); + System.out.println(sn); + + } catch (Exception e) { + System.out.println("Err 0.4 : Unexpected exception : " + e); + e.printStackTrace(); + System.exit(1); + } + // Print a summary of the tests and return test results + try { + TestReport tr = new TestReport(nbTests, nbErrors); + System.out.println("InitTest : " + tr); + return tr; + } catch (NotTestReportException e) { //This shouldn't happen + System.out.println("Unexpected error in InitTest test code - Can't return valuable test results"); + return null; + } + } + + /** + * Launches test() + * + * @param args not used + */ + public static void main(String[] args) { + test(); + } + - /** - * Main test for the <i>SocialNetwork()</i> constructor. - * @return a summary of the performed tests - */ - public static TestReport test(){ - int nbTests = 0; // total number of performed tests - int nbErrors = 0; // total number of failed tests - - - System.out.println("Testing brand new Social Networks... "); - - - try { - - // a fresh SocialNetwork should not contain any member, book or film - ISocialNetwork sn = new SocialNetwork(); - nbTests++; - if (sn.nbMembers()!= 0) { - nbErrors++; - System.out.println("Err 0.1 : non-zero number of members in a newly instanciated Social Network"); - } - nbTests++; - if (sn.nbBooks() != 0) { - nbErrors++; - System.out.println("Err 0.2 : non-zero number of books in a newly instanciated Social Network"); - } - nbTests++; - if (sn.nbFilms() != 0) { - nbErrors++; - System.out.println("Err 0.3 : non-zero number of films in a newly instanciated Social Network"); - } - - - // Show the Social Network, just in case the tester could detect a problem - System.out.println("Here is the newly created SocialNetwork :"); - System.out.println(sn); - - } - catch (Exception e) { - System.out.println("Err 0.4 : Unexpected exception : " + e); - e.printStackTrace(); - System.exit(1); - } - // Print a summary of the tests and return test results - try{ - TestReport tr = new TestReport(nbTests, nbErrors); - System.out.println("InitTest : " + tr); - return tr; - } - catch (NotTestReportException e){ //This shouldn't happen - System.out.println("Unexpected error in InitTest test code - Can't return valuable test results"); - return null; - } - } - - /** - * Launches test() - * @param args not used - */ - public static void main(String[] args) { - test(); - } - - - } \ No newline at end of file diff --git a/src/tests/SocialNetworkTest.java b/src/tests/SocialNetworkTest.java index c991d3e1dc75d8372a9bd7eee0a54a90603c5a52..f30c2281d284a5d006670e37775f677026a0f3c5 100644 --- a/src/tests/SocialNetworkTest.java +++ b/src/tests/SocialNetworkTest.java @@ -1,40 +1,40 @@ package tests; - -/** +/** * This class launches a test suite for the SocialNetwork + * * @author B. Prou, GO * @version V2.0 - April 2018 - * */ public class SocialNetworkTest { - /** - * @param args not used - */ - public static void main(String[] args) { - - try { - TestReport testSuiteReport = new TestReport(0,0); - TestReport tr; - tr = InitTest.test(); - testSuiteReport.add(tr); - System.out.println("\n\n **********************************************************************************************\n"); - // - tr = AddMemberTest.test(); - testSuiteReport.add(tr); - System.out.println("\n\n **********************************************************************************************\n"); - // - // TODO : calls to other tests have to be added from here - // - - - // End of the test suite : give some feedback to the tester - System.out.println("Global tests results : \n" + testSuiteReport); - } - catch (Exception e) {System.out.println("ERROR : Some exception was throw unexpectedly");} - - } + /** + * @param args not used + */ + public static void main(String[] args) { + + try { + TestReport testSuiteReport = new TestReport(0, 0); + TestReport tr; + tr = InitTest.test(); + testSuiteReport.add(tr); + System.out.println("\n\n **********************************************************************************************\n"); + // + tr = AddMemberTest.test(); + testSuiteReport.add(tr); + System.out.println("\n\n **********************************************************************************************\n"); + // + // TODO : calls to other tests have to be added from here + // + + + // End of the test suite : give some feedback to the tester + System.out.println("Global tests results : \n" + testSuiteReport); + } catch (Exception e) { + System.out.println("ERROR : Some exception was throw unexpectedly"); + } + + } } diff --git a/src/tests/TestReport.java b/src/tests/TestReport.java index c43d604d8990610fc51f757f9d7806d43fee0d78..f6ac78dcd480396900d11d26875972c30539ed2c 100644 --- a/src/tests/TestReport.java +++ b/src/tests/TestReport.java @@ -1,112 +1,111 @@ package tests; + import exceptions.NotTestReportException; /** * TestReport helps to convey information about performed tests - * @author cousin * + * @author cousin */ public class TestReport { - - private int nbTests; // Total number of tests that were run - private int nbErrors; // Total number of errors that were detected while running these tests - - /** - * - * @param nbTests Total number of tests that were run. - * @param nbErrors Total number of errors that were detected while running these tests. - * @throws NotTestReportException if nbTests and/or nbErrors are not complying with the following constraints : nbTests and nbErrors should be positive, nbTests should be greater or equal to nbErrors - */ - public TestReport (int nbTests, int nbErrors) throws NotTestReportException { - if ((nbTests<0) || (nbErrors <0) || (nbTests < nbErrors)) throw new NotTestReportException(); - this.nbTests = nbTests; - this.nbErrors = nbErrors; - } - - /** - * Get a String representation of a TestReport - */ - public String toString (){ - String s = "[ Nb of performed tests : " + nbTests + " / nb of detected error(s) : "+ nbErrors + " ]"; - return s; - } - - /** - * Add to the current TestReport the results contained in an other TestReport - * @param other another TestReport - */ - public void add (TestReport other){ - this.nbTests += other.nbTests; - this.nbErrors += other.nbErrors; - } - - /** - * Two TestReport are equals if all their attributes are equals. - */ - public boolean equals (Object o){ - if (o instanceof TestReport){ - TestReport tr = (TestReport) o; - return ((this.nbTests == tr.nbTests) && (this.nbErrors == tr.nbErrors)); - } - return false; - } - /** - * This is only a (very) small auto-test for the TestReport class - * @param args not used - */ - public static void main(String[] args) { - int nbErrors = 0; - System.out.println("*** Launching auto-test for TestReport class ***"); - - try { - // basic tests - TestReport tr1 = new TestReport(10,5); - TestReport tr2 = new TestReport(3,0); - tr1.add(tr2); // this should change tr1 attributes appropriately : - if ((tr1.nbTests != 13)||(tr1.nbErrors != 5)){ - nbErrors++; - System.out.println("Error : TestReport.add() seems not to work appropriately"); - } - // - TestReport tr3 = new TestReport(3,0); - if (! tr3.equals(tr2)){ - nbErrors++; - System.out.println("Autotest error : TestReport.equals() seems not to work appropriately"); - } - // - tr3.add(new TestReport(0,0)); - if (! tr3.equals(tr2)){ - nbErrors++; - System.out.println("Autotest error : TestReport.add() seems not to work appropriately"); - } - System.out.println("Here is how TestReport is converted into String :"); - System.out.println("--------------------------------"); - System.out.println("tr1 :" + tr1); - System.out.println("tr2 :" + tr2); - System.out.println("--------------------------------"); - } - catch (NotTestReportException e){ - nbErrors++; - System.out.println ("Autotest error : NotTestReportException was thrown unexpectedly"); - } - // check if TestReport() throws NotTestReportException for some inaccurate arguments - try{ - TestReport tr = new TestReport(10,-5); - // the end of this bloc shouldn't be executed - nbErrors++; - System.out.println ("Autotest error : NotTestReportException should have been thrown"); - } - catch (NotTestReportException e){ // nothing to do here because it is what was awaited - } - - if (nbErrors==0) { - System.out.println("*** Auto-test was OK ***"); - } - else { - System.out.println("*** Errors were detected in the auto-test. The TestReport class shoudn't be used ***"); - } - - } + private int nbTests; // Total number of tests that were run + private int nbErrors; // Total number of errors that were detected while running these tests + + /** + * @param nbTests Total number of tests that were run. + * @param nbErrors Total number of errors that were detected while running these tests. + * @throws NotTestReportException if nbTests and/or nbErrors are not complying with the following constraints : nbTests and nbErrors should be positive, nbTests should be greater or equal to nbErrors + */ + public TestReport(int nbTests, int nbErrors) throws NotTestReportException { + if ((nbTests < 0) || (nbErrors < 0) || (nbTests < nbErrors)) throw new NotTestReportException(); + this.nbTests = nbTests; + this.nbErrors = nbErrors; + } + + /** + * Get a String representation of a TestReport + */ + public String toString() { + String s = "[ Nb of performed tests : " + nbTests + " / nb of detected error(s) : " + nbErrors + " ]"; + return s; + } + + /** + * Add to the current TestReport the results contained in an other TestReport + * + * @param other another TestReport + */ + public void add(TestReport other) { + this.nbTests += other.nbTests; + this.nbErrors += other.nbErrors; + } + + /** + * Two TestReport are equals if all their attributes are equals. + */ + public boolean equals(Object o) { + if (o instanceof TestReport) { + TestReport tr = (TestReport) o; + return ((this.nbTests == tr.nbTests) && (this.nbErrors == tr.nbErrors)); + } + return false; + } + + /** + * This is only a (very) small auto-test for the TestReport class + * + * @param args not used + */ + public static void main(String[] args) { + int nbErrors = 0; + System.out.println("*** Launching auto-test for TestReport class ***"); + + try { + // basic tests + TestReport tr1 = new TestReport(10, 5); + TestReport tr2 = new TestReport(3, 0); + tr1.add(tr2); // this should change tr1 attributes appropriately : + if ((tr1.nbTests != 13) || (tr1.nbErrors != 5)) { + nbErrors++; + System.out.println("Error : TestReport.add() seems not to work appropriately"); + } + // + TestReport tr3 = new TestReport(3, 0); + if (!tr3.equals(tr2)) { + nbErrors++; + System.out.println("Autotest error : TestReport.equals() seems not to work appropriately"); + } + // + tr3.add(new TestReport(0, 0)); + if (!tr3.equals(tr2)) { + nbErrors++; + System.out.println("Autotest error : TestReport.add() seems not to work appropriately"); + } + System.out.println("Here is how TestReport is converted into String :"); + System.out.println("--------------------------------"); + System.out.println("tr1 :" + tr1); + System.out.println("tr2 :" + tr2); + System.out.println("--------------------------------"); + } catch (NotTestReportException e) { + nbErrors++; + System.out.println("Autotest error : NotTestReportException was thrown unexpectedly"); + } + // check if TestReport() throws NotTestReportException for some inaccurate arguments + try { + TestReport tr = new TestReport(10, -5); + // the end of this bloc shouldn't be executed + nbErrors++; + System.out.println("Autotest error : NotTestReportException should have been thrown"); + } catch (NotTestReportException e) { // nothing to do here because it is what was awaited + } + + if (nbErrors == 0) { + System.out.println("*** Auto-test was OK ***"); + } else { + System.out.println("*** Errors were detected in the auto-test. The TestReport class shoudn't be used ***"); + } + + } }