View Javadoc

1   /*
2    * #%L
3    * Wao :: Business
4    * %%
5    * Copyright (C) 2009 - 2010 Ifremer
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Affero General Public License as published by
9    * the Free Software Foundation, either version 3 of the License, or
10   * (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   * 
17   * You should have received a copy of the GNU Affero General Public License
18   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19   * #L%
20   */
21  
22  package fr.ifremer.wao.service;
23  
24  import fr.ifremer.wao.bean.ContactFilter;
25  import fr.ifremer.wao.bean.ContactFilterImpl;
26  import fr.ifremer.wao.bean.UserRole;
27  import fr.ifremer.wao.entity.Contact;
28  import fr.ifremer.wao.entity.WaoUser;
29  import org.junit.Assert;
30  import org.junit.Before;
31  import org.junit.Test;
32  import org.nuiton.topia.TopiaException;
33  import org.slf4j.Logger;
34  import org.slf4j.LoggerFactory;
35  
36  import java.util.Map;
37  
38  /**
39   * ServiceContactImplTest
40   *
41   * Created: 3 mai 2010
42   *
43   * @author fdesbois
44   * $Id: ServiceContactTest.java 1633 2012-11-22 21:45:18Z bleny $
45   */
46  public class ServiceContactTest extends AbstractServiceTest {
47  
48      private static final Logger log =
49              LoggerFactory.getLogger(ServiceContactTest.class);
50  
51      private ServiceContact service;
52  
53      @Before
54      public void initialize() {
55          service = manager.getServiceContact();
56      }
57  
58      @Test
59      public void testGetContactsFilteredByObserver() throws TopiaException {
60          /** PREPARE DATA **/
61          Contact contact = obsMerFixtures.defaultContact();
62  
63          /** EXEC METHOD **/
64          ContactFilter filter = new ContactFilterImpl();
65          filter.setObserver(obsMerFixtures.homerSimpson());
66  
67          log.info("test 1 : Ok good filter, contact is correctly returned");
68          Map<String, Contact> results = service.getContacts(filter);
69  
70          Assert.assertEquals(1, results.size());
71          Contact contactFind = results.get(contact.getTopiaId());
72          Assert.assertEquals(contact, contactFind);
73  
74          log.info("test 2 : Bad filter, no contact is returned");
75          WaoUser observer2 = obsMerFixtures.billMurray();
76  
77          filter.setObserver(observer2);
78  
79          results = service.getContacts(filter);
80          Assert.assertEquals(0, results.size());
81      }
82  
83      @Test
84      public void testSaveContactWithMultipleObservers() throws TopiaException {
85          Contact contact = obsMerFixtures.defaultContact();
86  
87          WaoUser observer1 = obsMerFixtures.jeanMichmuche();
88          WaoUser observer2 = obsMerFixtures.jacquesMichmuche();
89          contact.addSecondaryObservers(observer1);
90          contact.addSecondaryObservers(observer2);
91  
92          service.saveContact(obsMerFixtures.jeanMichmucheAsObserver(), contact, false);
93  
94          Contact savedContact = service.getContact(contact.getTopiaId());
95          Assert.assertEquals(2, savedContact.getSecondaryObservers().size());
96  
97          contact.clearSecondaryObservers();
98          service.saveContact(obsMerFixtures.jeanMichmucheAsObserver(), contact, false);
99          savedContact = service.getContact(contact.getTopiaId());
100         Assert.assertEquals(0, savedContact.getSecondaryObservers().size());
101     }
102 
103 
104 }