@Test( expected = DebugWsException.class ) public void testLogin_failure() throws Exception { Mockito.doThrow( new LoginException( "for test" )).when( this.authService ).authenticate( "u", "p" ); this.client.getAuthenticationWsDelegate().login( "u", "p" ); }
public String login( String username, String password ) throws DebugWsException { this.logger.finer( "Logging in as " + username ); WebResource path = this.resource.path( UrlConstants.AUTHENTICATION ).path( "e" ); ClientResponse response = path .header( "u", username ) .header( "p", password ) .post( ClientResponse.class ); if( Family.SUCCESSFUL != response.getStatusInfo().getFamily()) { String value = response.getEntity( String.class ); this.logger.finer( response.getStatusInfo() + ": " + value ); throw new DebugWsException( response.getStatusInfo().getStatusCode(), value ); } String sessionId = null; List<NewCookie> cookies = response.getCookies(); if( cookies != null ) { for( NewCookie cookie : cookies ) { if( UrlConstants.SESSION_ID.equals( cookie.getName())) { sessionId = cookie.getValue(); break; } } } this.wsClient.setSessionId( sessionId ); this.logger.finer( "Session ID: " + sessionId ); return sessionId; }
AuthenticationWsDelegate { public String login( String username, String password ) throws DebugWsException { this.logger.finer( "Logging in as " + username ); WebResource path = this.resource.path( UrlConstants.AUTHENTICATION ).path( "e" ); ClientResponse response = path .header( "u", username ) .header( "p", password ) .post( ClientResponse.class ); if( Family.SUCCESSFUL != response.getStatusInfo().getFamily()) { String value = response.getEntity( String.class ); this.logger.finer( response.getStatusInfo() + ": " + value ); throw new DebugWsException( response.getStatusInfo().getStatusCode(), value ); } String sessionId = null; List<NewCookie> cookies = response.getCookies(); if( cookies != null ) { for( NewCookie cookie : cookies ) { if( UrlConstants.SESSION_ID.equals( cookie.getName())) { sessionId = cookie.getValue(); break; } } } this.wsClient.setSessionId( sessionId ); this.logger.finer( "Session ID: " + sessionId ); return sessionId; } }
AuthenticationWsDelegate { public String login( String username, String password ) throws DebugWsException { this.logger.finer( "Logging in as " + username ); WebResource path = this.resource.path( UrlConstants.AUTHENTICATION ).path( "e" ); ClientResponse response = path .header( "u", username ) .header( "p", password ) .post( ClientResponse.class ); if( Family.SUCCESSFUL != response.getStatusInfo().getFamily()) { String value = response.getEntity( String.class ); this.logger.finer( response.getStatusInfo() + ": " + value ); throw new DebugWsException( response.getStatusInfo().getStatusCode(), value ); } String sessionId = null; List<NewCookie> cookies = response.getCookies(); if( cookies != null ) { for( NewCookie cookie : cookies ) { if( UrlConstants.SESSION_ID.equals( cookie.getName())) { sessionId = cookie.getValue(); break; } } } this.wsClient.setSessionId( sessionId ); this.logger.finer( "Session ID: " + sessionId ); return sessionId; } AuthenticationWsDelegate( WebResource resource, WsClient wsClient ); }
AuthenticationWsDelegate { public String login( String username, String password ) throws DebugWsException { this.logger.finer( "Logging in as " + username ); WebResource path = this.resource.path( UrlConstants.AUTHENTICATION ).path( "e" ); ClientResponse response = path .header( "u", username ) .header( "p", password ) .post( ClientResponse.class ); if( Family.SUCCESSFUL != response.getStatusInfo().getFamily()) { String value = response.getEntity( String.class ); this.logger.finer( response.getStatusInfo() + ": " + value ); throw new DebugWsException( response.getStatusInfo().getStatusCode(), value ); } String sessionId = null; List<NewCookie> cookies = response.getCookies(); if( cookies != null ) { for( NewCookie cookie : cookies ) { if( UrlConstants.SESSION_ID.equals( cookie.getName())) { sessionId = cookie.getValue(); break; } } } this.wsClient.setSessionId( sessionId ); this.logger.finer( "Session ID: " + sessionId ); return sessionId; } AuthenticationWsDelegate( WebResource resource, WsClient wsClient ); String login( String username, String password ); void logout( String sessionId ); }
AuthenticationWsDelegate { public String login( String username, String password ) throws DebugWsException { this.logger.finer( "Logging in as " + username ); WebResource path = this.resource.path( UrlConstants.AUTHENTICATION ).path( "e" ); ClientResponse response = path .header( "u", username ) .header( "p", password ) .post( ClientResponse.class ); if( Family.SUCCESSFUL != response.getStatusInfo().getFamily()) { String value = response.getEntity( String.class ); this.logger.finer( response.getStatusInfo() + ": " + value ); throw new DebugWsException( response.getStatusInfo().getStatusCode(), value ); } String sessionId = null; List<NewCookie> cookies = response.getCookies(); if( cookies != null ) { for( NewCookie cookie : cookies ) { if( UrlConstants.SESSION_ID.equals( cookie.getName())) { sessionId = cookie.getValue(); break; } } } this.wsClient.setSessionId( sessionId ); this.logger.finer( "Session ID: " + sessionId ); return sessionId; } AuthenticationWsDelegate( WebResource resource, WsClient wsClient ); String login( String username, String password ); void logout( String sessionId );  }