Package org.springside.examples.showcase.entity

Examples of org.springside.examples.showcase.entity.User


  /**
   * 测试创建用户.
   */
  @Test
  public void createUser() {
    User user = UserData.randomUser();
    UserDTO userDTO = BeanMapper.map(user, UserDTO.class);

    IdResult response = accountWebServiceClient.createUser(userDTO);
    assertThat(response.getId()).isNotNull();
    GetUserResult response2 = accountWebServiceClient.getUser(response.getId());
    assertThat(response2.getUser().getLoginName()).isEqualTo(user.getLoginName());
  }
View Full Code Here


  /**
   * 测试创建用户,使用错误的登录名.
   */
  @Test
  public void createUserWithInvalidLoginName() {
    User user = UserData.randomUser();
    UserDTO userDTO = BeanMapper.map(user, UserDTO.class);

    // 登录名为空
    userDTO.setLoginName(null);
    IdResult response = accountWebServiceClient.createUser(userDTO);
View Full Code Here

   */
  @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  public UserDTO getUser(@PathVariable("id") Long id) {
    final TimerContext exectuionTimer = executionMetrics.start();
    try {
      User user = accountService.getUser(id);

      if (user == null) {
        String message = "用户不存在(id:" + id + ")";
        logger.warn(message);
        throw new RestException(HttpStatus.NOT_FOUND, message);
      }

      // 使用Dozer转换DTO类,并补充Dozer不能自动绑定的属性
      UserDTO dto = BeanMapper.map(user, UserDTO.class);
      dto.setTeamId(user.getTeam().getId());
      return dto;
    } finally {
      exectuionTimer.stop();
    }
  }
View Full Code Here

  @GET
  @Path("/{id}.xml")
  @Produces(MediaTypes.APPLICATION_XML_UTF_8)
  public UserDTO getAsXml(@PathParam("id") Long id) {
    User user = accountService.getUser(id);
    if (user == null) {
      String message = "用户不存在(id:" + id + ")";
      logger.warn(message);
      throw buildException(Status.NOT_FOUND, message);
    }
View Full Code Here

  @GET
  @Path("/{id}.json")
  @Produces(MediaTypes.JSON_UTF_8)
  public UserDTO getAsJson(@PathParam("id") Long id) {
    User user = accountService.getUser(id);
    if (user == null) {
      String message = "用户不存在(id:" + id + ")";
      logger.warn(message);
      throw buildException(Status.NOT_FOUND, message);
    }
View Full Code Here

    GetUserResult result = new GetUserResult();
    try {

      Validate.notNull(id, "id参数为空");

      User user = accountService.getUser(id);

      Validate.notNull(user, "用户不存在(id:" + id + ")");

      UserDTO dto = BeanMapper.map(user, UserDTO.class);
      result.setUser(dto);
View Full Code Here

  public IdResult createUser(UserDTO user) {
    IdResult result = new IdResult();
    try {
      Validate.notNull(user, "用户参数为空");

      User userEntity = BeanMapper.map(user, User.class);
      BeanValidators.validateWithException(validator, userEntity);

      accountService.saveUser(userEntity);

      return new IdResult(userEntity.getId());
    } catch (ConstraintViolationException e) {
      String message = StringUtils.join(BeanValidators.extractPropertyAndMessageAsList(e, " "), "\n");
      return handleParameterError(result, e, message);
    } catch (RuntimeException e) {
      if (Exceptions.isCausedBy(e, DuplicateKeyException.class)) {
View Full Code Here

    // 插入appender用于assert。
    LogbackListAppender appender = new LogbackListAppender();
    appender.addToLogger(GuavaCacheDemo.class);

    // 第一次加载会查数据库
    User user = cache.get(1L);
    assertThat(user.getLoginName()).isEqualTo("admin");
    assertThat(appender.isEmpty()).isFalse();
    appender.clearLogs();

    // 第二次加载时直接从缓存里取
    User user2 = cache.get(1L);
    assertThat(user2.getLoginName()).isEqualTo("admin");
    assertThat(appender.isEmpty()).isTrue();

    // 第三次加载时,因为缓存已经过期所以会查数据库
    Threads.sleep(10, TimeUnit.SECONDS);
    User user3 = cache.get(1L);
    assertThat(user3.getLoginName()).isEqualTo("admin");
    assertThat(appender.isEmpty()).isFalse();
  }
View Full Code Here

    return null;
  }

  private UserDTO handleRequest(Long id) {
    User user = accountService.getUser(id);
    UserDTO dto = BeanMapper.map(user, UserDTO.class);
    dto.setTeamId(user.getTeam().getId());
    return dto;
  }
View Full Code Here

    String jsonString = memcachedClient.get(key);

    if (jsonString != null) {
      return jsonMapper.fromJson(jsonString, User.class);
    } else {
      User user = userDao.get(id);
      if (user != null) {
        jsonString = jsonMapper.toJson(user);
        memcachedClient.set(key, MemcachedObjectType.USER.getExpiredTime(), jsonString);
      }
      return user;
View Full Code Here

TOP

Related Classes of org.springside.examples.showcase.entity.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.