TestBundleUserManagerFactory.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *
00024  */
00025 package org.openmobileis.module.test.server;
00026 
00027 import org.openmobileis.common.user.User;
00028 import org.openmobileis.common.user.UserAlreadyExistException;
00029 import org.openmobileis.common.user.UserManagerFactory;
00030 import org.openmobileis.common.user.UserNotFoundException;
00031 import org.openmobileis.common.util.exception.ServiceException;
00032 
00040 public final class TestBundleUserManagerFactory implements UserManagerFactory {
00041   private User defaultUser;
00042   private int i=0;
00046   public TestBundleUserManagerFactory() {
00047     super();
00048     defaultUser =  new User();
00049     defaultUser.setId("1");
00050     defaultUser.setLogin("test");
00051     defaultUser.setPassword("test");
00052     defaultUser.setProfil("default");
00053     defaultUser.setGroup("default");
00054  }
00055 
00056   /* (non-Javadoc)
00057    * @see org.openmobileis.common.user.UserManagerFactory#authenticateUser(java.lang.String, java.lang.String)
00058    */
00059   public String authenticateUser(String login, String pass) throws ServiceException, UserNotFoundException {
00060     if ((login.equals(defaultUser.getLogin())) && (pass.equals(defaultUser.getPassword()))) {
00061       return defaultUser.getId();
00062     } else  {
00063       throw new UserNotFoundException("Bad authentication for login :"+login);
00064     }
00065   }
00066 
00067   public void logoutUser(String userid) throws ServiceException {
00068 
00069   }
00070 
00071   /* (non-Javadoc)
00072    * @see org.openmobileis.common.user.UserManagerFactory#storeUser(org.openmobileis.common.user.User)
00073    */
00074   public void storeUser(User user) throws ServiceException, UserAlreadyExistException {
00075     // do nothing
00076 
00077   }
00078 
00079   /* (non-Javadoc)
00080    * @see org.openmobileis.common.user.UserManagerFactory#getUser(java.lang.String)
00081    */
00082   public User getUser(String userID) throws ServiceException, UserNotFoundException {
00083     if (userID.equals(defaultUser.getId())) {
00084  /*     if( i%2 == 0){
00085                 if (defaultUser.getProfil().equals("default"))
00086                         defaultUser.setProfil("defaultv2");
00087                 else
00088                         defaultUser.setProfil("default");
00089         } */
00090         i++;
00091                   defaultUser.setProfil("default");
00092       return defaultUser;
00093     } else  {
00094       throw new UserNotFoundException("No user found for Id :"+userID);
00095     }
00096   }
00097 
00098   /* (non-Javadoc)
00099    * @see org.openmobileis.common.user.UserManagerFactory#deleteUser(java.lang.String)
00100    */
00101   public void deleteUser(String userID) throws ServiceException, UserNotFoundException {
00102     // Do nothing
00103 
00104   }
00105 
00106 }

Generated on Mon Jan 11 21:19:17 2010 for OpenMobileIS by  doxygen 1.5.4