use of org.apache.neethi.PolicyComponent in project cxf by apache.
the class JaxbAssertionTest method testNormalise.
@Test
public void testNormalise() {
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);
JaxbAssertion<?> normalised = (JaxbAssertion<?>) assertion.normalize();
assertTrue(normalised.equal(assertion));
assertSame(assertion.getData(), normalised.getData());
assertion.setOptional(true);
PolicyComponent pc = assertion.normalize();
assertEquals(Constants.TYPE_POLICY, pc.getType());
Policy p = (Policy) pc;
Iterator<List<Assertion>> alternatives = p.getAlternatives();
int total = 0;
for (int i = 0; i < 2; i++) {
List<Assertion> pcs = alternatives.next();
if (!pcs.isEmpty()) {
assertTrue(assertion.equal(pcs.get(0)));
total += pcs.size();
}
}
assertTrue(!alternatives.hasNext());
assertEquals(1, total);
}
Aggregations