ContextHandlerImpl implements ContextHandler { @Override public XacmlResponse enforcePolicy(XacmlRequest xacmlRequest) throws AuditException, NoPolicyFoundException, PolicyProviderException { LOGGER.debug(xacmlRequest.getMessageId(), "policyDesicionPoint.evaluateRequest(xacmlRequest) is invoked"); return policyDesicionPoint.evaluateRequest(xacmlRequest); } ContextHandlerImpl(PolicyDecisionPoint policyDesicionPoint); @Override XacmlResponse enforcePolicy(XacmlRequest xacmlRequest); @Override PdpRequestResponse makeDecisionForTryingPolicy(String xacmlPolicy,
			String purposeOfUse);  }
@Test public void testEnforcePolicy() throws AuditException, NoPolicyFoundException, PolicyProviderException { final XacmlRequest xacmlRequest = mock(XacmlRequest.class); final XacmlResponse xacmlResponse = mock(XacmlResponse.class); when(policyDesicionPoint.evaluateRequest(xacmlRequest)).thenReturn( xacmlResponse); final XacmlResponse response = sut.enforcePolicy(xacmlRequest); verify(policyDesicionPoint, times(1)).evaluateRequest(xacmlRequest); assertEquals(xacmlResponse, response); }
@SuppressWarnings("unchecked") @Test public void testEnforcePolicy_Throws_AuditException() throws AuditException, NoPolicyFoundException, PolicyProviderException { thrown.expect(AuditException.class); final XacmlRequest xacmlRequest = mock(XacmlRequest.class); final XacmlResponse xacmlResponse = mock(XacmlResponse.class); when(policyDesicionPoint.evaluateRequest(xacmlRequest)).thenThrow( AuditException.class); final XacmlResponse response = sut.enforcePolicy(xacmlRequest); verify(policyDesicionPoint, times(1)).evaluateRequest(xacmlRequest); assertEquals(xacmlResponse, response); }
@SuppressWarnings("unchecked") @Test public void testEnforcePolicy_Throws_NoPolicyFoundException() throws AuditException, NoPolicyFoundException, PolicyProviderException { thrown.expect(NoPolicyFoundException.class); final XacmlRequest xacmlRequest = mock(XacmlRequest.class); final XacmlResponse xacmlResponse = mock(XacmlResponse.class); when(policyDesicionPoint.evaluateRequest(xacmlRequest)).thenThrow( NoPolicyFoundException.class); final XacmlResponse response = sut.enforcePolicy(xacmlRequest); verify(policyDesicionPoint, times(1)).evaluateRequest(xacmlRequest); assertEquals(xacmlResponse, response); }
@SuppressWarnings("unchecked") @Test public void testEnforcePolicy_Throws_PolicyProviderException() throws AuditException, NoPolicyFoundException, PolicyProviderException { thrown.expect(PolicyProviderException.class); final XacmlRequest xacmlRequest = mock(XacmlRequest.class); final XacmlResponse xacmlResponse = mock(XacmlResponse.class); when(policyDesicionPoint.evaluateRequest(xacmlRequest)).thenThrow( PolicyProviderException.class); final XacmlResponse response = sut.enforcePolicy(xacmlRequest); verify(policyDesicionPoint, times(1)).evaluateRequest(xacmlRequest); assertEquals(xacmlResponse, response); }