HttpSsoServerClient implements ServerClient { @Override public Subject getSubject(String token, String clientUrl) { try { final HttpJsonRequest currentPrincipalRequest = requestFactory .fromUrl( UriBuilder.fromUri(apiEndpoint) .path(SsoService.class) .path(SsoService.class, "getCurrentPrincipal") .build(token) .toString()) .useGetMethod() .addQueryParam("clienturl", clientUrl); final SubjectDto subjectDto = currentPrincipalRequest.request().asDto(SubjectDto.class); return new SubjectImpl( subjectDto.getName(), subjectDto.getId(), subjectDto.getToken(), false); } catch (ApiException | IOException e) { LOG.warn(e.getLocalizedMessage()); } return null; } @Inject  HttpSsoServerClient(
      @Named("che.api") String apiEndpoint, HttpJsonRequestFactory requestFactory); @Override Subject getSubject(String token, String clientUrl); @Override void unregisterClient(String token, String clientUrl);  }
@Test public void shouldRequestUser() throws Exception { final SubjectDto subjectDto = createUserDto(); when(response.asDto(anyObject())).thenReturn(subjectDto); final Subject subject = ssoClient.getSubject("token123", CLIENT_URL); assertEquals(subject.getUserId(), subject.getUserId()); assertEquals(subject.getUserName(), subject.getUserName()); assertEquals(subject.getToken(), subject.getToken()); assertEquals(subject.isTemporary(), subject.isTemporary()); verify(requestFactory) .fromUrl( eq( UriBuilder.fromUri(API_ENDPOINT) .path(SsoService.class) .path(SsoService.class, "getCurrentPrincipal") .build("token123") .toString())); verify(request).addQueryParam(eq("clienturl"), eq(CLIENT_URL)); verify(request).useGetMethod(); verify(request).request(); verifyNoMoreInteractions(request); }
@Test public void shouldReturnsNullWhenSomeExceptionOccurs() throws Exception { final SubjectDto subjectDto = createUserDto(); when(response.asDto(anyObject())).thenReturn(subjectDto); when(request.request()).thenThrow(new NotFoundException("not found")); final Subject subject = ssoClient.getSubject("token123", CLIENT_URL); assertNull(subject); verify(requestFactory) .fromUrl( eq( UriBuilder.fromUri(API_ENDPOINT) .path(SsoService.class) .path(SsoService.class, "getCurrentPrincipal") .build("token123") .toString())); verify(request).addQueryParam(eq("clienturl"), eq(CLIENT_URL)); verify(request).useGetMethod(); verify(request).request(); verifyNoMoreInteractions(request); }