Search in sources :

Example 11 with Policy

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();
}
Also used : Policy(org.apache.neethi.Policy) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) Interceptor(org.apache.cxf.interceptor.Interceptor) Test(org.junit.Test)

Example 12 with Policy

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));
}
Also used : IMocksControl(org.easymock.IMocksControl) Policy(org.apache.neethi.Policy) Test(org.junit.Test)

Example 13 with Policy

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();
}
Also used : Policy(org.apache.neethi.Policy) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 14 with Policy

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);
    }
}
Also used : Policy(org.apache.neethi.Policy) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 15 with 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();
}
Also used : Policy(org.apache.neethi.Policy) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) Element(org.w3c.dom.Element) PolicyBuilder(org.apache.cxf.ws.policy.PolicyBuilder) URL(java.net.URL)

Aggregations

Policy (org.apache.neethi.Policy)122 Test (org.junit.Test)47 Assertion (org.apache.neethi.Assertion)27 QName (javax.xml.namespace.QName)23 ArrayList (java.util.ArrayList)21 All (org.apache.neethi.All)18 ExactlyOne (org.apache.neethi.ExactlyOne)18 Message (org.apache.cxf.message.Message)15 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)14 Element (org.w3c.dom.Element)13 Bus (org.apache.cxf.Bus)12 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)12 List (java.util.List)9 Interceptor (org.apache.cxf.interceptor.Interceptor)9 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)9 HashMap (java.util.HashMap)7 OMElement (org.apache.axiom.om.OMElement)7 MessageImpl (org.apache.cxf.message.MessageImpl)7 ReferenceResolver (org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver)6 InputStream (java.io.InputStream)5