jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruno Dusausoy <bdusau...@yp5.be>
Subject All in-memory and unit/integration tests
Date Tue, 29 Mar 2011 09:02:35 GMT
Hi,

I'm quite new to Jackrabbit and I have a question regarding 
unit/integration tests.

I'm testing if my data are being saved into the repository.
I'm using a TransientRepository for that purpose. But since I don't have 
a specific configuration, it saves everything in the file system, which 
is fine but slow, too slow for a unit/integration test.
So I googled a bit and found an article about how to speed up tests with 
Jackrabbit[1].
The problem is that, if I do the changes they recommend, I lose all my 
data between the sessions, which is of course not what I want.

I got this kind of code in my tests :

     @Before
     public void setUp() {
         FileUtils.deleteQuietly(JACKRABBIT_REPOSITORY);
         repository = new TransientRepository(JACKRABBIT_CONFIG, 
JACKRABBIT_REPOSITORY);
         management = new JackrabbitModelManagement();
         management.setUsername(username);
         management.setPassword(password);
         management.setRepository(repository);
     }

     @After
     public void tearDown() {
         FileUtils.deleteQuietly(JACKRABBIT_REPOSITORY);
     }

     @Test
     public void testSetModelDescriptorWithoutIdNode() throws Exception {
         BaseModelVersionDescriptor descriptor =
                 new BaseModelVersionDescriptor(new 
BaseModelDescriptor(1, "first"), "1.0", 1);
         String content = "foo";
         InputStream input = IOUtils.toInputStream(content);

         // Method to test.
         management.setModelDescriptor(descriptor, input);

         Session session = repository.login(new 
SimpleCredentials(username, password.toCharArray()));
         // Retrieve content
         Node root = session.getRootNode();
         Node node = root.getNode("1/1.0/model/jcr:content");
         String actual = node.getProperty("jcr:data").getString();
         assertEquals(content, actual);
         session.logout();
     }


My code used to retrieve the content throws a PathNotFoundException 
because data has been lost between the two sessions (my 
management.setModelDescriptor() method opens and then closes a session.)

So is there a recommended way to use a "all-in-memory" configuration for 
use with tests ?

Regards.

[1] 
http://modeshape.wordpress.com/2008/02/22/speedy-unit-testing-with-jackrabbit/
--
Pensez environnement : limitez l'impression de ce mail.
Please don't print this e-mail unless you really need to.

Mime
View raw message