use of org.apache.neethi.ExactlyOne in project cxf by apache.
the class JaxbAssertionTest method testEqual.
@Test
public void testEqual() {
JaxbAssertion<FooType> assertion = new JaxbAssertion<FooType>();
FooType data = new FooType();
data.setName("CXF");
data.setNumber(2);
QName qn = new QName("http://cxf.apache.org/test/assertions/foo", "FooType");
assertion.setName(qn);
assertion.setData(data);
PolicyComponent pc = new Policy();
assertTrue(!assertion.equal(pc));
pc = new All();
assertTrue(!assertion.equal(pc));
pc = new ExactlyOne();
assertTrue(!assertion.equal(pc));
IMocksControl ctrl = EasyMock.createNiceControl();
PrimitiveAssertion xpa = ctrl.createMock(PrimitiveAssertion.class);
QName oqn = new QName("http://cxf.apache.org/test/assertions/blah", "OtherType");
EasyMock.expect(xpa.getName()).andReturn(oqn);
EasyMock.expect(xpa.getType()).andReturn(Constants.TYPE_ASSERTION);
ctrl.replay();
assertTrue(!assertion.equal(xpa));
ctrl.verify();
FooType odata = new FooType();
odata.setName(data.getName());
odata.setNumber(data.getNumber());
JaxbAssertion<FooType> oassertion = new JaxbAssertion<FooType>();
oassertion.setData(odata);
oassertion.setName(qn);
assertTrue(!assertion.equal(oassertion));
oassertion.setData(data);
assertTrue(assertion.equal(oassertion));
assertTrue(assertion.equal(assertion));
}
use of org.apache.neethi.ExactlyOne in project cxf by apache.
the class FirstAlternativeSelectorTest method testChooseAlternative.
@Test
public void testChooseAlternative() {
AlternativeSelector selector = new FirstAlternativeSelector();
PolicyEngine engine = control.createMock(PolicyEngine.class);
Assertor assertor = control.createMock(Assertor.class);
Policy policy = new Policy();
ExactlyOne ea = new ExactlyOne();
All all = new All();
PolicyAssertion a1 = new TestAssertion();
all.addAssertion(a1);
ea.addPolicyComponent(all);
Collection<PolicyAssertion> firstAlternative = CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class);
policy.addPolicyComponent(ea);
Message m = new MessageImpl();
EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor, m)).andReturn(false);
control.replay();
assertNull(selector.selectAlternative(policy, engine, assertor, null, m));
control.verify();
control.reset();
EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor, m)).andReturn(true);
control.replay();
Collection<Assertion> chosen = selector.selectAlternative(policy, engine, assertor, null, m);
assertSame(1, chosen.size());
assertSame(chosen.size(), firstAlternative.size());
assertSame(chosen.iterator().next(), firstAlternative.iterator().next());
control.verify();
control.reset();
All other = new All();
other.addAssertion(a1);
ea.addPolicyComponent(other);
Collection<PolicyAssertion> secondAlternative = CastUtils.cast(other.getPolicyComponents(), PolicyAssertion.class);
EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor, m)).andReturn(false);
EasyMock.expect(engine.supportsAlternative(secondAlternative, assertor, m)).andReturn(true);
control.replay();
chosen = selector.selectAlternative(policy, engine, assertor, null, m);
assertSame(1, chosen.size());
assertSame(chosen.size(), secondAlternative.size());
assertSame(chosen.iterator().next(), secondAlternative.iterator().next());
control.verify();
}
use of org.apache.neethi.ExactlyOne in project cxf by apache.
the class MinimalMaximalAlternativeSelectorTest method testChooseMinAlternative.
@Test
public void testChooseMinAlternative() {
Message m = new MessageImpl();
AlternativeSelector selector = new MinimalAlternativeSelector();
PolicyEngine engine = control.createMock(PolicyEngine.class);
Assertor assertor = control.createMock(Assertor.class);
Policy policy = new Policy();
ExactlyOne ea = new ExactlyOne();
All all = new All();
PolicyAssertion a1 = new TestAssertion();
all.addAssertion(a1);
ea.addPolicyComponent(all);
Collection<PolicyAssertion> maxAlternative = CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class);
all = new All();
ea.addPolicyComponent(all);
Collection<PolicyAssertion> minAlternative = CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class);
policy.addPolicyComponent(ea);
EasyMock.expect(engine.supportsAlternative(maxAlternative, assertor, m)).andReturn(true);
EasyMock.expect(engine.supportsAlternative(minAlternative, assertor, m)).andReturn(true);
control.replay();
Collection<Assertion> choice = selector.selectAlternative(policy, engine, assertor, null, m);
assertEquals(0, choice.size());
control.verify();
}
use of org.apache.neethi.ExactlyOne in project cxf by apache.
the class EndpointPolicyImpl method checkExactlyOnes.
void checkExactlyOnes() {
// Policy has been normalized and merged by now but unfortunately
// ExactlyOnce have not been normalized properly by Neethi, for ex
// <Policy>
// <ExactlyOne><All><A></All></ExactlyOne>
// <ExactlyOne><All><B></All></ExactlyOne>
// </Policy>
// this is what we can see after the normalization happens but in fact this
// is still unnormalized expression, should be
// <Policy>
// <ExactlyOne><All><A></All><All><B></All></ExactlyOne>
// </Policy>
List<?> assertions = policy.getPolicyComponents();
if (assertions.size() <= 1) {
return;
}
Policy p = new Policy();
ExactlyOne alternatives = new ExactlyOne();
p.addPolicyComponent(alternatives);
for (Object a : assertions) {
alternatives.addPolicyComponents(((ExactlyOne) a).getPolicyComponents());
}
setPolicy(p);
}
Aggregations