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());
}
}
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);
}
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));
}
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();
}
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();
}
Aggregations