/** Test the failure path for authorization. */ @Test(expected = AuthorizationException.class) public void testAuthorizeFailBadStreamView() { context.checking( new Expectations() { { oneOf(principalMock).getId(); will(returnValue(1L)); oneOf(findUserStreamViewByIdMock) .execute(with(any(FindUserStreamFilterByIdRequest.class))); will(throwException(new NoResultException())); } }); ServiceActionContext currentContext = new ServiceActionContext(fields, principalMock); sut.authorize(currentContext); context.assertIsSatisfied(); }
/** Test the successful path for authorization. */ @Test public void testAuthorize() { context.checking( new Expectations() { { oneOf(principalMock).getId(); will(returnValue(1L)); oneOf(findUserStreamViewByIdMock) .execute(with(any(FindUserStreamFilterByIdRequest.class))); will(returnValue(streamViewMock)); oneOf(streamViewMock).getType(); will(returnValue(null)); } }); ServiceActionContext currentContext = new ServiceActionContext(fields, principalMock); sut.authorize(currentContext); context.assertIsSatisfied(); }