use of org.apache.cxf.test.assertions.foo.FooType in project cxf by apache.
the class JaxbAssertionBuilderTest method testBuild.
@Test
public void testBuild() throws Exception {
QName qn = new QName("http://cxf.apache.org/test/assertions/foo", "FooType");
JaxbAssertionBuilder<FooType> ab = new JaxbAssertionBuilder<>(FooType.class, qn);
assertNotNull(ab);
InputStream is = JaxbAssertionBuilderTest.class.getResourceAsStream("foo.xml");
Document doc = StaxUtils.read(is);
Element elem = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(), "http://cxf.apache.org/test/assertions/foo", "foo").get(0);
Assertion a = ab.build(elem, null);
JaxbAssertion<FooType> jba = JaxbAssertion.cast(a, FooType.class);
FooType foo = jba.getData();
assertEquals("CXF", foo.getName());
assertEquals(2, foo.getNumber().intValue());
}
use of org.apache.cxf.test.assertions.foo.FooType in project cxf by apache.
the class JaxbAssertionBuilderTest method testConstructors.
@Test
public void testConstructors() throws Exception {
QName qn = new QName("http://cxf.apache.org/test/assertions/foo", "FooType");
try {
new JaxbAssertionBuilder<Object>("org.apache.cxf.test.assertions.foo.UnknownType", qn);
fail("Expected ClassNotFoundException not thrown.");
} catch (ClassNotFoundException ex) {
// expected
}
assertNotNull(new JaxbAssertionBuilder<Object>(qn));
assertNotNull(new JaxbAssertionBuilder<Object>(FooType.class.getName(), qn));
assertNotNull(new JaxbAssertionBuilder<FooType>(FooType.class, qn));
}
use of org.apache.cxf.test.assertions.foo.FooType in project cxf by apache.
the class JaxbAssertionTest method testBasic.
@Test
public void testBasic() {
JaxbAssertion<FooType> assertion = new JaxbAssertion<>();
assertNull(assertion.getName());
assertNull(assertion.getData());
assertFalse(assertion.isOptional());
assertEquals(Constants.TYPE_ASSERTION, assertion.getType());
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);
assertion.setOptional(true);
assertSame(qn, assertion.getName());
assertSame(data, assertion.getData());
assertTrue(assertion.isOptional());
assertEquals(Constants.TYPE_ASSERTION, assertion.getType());
}
use of org.apache.cxf.test.assertions.foo.FooType in project cxf by apache.
the class JaxbAssertionTest method testNormalise.
@Test
public void testNormalise() {
JaxbAssertion<FooType> assertion = new JaxbAssertion<>();
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();
}
}
assertFalse(alternatives.hasNext());
assertEquals(1, total);
}
use of org.apache.cxf.test.assertions.foo.FooType in project cxf by apache.
the class JaxbAssertionTest method testEqual.
@Test
public void testEqual() {
JaxbAssertion<FooType> assertion = new JaxbAssertion<>();
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();
assertFalse(assertion.equal(pc));
pc = new All();
assertFalse(assertion.equal(pc));
pc = new ExactlyOne();
assertFalse(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();
assertFalse(assertion.equal(xpa));
ctrl.verify();
FooType odata = new FooType();
odata.setName(data.getName());
odata.setNumber(data.getNumber());
JaxbAssertion<FooType> oassertion = new JaxbAssertion<>();
oassertion.setData(odata);
oassertion.setName(qn);
assertFalse(assertion.equal(oassertion));
oassertion.setData(data);
assertTrue(assertion.equal(oassertion));
assertTrue(assertion.equal(assertion));
}
Aggregations