@Test
public void testExecute_withRealDataSource() throws Exception {

	// Create a H2 data source
	JdbcDataSource ds = new JdbcDataSource();
	File dataFile = this.folder.newFile();
	ds.setURL( "jdbc:h2:" + dataFile.getAbsolutePath());
	ds.setUser( "roboconf" );
	ds.setPassword( "roboconf" );
	// Prepare the mock
	ServiceReference<DataSource> sr = Mockito.mock( ServiceReference.class );
	PruneHistoryCommand pruneHistoryCmd = new PruneHistoryCommand();
	pruneHistoryCmd.bundleContext = Mockito.mock( BundleContext.class );
	Mockito.when( pruneHistoryCmd.bundleContext.getServiceReferences(
			DataSource.class,
			"(dataSourceName=roboconf-dm-db)" )).thenReturn( Arrays.asList( sr ));
	Mockito.when( pruneHistoryCmd.bundleContext.getService( sr )).thenReturn( ds );
	// Populate the database
	Manager manager = Mockito.mock( Manager.class );
	Mockito.when( manager.getDataSource()).thenReturn( ds );
	CommandsMngrImpl cmdMngr = new CommandsMngrImpl( manager ) ;
	TestApplication app = new TestApplication();
	app.setDirectory( this.folder.newFolder());
	String cmdName = "my-command";
	String line = "rename /tomcat-vm as tomcat-vm-copy";
	cmdMngr.createOrUpdateCommand( app, cmdName, line );
	final int count = 5;
	for( int i=0; i<count; i++ ) {
		try {
			cmdMngr.execute( app, cmdName, CommandHistoryItem.ORIGIN_REST_API, "some source" );
		} catch( Exception e ) {
			// nothing
		}
	}
	List<CommandHistoryItem> historyItems = cmdMngr.getHistory( 0, 10, null, null, app.getName());
	Assert.assertEquals( count, historyItems.size());
	// Invalid argument? => Nothing is deleted.
	ByteArrayOutputStream os = new ByteArrayOutputStream();
	pruneHistoryCmd.out = new PrintStream( os, true, "UTF-8" );
	pruneHistoryCmd.daysToKeep = -10;
	pruneHistoryCmd.execute();
	historyItems = cmdMngr.getHistory( 0, 10, null, null, app.getName());
	Assert.assertEquals( count, historyItems.size());
	Assert.assertEquals( "[ WARNING ] The daysToKeep argument must be equal or greater than 0. Operation cancelled.", os.toString( "UTF-8" ).trim());
	// Remove entries older than two days. => Here, nothing will be deleted.
	os = new ByteArrayOutputStream();
	pruneHistoryCmd.out = new PrintStream( os, true, "UTF-8" );
	pruneHistoryCmd.daysToKeep = 2;
	pruneHistoryCmd.execute();
	historyItems = cmdMngr.getHistory( 0, 10, null, null, app.getName());
	Assert.assertEquals( count, historyItems.size());
	Assert.assertEquals( "Pruning the commands history.\nOnly the last 2 days will be kept.\nPruning done.", os.toString( "UTF-8" ).trim());
	// Remove entries older than two days. => Here, nothing will be deleted.
	os = new ByteArrayOutputStream();
	pruneHistoryCmd.out = new PrintStream( os, true, "UTF-8" );
	pruneHistoryCmd.daysToKeep = 1;
	pruneHistoryCmd.execute();
	historyItems = cmdMngr.getHistory( 0, 10, null, null, app.getName());
	Assert.assertEquals( count, historyItems.size());
	Assert.assertEquals( "Pruning the commands history.\nOnly the last 1 day will be kept.\nPruning done.", os.toString( "UTF-8" ).trim());
	// Remove all the entries
	os = new ByteArrayOutputStream();
	pruneHistoryCmd.out = new PrintStream( os, true, "UTF-8" );
	pruneHistoryCmd.daysToKeep = 0;
	pruneHistoryCmd.execute();
	historyItems = cmdMngr.getHistory( 0, 10, null, null, app.getName());
	Assert.assertEquals( 0, historyItems.size());
	Assert.assertEquals( "Pruning the commands history.\nAll the entries will be deleted.\nPruning done.", os.toString( "UTF-8" ).trim());
}