Search in sources :

Example 41 with Policy

use of org.apache.neethi.Policy in project cxf by apache.

the class PolicyBuilderTest method testGetPolicy.

@Test
public void testGetPolicy() throws Exception {
    String name = "/samples/test25.xml";
    InputStream is = PolicyBuilderTest.class.getResourceAsStream(name);
    Policy p = builder.getPolicy(is);
    assertNotNull(p);
    List<PolicyComponent> a = CastUtils.cast(p.getAssertions(), PolicyComponent.class);
    assertEquals(3, a.size());
    for (int i = 0; i < 3; i++) {
        assertEquals(Constants.TYPE_ASSERTION, a.get(i).getType());
    }
}
Also used : Policy(org.apache.neethi.Policy) PolicyComponent(org.apache.neethi.PolicyComponent) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 42 with Policy

use of org.apache.neethi.Policy in project cxf by apache.

the class PolicyBuilderTest method testGetPolicyWithAttributes.

@Test
public void testGetPolicyWithAttributes() throws Exception {
    String name = "/samples/test28.xml";
    InputStream is = PolicyBuilderTest.class.getResourceAsStream(name);
    Policy p = builder.getPolicy(is);
    assertNotNull(p);
    assertTrue(p.getAttributes().size() >= 2);
    QName n1 = new QName("nonsattr");
    Object v1 = p.getAttribute(n1);
    assertNotNull(v1);
    QName n2 = new QName("http://x.y.z", "nsattr");
    Object v2 = p.getAttribute(n2);
    assertNotNull(v2);
}
Also used : Policy(org.apache.neethi.Policy) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 43 with Policy

use of org.apache.neethi.Policy in project cxf by apache.

the class PolicyEngineTest method testEndpointPolicyWithEqualPolicies.

@Test
public void testEndpointPolicyWithEqualPolicies() throws Exception {
    engine = new PolicyEngineImpl();
    EndpointInfo ei = createMockEndpointInfo();
    ServiceInfo si = control.createMock(ServiceInfo.class);
    ei.setService(si);
    si.getExtensor(Policy.class);
    EasyMock.expectLastCall().andReturn(null).times(2);
    EndpointPolicyImpl epi = control.createMock(EndpointPolicyImpl.class);
    control.replay();
    engine.setServerEndpointPolicy(ei, epi);
    engine.setClientEndpointPolicy(ei, epi);
    assertSame(epi, engine.getClientEndpointPolicy(ei, (Conduit) null, msg));
    assertSame(epi, engine.getServerEndpointPolicy(ei, (Destination) null, msg));
    control.reset();
    ei.setService(si);
    Policy p = new Policy();
    si.getExtensor(Policy.class);
    EasyMock.expectLastCall().andReturn(p).times(2);
    epi.getPolicy();
    EasyMock.expectLastCall().andReturn(p).times(2);
    control.replay();
    assertSame(epi, engine.getServerEndpointPolicy(ei, (Destination) null, msg));
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) Policy(org.apache.neethi.Policy) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Destination(org.apache.cxf.transport.Destination) Conduit(org.apache.cxf.transport.Conduit) Test(org.junit.Test)

Example 44 with Policy

use of org.apache.neethi.Policy in project cxf by apache.

the class PolicyEngineTest method testGetAggregatedEndpointPolicy.

@Test
public void testGetAggregatedEndpointPolicy() throws Exception {
    engine = new PolicyEngineImpl();
    EndpointInfo ei = createMockEndpointInfo();
    control.replay();
    Policy p = engine.getAggregatedEndpointPolicy(ei, null);
    assertTrue(p.isEmpty());
    control.verify();
    control.reset();
    PolicyProvider provider1 = control.createMock(PolicyProvider.class);
    engine.getPolicyProviders().add(provider1);
    Policy p1 = control.createMock(Policy.class);
    EasyMock.expect(provider1.getEffectivePolicy(ei, null)).andReturn(p1);
    control.replay();
    assertSame(p1, engine.getAggregatedEndpointPolicy(ei, null));
    control.verify();
    control.reset();
    PolicyProvider provider2 = control.createMock(PolicyProvider.class);
    engine.getPolicyProviders().add(provider2);
    Policy p2 = control.createMock(Policy.class);
    Policy p3 = control.createMock(Policy.class);
    EasyMock.expect(provider1.getEffectivePolicy(ei, null)).andReturn(p1);
    EasyMock.expect(provider2.getEffectivePolicy(ei, null)).andReturn(p2);
    EasyMock.expect(p1.merge(p2)).andReturn(p3);
    control.replay();
    assertSame(p3, engine.getAggregatedEndpointPolicy(ei, null));
    control.verify();
}
Also used : Policy(org.apache.neethi.Policy) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Test(org.junit.Test)

Example 45 with Policy

use of org.apache.neethi.Policy in project cxf by apache.

the class PolicyEngineTest method testGetAggregatedOperationPolicy.

@Test
public void testGetAggregatedOperationPolicy() throws Exception {
    engine = new PolicyEngineImpl();
    BindingOperationInfo boi = createMockBindingOperationInfo();
    control.replay();
    Policy p = engine.getAggregatedOperationPolicy(boi, null);
    assertTrue(p.isEmpty());
    control.verify();
    control.reset();
    PolicyProvider provider1 = control.createMock(PolicyProvider.class);
    engine.getPolicyProviders().add(provider1);
    Policy p1 = control.createMock(Policy.class);
    EasyMock.expect(provider1.getEffectivePolicy(boi, null)).andReturn(p1);
    control.replay();
    assertSame(p1, engine.getAggregatedOperationPolicy(boi, null));
    control.verify();
    control.reset();
    PolicyProvider provider2 = control.createMock(PolicyProvider.class);
    engine.getPolicyProviders().add(provider2);
    Policy p2 = control.createMock(Policy.class);
    Policy p3 = control.createMock(Policy.class);
    EasyMock.expect(provider1.getEffectivePolicy(boi, null)).andReturn(p1);
    EasyMock.expect(provider2.getEffectivePolicy(boi, null)).andReturn(p2);
    EasyMock.expect(p1.merge(p2)).andReturn(p3);
    control.replay();
    assertSame(p3, engine.getAggregatedOperationPolicy(boi, null));
    control.verify();
}
Also used : Policy(org.apache.neethi.Policy) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Test(org.junit.Test)

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