use of org.apache.neethi.All in project cxf by apache.
the class EndpointPolicyImplTest method testUpdatePolicy.
@Test
public void testUpdatePolicy() {
EndpointPolicyImpl epi = new TestEndpointPolicy();
Policy p1 = new Policy();
QName aqn1 = new QName("http://x.y.z", "a");
p1.addAssertion(mockAssertion(aqn1, 5, true));
Policy p2 = new Policy();
QName aqn2 = new QName("http://x.y.z", "b");
p2.addAssertion(mockAssertion(aqn2, 5, true));
control.replay();
epi.setPolicy(p1.normalize(null, true));
Policy ep = epi.updatePolicy(p2, createMessage()).getPolicy();
List<ExactlyOne> pops = CastUtils.cast(ep.getPolicyComponents(), ExactlyOne.class);
assertEquals("New policy must have 1 top level policy operator", 1, pops.size());
List<All> alts = CastUtils.cast(pops.get(0).getPolicyComponents(), All.class);
assertEquals("2 alternatives should be available", 2, alts.size());
List<PolicyAssertion> assertions1 = CastUtils.cast(alts.get(0).getAssertions(), PolicyAssertion.class);
assertEquals("1 assertion should be available", 1, assertions1.size());
List<PolicyAssertion> assertions2 = CastUtils.cast(alts.get(1).getAssertions(), PolicyAssertion.class);
assertEquals("1 assertion should be available", 1, assertions2.size());
QName n1 = assertions1.get(0).getName();
QName n2 = assertions2.get(0).getName();
assertTrue("Policy was not merged", n1.equals(aqn1) && n2.equals(aqn2) || n1.equals(aqn2) && n2.equals(aqn1));
}
use of org.apache.neethi.All in project cxf by apache.
the class EndpointPolicyImplTest method doTestUpdateWithEmptyPolicy.
private void doTestUpdateWithEmptyPolicy(Policy emptyPolicy) {
Policy p1 = new Policy();
QName aqn1 = new QName("http://x.y.z", "a");
p1.addAssertion(mockAssertion(aqn1, 5, true));
EndpointPolicyImpl epi = new TestEndpointPolicy();
control.replay();
epi.setPolicy(p1.normalize(true));
Policy ep = epi.updatePolicy(emptyPolicy, createMessage()).getPolicy();
List<ExactlyOne> pops = CastUtils.cast(ep.getPolicyComponents(), ExactlyOne.class);
assertEquals("New policy must have 1 top level policy operator", 1, pops.size());
List<All> alts = CastUtils.cast(pops.get(0).getPolicyComponents(), All.class);
assertEquals("1 alternatives should be available", 1, alts.size());
List<PolicyAssertion> assertions1 = CastUtils.cast(alts.get(0).getAssertions(), PolicyAssertion.class);
assertEquals("1 assertion should be available", 1, assertions1.size());
QName n1 = assertions1.get(0).getName();
assertTrue("Policy was not merged", n1.equals(aqn1));
}
use of org.apache.neethi.All in project cxf by apache.
the class EndpointPolicyImplTest method testUpdatePolicyWithEmptyAll.
@Test
public void testUpdatePolicyWithEmptyAll() {
Policy emptyPolicy = new Policy();
emptyPolicy.addPolicyComponent(new All());
emptyPolicy.addPolicyComponent(new All());
doTestUpdateWithEmptyPolicy(emptyPolicy);
}
Aggregations