DocQueryPolicyChecker { protected boolean validatePolicyResponse(CheckPolicyResponseType policyResp) { return policyResp.getResponse() != null && NullChecker.isNotNullish(policyResp.getResponse().getResult()) && policyResp.getResponse().getResult().get(0).getDecision() == DecisionType.PERMIT; }  boolean checkIncomingPolicy(AdhocQueryRequest message, AssertionType assertion); boolean checkOutgoingPolicy(AdhocQueryRequest message, AssertionType assertion); boolean checkIncomingResponsePolicy(AdhocQueryResponse message, AssertionType assertion); boolean checkOutgoingResponsePolicy(AdhocQueryResponse message, AssertionType assertion,
            HomeCommunityType receiverHcid); boolean checkOutgoingRequestPolicy(AdhocQueryRequest message, AssertionType assertion,
            HomeCommunityType receiverHcid);  }
@Test public void testValidatePolicyResponse_null_PolicyResponse_returns_false() { final CheckPolicyResponseType mockResponse = mockery.mock(CheckPolicyResponseType.class); DocQueryPolicyChecker testSubject = new DocQueryPolicyChecker(); mockery.checking(new Expectations() { { one(mockResponse).getResponse(); will(returnValue(null)); } }); assertFalse(testSubject.validatePolicyResponse(mockResponse)); mockery.assertIsSatisfied(); }
@Test public void testValidatePolicyResponse_null_Result_returns_false() { final CheckPolicyResponseType mockPolicyResponse = mockery.mock(CheckPolicyResponseType.class); final ResponseType mockResponse = mockery.mock(ResponseType.class); DocQueryPolicyChecker testSubject = new DocQueryPolicyChecker(); mockery.checking(new Expectations() { { atLeast(1).of(mockPolicyResponse).getResponse(); will(returnValue(mockResponse)); atLeast(1).of(mockResponse).getResult(); will(returnValue(null)); } }); assertFalse(testSubject.validatePolicyResponse(mockPolicyResponse)); mockery.assertIsSatisfied(); }
@Test public void testValidatePolicyResponse_DecisionType_not_PERMIT_returns_false() { final CheckPolicyResponseType mockPolicyResponse = mockery.mock(CheckPolicyResponseType.class); final ResponseType mockResponse = mockery.mock(ResponseType.class); final ResultType mockResult = mockery.mock(ResultType.class); final List<ResultType> results = new ArrayList<>(); results.add(mockResult); DocQueryPolicyChecker testSubject = new DocQueryPolicyChecker(); mockery.checking(new Expectations() { { allowing(mockPolicyResponse).getResponse(); will(returnValue(mockResponse)); allowing(mockResponse).getResult(); will(returnValue(results)); one(mockResult).getDecision(); } }); assertFalse(testSubject.validatePolicyResponse(mockPolicyResponse)); mockery.assertIsSatisfied(); }
@Test public void testValidatePolicyResponse_DecisionType_PERMIT_returns_true() { final CheckPolicyResponseType mockPolicyResponse = mockery.mock(CheckPolicyResponseType.class); final ResponseType mockResponse = mockery.mock(ResponseType.class); final ResultType mockResult = mockery.mock(ResultType.class); final List<ResultType> results = new ArrayList<>(); results.add(mockResult); DocQueryPolicyChecker testSubject = new DocQueryPolicyChecker(); mockery.checking(new Expectations() { { allowing(mockPolicyResponse).getResponse(); will(returnValue(mockResponse)); allowing(mockResponse).getResult(); will(returnValue(results)); one(mockResult).getDecision(); will(returnValue(DecisionType.PERMIT)); } }); assertTrue(testSubject.validatePolicyResponse(mockPolicyResponse)); mockery.assertIsSatisfied(); }