use of org.apache.neethi.Policy in project cxf by apache.
the class PolicyInterceptorsTest method testClientPolicyInInterceptor.
@SuppressWarnings("unchecked")
@Test
public void testClientPolicyInInterceptor() {
PolicyInInterceptor interceptor = new PolicyInInterceptor();
doTestBasics(interceptor, true, false);
control.reset();
setupMessage(true, true, true, true, true, true);
EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class);
EasyMock.expect(pe.getEffectiveClientResponsePolicy(ei, boi, message)).andReturn(effectivePolicy);
EasyMock.expect(effectivePolicy.getPolicy()).andReturn(new Policy()).times(2);
Interceptor<? extends Message> i = control.createMock(Interceptor.class);
List<Interceptor<? extends Message>> lst = new ArrayList<Interceptor<? extends Message>>();
lst.add(i);
EasyMock.expect(effectivePolicy.getInterceptors()).andReturn(lst);
InterceptorChain ic = control.createMock(InterceptorChain.class);
EasyMock.expect(message.getInterceptorChain()).andReturn(ic).anyTimes();
ic.add(i);
EasyMock.expectLastCall();
message.put(EasyMock.eq(AssertionInfoMap.class), EasyMock.isA(AssertionInfoMap.class));
EasyMock.expectLastCall();
ic.add(PolicyVerificationInInterceptor.INSTANCE);
control.replay();
interceptor.handleMessage(message);
control.verify();
}
use of org.apache.neethi.Policy in project cxf by apache.
the class PolicyRegistryImplTest method testAll.
@Test
public void testAll() {
PolicyRegistryImpl reg = new PolicyRegistryImpl();
IMocksControl control = EasyMock.createNiceControl();
Policy policy = control.createMock(Policy.class);
String key = "key";
assertNull(reg.lookup(key));
reg.register(key, policy);
assertSame(policy, reg.lookup(key));
reg.remove(key);
assertNull(reg.lookup(key));
}
use of org.apache.neethi.Policy in project cxf by apache.
the class PolicyVerificationInInterceptorTest method testHandleMessage.
@Test
public void testHandleMessage() throws NoSuchMethodException {
control.reset();
Method m = AbstractPolicyInterceptor.class.getDeclaredMethod("getTransportAssertions", new Class[] { Message.class });
PolicyVerificationInInterceptor interceptor = EasyMock.createMockBuilder(PolicyVerificationInInterceptor.class).addMockedMethod(m).createMock(control);
setupMessage(true, true, true, true);
EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.FALSE);
interceptor.getTransportAssertions(message);
EasyMock.expectLastCall();
EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class);
EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE);
EasyMock.expect(engine.getEffectiveClientResponsePolicy(ei, boi, message)).andReturn(effectivePolicy);
Policy policy = control.createMock(Policy.class);
EasyMock.expect(effectivePolicy.getPolicy()).andReturn(policy);
aim.checkEffectivePolicy(policy);
EasyMock.expectLastCall().andReturn(null);
control.replay();
interceptor.handleMessage(message);
control.verify();
control.reset();
setupMessage(true, true, true, true);
EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.FALSE);
interceptor.getTransportAssertions(message);
EasyMock.expectLastCall();
effectivePolicy = control.createMock(EffectivePolicy.class);
EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE);
EasyMock.expect(engine.getEffectiveServerRequestPolicy(ei, boi, message)).andReturn(effectivePolicy);
policy = control.createMock(Policy.class);
EasyMock.expect(effectivePolicy.getPolicy()).andReturn(policy);
aim.checkEffectivePolicy(policy);
EasyMock.expectLastCall().andReturn(null);
control.replay();
interceptor.handleMessage(message);
control.verify();
}
use of org.apache.neethi.Policy in project cxf by apache.
the class ExternalAttachmentProviderTest method setUpAttachment.
void setUpAttachment(Object subject, boolean applies, ExternalAttachmentProvider eap) {
attachments.clear();
attachment = control.createMock(PolicyAttachment.class);
attachments.add(attachment);
policy = new Policy();
assertion = new PrimitiveAssertion(TEST_ASSERTION_TYPE);
policy.addAssertion(assertion);
eap.setAttachments(attachments);
if (subject instanceof ServiceInfo) {
EasyMock.expect(attachment.appliesTo((ServiceInfo) subject)).andReturn(applies);
} else if (subject instanceof EndpointInfo) {
EasyMock.expect(attachment.appliesTo((EndpointInfo) subject)).andReturn(applies);
} else if (subject instanceof BindingOperationInfo) {
EasyMock.expect(attachment.appliesTo((BindingOperationInfo) subject)).andReturn(applies);
} else if (subject instanceof BindingMessageInfo) {
EasyMock.expect(attachment.appliesTo((BindingMessageInfo) subject)).andReturn(applies);
} else if (subject instanceof BindingFaultInfo) {
EasyMock.expect(attachment.appliesTo((BindingFaultInfo) subject)).andReturn(applies);
} else {
System.err.println("subject class: " + subject.getClass());
}
if (applies) {
EasyMock.expect(attachment.getPolicy()).andReturn(policy);
}
}
use of org.apache.neethi.Policy in project cxf by apache.
the class ReferenceResolverTest method doTestRemoteResolver.
private void doTestRemoteResolver(String policyNs) {
URL url = ReferenceResolverTest.class.getResource("referring.wsdl");
String baseURI = url.toString();
PolicyBuilder builder = control.createMock(PolicyBuilder.class);
RemoteReferenceResolver resolver = new RemoteReferenceResolver(baseURI, builder);
assertNull(resolver.resolveReference("referred.wsdl#PolicyB"));
Policy p = control.createMock(Policy.class);
EasyMock.expect(builder.getPolicy(EasyMock.isA(Element.class))).andReturn(p);
control.replay();
assertSame(p, resolver.resolveReference("referred.wsdl#PolicyA"));
control.verify();
control.reset();
}
Aggregations