{
ConnectionFactoryMock connFactory = new ConnectionFactoryMock();
Dictionary props = new Hashtable();
props.put(ConnectionFactory.IO_SCHEME, "file");
ServiceRegistration registration = registerConnectionFactory(connFactory, props);
ConnectorService service = getConnectorService();
Connection connection = service.open("file://test.txt");
assertEquals("file://test.txt", connFactory.getName());
assertEquals(ConnectorService.READ_WRITE, connFactory.getMode());
assertEquals(false, connFactory.isTimeout());
assertNotNull("checks returned Connection", connection);
connection = service.open("file://test.txt", ConnectorService.READ);
assertEquals("file://test.txt", connFactory.getName());
assertEquals(ConnectorService.READ, connFactory.getMode());
assertEquals(false, connFactory.isTimeout());
assertNotNull("checks returned Connection", connection);
connection = service.open("file://test.txt", ConnectorService.WRITE);
assertEquals("file://test.txt", connFactory.getName());
assertEquals(ConnectorService.WRITE, connFactory.getMode());
assertEquals(false, connFactory.isTimeout());
assertNotNull("checks returned Connection", connection);
connection = service.open("file://test.txt", ConnectorService.READ, true);
assertEquals("file://test.txt", connFactory.getName());
assertEquals(ConnectorService.READ, connFactory.getMode());
assertEquals(true, connFactory.isTimeout());
assertNotNull("checks returned Connection", connection);
try
{
connection = service.open("http://test.txt", ConnectorService.READ);
fail("Connection shouldn't be created");
} catch (ConnectionNotFoundException e)
{
// "expected"
}
try
{
service.open("file.txt");
fail("Illegal format of uri");
} catch (IllegalArgumentException e)
{
// expected
}
DataInputStream dataInStream = service.openDataInputStream("file://test.txt");
assertEquals("file://test.txt", connFactory.getName());
assertEquals(ConnectorService.READ, connFactory.getMode());
assertEquals(false, connFactory.isTimeout());
assertNotNull("checks returned DataInputStream", dataInStream);
DataOutputStream dataOutStream = service.openDataOutputStream("file://test.txt");
assertEquals("file://test.txt", connFactory.getName());
assertEquals(ConnectorService.WRITE, connFactory.getMode());
assertEquals(false, connFactory.isTimeout());
assertNotNull("checks returned DataOutputStream", dataOutStream);
InputStream inStream = service.openInputStream("file://test.txt");
assertEquals("file://test.txt", connFactory.getName());
assertEquals(ConnectorService.READ, connFactory.getMode());
assertEquals(false, connFactory.isTimeout());
assertNotNull("checks returned InputStream", inStream);
OutputStream outStream = service.openOutputStream("file://test.txt");
assertEquals("file://test.txt", connFactory.getName());
assertEquals(ConnectorService.WRITE, connFactory.getMode());
assertEquals(false, connFactory.isTimeout());
assertNotNull("checks returned OutputStream", outStream);