package org.appfuse.service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.appfuse.model.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertNotNull;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
locations = {"/applicationContext-service.xml",
"/applicationContext-resources.xml",
"classpath:/applicationContext-dao.xml"})
public class UserExistsExceptionTest {
@Autowired
private UserManager manager;
private Log log = LogFactory.getLog(UserExistsExceptionTest.class);
@Test(expected = UserExistsException.class)
public void testAddExistingUser() throws Exception {
log.debug("entered 'testAddExistingUser' method");
assertNotNull(manager);
User user = manager.getUser("-1");
// create new object with null id - Hibernate doesn't like setId(null)
User user2 = new User();
BeanUtils.copyProperties(user, user2);
user2.setId(null);
user2.setVersion(null);
user2.setRoles(null);
// try saving as new user, this should fail UserExistsException b/c of unique keys
manager.saveUser(user2);
}
}