Hi,

I just tested against the brandnew 2.2.7, and can still repro this bug. Would 
you please check yourself? The test class code is below.

Simply grab a repositorty.xml file (I took mine from 
"jackrabbit-core-2.2.7-sources.jar\org\apache\jackrabbit\core\repository.xml").

When you start the test on a missing or empty repo-folder, it works. Running it 
a second time doesn’t.

Thanks!
Tom


package de.byteconsult.spoon.cmd;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;

import org.apache.jackrabbit.core.RepositoryImpl;
import org.apache.jackrabbit.core.config.RepositoryConfig;
import org.junit.Assert;
import org.junit.Test;

public class TestRepoBug {

        @Test
        public void addTest() throws Exception {
                Repository repo = 
this.createFileBasedRepository("target/test-jackrabbit",
                                "src/test/resources/test-repository.xml");
                if (repo != null) {
                        System.out.println("Version: " + 
repo.getDescriptor(Repository.REP_VERSION_DESC));
                        SimpleCredentials credentials = new 
SimpleCredentials("admin", "admin".toCharArray());
                        Session session = repo.login(credentials);
                        String path = "/test";
                        if (session.itemExists(path)) {
                                System.out.println("removing item at " + path);
                                session.removeItem(path);
                        }
                        Node node = session.getRootNode().addNode("test");
                        boolean existsBefore = session.itemExists(path);
                        node.getPath();
                        boolean existsAfter = session.itemExists(path);
                        Assert.assertTrue("Node must already exist before 
calling node.getPath()", existsBefore);
                        Assert.assertTrue("Node must still exist after calling 
node.getPath()", existsAfter);
                        session.save();
                }
                else {
                        Assert.fail("Failed to create repository");
                }
        }

        protected Repository createFileBasedRepository(String folderPath, 
String repositoryXmlPath)
                        throws RepositoryException, FileNotFoundException {
                // create homedir
                File homeDir = new File(folderPath);
                homeDir.mkdirs();

                File confFile = new File(repositoryXmlPath);
                if (!confFile.isFile()) {
                        throw new IllegalArgumentException("Repository config 
file is not a valid file: "
                                        + confFile.getAbsolutePath());
                }

                // create RepositoryConfig instance
                RepositoryConfig repositoryConfig = RepositoryConfig.create(new 
FileInputStream(confFile),
                                homeDir.getAbsolutePath());
                Repository repository = RepositoryImpl.create(repositoryConfig);
                return repository;
        }

}



-----Ursprüngliche Nachricht-----
Von: Tobias Bocanegra [mailto:[email protected]] 
Gesendet: Mittwoch, 8. Juni 2011 09:05
An: [email protected]
Betreff: Re: Session Question

hi,
i tested it with jackrabbit 2.2.5 and 2.2.6 and i always get 'true', 'true'.

but with this test case:

    @Test
    public void addTest() throws RepositoryException {
        TransientRepository repo = new TransientRepository();
        System.out.println("Version: " + 
repo.getDescriptor(Repository.REP_VERSION_DESC));
        Session session = repo.login();
        String path = "/test";
        if (session.itemExists(path)) {
            System.out.println("removing item at " + path);
            session.removeItem(path);
        }
        Node node = session.getRootNode().addNode("test");
        System.out.println(session.itemExists(path));
        node.getPath();
        System.out.println(session.itemExists(path));
    }

regards, toby

On Tue, Jun 7, 2011 at 2:37 AM, Thomas Auinger <[email protected]> wrote:
> A very basic problem has just come up (Jackrabbit 2.2.5). It seems that 
> session.itemExists() returns true for a newly created Node only after 
> node.getPath() has been called.?!
>
> Here is the code:
>
>                Session session = prompt.getSession();
>                String path = "/test";
>                if (session.itemExists(path)) {
>                        System.out.println("removing item at " + path);
>                        session.removeItem(path);
>                }
>                Node node = session.getRootNode().addNode("test");
>                System.out.println(session.itemExists(path));
>                node.getPath();
>                System.out.println(session.itemExists(path));
>
> And the output is
>
> removing item at /test
> false
> true
>
> Does that make any sense at all? I know that I can get it to work by 
> calling session.save() after the addNode() line, but since its all the 
> same session, it seems like a bug. Yet a bug too fundamental to really 
> be one... :O
>
> The code runs with Spring Testing Framework, in-VM Repository, Session 
> created via Springmodules Bean
>
> Thanks
> Tom
>
>
>
> Behalten Sie die Zukunft von Marketing und IT im Blick. Abonnieren Sie 
> unseren Newsletter unter http://newsletter.byteconsult.de
>
>


Behalten Sie die Zukunft von Marketing und IT im Blick. Abonnieren Sie unseren 
Newsletter unter http://newsletter.byteconsult.de

Reply via email to