Package com.github.ebnew.ki4so.core.app

Examples of com.github.ebnew.ki4so.core.app.AppService


        String password = "pwdsssss";
        UsernamePasswordCredential credential = new UsernamePasswordCredential(username, password);
        DefaultUserPrincipal principal = new DefaultUserPrincipal();
        principal.setId(username);
        //设置模拟服务。
        AppService appService = Mockito.mock(AppService.class);
        Mockito.when(appService.findKi4soServerApp()).thenReturn(null);
        this.handler.setAppService(appService);
        try {
            this.handler.postAuthentication(credential, principal);
            fail("应该抛出异常");
        } catch (NoKi4soKeyException e) {

        }

         /**
         * 测试参数正确的情况,但是ki4so 服务器的app对象不为空的情况。
         * 服务对应的key信息不为的正常情况。
         */
        String appId = "1000";
        String app2Id = "1001";
        String keyId = "1000000";
        String encStringValue = "ssssdafdsafdsafdsafdasfdsafdsa";
        String service = "http://loacahost:8080/ki4so-app/home.do";
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put(WebConstants.SERVICE_PARAM_NAME, service);
        credential.setParameters(parameters);
        App app = new App();
        app.setAppId(appId);
       
        App clientApp = new App();
        clientApp.setAppId(app2Id);
       
        Ki4soKey key = new Ki4soKey();
        key.setKeyId(keyId);
       
        Mockito.when(appService.findKi4soServerApp()).thenReturn(app);
        Mockito.when(appService.findAppByHost(service)).thenReturn(clientApp);
        
        KeyService keyService = Mockito.mock(KeyService.class);
        Mockito.when(keyService.findKeyByAppId(appId)).thenReturn(key);
        Mockito.when(keyService.findKeyByAppId(app2Id)).thenReturn(key);
       
View Full Code Here


  public void testGetAppList(){
   
    //当调用认证方法则抛出异常信息。模拟测试数据。
    AuthenticationManager authenticationManager = Mockito.mock(AuthenticationManager.class);
    UserLoggedStatusStore userLoggedStatusStore = Mockito.mock(UserLoggedStatusStore.class);
    AppService appService = Mockito.mock(AppService.class);
    this.ki4soService.setAuthenticationManager(authenticationManager);
    this.ki4soService.setUserLoggedStatusStore(userLoggedStatusStore);
    this.ki4soService.setAppService(appService);
   
    /**
     * 测试传递错误参数的情况。
     */
    Assert.assertEquals(0, this.ki4soService.getAppList(null).size());
   
    /**
     * 测试正确参数的情况。
     */
    Credential credential = Mockito.mock(Credential.class);
    Assert.assertEquals(0, this.ki4soService.getAppList(credential).size());
   
    /**
     * 测试正确参数,但是返回值的属principal为空的情况。
     */
    credential = Mockito.mock(Credential.class);
    Authentication authentication = Mockito.mock(Authentication.class);
    Mockito.when(authenticationManager.authenticate(credential)).thenReturn(authentication);
    Assert.assertEquals(0, this.ki4soService.getAppList(credential).size());
   
   
    /**
     * 测试正确参数,但是返回值的属principal不是空的情况。
     */
    credential = Mockito.mock(Credential.class);
    authentication = Mockito.mock(Authentication.class);
    Mockito.when(authenticationManager.authenticate(credential)).thenReturn(authentication);
    Mockito.when(authentication.getPrincipal()).thenReturn(Mockito.mock(Principal.class));
    List<UserLoggedStatus> list = new ArrayList<UserLoggedStatus>();
    UserLoggedStatus loggedStatus = new UserLoggedStatus("test", "1001");
    list.add(loggedStatus);
    Mockito.when(userLoggedStatusStore.findUserLoggedStatus(Mockito.anyString())).thenReturn(list);
    App app = new App();
    Mockito.when(appService.findAppById(Mockito.anyString())).thenReturn(app);
    Assert.assertEquals(1, this.ki4soService.getAppList(credential).size());
  }
View Full Code Here

TOP

Related Classes of com.github.ebnew.ki4so.core.app.AppService

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.