RsrcCtxWrapper implements ResourceContext { public void throwZtsException(com.yahoo.athenz.common.server.rest.ResourceException restExc) { metric.increment("authfailure"); ctx.sendAuthenticateChallenges(restExc); String msg = null; Object data = restExc.getData(); if (data instanceof String) { msg = (String) data; } if (msg == null) { msg = restExc.getMessage(); } throw new com.yahoo.athenz.zts.ResourceException(restExc.getCode(), new ResourceError().code(restExc.getCode()).message(msg)); } RsrcCtxWrapper(HttpServletRequest request, HttpServletResponse response,
            Http.AuthorityList authList,  boolean optionalAuth, Authorizer authorizer,
            Metric metric, Object timerMetric, String apiName); com.yahoo.athenz.common.server.rest.ResourceContext context(); Principal principal(); String getRequestDomain(); Object getTimerMetric(); void setRequestDomain(String requestDomain); @Override HttpServletRequest request(); @Override HttpServletResponse response(); @Override String getApiName(); @Override String getHttpMethod(); @Override void authenticate(); @Override void authorize(String action, String resource, String trustedDomain); void logPrincipal(final Principal principal); void logPrincipal(final String principal); void logAuthorityId(Authority authority); void throwZtsException(com.yahoo.athenz.common.server.rest.ResourceException restExc);  }
@Test public void testThrowZtsException() { HttpServletRequest servletRequest = new MockHttpServletRequest(); HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class); AuthorityList authListMock = new AuthorityList(); Authorizer authorizerMock = Mockito.mock(Authorizer.class); Metric metricMock = Mockito.mock(Metric.class); Object timerMetricMock = Mockito.mock(Object.class); RsrcCtxWrapper wrapper = new RsrcCtxWrapper(servletRequest, servletResponse, authListMock, false, authorizerMock, metricMock, timerMetricMock, "apiName"); com.yahoo.athenz.common.server.rest.ResourceException restExc = new com.yahoo.athenz.common.server.rest.ResourceException(503, null); try { wrapper.throwZtsException(restExc); fail(); } catch (ResourceException ex) { assertEquals(503, ex.getCode()); } }