Author: fdesbois Date: 2010-12-23 19:09:52 +0000 (Thu, 23 Dec 2010) New Revision: 856 Log: Add broken test for updateUser Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java trunk/wao-business/src/test/java/fr/ifremer/wao/AbstractServiceTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceUserImplTest.java Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java 2010-12-23 17:15:46 UTC (rev 855) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java 2010-12-23 19:09:52 UTC (rev 856) @@ -24,36 +24,10 @@ package fr.ifremer.wao.service; -import fr.ifremer.wao.WaoBusinessException; +import fr.ifremer.wao.*; import fr.ifremer.wao.WaoBusinessException.Type; -import fr.ifremer.wao.WaoContext; -import fr.ifremer.wao.WaoDAOHelper; -import fr.ifremer.wao.WaoException; -import fr.ifremer.wao.WaoProperty; -import fr.ifremer.wao.WaoQueryHelper; -import fr.ifremer.wao.bean.BoatFilter; -import fr.ifremer.wao.bean.BoatFilterImpl; -import fr.ifremer.wao.bean.ConnectedUser; -import fr.ifremer.wao.bean.ConnectedUserImpl; -import fr.ifremer.wao.bean.ObsProgram; -import fr.ifremer.wao.bean.SamplingFilter; -import fr.ifremer.wao.bean.SamplingFilterImpl; -import fr.ifremer.wao.bean.UserRole; -import fr.ifremer.wao.entity.Boat; -import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.entity.CompanyDAO; -import fr.ifremer.wao.entity.Contact; -import fr.ifremer.wao.entity.ContactDAO; -import fr.ifremer.wao.entity.News; -import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.entity.SampleRowLog; -import fr.ifremer.wao.entity.SampleRowLogDAO; -import fr.ifremer.wao.entity.UserProfile; -import fr.ifremer.wao.entity.UserProfileDAO; -import fr.ifremer.wao.entity.UserProfileImpl; -import fr.ifremer.wao.entity.WaoUser; -import fr.ifremer.wao.entity.WaoUserDAO; -import fr.ifremer.wao.entity.WaoUserImpl; +import fr.ifremer.wao.bean.*; +import fr.ifremer.wao.entity.*; import org.apache.commons.mail.EmailException; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; @@ -482,6 +456,10 @@ return users; } + /** + *@deprecated FIXME-fdesbois-2010-12-23 : move this method into WaoUserDAO + */ + @Deprecated protected List<WaoUser> getUsersByCompany(TopiaContext transaction, Company company) throws TopiaException { WaoUserDAO dao = WaoDAOHelper.getWaoUserDAO(transaction); Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/AbstractServiceTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/AbstractServiceTest.java 2010-12-23 17:15:46 UTC (rev 855) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/AbstractServiceTest.java 2010-12-23 19:09:52 UTC (rev 856) @@ -23,24 +23,8 @@ import fr.ifremer.wao.bean.ContactState; import fr.ifremer.wao.bean.UserRole; -import fr.ifremer.wao.entity.Boat; -import fr.ifremer.wao.entity.BoatDAO; -import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.entity.CompanyDAO; -import fr.ifremer.wao.entity.Contact; -import fr.ifremer.wao.entity.ContactDAO; -import fr.ifremer.wao.entity.ContactImpl; -import fr.ifremer.wao.entity.ElligibleBoat; -import fr.ifremer.wao.entity.ElligibleBoatDAO; -import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.entity.SampleRowDAO; -import fr.ifremer.wao.entity.WaoUser; -import fr.ifremer.wao.entity.WaoUserDAO; -import fr.ifremer.wao.service.ServiceBoat; -import fr.ifremer.wao.service.ServiceContact; -import fr.ifremer.wao.service.ServiceReferential; -import fr.ifremer.wao.service.ServiceSampling; -import fr.ifremer.wao.service.ServiceSamplingImpl; +import fr.ifremer.wao.entity.*; +import fr.ifremer.wao.service.*; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -103,8 +87,7 @@ log.debug("Start manager"); } manager.start(); - serviceSampling = (ServiceSamplingImpl)manager.getServiceSampling(); - //initialize(); + serviceSampling = (ServiceSamplingImpl) manager.getServiceSampling(); } @After @@ -113,12 +96,6 @@ } /** - * Initialize data before each test. By default do nothing. - */ -// protected void initialize() { -// } - - /** * Create a company : <br /> * <ul> * <li>first name : Homer</li> Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceUserImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceUserImplTest.java 2010-12-23 17:15:46 UTC (rev 855) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceUserImplTest.java 2010-12-23 19:09:52 UTC (rev 856) @@ -24,93 +24,54 @@ package fr.ifremer.wao.service; +import fr.ifremer.wao.AbstractServiceTest; import fr.ifremer.wao.TestManager; import fr.ifremer.wao.WaoBusinessException; import fr.ifremer.wao.WaoDAOHelper; import fr.ifremer.wao.bean.ObsProgram; import fr.ifremer.wao.bean.UserRole; -import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.entity.CompanyImpl; -import fr.ifremer.wao.entity.UserProfile; -import fr.ifremer.wao.entity.UserProfileDAO; -import fr.ifremer.wao.entity.UserProfileImpl; -import fr.ifremer.wao.entity.WaoUser; -import fr.ifremer.wao.entity.WaoUserImpl; -import org.junit.After; -import org.junit.AfterClass; +import fr.ifremer.wao.entity.*; import org.junit.Assert; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; /** - * * @author fdesbois <fdesbois at codelutin.com> + * @version $Id$ */ -public class ServiceUserImplTest { +public class ServiceUserImplTest extends AbstractServiceTest { - private static TestManager manager; - private static final Logger log = LoggerFactory.getLogger(ServiceUserImplTest.class); private ServiceUser service; - public ServiceUserImplTest() { - } - - @BeforeClass - public static void setUpClass() throws Exception { - manager = new TestManager(); - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - @Before public void setUp() throws Exception { - manager.start(); + super.setUp(); service = manager.getServiceUser(); } - @After - public void tearDown() throws Exception { - manager.stop(); - } - /** - * Test of connect method, of class ServiceUserImpl. - */ - //@Test - public void testConnect() throws Exception { - System.out.println("connect"); - } - - /** - * Test of forgetPassword method, of class ServiceUserImpl. - */ - //@Test - public void testForgetPassword() throws Exception { - System.out.println("forgetPassword"); - } - - /** * Test of createUpdateUser method, of class ServiceUserImpl. * * This test is not complete : it doesn't check if given data are well * registered. For profile updating, it only checks that no exception is * raised. + * + * @throws Exception all exceptions */ @Test public void testCreateUpdateUser() throws Exception { - System.out.println("createUpdateUser"); + log.info("############### START ############### testCreateUpdateUser"); // create a user with no role WaoUser user = new WaoUserImpl(); @@ -122,8 +83,16 @@ List<UserProfile> profiles = new LinkedList<UserProfile>(); user.setUserProfile(profiles); - UserProfile adminProfile = new UserProfileImpl(ObsProgram.OBSMER, UserRole.ADMIN, true); - UserProfile coordinatorProfile = new UserProfileImpl(ObsProgram.OBSMER, UserRole.COORDINATOR, true); + UserProfile adminProfile = new UserProfileImpl( + ObsProgram.OBSMER, + UserRole.ADMIN, + true + ); + UserProfile coordinatorProfile = new UserProfileImpl( + ObsProgram.OBSMER, + UserRole.COORDINATOR, + true + ); profiles.add(adminProfile); @@ -149,46 +118,85 @@ service.createUpdateUser(user, false); Assert.fail("an exception should have been raised"); } catch (WaoBusinessException e) { - Assert.assertEquals(WaoBusinessException.Type.ALREADY_EXISTS, e.getType()); + Assert.assertEquals(WaoBusinessException.Type.ALREADY_EXISTS, + e.getType()); } } - /** - * Test of deleteUser method, of class ServiceUserImpl. - */ - //@Test - public void testDeleteUser() throws Exception { - System.out.println("deleteUser"); - } + @Test + public void testUpdateUser() throws WaoBusinessException, TopiaException { + log.info("############### START ############### testUpdateUser"); - /** - * Test of createUpdateCompany method, of class ServiceUserImpl. - */ - //@Test - public void testCreateUpdateCompany() throws Exception { - System.out.println("createUpdateCompany"); - } + // ---- PREPARE DATA ---- // - /** - * Test of getCompanies method, of class ServiceUserImpl. - */ - //@Test - public void testGetCompanies() throws Exception { - System.out.println("getCompanies"); + String login = "login"; + + // First instance to create the user + WaoUser user = new WaoUserImpl(); + user.setLogin(login); + user.setActive(true); + service.createUpdateUser(user, false); + + log.debug("user in session = " + user + + " [ID=" + user.getTopiaId() + "]"); + + // Create a new instance + WaoUser userToUpdate = new WaoUserImpl(); + userToUpdate.setLogin(user.getLogin()); + userToUpdate.setTopiaId(user.getTopiaId()); + userToUpdate.setActive(false); + // Avoid NPE on UserProfile for each + userToUpdate.setUserProfile(new ArrayList<UserProfile>()); + + log.debug("user to update = " + userToUpdate); + + // ---- EXECUTE ---- // + + service.createUpdateUser(userToUpdate, false); + + // ---- CHECK DATA ---- // + + WaoUser userFound = findUserByLogin(login); + + log.debug("user found = " + userFound); + + Assert.assertFalse(userFound.isActive()); } /** * Test of getObservers method, of class ServiceUserImpl. + * + * @throws Exception all exceptions */ @Test public void testGetObservers() throws Exception { - log.info("## START ## getObservers"); + log.info("############### START ############### testGetObservers"); - UserProfile adminProfile = new UserProfileImpl(ObsProgram.OBSMER, UserRole.ADMIN, true); - UserProfile coordinatorProfile = new UserProfileImpl(ObsProgram.OBSMER, UserRole.COORDINATOR, true); - UserProfile coordinatorProfile2 = new UserProfileImpl(ObsProgram.OBSMER, UserRole.COORDINATOR, true); - UserProfile observerProfile = new UserProfileImpl(ObsProgram.OBSMER, UserRole.OBSERVER, true); - UserProfile observerProfile2 = new UserProfileImpl(ObsProgram.OBSMER, UserRole.OBSERVER, true); + UserProfile adminProfile = new UserProfileImpl( + ObsProgram.OBSMER, + UserRole.ADMIN, + true + ); + UserProfile coordinatorProfile = new UserProfileImpl( + ObsProgram.OBSMER, + UserRole.COORDINATOR, + true + ); + UserProfile coordinatorProfile2 = new UserProfileImpl( + ObsProgram.OBSMER, + UserRole.COORDINATOR, + true + ); + UserProfile observerProfile = new UserProfileImpl( + ObsProgram.OBSMER, + UserRole.OBSERVER, + true + ); + UserProfile observerProfile2 = new UserProfileImpl( + ObsProgram.OBSMER, + UserRole.OBSERVER, + true + ); TopiaContext context = manager.getContext().beginTransaction(); UserProfileDAO userProfileDAO = WaoDAOHelper.getUserProfileDAO(context); @@ -266,10 +274,12 @@ /** * Test of initApplication method, of class WaoGlobal. + * + * @throws Exception all exceptions */ @Test public void testCreateDefaultAdmin() throws Exception { - log.info("## START ## createDefaultAdmin"); + log.info("############### START ############### testCreateDefaultAdmin"); service.createDefaultAdmin();