RsrcCtxWrapper implements ResourceContext { @Override public void authenticate() { try { ctx.authenticate(optionalAuth); } catch (com.yahoo.athenz.common.server.rest.ResourceException restExc) { throwZmsException(restExc); } } RsrcCtxWrapper(HttpServletRequest request, HttpServletResponse response,
                   Http.AuthorityList authList, boolean optionalAuth,
                   Authorizer authorizer, Object timerMetric, String apiName); Principal principal(); String getRequestDomain(); Object getTimerMetric(); void setRequestDomain(String requestDomain); @Override String getApiName(); @Override String getHttpMethod(); @Override HttpServletRequest request(); @Override HttpServletResponse response(); @Override void authenticate(); @Override void authorize(String action, String resource, String trustedDomain); void logPrincipal(final Principal principal); void logAuthorityId(Authority authority);  }
@Test public void testAuthenticateException() { HttpServletRequest reqMock = Mockito.mock(HttpServletRequest.class); HttpServletResponse resMock = Mockito.mock(HttpServletResponse.class); AuthorityList authListMock = new AuthorityList(); Authorizer authorizerMock = Mockito.mock(Authorizer.class); Authority authMock = Mockito.mock(Authority.class); Mockito.when(authMock.getHeader()).thenReturn("testheader"); Mockito.when(reqMock.getHeader("testheader")).thenReturn("testcred"); Mockito.when(authMock.getCredSource()).thenReturn(Authority.CredSource.HEADER); Mockito.when(authMock.authenticate(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) .thenThrow(new com.yahoo.athenz.common.server.rest.ResourceException(403)); Mockito.when(reqMock.getRemoteAddr()).thenReturn("1.1.1.1"); Mockito.when(reqMock.getMethod()).thenReturn("POST"); authListMock.add(authMock); Object timerMetric = new Object(); RsrcCtxWrapper wrapper = new RsrcCtxWrapper(reqMock, resMock, authListMock, false, authorizerMock, timerMetric, "apiName"); try { wrapper.authenticate(); } catch (ResourceException ex) { assertEquals(403, ex.getCode()); } }