PolicyEvaluationRequestCacheKey { @Override public boolean equals(final Object obj) { if (obj instanceof PolicyEvaluationRequestCacheKey) { final PolicyEvaluationRequestCacheKey other = (PolicyEvaluationRequestCacheKey) obj; return new EqualsBuilder().append(this.request, other.request).append(this.zoneId, other.zoneId).isEquals(); } return false; } PolicyEvaluationRequestCacheKey(final PolicyEvaluationRequestV1 request,
            final LinkedHashSet<String> policySetIds, final String zoneId);  PolicyEvaluationRequestCacheKey(final LinkedHashSet<String> policySetIds, final String resourceId,
            final String subjectId, final String zoneId); String toDecisionKey(); @Override int hashCode(); @Override boolean equals(final Object obj); PolicyEvaluationRequestV1 getRequest(); LinkedHashSet<String> getPolicySetIds(); String getResourceId(); String getSubjectId(); String getZoneId();  }
@Test public void testKeyEqualsForSameRequests() { PolicyEvaluationRequestV1 request = new PolicyEvaluationRequestV1(); request.setAction(ACTION_GET); request.setSubjectIdentifier(AGENT_MULDER); request.setResourceIdentifier(XFILES_ID); request.setPolicySetsEvaluationOrder( Stream.of("policyOne").collect(Collectors.toCollection(LinkedHashSet::new))); PolicyEvaluationRequestCacheKey key = new PolicyEvaluationRequestCacheKey.Builder().zoneId(ZONE_NAME) .request(request).build(); PolicyEvaluationRequestV1 otherRequest = new PolicyEvaluationRequestV1(); otherRequest.setAction(ACTION_GET); otherRequest.setSubjectIdentifier(AGENT_MULDER); otherRequest.setResourceIdentifier(XFILES_ID); otherRequest.setPolicySetsEvaluationOrder( Stream.of("policyOne").collect(Collectors.toCollection(LinkedHashSet::new))); PolicyEvaluationRequestCacheKey otherKey = new PolicyEvaluationRequestCacheKey.Builder().zoneId(ZONE_NAME) .request(otherRequest).build(); assertTrue(key.equals(otherKey)); }
@Test public void testKeyEqualsForDifferentRequests() { PolicyEvaluationRequestV1 request = new PolicyEvaluationRequestV1(); request.setAction(ACTION_GET); request.setSubjectIdentifier(AGENT_MULDER); request.setResourceIdentifier(XFILES_ID); request.setPolicySetsEvaluationOrder( Stream.of("policyOne").collect(Collectors.toCollection(LinkedHashSet::new))); PolicyEvaluationRequestCacheKey key = new PolicyEvaluationRequestCacheKey.Builder().zoneId(ZONE_NAME) .request(request).build(); PolicyEvaluationRequestV1 otherRequest = new PolicyEvaluationRequestV1(); otherRequest.setAction(ACTION_GET); otherRequest.setSubjectIdentifier(AGENT_MULDER); otherRequest.setResourceIdentifier(XFILES_ID); PolicyEvaluationRequestCacheKey otherKey = new PolicyEvaluationRequestCacheKey.Builder().zoneId(ZONE_NAME) .request(otherRequest).build(); assertFalse(key.equals(otherKey)); }