Package org.springside.examples.miniservice.ws.result

Examples of org.springside.examples.miniservice.ws.result.AuthUserResult


  /**
   * 测试认证用户,在Spring applicaitonContext.xml中用<jaxws:client/>创建Client.
   */
  @Test
  public void authUser() {
    AuthUserResult result = userWebService.authUser("admin", "admin");
    assertEquals(true, result.isValid());
  }
View Full Code Here


  /**
   * @see UserWebService#authUser(String, String)
   */
  public AuthUserResult authUser(String loginName, String password) {
    AuthUserResult result = new AuthUserResult();

    //校验请求参数
    try {
      Assert.hasText(loginName, "登录名参数为空");
      Assert.hasText(password, "密码参数为空");
    } catch (IllegalArgumentException e) {
      logger.error(e.getMessage());
      return result.buildResult(WSResult.PARAMETER_ERROR, e.getMessage());
    }

    //认证
    try {
      if (accountManager.authenticate(loginName, password)) {
        result.setValid(true);
      } else {
        result.setValid(false);
      }
      return result;
    } catch (RuntimeException e) {
      logger.error(e.getMessage(), e);
      return result.buildDefaultErrorResult();
    }
  }
View Full Code Here

    EasyMock.expect(mockAccountManager.authenticate("admin", "admin")).andReturn(true);
    EasyMock.expect(mockAccountManager.authenticate("admin", "errorPasswd")).andReturn(false);
    control.replay();

    //执行输入正确的测试
    AuthUserResult result = userWebService.authUser("admin", "admin");
    assertEquals(WSResult.SUCCESS, result.getCode());
    assertEquals(true, result.isValid());

    //执行输入错误的测试
    result = userWebService.authUser("admin", "errorPasswd");
    assertEquals(WSResult.SUCCESS, result.getCode());
    assertEquals(false, result.isValid());

    result = userWebService.authUser("admin", "");
    assertEquals(WSResult.PARAMETER_ERROR, result.getCode());
    assertEquals(false, result.isValid());
  }
View Full Code Here

TOP

Related Classes of org.springside.examples.miniservice.ws.result.AuthUserResult

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.