use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.
the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_incomingPolicyCompliant_assertNoCertsFiltered.
public void testFilterCertificateByPolicy_incomingPolicyCompliant_assertNoCertsFiltered() throws Exception {
final PolicyFilter filter = mock(PolicyFilter.class);
when(filter.isCompliant((X509Certificate) any(), (PolicyExpression) any())).thenReturn(true);
final PolicyExpression expression = mock(PolicyExpression.class);
final X509Certificate cert = mock(X509Certificate.class);
final Collection<X509Certificate> certs = Arrays.asList(cert);
final PolicyResolver resolver = mock(PolicyResolver.class);
when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
final DefaultNHINDAgent agent = new DefaultNHINDAgent("", mock(CertificateResolver.class), mock(CertificateResolver.class), mock(TrustAnchorResolver.class));
agent.setPolicyFilter(filter);
Collection<X509Certificate> filteredCerts = agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), resolver, certs, true);
assertEquals(1, filteredCerts.size());
}
use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.
the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_noIncomingExpressions_assertNoCertsFiltered.
public void testFilterCertificateByPolicy_noIncomingExpressions_assertNoCertsFiltered() throws Exception {
final X509Certificate cert = mock(X509Certificate.class);
final Collection<X509Certificate> certs = Arrays.asList(cert);
final PolicyResolver resolver = mock(PolicyResolver.class);
when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(new ArrayList<PolicyExpression>());
final DefaultNHINDAgent agent = new DefaultNHINDAgent("", mock(CertificateResolver.class), mock(CertificateResolver.class), mock(TrustAnchorResolver.class));
Collection<X509Certificate> filteredCerts = agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), resolver, certs, true);
assertEquals(1, filteredCerts.size());
}
use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.
the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_requiredFieldMissing_assertNoCertsFiltered.
public void testFilterCertificateByPolicy_requiredFieldMissing_assertNoCertsFiltered() throws Exception {
final PolicyFilter filter = mock(PolicyFilter.class);
doThrow(new PolicyRequiredException("Just Passing Through")).when(filter).isCompliant((X509Certificate) any(), (PolicyExpression) any());
final PolicyExpression expression = mock(PolicyExpression.class);
final X509Certificate cert = mock(X509Certificate.class);
final Collection<X509Certificate> certs = Arrays.asList(cert);
final PolicyResolver resolver = mock(PolicyResolver.class);
when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
final DefaultNHINDAgent agent = new DefaultNHINDAgent("", mock(CertificateResolver.class), mock(CertificateResolver.class), mock(TrustAnchorResolver.class));
agent.setPolicyFilter(filter);
Collection<X509Certificate> filteredCerts = agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), resolver, certs, true);
assertEquals(0, filteredCerts.size());
}
use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.
the class DomainPolicyResolver_getPolicyTest method testGetPolicy_incomingPolicyExists_assertPolicies.
public void testGetPolicy_incomingPolicyExists_assertPolicies() throws Exception {
final PolicyExpression expression = mock(PolicyExpression.class);
final List<PolicyExpression> expressions = Arrays.asList(expression);
final Map<String, Collection<PolicyExpression>> policies = new HashMap<String, Collection<PolicyExpression>>();
policies.put("testdomain.com", expressions);
final DomainPolicyResolver resolver = new DomainPolicyResolver(policies);
Collection<PolicyExpression> retrievedExpressions = resolver.getIncomingPolicy(new InternetAddress("me@testdomain.com"));
assertNotNull(retrievedExpressions);
assertEquals(1, retrievedExpressions.size());
}
use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.
the class DomainPolicyResolver_getPolicyTest method testGetPolicy_outgoingPolicyExists_assertPolicies.
public void testGetPolicy_outgoingPolicyExists_assertPolicies() throws Exception {
final PolicyExpression expression = mock(PolicyExpression.class);
final List<PolicyExpression> expressions = Arrays.asList(expression);
final Map<String, Collection<PolicyExpression>> policies = new HashMap<String, Collection<PolicyExpression>>();
policies.put("testdomain.com", expressions);
final DomainPolicyResolver resolver = new DomainPolicyResolver(policies);
Collection<PolicyExpression> retrievedExpressions = resolver.getOutgoingPolicy(new InternetAddress("me@testdomain.com"));
assertNotNull(retrievedExpressions);
assertEquals(1, retrievedExpressions.size());
}
Aggregations