Package org.springside.examples.miniservice.entity.account

Examples of org.springside.examples.miniservice.entity.account.User


  /**
   * 测试创建用户,在Spring applicaitonContext.xml中用<jaxws:client/>创建Client.
   */
  @Test
  public void createUser() {
    User user = AccountData.getRandomUser();

    UserDTO userDTO = new UserDTO();
    userDTO.setLoginName(user.getLoginName());
    userDTO.setName(user.getName());
    userDTO.setEmail(user.getEmail());

    RoleDTO roleDTO = new RoleDTO();
    roleDTO.setId(1L);
    userDTO.getRoleList().add(roleDTO);

View Full Code Here


  //@Rollback(false)
  public void crudEntityWithRole() throws Exception {
    DbUnitUtils.loadData(dataSource, "/data/default-data.xml");

    //新建并保存带角色的用户
    User user = AccountData.getRandomUserWithAdminRole();
    entityDao.save(user);
    //强制执行保存sql
    entityDao.flush();

    //查找用户
    user = entityDao.findUniqueBy("id", user.getId());
    assertEquals(1, user.getRoleList().size());

    //删除用户的角色
    user.getRoleList().remove(0);
    entityDao.flush();
    user = entityDao.findUniqueBy("id", user.getId());
    assertEquals(0, user.getRoleList().size());

    //删除用户
    entityDao.delete(user.getId());
    entityDao.flush();
    user = entityDao.findUniqueBy("id", user.getId());
    assertNull(user);
  }
View Full Code Here

    }
  }

  @Test
  public void createUser() {
    User user = AccountData.getRandomUser();
    UserDTO dto = new DozerBeanMapper().map(user, UserDTO.class);

    URI uri = client.createUser(dto);
    assertNotNull(uri);
    System.out.println("Created user uri:" + uri);
View Full Code Here

    assertNull(user);
  }

  @Test(expected = org.hibernate.exception.ConstraintViolationException.class)
  public void saveNotUniqueUser() throws Exception {
    User user = AccountData.getRandomUser();
    user.setLoginName("admin");

    entityDao.save(user);
    entityDao.flush();
  }
View Full Code Here

public class AccountData {

  public static User getRandomUser() {
    String userName = DataUtils.randomName("User");

    User user = new User();
    user.setLoginName(userName);
    user.setName(userName);
    user.setPassword("123456");
    user.setEmail(userName + "@springside.org.cn");

    return user;
  }
View Full Code Here

    return user;
  }

  public static User getRandomUserWithAdminRole() {
    User user = AccountData.getRandomUser();
    Role adminRole = AccountData.getAdminRole();
    user.getRoleList().add(adminRole);
    return user;
  }
View Full Code Here

  @GET
  @Path("{id}")
  @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML + CHARSET })
  public UserDTO getUser(@PathParam("id") Long id) {
    try {
      User entity = accountManager.getInitedUser(id);

      UserDTO dto = dozer.map(entity, UserDTO.class);

      return dto;
    } catch (ObjectNotFoundException e) {
View Full Code Here

   */
  @POST
  @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML + CHARSET })
  public Response createUser(UserDTO user) {
    try {
      User userEntity = dozer.map(user, User.class);

      accountManager.saveUser(userEntity);

      URI createdUri = uriInfo.getAbsolutePathBuilder().path(userEntity.getId().toString()).build();

      return Response.created(createdUri).build();
    } catch (ConstraintViolationException e) {
      String message = "新建用户参数存在唯一性冲突(用户:" + user + ")";
      logger.error(message, e);
View Full Code Here

  /**
   * 获取用户, 并对用户的延迟加载关联进行初始化.
   */
  @Transactional(readOnly = true)
  public User getInitedUser(Long id) {
    User user = userDao.get(id);
    userDao.initUser(user);
    return user;
  }
View Full Code Here

      return result.buildResult(WSResult.PARAMETER_ERROR, e.getMessage());
    }

    //获取用户
    try {
      User entity = accountManager.getInitedUser(id);
      UserDTO dto = dozer.map(entity, UserDTO.class);

      result.setUser(dto);
      return result;
    } catch (ObjectNotFoundException e) {
View Full Code Here

TOP

Related Classes of org.springside.examples.miniservice.entity.account.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.