metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
RepositorySession repositorySession = mock( RepositorySession.class );
when( repositorySession.getRepository() ).thenReturn( metadataRepository );
TestRepositorySessionFactory factory =
applicationContext.getBean( "repositorySessionFactory#test", TestRepositorySessionFactory.class );
factory.setRepositorySession( repositorySession );
}