public void testNioDatagramAcceptor() throws Exception {
ClassLoader classLoader = this.getClass().getClassLoader();
URL configURL = classLoader.getResource("org/apache/mina/integration/xbean/datagramAcceptor.xml");
File configF = new File(configURL.toURI());
ApplicationContext factory = new FileSystemXmlApplicationContext(configF.toURI().toURL().toString());
// test default without any properties
NioDatagramAcceptor acceptor0 = (NioDatagramAcceptor) factory.getBean("datagramAcceptor0");
assertNotNull("acceptor0 should not be null", acceptor0);
assertTrue(
"Default constructor for NioDatagramAcceptor should have true value for closeOnDeactivation property",
acceptor0.isCloseOnDeactivation());
// test setting the port and IP for the acceptor
NioDatagramAcceptor acceptor1 = (NioDatagramAcceptor) factory.getBean("datagramAcceptor1");
assertNotNull("acceptor1 should not be null", acceptor1);
assertEquals("192.168.0.1", acceptor1.getDefaultLocalAddress().getAddress().getHostAddress());
assertEquals(110, acceptor1.getDefaultLocalAddress().getPort());
// test creating with executor and some primitive properties
NioDatagramAcceptor acceptor2 = (NioDatagramAcceptor) factory.getBean("datagramAcceptor2");
assertNotNull(acceptor2);
assertFalse(acceptor2.isCloseOnDeactivation());
assertFalse("NioDatagramAcceptor should have false value for closeOnDeactivation property",
acceptor2.isCloseOnDeactivation());
// test creating with multiple addresses
NioDatagramAcceptor acceptor3 = (NioDatagramAcceptor) factory.getBean("datagramAcceptor3");
assertNotNull(acceptor3);
assertEquals(3, acceptor3.getDefaultLocalAddresses().size());
InetSocketAddress address1 = (InetSocketAddress) acceptor3.getDefaultLocalAddresses().get(0);
assertEquals("192.168.0.1", address1.getAddress().getHostAddress());