package com.test;

import java.io.File;

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

import org.apache.jackrabbit.core.TransientRepository;
import org.junit.Test;

import com.omf.om.api.session.factory.SessionFactory;
import com.omf.om.core.mapping.extractor.EntityMappingExtractorImpl;
import com.omf.om.core.mapping.registry.OnDemandMappingRegistry;
import com.omf.om.core.persistence.cglib.CglibProxyFactory;
import com.omf.om.core.persistence.interceptor.factory.PersistenceInterceptorFactoryImpl;
import com.omf.om.core.persistence.jcr.JcrPersistenceContext;
import com.omf.om.core.persistence.jcr.JcrPersistenceDelegateFactory;
import com.omf.om.core.session.factory.ImmutableSessionFactory;

public class JackrabbitTest {

	@Test
	public void testFoo() throws Exception {
		File file = new File(".");
		System.out.println("JackrabbitTest.testFoo() " + file.getAbsolutePath());
		Repository repository = new TransientRepository(new File(file, "target/repository"));
		System.out.println("JackrabbitTest.testFoo() " + repository);

		Session session = repository.login();

		final Node rootNode = session.getRootNode();

		Node foo = rootNode.addNode("foo");
		Node bar = foo.addNode("bar");

		bar.setProperty("foobar", "Horray!!");

		recurse(rootNode);

		SessionFactory sessionFactory = new ImmutableSessionFactory(new JcrPersistenceDelegateFactory(), new OnDemandMappingRegistry(
				new EntityMappingExtractorImpl()), new CglibProxyFactory(new PersistenceInterceptorFactoryImpl()));

		com.omf.om.api.session.Session s = sessionFactory.getSession(new JcrPersistenceContext(session));

		TestEntity testEntity = s.get(TestEntity.class, "foo/bar");

		System.out.println("JackrabbitTest.testFoo() " + testEntity);

		System.out.println("JackrabbitTest.testFoo() " + testEntity.getFoobar());

	}

	private void recurse(Node node) throws RepositoryException {
		System.out.println("JackrabbitTest.recurse() " + node.getPath());

		if (node.hasNodes()) {
			for (NodeIterator ni = node.getNodes(); ni.hasNext();) {
				recurse(ni.nextNode());
			}
		}

	}

}

@@ -1335,16 +1335,61 @@
 ray!!%22);
+%0A%09%09bar.setProperty(%22mycoolfield%22, %221000000%22);
 %0A%0A%09%09recu
@@ -1942,16 +1942,91 @@
 bar());%0A
+%09%09System.out.println(%22JackrabbitTest.testFoo() %22 + testEntity.getBlargh());
 %0A%09%7D%0A%0A%09pr

Test that runs jackrabbit