You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ma...@apache.org on 2019/08/16 20:36:18 UTC

[archiva] 01/02: Improving metadata session handling and JCR indexing

This is an automated email from the ASF dual-hosted git repository.

martin_s pushed a commit to branch feature/storage_refactoring
in repository https://gitbox.apache.org/repos/asf/archiva.git

commit e4f38c2fbe1f6ce82da98ca9d67d6cc41757f833
Author: Martin Stockhammer <ma...@apache.org>
AuthorDate: Thu Aug 15 22:54:14 2019 +0200

    Improving metadata session handling and JCR indexing
---
 .../repository/AbstractMetadataRepositoryTest.java | 2645 +++++++++++---------
 .../cassandra/CassandraMetadataRepositoryTest.java |   17 +-
 .../file/FileMetadataRepositoryTest.java           |   17 +
 .../metadata/repository/jcr/JcrConstants.java      |   46 +
 .../repository/jcr/JcrMetadataRepository.java      |  246 +-
 .../{JcrSession.java => JcrRepositorySession.java} |    6 +-
 .../jcr/JcrRepositorySessionFactory.java           |   11 +-
 .../repository/jcr/OakRepositoryFactory.java       |  684 +++++
 .../metadata/repository/jcr/RepositoryFactory.java |  367 ---
 .../archiva/metadata/repository/jcr/jcr-schema.cnd |  108 +
 .../repository/jcr/JcrMetadataRepositoryTest.java  |  173 +-
 .../JcrRepositoryStatisticsGatheringTest.java      |   98 +-
 .../src/test/resources/log4j2-test.xml             |    6 +-
 13 files changed, 2731 insertions(+), 1693 deletions(-)

diff --git a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java
index 78b5b4d..2d75879 100644
--- a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java
+++ b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java
@@ -25,10 +25,12 @@ import org.apache.archiva.metadata.generic.GenericMetadataFacetFactory;
 import org.apache.archiva.metadata.model.*;
 import org.apache.archiva.repository.Repository;
 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.format.annotation.NumberFormat;
 import org.springframework.test.context.ContextConfiguration;
 
 import java.text.SimpleDateFormat;
@@ -36,14 +38,13 @@ import java.util.*;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-@RunWith(ArchivaSpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = {"classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml"})
+@RunWith( ArchivaSpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml"} )
 public abstract class AbstractMetadataRepositoryTest
-        extends TestCase {
+    extends TestCase
+{
     protected static final String OTHER_REPO_ID = "other-repo";
 
-    protected MetadataRepository repository;
-    protected RepositorySessionFactory sessionFactory;
 
     protected static final String TEST_REPO_ID = "test";
 
@@ -55,9 +56,9 @@ public abstract class AbstractMetadataRepositoryTest
 
     private static final String TEST_PROJECT_VERSION_2_0 = "2.0";
 
-    private static final String TEST_URL = "http://archiva.apache.org";
+    protected static final String TEST_URL = "http://archiva.apache.org";
 
-    private static final Organization TEST_ORGANIZATION = new Organization("Apache", "http://apache.org");
+    private static final Organization TEST_ORGANIZATION = new Organization( "Apache", "http://apache.org" );
 
     private static final String TEST_FACET_ID = "test-facet-id";
 
@@ -75,790 +76,958 @@ public abstract class AbstractMetadataRepositoryTest
 
     private static final String TEST_METADATA_VALUE = "testmetadata";
 
-    protected Logger log = LoggerFactory.getLogger(getClass());
+    protected Logger log = LoggerFactory.getLogger( getClass( ) );
 
     /*
      * Used by tryAssert to allow to throw exceptions in the lambda expression.
      */
     @FunctionalInterface
-    private interface AssertFunction {
-        void accept() throws Exception;
+    protected interface AssertFunction
+    {
+        void accept( ) throws Exception;
     }
 
-    private void tryAssert(AssertFunction func) throws Exception {
-        tryAssert(func, 5, 500);
+    protected void tryAssert( AssertFunction func ) throws Exception
+    {
+        tryAssert( func, 20, 500 );
     }
 
+
+    protected abstract RepositorySessionFactory getSessionFactory( );
+
+    protected abstract MetadataRepository getRepository( );
+
     /*
      * Runs the assert method until the assert is successful or the number of retries
-     * is reached. Needed because the JCR Oak index update is asynchronous, so updates
+     * is reached. This is needed because the JCR Oak index update is asynchronous, so updates
      * may not be visible immediately after the modification.
      */
-    private void tryAssert(AssertFunction func, int retries, int sleepMillis) throws Exception {
+    private void tryAssert( AssertFunction func, int retries, int sleepMillis ) throws Exception
+    {
         Throwable t = null;
         int retry = retries;
-        while (retry-- > 0) {
-            try {
-                func.accept();
+        while ( retry-- > 0 )
+        {
+            try
+            {
+                func.accept( );
                 return;
-            } catch (Exception | AssertionError e) {
+            }
+            catch ( Exception | AssertionError e )
+            {
                 t = e;
-                Thread.currentThread().sleep(sleepMillis);
-                log.warn("Retrying assert " + retry);
+                Thread.currentThread( ).sleep( sleepMillis );
+                log.warn( "Retrying assert {}: {}", retry, e.getMessage( ) );
             }
         }
-        if (retry <= 0 && t != null) {
-            if (t instanceof RuntimeException) {
+        log.warn( "Retries: {}, Exception: {}", retry, t.getMessage( ) );
+        if ( retry <= 0 && t != null )
+        {
+            if ( t instanceof RuntimeException )
+            {
                 throw (RuntimeException) t;
-            } else if (t instanceof Exception) {
+            }
+            else if ( t instanceof Exception )
+            {
                 throw (Exception) t;
             }
+            else if ( t instanceof Error )
+            {
+                throw (Error) t;
+            }
         }
     }
 
 
-    public static Map<String, MetadataFacetFactory> createTestMetadataFacetFactories() {
-        Map<String, MetadataFacetFactory> factories = new HashMap<>();
-        factories.put(TEST_FACET_ID, new MetadataFacetFactory() {
+    public static Map<String, MetadataFacetFactory> createTestMetadataFacetFactories( )
+    {
+        Map<String, MetadataFacetFactory> factories = new HashMap<>( );
+        factories.put( TEST_FACET_ID, new MetadataFacetFactory( )
+        {
             @Override
-            public MetadataFacet createMetadataFacet() {
-                return new TestMetadataFacet(TEST_METADATA_VALUE);
+            public MetadataFacet createMetadataFacet( )
+            {
+                return new TestMetadataFacet( TEST_METADATA_VALUE );
             }
 
             @Override
-            public MetadataFacet createMetadataFacet(String repositoryId, String name) {
-                return new TestMetadataFacet(TEST_METADATA_VALUE);
+            public MetadataFacet createMetadataFacet( String repositoryId, String name )
+            {
+                return new TestMetadataFacet( TEST_METADATA_VALUE );
             }
-        });
+        } );
 
         // add to ensure we don't accidentally create an empty facet ID.
-        factories.put("", new MetadataFacetFactory() {
+        factories.put( "", new MetadataFacetFactory( )
+        {
             @Override
-            public MetadataFacet createMetadataFacet() {
-                return new TestMetadataFacet("", TEST_VALUE);
+            public MetadataFacet createMetadataFacet( )
+            {
+                return new TestMetadataFacet( "", TEST_VALUE );
             }
 
             @Override
-            public MetadataFacet createMetadataFacet(String repositoryId, String name) {
-                return new TestMetadataFacet("", TEST_VALUE);
+            public MetadataFacet createMetadataFacet( String repositoryId, String name )
+            {
+                return new TestMetadataFacet( "", TEST_VALUE );
             }
-        });
+        } );
 
         // for the getArtifactsByProjectVersionMetadata tests
-        factories.put(GenericMetadataFacet.FACET_ID, new GenericMetadataFacetFactory());
+        factories.put( GenericMetadataFacet.FACET_ID, new GenericMetadataFacetFactory( ) );
 
         return factories;
     }
 
     @Test
-    public void testRootNamespaceWithNoMetadataRepository()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            Collection<String> namespaces = repository.getRootNamespaces(session, TEST_REPO_ID);
-            assertThat(namespaces).isNotNull().isEmpty();
+    public void testRootNamespaceWithNoMetadataRepository( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            tryAssert( ( ) -> {
+                Collection<String> namespaces = getRepository( ).getRootNamespaces( session, TEST_REPO_ID );
+                assertThat( namespaces ).isNotNull( ).isEmpty( );
+            } );
         }
     }
 
     @Test
-    public void testGetNamespaceOnly()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            assertThat(repository.getRootNamespaces(session, TEST_REPO_ID)).isNotNull().isEmpty();
+    public void testGetNamespaceOnly( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            tryAssert( ( ) -> {
+                assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( );
+            } );
+            getRepository( ).updateNamespace( session, TEST_REPO_ID, TEST_NAMESPACE );
 
-            repository.updateNamespace(session, TEST_REPO_ID, TEST_NAMESPACE);
+            tryAssert( ( ) -> {
+                assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isNotEmpty( ).contains(
+                    TEST_NAMESPACE ).hasSize( 1 );
+            } );
+            getRepository( ).removeNamespace( session, TEST_REPO_ID, TEST_NAMESPACE );
 
-            assertThat(repository.getRootNamespaces(session, TEST_REPO_ID)).isNotNull().isNotEmpty().contains(
-                    TEST_NAMESPACE).hasSize(1);
-
-            repository.removeNamespace(session, TEST_REPO_ID, TEST_NAMESPACE);
-
-            assertThat(repository.getRootNamespaces(session, TEST_REPO_ID)).isNotNull().isEmpty();
+            tryAssert( ( ) -> {
+                assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( );
+            } );
         }
     }
 
     @Test
-    public void testGetProjectOnly()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testGetProjectOnly( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 
-            assertNull(repository.getProject(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT));
-            assertThat(repository.getRootNamespaces(session, TEST_REPO_ID)).isNotNull().isEmpty();
+            tryAssert( ( ) -> {
+                assertNull( getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) );
+                assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( );
+            } );
 
-            ProjectMetadata project = new ProjectMetadata();
-            project.setId(TEST_PROJECT);
-            project.setNamespace(TEST_NAMESPACE);
+            ProjectMetadata project = new ProjectMetadata( );
+            project.setId( TEST_PROJECT );
+            project.setNamespace( TEST_NAMESPACE );
 
-            repository.updateProject(session, TEST_REPO_ID, project);
+            getRepository( ).updateProject( session, TEST_REPO_ID, project );
 
-            project = repository.getProject(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT);
-            assertEquals(TEST_PROJECT, project.getId());
-            assertEquals(TEST_NAMESPACE, project.getNamespace());
+            tryAssert( ( ) -> {
+                ProjectMetadata proj = getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
+                assertEquals( TEST_PROJECT, proj.getId( ) );
+                assertEquals( TEST_NAMESPACE, proj.getNamespace( ) );
+            } );
 
             // test that namespace is also constructed
 
-            Collection<String> namespaces = repository.getRootNamespaces( session, TEST_REPO_ID);
 
-            assertThat(namespaces).isNotNull().isNotEmpty().contains(TEST_NAMESPACE).hasSize(1);
+            tryAssert( ( ) -> {
+                Collection<String> namespaces = getRepository( ).getRootNamespaces( session, TEST_REPO_ID );
+
+                assertThat( namespaces ).isNotNull( ).isNotEmpty( ).contains( TEST_NAMESPACE ).hasSize( 1 );
+            } );
         }
     }
 
     @Test
-    public void testGetProjectVersionOnly()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testGetProjectVersionOnly( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+
+            tryAssert( ( ) -> {
+                assertNull( getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) );
+                assertNull( getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) );
+                assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( );
+            } );
+
+            ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
+            metadata.setId( TEST_PROJECT_VERSION );
 
-            assertNull(repository.getProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION));
-            assertNull(repository.getProject(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT));
-            assertThat(repository.getRootNamespaces(session, TEST_REPO_ID)).isNotNull().isEmpty();
+            getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
 
-            ProjectVersionMetadata metadata = new ProjectVersionMetadata();
-            metadata.setId(TEST_PROJECT_VERSION);
+            metadata = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+            assertEquals( TEST_PROJECT_VERSION, metadata.getId( ) );
 
-            repository.updateProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
+            tryAssert( ( ) -> {
 
-            metadata = repository.getProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
-            assertEquals(TEST_PROJECT_VERSION, metadata.getId());
+                // test that namespace and project is also constructed
+                Collection<String> namespaces = getRepository( ).getRootNamespaces( session, TEST_REPO_ID );
 
-            // test that namespace and project is also constructed
-            Collection<String> namespaces = repository.getRootNamespaces(session, TEST_REPO_ID);
+                assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_NAMESPACE );
 
-            assertThat(namespaces).isNotNull().isNotEmpty().hasSize(1).contains(TEST_NAMESPACE);
+            } );
 
-            ProjectMetadata projectMetadata = repository.getProject(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT);
-            assertNotNull(projectMetadata);
-            assertEquals(TEST_PROJECT, projectMetadata.getId());
-            assertEquals(TEST_NAMESPACE, projectMetadata.getNamespace());
+            tryAssert( ( ) -> {
+
+                ProjectMetadata projectMetadata = getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
+                assertNotNull( projectMetadata );
+                assertEquals( TEST_PROJECT, projectMetadata.getId( ) );
+                assertEquals( TEST_NAMESPACE, projectMetadata.getNamespace( ) );
+            } );
         }
     }
 
     @Test
-    public void testGetArtifactOnly()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testGetArtifactOnly( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 
-            assertThat(new ArrayList<>(
-                    repository.getArtifacts(session, TEST_REPO_ID, TEST_NAMESPACE,
-                            TEST_PROJECT, TEST_PROJECT_VERSION))).isNotNull().isEmpty();
-            assertThat(
-                    repository.getProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION)).isNull();
-            assertThat(repository.getProject(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT)).isNull();
+            tryAssert( ( ) -> {
+                assertThat( new ArrayList<>(
+                    getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
+                        TEST_PROJECT, TEST_PROJECT_VERSION ) ) ).isNotNull( ).isEmpty( );
+                assertThat(
+                    getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNull( );
+                assertThat( getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) ).isNull( );
 
-            assertThat(repository.getRootNamespaces(session, TEST_REPO_ID)).isNotNull().isEmpty();
+                assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isEmpty( );
 
-            ArtifactMetadata metadata = createArtifact();
+            } );
 
-            repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata);
+            ArtifactMetadata metadata = createArtifact( );
 
-            Collection<ArtifactMetadata> artifacts =
-                    repository.getArtifacts(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
-            //assertEquals( Collections.singletonList( metadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
-            assertThat(artifacts).containsExactly(metadata);
-            // test that namespace, project and project version is also constructed
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
+
+            tryAssert( ( ) -> {
+                Collection<ArtifactMetadata> artifacts =
+                    getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+                //assertEquals( Collections.singletonList( metadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
+                assertThat( artifacts ).containsExactly( metadata );
+                // test that namespace, project and project version is also constructed
 
-            assertThat(repository.getRootNamespaces(session, TEST_REPO_ID)).isNotNull().isNotEmpty().contains(
-                    TEST_NAMESPACE).hasSize(1);
+                assertThat( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ) ).isNotNull( ).isNotEmpty( ).contains(
+                    TEST_NAMESPACE ).hasSize( 1 );
 
-            ProjectMetadata projectMetadata = repository.getProject(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT);
-            assertEquals(TEST_PROJECT, projectMetadata.getId());
-            assertEquals(TEST_NAMESPACE, projectMetadata.getNamespace());
+                ProjectMetadata projectMetadata = getRepository( ).getProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
+                assertEquals( TEST_PROJECT, projectMetadata.getId( ) );
+                assertEquals( TEST_NAMESPACE, projectMetadata.getNamespace( ) );
 
-            ProjectVersionMetadata projectVersionMetadata =
-                    repository.getProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
-            assertEquals(TEST_PROJECT_VERSION, projectVersionMetadata.getId());
+                ProjectVersionMetadata projectVersionMetadata =
+                    getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+                assertEquals( TEST_PROJECT_VERSION, projectVersionMetadata.getId( ) );
+            } );
         }
     }
 
     @Test
-    public void testUpdateProjectVersionMetadataWithNoOtherArchives()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testUpdateProjectVersionMetadataWithNoOtherArchives( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 
-            ProjectVersionMetadata metadata = new ProjectVersionMetadata();
-            metadata.setId(TEST_PROJECT_VERSION);
-            MailingList mailingList = new MailingList();
-            mailingList.setName("Foo List");
-            mailingList.setOtherArchives(Collections.<String>emptyList());
-            metadata.setMailingLists(Arrays.asList(mailingList));
-            repository.updateProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
+            ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
+            metadata.setId( TEST_PROJECT_VERSION );
+            MailingList mailingList = new MailingList( );
+            mailingList.setName( "Foo List" );
+            mailingList.setOtherArchives( Collections.<String>emptyList( ) );
+            metadata.setMailingLists( Arrays.asList( mailingList ) );
+            getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
 
-            metadata = repository.getProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
-            assertEquals(TEST_PROJECT_VERSION, metadata.getId());
+            metadata = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+            assertEquals( TEST_PROJECT_VERSION, metadata.getId( ) );
 
-            List<MailingList> mailingLists = metadata.getMailingLists();
+            List<MailingList> mailingLists = metadata.getMailingLists( );
 
-            assertThat(mailingLists).isNotNull().isNotEmpty().hasSize(1);
+            assertThat( mailingLists ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
 
-            mailingList = metadata.getMailingLists().get(0);
-            assertEquals("Foo List", mailingList.getName());
+            mailingList = metadata.getMailingLists( ).get( 0 );
+            assertEquals( "Foo List", mailingList.getName( ) );
 
-            List<String> others = mailingList.getOtherArchives();
-            assertThat(others).isNotNull().isEmpty();
+            List<String> others = mailingList.getOtherArchives( );
+            assertThat( others ).isNotNull( ).isEmpty( );
         }
     }
 
     @Test
-    public void testUpdateProjectVersionMetadataWithAllElements()
-            throws Exception {
-
-        try (RepositorySession session = sessionFactory.createSession()) {
-
-            ProjectVersionMetadata metadata = new ProjectVersionMetadata();
-            metadata.setId(TEST_PROJECT_VERSION);
+    public void testUpdateProjectVersionMetadataWithAllElements( )
+        throws Exception
+    {
 
-            metadata.setName("project name");
-            metadata.setDescription("project description");
-            metadata.setUrl("the url");
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 
-            MailingList mailingList = new MailingList();
-            mailingList.setName("Foo List");
-            mailingList.setUnsubscribeAddress("UnsubscribeAddress");
-            mailingList.setSubscribeAddress("SubscribeAddress");
-            mailingList.setPostAddress("PostAddress");
-            mailingList.setMainArchiveUrl("MainArchiveUrl");
-            mailingList.setOtherArchives(Arrays.asList("other archive"));
-            metadata.setMailingLists(Arrays.asList(mailingList));
+            ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
+            metadata.setId( TEST_PROJECT_VERSION );
 
-            Scm scm = new Scm();
-            scm.setConnection("connection");
-            scm.setDeveloperConnection("dev conn");
-            scm.setUrl("url");
-            metadata.setScm(scm);
-
-            CiManagement ci = new CiManagement();
-            ci.setSystem("system");
-            ci.setUrl("ci url");
-            metadata.setCiManagement(ci);
-
-            IssueManagement tracker = new IssueManagement();
-            tracker.setSystem("system");
-            tracker.setUrl("issue tracker url");
-            metadata.setIssueManagement(tracker);
+            metadata.setName( "project name" );
+            metadata.setDescription( "project description" );
+            metadata.setUrl( "the url" );
 
-            metadata.setOrganization(TEST_ORGANIZATION);
+            MailingList mailingList = new MailingList( );
+            mailingList.setName( "Foo List" );
+            mailingList.setUnsubscribeAddress( "UnsubscribeAddress" );
+            mailingList.setSubscribeAddress( "SubscribeAddress" );
+            mailingList.setPostAddress( "PostAddress" );
+            mailingList.setMainArchiveUrl( "MainArchiveUrl" );
+            mailingList.setOtherArchives( Arrays.asList( "other archive" ) );
+            metadata.setMailingLists( Arrays.asList( mailingList ) );
 
-            License l = new License();
-            l.setName("license name");
-            l.setUrl("license url");
-            metadata.addLicense(l);
+            Scm scm = new Scm( );
+            scm.setConnection( "connection" );
+            scm.setDeveloperConnection( "dev conn" );
+            scm.setUrl( "url" );
+            metadata.setScm( scm );
+
+            CiManagement ci = new CiManagement( );
+            ci.setSystem( "system" );
+            ci.setUrl( "ci url" );
+            metadata.setCiManagement( ci );
+
+            IssueManagement tracker = new IssueManagement( );
+            tracker.setSystem( "system" );
+            tracker.setUrl( "issue tracker url" );
+            metadata.setIssueManagement( tracker );
+
+            metadata.setOrganization( TEST_ORGANIZATION );
 
-            Dependency d = new Dependency();
-            d.setArtifactId("artifactId");
-            d.setClassifier("classifier");
-            d.setGroupId("groupId");
-            d.setScope("scope");
-            d.setSystemPath("system path");
-            d.setType("type");
-            d.setVersion("version");
-            d.setOptional(true);
-            metadata.addDependency(d);
+            License l = new License( );
+            l.setName( "license name" );
+            l.setUrl( "license url" );
+            metadata.addLicense( l );
+
+            Dependency d = new Dependency( );
+            d.setArtifactId( "artifactId" );
+            d.setClassifier( "classifier" );
+            d.setGroupId( "groupId" );
+            d.setScope( "scope" );
+            d.setSystemPath( "system path" );
+            d.setType( "type" );
+            d.setVersion( "version" );
+            d.setOptional( true );
+            metadata.addDependency( d );
+
+            getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
+
+            metadata = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+            assertEquals( TEST_PROJECT_VERSION, metadata.getId( ) );
+            assertEquals( TEST_PROJECT_VERSION, metadata.getVersion( ) );
+            assertEquals( "project name", metadata.getName( ) );
+            assertEquals( "project description", metadata.getDescription( ) );
+            assertEquals( "the url", metadata.getUrl( ) );
+
+            assertEquals( "connection", metadata.getScm( ).getConnection( ) );
+            assertEquals( "dev conn", metadata.getScm( ).getDeveloperConnection( ) );
+            assertEquals( "url", metadata.getScm( ).getUrl( ) );
+
+            assertEquals( "system", metadata.getCiManagement( ).getSystem( ) );
+            assertEquals( "ci url", metadata.getCiManagement( ).getUrl( ) );
+
+            assertEquals( "system", metadata.getIssueManagement( ).getSystem( ) );
+            assertEquals( "issue tracker url", metadata.getIssueManagement( ).getUrl( ) );
+
+            assertEquals( TEST_ORGANIZATION.getName( ), metadata.getOrganization( ).getName( ) );
+            assertEquals( TEST_ORGANIZATION.getUrl( ), metadata.getOrganization( ).getUrl( ) );
+
+            assertEquals( 1, metadata.getMailingLists( ).size( ) );
+            MailingList retrievedMailingList = metadata.getMailingLists( ).get( 0 );
+            assertEquals( mailingList.getName( ), retrievedMailingList.getName( ) );
+            assertEquals( mailingList.getMainArchiveUrl( ), retrievedMailingList.getMainArchiveUrl( ) );
+            assertEquals( mailingList.getPostAddress( ), retrievedMailingList.getPostAddress( ) );
+            assertEquals( mailingList.getSubscribeAddress( ), retrievedMailingList.getSubscribeAddress( ) );
+            assertEquals( mailingList.getUnsubscribeAddress( ), retrievedMailingList.getUnsubscribeAddress( ) );
+            assertThat( retrievedMailingList.getOtherArchives( ) ) //
+                .isNotNull( ) //
+                .isNotEmpty( ) //
+                .hasSize( 1 ) //
+                .contains( "other archive" );
+
+            assertEquals( 1, metadata.getLicenses( ).size( ) );
+            l = metadata.getLicenses( ).get( 0 );
+            assertEquals( "license name", l.getName( ) );
+            assertEquals( "license url", l.getUrl( ) );
+
+            assertEquals( 1, metadata.getDependencies( ).size( ) );
+            d = metadata.getDependencies( ).get( 0 );
+            assertEquals( "artifactId", d.getArtifactId( ) );
+            assertEquals( "classifier", d.getClassifier( ) );
+            assertEquals( "groupId", d.getGroupId( ) );
+            assertEquals( "scope", d.getScope( ) );
+            assertEquals( "system path", d.getSystemPath( ) );
+            assertEquals( "type", d.getType( ) );
+            assertEquals( "version", d.getVersion( ) );
+            assertTrue( d.isOptional( ) );
+        }
+    }
+
+    @Test
+    public void testUpdateProjectVersionMetadataIncomplete( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+
+            ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
+            metadata.setId( TEST_PROJECT_VERSION );
+            metadata.setIncomplete( true );
+            getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
 
-            repository.updateProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
-
-            metadata = repository.getProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
-            assertEquals(TEST_PROJECT_VERSION, metadata.getId());
-            assertEquals(TEST_PROJECT_VERSION, metadata.getVersion());
-            assertEquals("project name", metadata.getName());
-            assertEquals("project description", metadata.getDescription());
-            assertEquals("the url", metadata.getUrl());
+            tryAssert( ( ) -> {
+                ProjectVersionMetadata metadata1 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+                assertEquals( true, metadata1.isIncomplete( ) );
+                assertNull( metadata1.getCiManagement( ) );
+                assertNull( metadata1.getScm( ) );
+                assertNull( metadata1.getIssueManagement( ) );
+                assertNull( metadata1.getOrganization( ) );
+                assertEquals( "", metadata1.getDescription( ) );
+                assertEquals( "", metadata1.getName( ) );
+                assertEquals( TEST_PROJECT_VERSION, metadata1.getId( ) );
+                assertEquals( TEST_PROJECT_VERSION, metadata1.getVersion( ) );
+                assertTrue( metadata1.getMailingLists( ).isEmpty( ) );
+                assertTrue( metadata1.getLicenses( ).isEmpty( ) );
+                assertTrue( metadata1.getDependencies( ).isEmpty( ) );
+            } );
+        }
+    }
 
-            assertEquals("connection", metadata.getScm().getConnection());
-            assertEquals("dev conn", metadata.getScm().getDeveloperConnection());
-            assertEquals("url", metadata.getScm().getUrl());
+    @Test
+    public void testUpdateProjectVersionMetadataWithExistingFacets( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 
-            assertEquals("system", metadata.getCiManagement().getSystem());
-            assertEquals("ci url", metadata.getCiManagement().getUrl());
+            ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
+            metadata.setId( TEST_PROJECT_VERSION );
+            MetadataFacet facet = new TestMetadataFacet( "baz" );
+            metadata.addFacet( facet );
+            getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
 
-            assertEquals("system", metadata.getIssueManagement().getSystem());
-            assertEquals("issue tracker url", metadata.getIssueManagement().getUrl());
+            tryAssert( ( ) -> {
 
-            assertEquals(TEST_ORGANIZATION.getName(), metadata.getOrganization().getName());
-            assertEquals(TEST_ORGANIZATION.getUrl(), metadata.getOrganization().getUrl());
+                ProjectVersionMetadata metadata1 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+                assertEquals( Collections.singleton( TEST_FACET_ID ), metadata1.getFacetIds( ) );
+            } );
 
-            assertEquals(1, metadata.getMailingLists().size());
-            MailingList retrievedMailingList = metadata.getMailingLists().get(0);
-            assertEquals(mailingList.getName(), retrievedMailingList.getName());
-            assertEquals(mailingList.getMainArchiveUrl(), retrievedMailingList.getMainArchiveUrl());
-            assertEquals(mailingList.getPostAddress(), retrievedMailingList.getPostAddress());
-            assertEquals(mailingList.getSubscribeAddress(), retrievedMailingList.getSubscribeAddress());
-            assertEquals(mailingList.getUnsubscribeAddress(), retrievedMailingList.getUnsubscribeAddress());
-            assertThat(retrievedMailingList.getOtherArchives()) //
-                    .isNotNull() //
-                    .isNotEmpty() //
-                    .hasSize(1) //
-                    .contains("other archive");
+            metadata = new ProjectVersionMetadata( );
+            metadata.setId( TEST_PROJECT_VERSION );
+            getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
 
-            assertEquals(1, metadata.getLicenses().size());
-            l = metadata.getLicenses().get(0);
-            assertEquals("license name", l.getName());
-            assertEquals("license url", l.getUrl());
+            tryAssert( ( ) -> {
 
-            assertEquals(1, metadata.getDependencies().size());
-            d = metadata.getDependencies().get(0);
-            assertEquals("artifactId", d.getArtifactId());
-            assertEquals("classifier", d.getClassifier());
-            assertEquals("groupId", d.getGroupId());
-            assertEquals("scope", d.getScope());
-            assertEquals("system path", d.getSystemPath());
-            assertEquals("type", d.getType());
-            assertEquals("version", d.getVersion());
-            assertTrue(d.isOptional());
+                ProjectVersionMetadata metadata2 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+                assertEquals( Collections.singleton( TEST_FACET_ID ), metadata2.getFacetIds( ) );
+                TestMetadataFacet testFacet = (TestMetadataFacet) metadata2.getFacet( TEST_FACET_ID );
+                assertEquals( "baz", testFacet.getValue( ) );
+            } );
         }
     }
 
     @Test
-    public void testUpdateProjectVersionMetadataIncomplete()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testUpdateProjectVersionMetadataWithNoExistingFacets( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 
-            ProjectVersionMetadata metadata = new ProjectVersionMetadata();
-            metadata.setId(TEST_PROJECT_VERSION);
-            metadata.setIncomplete(true);
-            repository.updateProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
+            ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
+            metadata.setId( TEST_PROJECT_VERSION );
+            getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
 
-            metadata = repository.getProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
-            assertEquals(true, metadata.isIncomplete());
-            assertNull(metadata.getCiManagement());
-            assertNull(metadata.getScm());
-            assertNull(metadata.getIssueManagement());
-            assertNull(metadata.getOrganization());
-            assertNull(metadata.getDescription());
-            assertNull(metadata.getName());
-            assertEquals(TEST_PROJECT_VERSION, metadata.getId());
-            assertEquals(TEST_PROJECT_VERSION, metadata.getVersion());
-            assertTrue(metadata.getMailingLists().isEmpty());
-            assertTrue(metadata.getLicenses().isEmpty());
-            assertTrue(metadata.getDependencies().isEmpty());
-        }
-    }
-
-    @Test
-    public void testUpdateProjectVersionMetadataWithExistingFacets()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
 
-            ProjectVersionMetadata metadata = new ProjectVersionMetadata();
-            metadata.setId(TEST_PROJECT_VERSION);
-            MetadataFacet facet = new TestMetadataFacet("baz");
-            metadata.addFacet(facet);
-            repository.updateProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
+            tryAssert( ( ) -> {
+                ProjectVersionMetadata metadata1 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
 
-            metadata = repository.getProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
-            assertEquals(Collections.singleton(TEST_FACET_ID), metadata.getFacetIds());
+                assertThat( metadata1.getFacetIds( ) ).isNotNull( ).isEmpty( );
+            } );
 
-            metadata = new ProjectVersionMetadata();
-            metadata.setId(TEST_PROJECT_VERSION);
-            repository.updateProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
+            ProjectVersionMetadata metadata1 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+            metadata = new ProjectVersionMetadata( );
+            metadata.setId( TEST_PROJECT_VERSION );
+            getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
 
-            metadata = repository.getProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
-            assertEquals(Collections.singleton(TEST_FACET_ID), metadata.getFacetIds());
-            TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet(TEST_FACET_ID);
-            assertEquals("baz", testFacet.getValue());
+            tryAssert( ( ) -> {
+                ProjectVersionMetadata metadata2 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+                assertThat( metadata2.getFacetIds( ) ).isNotNull( ).isEmpty( );
+            } );
         }
     }
 
     @Test
-    public void testUpdateProjectVersionMetadataWithNoExistingFacets()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testUpdateProjectVersionMetadataWithExistingFacetsFacetPropertyWasRemoved( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 
-            ProjectVersionMetadata metadata = new ProjectVersionMetadata();
-            metadata.setId(TEST_PROJECT_VERSION);
-            repository.updateProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
+            ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
+            metadata.setId( TEST_PROJECT_VERSION );
 
-            metadata = repository.getProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
+            Map<String, String> additionalProps = new HashMap<>( );
+            additionalProps.put( "deleteKey", "deleteValue" );
 
-            assertThat(metadata.getFacetIds()).isNotNull().isEmpty();
+            MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz", additionalProps );
+            metadata.addFacet( facet );
+            getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
 
-            metadata = new ProjectVersionMetadata();
-            metadata.setId(TEST_PROJECT_VERSION);
-            repository.updateProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
 
-            metadata = repository.getProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
-            assertThat(metadata.getFacetIds()).isNotNull().isEmpty();
-        }
-    }
-
-    @Test
-    public void testUpdateProjectVersionMetadataWithExistingFacetsFacetPropertyWasRemoved()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+            tryAssert( ( ) -> {
 
-            ProjectVersionMetadata metadata = new ProjectVersionMetadata();
-            metadata.setId(TEST_PROJECT_VERSION);
+                ProjectVersionMetadata metad = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
 
-            Map<String, String> additionalProps = new HashMap<>();
-            additionalProps.put("deleteKey", "deleteValue");
+                assertThat( metad.getFacetIds( ) ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_FACET_ID );
 
-            MetadataFacet facet = new TestMetadataFacet(TEST_FACET_ID, "baz", additionalProps);
-            metadata.addFacet(facet);
-            repository.updateProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
 
-            metadata = repository.getProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
+            } );
 
-            assertThat(metadata.getFacetIds()).isNotNull().isNotEmpty().hasSize(1).contains(TEST_FACET_ID);
+            ProjectVersionMetadata metad = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+            TestMetadataFacet testFacet = (TestMetadataFacet) metad.getFacet( TEST_FACET_ID );
+            Map<String, String> facetProperties = testFacet.toProperties( );
 
-            TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet(TEST_FACET_ID);
-            Map<String, String> facetProperties = testFacet.toProperties();
+            assertEquals( "deleteValue", facetProperties.get( "deleteKey" ) );
 
-            assertEquals("deleteValue", facetProperties.get("deleteKey"));
+            facetProperties.remove( "deleteKey" );
 
-            facetProperties.remove("deleteKey");
+            TestMetadataFacet newTestFacet = new TestMetadataFacet( TEST_FACET_ID, testFacet.getValue( ), facetProperties );
+            metadata.addFacet( newTestFacet );
 
-            TestMetadataFacet newTestFacet = new TestMetadataFacet(TEST_FACET_ID, testFacet.getValue(), facetProperties);
-            metadata.addFacet(newTestFacet);
+            getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
 
-            repository.updateProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
 
-            metadata = repository.getProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
+            tryAssert( ( ) -> {
+                ProjectVersionMetadata metad2 = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
 
-            assertThat(metadata.getFacetIds()).isNotNull().isNotEmpty().hasSize(1).contains(TEST_FACET_ID);
-            testFacet = (TestMetadataFacet) metadata.getFacet(TEST_FACET_ID);
-            assertFalse(testFacet.toProperties().containsKey("deleteKey"));
+                assertThat( metad2.getFacetIds( ) ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_FACET_ID );
+                TestMetadataFacet testFacet2 = (TestMetadataFacet) metad2.getFacet( TEST_FACET_ID );
+                assertFalse( testFacet2.toProperties( ).containsKey( "deleteKey" ) );
+            } );
         }
     }
 
     @Test
-    public void testGetArtifactsDoesntReturnProjectVersionMetadataFacets()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testGetArtifactsDoesntReturnProjectVersionMetadataFacets( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 
-            ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
-            versionMetadata.setId(TEST_PROJECT_VERSION);
+            ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata( );
+            versionMetadata.setId( TEST_PROJECT_VERSION );
 
-            MetadataFacet facet = new TestMetadataFacet(TEST_FACET_ID, "baz");
-            versionMetadata.addFacet(facet);
-            repository.updateProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, versionMetadata);
+            MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz" );
+            versionMetadata.addFacet( facet );
+            getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, versionMetadata );
+            ArtifactMetadata artifactMetadata = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifactMetadata );
+            session.save( );
 
-            ArtifactMetadata artifactMetadata = createArtifact();
-            repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifactMetadata);
-            session.save();
+            tryAssert( ( ) -> {
 
-            Collection<ArtifactMetadata> artifacts =
-                    repository.getArtifacts(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
-            assertEquals(Collections.singletonList(artifactMetadata), new ArrayList<>(artifacts));
 
-            artifacts = repository.getArtifacts(session, TEST_REPO_ID);
-            assertEquals(Collections.singletonList(artifactMetadata), new ArrayList<>(artifacts));
+                Collection<ArtifactMetadata> artifacts =
+                    getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+                assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
+
+                artifacts = getRepository( ).getArtifacts( session, TEST_REPO_ID );
+                assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
 
-            artifacts = repository.getArtifactsByChecksum(session, TEST_REPO_ID, TEST_SHA1);
-            assertEquals(Collections.singletonList(artifactMetadata), new ArrayList<>(artifacts));
+                artifacts = getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 );
+                assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
 
-            artifacts = repository.getArtifactsByChecksum(session, TEST_REPO_ID, TEST_MD5);
-            assertEquals(Collections.singletonList(artifactMetadata), new ArrayList<>(artifacts));
+                artifacts = getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 );
+                assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
 
-            artifacts = repository.getArtifactsByDateRange(session, TEST_REPO_ID, null, null);
-            assertEquals(Collections.singletonList(artifactMetadata), new ArrayList<>(artifacts));
+                artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null );
+                assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<>( artifacts ) );
+            } );
         }
     }
 
     @Test
-    public void testUpdateArtifactMetadataWithExistingFacetsFacetPropertyWasRemoved()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testUpdateArtifactMetadataWithExistingFacetsFacetPropertyWasRemoved( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 
-            ArtifactMetadata metadata = createArtifact();
+            ArtifactMetadata metadata = createArtifact( );
 
-            Map<String, String> additionalProps = new HashMap<>();
-            additionalProps.put("deleteKey", "deleteValue");
+            Map<String, String> additionalProps = new HashMap<>( );
+            additionalProps.put( "deleteKey", "deleteValue" );
 
-            MetadataFacet facet = new TestMetadataFacet(TEST_FACET_ID, "baz", additionalProps);
-            metadata.addFacet(facet);
-            repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata);
+            MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz", additionalProps );
+            metadata.addFacet( facet );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
 
-            Collection<ArtifactMetadata> artifacts =
-                    repository.getArtifacts(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
+            tryAssert( ( ) -> {
+                Collection<ArtifactMetadata> artifacts =
+                    getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+
+                assertThat( artifacts ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
+            } );
 
-            assertThat(artifacts).isNotNull().isNotEmpty().hasSize(1);
-            metadata = artifacts.iterator().next();
+            Collection<ArtifactMetadata> artifacts =
+                getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+            metadata = artifacts.iterator( ).next( );
 
-            Collection<String> ids = metadata.getFacetIds();
-            assertThat(ids).isNotNull().isNotEmpty().hasSize(1).contains(TEST_FACET_ID);
+            Collection<String> ids = metadata.getFacetIds( );
+            assertThat( ids ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_FACET_ID );
 
-            TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet(TEST_FACET_ID);
-            Map<String, String> facetProperties = testFacet.toProperties();
+            TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
+            Map<String, String> facetProperties = testFacet.toProperties( );
 
-            assertEquals("deleteValue", facetProperties.get("deleteKey"));
+            assertEquals( "deleteValue", facetProperties.get( "deleteKey" ) );
 
-            facetProperties.remove("deleteKey");
+            facetProperties.remove( "deleteKey" );
 
-            TestMetadataFacet newTestFacet = new TestMetadataFacet(TEST_FACET_ID, testFacet.getValue(), facetProperties);
-            metadata.addFacet(newTestFacet);
+            TestMetadataFacet newTestFacet = new TestMetadataFacet( TEST_FACET_ID, testFacet.getValue( ), facetProperties );
+            metadata.addFacet( newTestFacet );
 
-            repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata);
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
+            session.save( );
 
-            artifacts = repository.getArtifacts(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
+            tryAssert( ( ) -> {
+                Collection<ArtifactMetadata> artifacts1 = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
 
-            assertThat(artifacts).isNotNull().isNotEmpty().hasSize(1);
-            metadata = artifacts.iterator().next();
+                assertThat( artifacts1 ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
+            } );
+            Collection<ArtifactMetadata> artifacts1 = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+            metadata = artifacts.iterator( ).next( );
 
-            ids = metadata.getFacetIds();
-            assertThat(ids).isNotNull().isNotEmpty().hasSize(1).contains(TEST_FACET_ID);
+            ids = metadata.getFacetIds( );
+            assertThat( ids ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_FACET_ID );
 
-            testFacet = (TestMetadataFacet) metadata.getFacet(TEST_FACET_ID);
+            testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
 
-            Map<String, String> props = testFacet.toProperties();
-            assertThat(props).isNotNull().doesNotContainKey("deleteKey");
+            Map<String, String> props = testFacet.toProperties( );
+            assertThat( props ).isNotNull( ).doesNotContainKey( "deleteKey" );
         }
     }
 
     @Test
-    public void testUpdateArtifactMetadataWithExistingFacets()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testUpdateArtifactMetadataWithExistingFacets( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 
-            ArtifactMetadata metadata = createArtifact();
-            MetadataFacet facet = new TestMetadataFacet("baz");
-            metadata.addFacet(facet);
-            repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata);
+            ArtifactMetadata metadata = createArtifact( );
+            MetadataFacet facet = new TestMetadataFacet( "baz" );
+            metadata.addFacet( facet );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
 
-            metadata = repository.getArtifacts(session, TEST_REPO_ID, TEST_NAMESPACE,
-                    TEST_PROJECT, TEST_PROJECT_VERSION).iterator().next();
-            assertEquals(Collections.singleton(TEST_FACET_ID), metadata.getFacetIds());
+            metadata = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
+                TEST_PROJECT, TEST_PROJECT_VERSION ).iterator( ).next( );
+            assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds( ) );
 
-            metadata = createArtifact();
-            repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata);
+            metadata = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
 
-            metadata = repository.getArtifacts(session, TEST_REPO_ID, TEST_NAMESPACE,
-                    TEST_PROJECT, TEST_PROJECT_VERSION).iterator().next();
-            assertEquals(Collections.singleton(TEST_FACET_ID), metadata.getFacetIds());
-            TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet(TEST_FACET_ID);
-            assertEquals("baz", testFacet.getValue());
+            metadata = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
+                TEST_PROJECT, TEST_PROJECT_VERSION ).iterator( ).next( );
+            assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds( ) );
+            TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
+            assertEquals( "baz", testFacet.getValue( ) );
         }
     }
 
     @Test
-    public void testUpdateArtifactMetadataWithNoExistingFacets()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata metadata = createArtifact();
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata);
+    public void testUpdateArtifactMetadataWithNoExistingFacets( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata metadata = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
+
+            tryAssert( ( ) -> {
+
+                ArtifactMetadata metadata2 = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
+                    TEST_PROJECT, TEST_PROJECT_VERSION ).iterator( ).next( );
+                assertEquals( Collections.<String>emptyList( ), new ArrayList<String>( metadata2.getFacetIds( ) ) );
 
-            metadata = repository.getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
-                    TEST_PROJECT, TEST_PROJECT_VERSION).iterator().next();
-            assertEquals(Collections.<String>emptyList(), new ArrayList<String>(metadata.getFacetIds()));
+            } );
 
-            metadata = createArtifact();
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata);
+            metadata = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
+                TEST_PROJECT, TEST_PROJECT_VERSION ).iterator( ).next( );
+            metadata = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata );
 
-            metadata = repository.getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
-                    TEST_PROJECT, TEST_PROJECT_VERSION).iterator().next();
-            assertEquals(Collections.<String>emptyList(), new ArrayList<String>(metadata.getFacetIds()));
 
+            tryAssert( ( ) -> {
+                ArtifactMetadata metadata3 = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
+                    TEST_PROJECT, TEST_PROJECT_VERSION ).iterator( ).next( );
+                assertEquals( Collections.<String>emptyList( ), new ArrayList<String>( metadata3.getFacetIds( ) ) );
+            } );
         }
     }
 
     @Test
-    public void testGetMetadataFacet()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            repository.addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet(TEST_VALUE));
+    public void testGetMetadataFacet( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
 
             TestMetadataFacet test =
-                    (TestMetadataFacet) repository.getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME);
+                (TestMetadataFacet) getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
 
-            assertEquals(new TestMetadataFacet(TEST_VALUE), test);
+            assertEquals( new TestMetadataFacet( TEST_VALUE ), test );
 
         }
     }
 
     @Test
-    public void testGetMetadataFacetWhenEmpty()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            assertNull(repository.getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME));
-
+    public void testGetMetadataFacetWhenEmpty( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            tryAssert( ( ) -> assertNull( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ) );
         }
     }
 
     @Test
-    public void testGetMetadataFacetWhenUnknownName()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            repository.addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet(TEST_VALUE));
-
-            assertNull(repository.getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, UNKNOWN));
+    public void testGetMetadataFacetWhenUnknownName( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
 
+            tryAssert( ( ) -> assertNull( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, UNKNOWN ) ) );
         }
     }
 
     @Test
-    public void testGetMetadataFacetWhenDefaultValue()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            repository.addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet(null));
+    public void testGetMetadataFacetWhenDefaultValue( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( null ) );
 
-            MetadataFacet metadataFacet = repository.getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME);
+            tryAssert( ( ) -> {
+                MetadataFacet metadataFacet = getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
 
-            assertEquals(new TestMetadataFacet(TEST_METADATA_VALUE), metadataFacet);
+                assertEquals( new TestMetadataFacet( TEST_METADATA_VALUE ), metadataFacet );
+            } );
 
         }
     }
 
     @Test
-    public void testGetMetadataFacetWhenUnknownFacetId()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            assertNull(repository.getMetadataFacet( session, TEST_REPO_ID, UNKNOWN, TEST_NAME));
+    public void testGetMetadataFacetWhenUnknownFacetId( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            assertNull( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, UNKNOWN, TEST_NAME ) );
 
         }
     }
 
     @Test
-    public void testGetMetadataFacets()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            repository.addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet(TEST_VALUE));
+    public void testGetMetadataFacets( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
 
-            assertEquals(Collections.singletonList(TEST_NAME),
-                    repository.getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID));
+            assertEquals( Collections.singletonList( TEST_NAME ),
+                getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID ) );
 
         }
     }
 
     @Test
-    public void testGetMetadataFacetsWhenEmpty()
-            throws Exception {
+    public void testGetMetadataFacetsWhenEmpty( )
+        throws Exception
+    {
 
-        try (RepositorySession session = sessionFactory.createSession()) {
-            List<String> facets = repository.getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID);
-            assertTrue(facets.isEmpty());
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            tryAssert( ( ) -> {
 
+                List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
+                assertTrue( facets.isEmpty( ) );
+            } );
         }
     }
 
     @Test
-    public void testRemoveFacets()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            repository.addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet(TEST_VALUE));
+    public void testRemoveFacets( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
 
-            List<String> facets = repository.getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID);
-            assertFalse(facets.isEmpty());
+            List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
+            assertFalse( facets.isEmpty( ) );
 
-            repository.removeMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID);
+            getRepository( ).removeMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
 
-            facets = repository.getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID);
-            assertTrue(facets.isEmpty());
+            facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
+            assertTrue( facets.isEmpty( ) );
 
         }
     }
 
     @Test
-    public void testRemoveFacetsWhenEmpty()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            List<String> facets = repository.getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID);
-            assertTrue(facets.isEmpty());
-
-            repository.removeMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID);
+    public void testRemoveFacetsWhenEmpty( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
+            assertTrue( facets.isEmpty( ) );
 
-            facets = repository.getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID);
-            assertTrue(facets.isEmpty());
+            getRepository( ).removeMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
 
+            tryAssert( ( ) -> {
+                List<String> facets1 = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
+                assertTrue( facets1.isEmpty( ) );
+            } );
         }
     }
 
     @Test
-    public void testRemoveFacetsWhenUnknown()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testRemoveFacetsWhenUnknown( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 // testing no exception
-            repository.removeMetadataFacets( session, TEST_REPO_ID, UNKNOWN);
+            getRepository( ).removeMetadataFacets( session, TEST_REPO_ID, UNKNOWN );
 
         }
     }
 
     @Test
-    public void testRemoveFacetWhenUnknown()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testRemoveFacetWhenUnknown( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 // testing no exception
-            repository.removeMetadataFacet( session, TEST_REPO_ID, UNKNOWN, TEST_NAME);
+            getRepository( ).removeMetadataFacet( session, TEST_REPO_ID, UNKNOWN, TEST_NAME );
 
         }
     }
 
     @Test
-    public void testRemoveFacet()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            TestMetadataFacet metadataFacet = new TestMetadataFacet(TEST_VALUE);
-            repository.addMetadataFacet( session, TEST_REPO_ID, metadataFacet);
+    public void testRemoveFacet( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            TestMetadataFacet metadataFacet = new TestMetadataFacet( TEST_VALUE );
+            getRepository( ).addMetadataFacet( session, TEST_REPO_ID, metadataFacet );
 
-            assertEquals(metadataFacet, repository.getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME));
-            List<String> facets = repository.getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID);
-            assertFalse(facets.isEmpty());
+            assertEquals( metadataFacet, getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
+            List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
+            assertFalse( facets.isEmpty( ) );
 
-            repository.removeMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME);
+            getRepository( ).removeMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
 
-            assertNull(repository.getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME));
-            facets = repository.getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID);
-            assertTrue(facets.isEmpty());
+            assertNull( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
+            facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
+            assertTrue( facets.isEmpty( ) );
 
         }
     }
 
     @Test
-    public void testRemoveFacetWhenEmpty()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            List<String> facets = repository.getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID);
-            assertThat(facets).isNotNull().isEmpty();
-            assertThat(repository.getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME)).isNull();
+    public void testRemoveFacetWhenEmpty( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            tryAssert( ( ) -> {
+
+                List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
+                assertThat( facets ).isNotNull( ).isEmpty( );
+                assertThat( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ).isNull( );
+
+            } );
+            getRepository( ).removeMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME );
 
-            repository.removeMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME);
+            tryAssert( ( ) -> {
 
-            facets = repository.getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID);
-            assertThat(facets).isNotNull().isEmpty();
-            assertThat(repository.getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME)).isNull();
+                List<String> facets2 = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, TEST_FACET_ID );
+                assertThat( facets2 ).isNotNull( ).isEmpty( );
+                assertThat( getRepository( ).getMetadataFacet( session, TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ).isNull( );
 
+            } );
         }
     }
 
     @Test
-    public void hasMetadataFacetStart()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            assertFalse(repository.hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName()));
+    public void hasMetadataFacetStart( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            assertFalse( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
 
 
         }
     }
 
     @Test
-    public void hasMetadataFacet()
-            throws Exception {
+    public void hasMetadataFacet( )
+        throws Exception
+    {
 
-        try (RepositorySession session = sessionFactory.createSession()) {
-            assertFalse(repository.hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName()));
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            assertFalse( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
 
-            Calendar cal = Calendar.getInstance();
+            Calendar cal = Calendar.getInstance( );
 
-            repository.addMetadataFacet( session, TEST_REPO_ID, new KindOfRepositoryStatistics("first", cal.getTime()));
+            getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new KindOfRepositoryStatistics( "first", cal.getTime( ) ) );
 
-            assertTrue(repository.hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName()));
+            assertTrue( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
 
-            cal.add(Calendar.MINUTE, 2);
+            cal.add( Calendar.MINUTE, 2 );
 
-            repository.addMetadataFacet( session, TEST_REPO_ID, new KindOfRepositoryStatistics("second", cal.getTime()));
+            getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new KindOfRepositoryStatistics( "second", cal.getTime( ) ) );
 
-            cal.add(Calendar.MINUTE, 2);
+            cal.add( Calendar.MINUTE, 2 );
 
-            repository.addMetadataFacet( session, TEST_REPO_ID, new KindOfRepositoryStatistics("third", cal.getTime()));
+            getRepository( ).addMetadataFacet( session, TEST_REPO_ID, new KindOfRepositoryStatistics( "third", cal.getTime( ) ) );
 
-            List<String> facets = repository.getMetadataFacets( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName());
+            List<String> facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) );
 
-            assertThat(facets).isNotNull().isNotEmpty().hasSize(3);
+            assertThat( facets ).isNotNull( ).isNotEmpty( ).hasSize( 3 );
 
-            assertTrue(repository.hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName()));
+            assertTrue( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
 
-            repository.removeMetadataFacets( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName());
+            getRepository( ).removeMetadataFacets( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) );
 
-            assertFalse(repository.hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName()));
+            assertFalse( getRepository( ).hasMetadataFacet( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) ) );
 
-            facets = repository.getMetadataFacets( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName());
+            facets = getRepository( ).getMetadataFacets( session, TEST_REPO_ID, KindOfRepositoryStatistics.class.getName( ) );
 
-            assertThat(facets).isNotNull().isEmpty();
+            assertThat( facets ).isNotNull( ).isEmpty( );
 
 
         }
@@ -866,1088 +1035,1293 @@ public abstract class AbstractMetadataRepositoryTest
 
 
     @Test
-    public void testGetArtifacts()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact1 = createArtifact();
-            ArtifactMetadata artifact2 = createArtifact("pom");
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1);
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2);
+    public void testGetArtifacts( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact1 = createArtifact( );
+            ArtifactMetadata artifact2 = createArtifact( "pom" );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
 
-            Collection<ArtifactMetadata> artifacts =
-                    repository.getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
-            ArrayList<ArtifactMetadata> actual = new ArrayList<>(artifacts);
-            Collections.sort(actual, (o1, o2) -> o1.getId().compareTo(o2.getId()));
-            assertEquals(Arrays.asList(artifact1, artifact2), actual);
+            tryAssert( ( ) -> {
+                Collection<ArtifactMetadata> artifacts =
+                    getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+                ArrayList<ArtifactMetadata> actual = new ArrayList<>( artifacts );
+                Collections.sort( actual, ( o1, o2 ) -> o1.getId( ).compareTo( o2.getId( ) ) );
+                assertEquals( Arrays.asList( artifact1, artifact2 ), actual );
+            } );
 
         }
     }
 
     @Test
-    public void testGetArtifactVersions()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact1 = createArtifact();
+    public void testGetArtifactVersions( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact1 = createArtifact( );
             String version1 = "1.0-20091212.012345-1";
-            artifact1.setId(artifact1.getProject() + "-" + version1 + ".jar");
-            artifact1.setVersion(version1);
-            ArtifactMetadata artifact2 = createArtifact();
+            artifact1.setId( artifact1.getProject( ) + "-" + version1 + ".jar" );
+            artifact1.setVersion( version1 );
+            ArtifactMetadata artifact2 = createArtifact( );
             String version2 = "1.0-20091212.123456-2";
-            artifact2.setId(artifact2.getProject() + "-" + version2 + ".jar");
-            artifact2.setVersion(version2);
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1);
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2);
+            artifact2.setId( artifact2.getProject( ) + "-" + version2 + ".jar" );
+            artifact2.setVersion( version2 );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
 
-            Collection<String> versions =
-                    repository.getArtifactVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
+            tryAssert( ( ) -> {
+                Collection<String> versions =
+                    getRepository( ).getArtifactVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
 
-            assertThat(versions).isNotNull().isNotEmpty().contains(version1, version2);
+                assertThat( versions ).isNotNull( ).isNotEmpty( ).contains( version1, version2 );
+            } );
 
         }
     }
 
     @Test
-    public void testGetArtifactVersionsMultipleArtifactsSingleVersion()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact1 = createArtifact();
-            artifact1.setId(TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar");
-            ArtifactMetadata artifact2 = createArtifact();
-            artifact2.setId(TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "-sources.jar");
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1);
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2);
+    public void testGetArtifactVersionsMultipleArtifactsSingleVersion( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact1 = createArtifact( );
+            artifact1.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
+            ArtifactMetadata artifact2 = createArtifact( );
+            artifact2.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "-sources.jar" );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
 
-            Collection<String> versions =
-                    repository.getArtifactVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
+            tryAssert( ( ) -> {
+                Collection<String> versions =
+                    getRepository( ).getArtifactVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
 
-            assertThat(versions).isNotNull().isNotEmpty().hasSize(1).containsExactly(TEST_PROJECT_VERSION);
+                assertThat( versions ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).containsExactly( TEST_PROJECT_VERSION );
+            } );
 
 
         }
     }
 
     @Test
-    public void testGetArtifactsByDateRangeOpen()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
-            session.save();
+    public void testGetArtifactsByDateRangeOpen( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+            session.save( );
 
-            List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange( session, TEST_REPO_ID, null, null);
-
-            assertEquals(Collections.singletonList(artifact), artifacts);
+            tryAssert( ( ) -> {
+                List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null );
 
+                assertEquals( Collections.singletonList( artifact ), artifacts );
+            } );
         }
     }
 
     @Test
-    public void testGetArtifactsByDateRangeSparseNamespace()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testGetArtifactsByDateRangeSparseNamespace( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
             String namespace = "org.apache.archiva";
-            ArtifactMetadata artifact = createArtifact();
-            artifact.setNamespace(namespace);
-            repository.updateArtifact( session, TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
-            session.save();
-
-            List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange( session, TEST_REPO_ID, null, null);
+            ArtifactMetadata artifact = createArtifact( );
+            artifact.setNamespace( namespace );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+            session.save( );
 
-            tryAssert(() -> assertEquals(Collections.singletonList(artifact), artifacts));
+            tryAssert( ( ) -> {
+                List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null );
 
+                tryAssert( ( ) -> assertEquals( Collections.singletonList( artifact ), artifacts ) );
+            } );
         }
     }
 
     @Test
-    public void testGetArtifactsByDateRangeLowerBound()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
-            session.save();
+    public void testGetArtifactsByDateRangeLowerBound( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+            session.save( );
 
-            Date date = new Date(artifact.getWhenGathered().getTime() - 10000);
+            Date date = new Date( artifact.getWhenGathered( ).getTime( ) - 10000 );
 
-            List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange( session, TEST_REPO_ID, date, null);
-
-            assertEquals(Collections.singletonList(artifact), artifacts);
+            tryAssert( ( ) -> {
+                List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, date, null );
 
+                assertEquals( Collections.singletonList( artifact ), artifacts );
+            } );
         }
     }
 
     @Test
-    public void testGetArtifactsByDateRangeLowerBoundOutOfRange()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
-
-            Date date = new Date(artifact.getWhenGathered().getTime() + 10000);
+    public void testGetArtifactsByDateRangeLowerBoundOutOfRange( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
 
-            List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange( session, TEST_REPO_ID, date, null);
+            Date date = new Date( artifact.getWhenGathered( ).getTime( ) + 10000 );
 
-            assertThat(artifacts).isNotNull().isEmpty();
+            tryAssert( ( ) -> {
+                List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, date, null );
 
+                assertThat( artifacts ).isNotNull( ).isEmpty( );
+            } );
         }
     }
 
     @Test
-    public void testGetArtifactsByDateRangeLowerAndUpperBound()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
-            session.save();
-
-            Date lower = new Date(artifact.getWhenGathered().getTime() - 10000);
-            Date upper = new Date(artifact.getWhenGathered().getTime() + 10000);
+    public void testGetArtifactsByDateRangeLowerAndUpperBound( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+            session.save( );
 
-            List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange( session, TEST_REPO_ID, lower, upper);
+            Date lower = new Date( artifact.getWhenGathered( ).getTime( ) - 10000 );
+            Date upper = new Date( artifact.getWhenGathered( ).getTime( ) + 10000 );
 
-            assertEquals(Collections.singletonList(artifact), artifacts);
+            tryAssert( ( ) -> {
+                List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, lower, upper );
 
+                assertEquals( Collections.singletonList( artifact ), artifacts );
+            } );
         }
     }
 
     @Test
-    public void testGetArtifactsByDateRangeUpperBound()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
-            session.save();
+    public void testGetArtifactsByDateRangeUpperBound( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+            session.save( );
 
-            Date upper = new Date(artifact.getWhenGathered().getTime() + 10000);
+            Date upper = new Date( artifact.getWhenGathered( ).getTime( ) + 10000 );
 
-            List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange( session, TEST_REPO_ID, null, upper);
-
-            assertEquals(Collections.singletonList(artifact), artifacts);
+            tryAssert( ( ) -> {
+                List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, upper );
 
+                assertEquals( Collections.singletonList( artifact ), artifacts );
+            } );
         }
     }
 
     @Test
-    public void testGetArtifactsByDateRangeUpperBoundOutOfRange()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
-            session.save();
-
-            Date upper = new Date(artifact.getWhenGathered().getTime() - 10000);
+    public void testGetArtifactsByDateRangeUpperBoundOutOfRange( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+            session.save( );
 
-            List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange( session, TEST_REPO_ID, null, upper);
+            Date upper = new Date( artifact.getWhenGathered( ).getTime( ) - 10000 );
 
-            assertThat(artifacts).isNotNull().isEmpty();
+            tryAssert( ( ) -> {
+                List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, upper );
 
+                assertThat( artifacts ).isNotNull( ).isEmpty( );
+            } );
         }
     }
 
     @Test
-    public void testGetArtifactsByRepoId()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
-            repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
-            session.save();
-
-            tryAssert(() -> {
-                        List<ArtifactMetadata> artifacts = repository.getArtifacts(session, TEST_REPO_ID);
-                        assertEquals(Collections.singletonList(artifact), artifacts);
-                    }
+    public void testGetArtifactsByRepoId( )
+        throws Exception
+    {
+        ArtifactMetadata artifact;
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            artifact = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+            session.save( );
+        }
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            tryAssert( ( ) -> {
+                    session.refreshAndDiscard( );
+                    List<ArtifactMetadata> artifacts = getRepository( ).getArtifacts( session, TEST_REPO_ID );
+                    assertEquals( Collections.singletonList( artifact ), artifacts );
+                }
             );
         }
     }
 
     @Test
-    public void testGetArtifactsByRepoIdMultipleCopies()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
+    public void testGetArtifactsByRepoIdMultipleCopies( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
 
-            ArtifactMetadata secondArtifact = createArtifact();
-            secondArtifact.setRepositoryId(OTHER_REPO_ID);
-            repository.updateArtifact( session, OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact);
-            session.save();
+            ArtifactMetadata secondArtifact = createArtifact( );
+            secondArtifact.setRepositoryId( OTHER_REPO_ID );
+            getRepository( ).updateArtifact( session, OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
+            session.save( );
 
             // test it restricts to the appropriate repository
-            tryAssert(() -> assertEquals(Collections.singletonList(artifact), repository.getArtifacts( session, TEST_REPO_ID)));
-            tryAssert(() -> assertEquals(Collections.singletonList(secondArtifact), repository.getArtifacts( session, OTHER_REPO_ID)));
+            tryAssert( ( ) -> assertEquals( Collections.singletonList( artifact ), getRepository( ).getArtifacts( session, TEST_REPO_ID ) ) );
+            tryAssert( ( ) -> assertEquals( Collections.singletonList( secondArtifact ), getRepository( ).getArtifacts( session, OTHER_REPO_ID ) ) );
 
         }
     }
 
 
     @Test
-    public void testGetArtifactsByDateRangeMultipleCopies()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
+    public void testGetArtifactsByDateRangeMultipleCopies( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
 
-            ArtifactMetadata secondArtifact = createArtifact();
-            secondArtifact.setRepositoryId(OTHER_REPO_ID);
-            repository.updateArtifact( session, OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact);
-            session.save();
-
-            // test it restricts to the appropriate repository
-            assertEquals(Collections.singletonList(artifact),
-                    repository.getArtifactsByDateRange( session, TEST_REPO_ID, null, null));
-            assertEquals(Collections.singletonList(secondArtifact),
-                    repository.getArtifactsByDateRange( session, OTHER_REPO_ID, null, null));
+            ArtifactMetadata secondArtifact = createArtifact( );
+            secondArtifact.setRepositoryId( OTHER_REPO_ID );
+            getRepository( ).updateArtifact( session, OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
+            session.save( );
 
+            tryAssert( ( ) -> {
+                // test it restricts to the appropriate repository
+                assertEquals( Collections.singletonList( artifact ),
+                    getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null ) );
+            } );
+            tryAssert( ( ) -> {
+                assertEquals( Collections.singletonList( secondArtifact ),
+                    getRepository( ).getArtifactsByDateRange( session, OTHER_REPO_ID, null, null ) );
+            } );
         }
     }
 
     @Test
-    public void testGetArtifactsByChecksumMultipleCopies()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
+    public void testGetArtifactsByChecksumMultipleCopies( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
 
-            ArtifactMetadata secondArtifact = createArtifact();
-            secondArtifact.setRepositoryId(OTHER_REPO_ID);
-            repository.updateArtifact( session, OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact);
-            session.save();
+            ArtifactMetadata secondArtifact = createArtifact( );
+            secondArtifact.setRepositoryId( OTHER_REPO_ID );
+            getRepository( ).updateArtifact( session, OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
+            session.save( );
 
-            // test it restricts to the appropriate repository
-            assertEquals(Collections.singletonList(artifact),
-                    new ArrayList<>(repository.getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1)));
-            assertEquals(Collections.singletonList(secondArtifact), new ArrayList<>(
-                    repository.getArtifactsByChecksum( session, OTHER_REPO_ID, TEST_SHA1)));
-            assertEquals(Collections.singletonList(artifact),
-                    new ArrayList<>(repository.getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5)));
-            assertEquals(Collections.singletonList(secondArtifact),
-                    new ArrayList<>(repository.getArtifactsByChecksum( session, OTHER_REPO_ID, TEST_MD5)));
+            tryAssert( ( ) -> {
+                // test it restricts to the appropriate repository
+                assertEquals( Collections.singletonList( artifact ),
+                    new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 ) ) );
+            } );
+            tryAssert( ( ) -> {
+                assertEquals( Collections.singletonList( secondArtifact ), new ArrayList<>(
+                    getRepository( ).getArtifactsByChecksum( session, OTHER_REPO_ID, TEST_SHA1 ) ) );
+            } );
+            tryAssert( ( ) -> {
+                assertEquals( Collections.singletonList( artifact ),
+                    new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 ) ) );
+            } );
+            tryAssert( ( ) -> {
+                assertEquals( Collections.singletonList( secondArtifact ),
+                    new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, OTHER_REPO_ID, TEST_MD5 ) ) );
 
+            } );
         }
     }
 
     @Test
-    public void testGetNamespacesWithSparseDepth()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            repository.updateNamespace( session, TEST_REPO_ID, "org.apache.maven.shared");
+    public void testGetNamespacesWithSparseDepth( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            getRepository( ).updateNamespace( session, TEST_REPO_ID, "org.apache.maven.shared" );
+
+            tryAssert( ( ) -> {
 
-            Collection<String> namespaces = repository.getRootNamespaces( session, TEST_REPO_ID);
+                Collection<String> namespaces = getRepository( ).getRootNamespaces( session, TEST_REPO_ID );
 
-            assertThat(namespaces).isNotNull().isNotEmpty().hasSize(1).contains("org");
+                assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "org" );
 
-            namespaces = repository.getNamespaces( session, TEST_REPO_ID, "org");
-            assertThat(namespaces).isNotNull().isNotEmpty().hasSize(1).contains("apache");
+                namespaces = getRepository( ).getNamespaces( session, TEST_REPO_ID, "org" );
+                assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "apache" );
 
-            namespaces = repository.getNamespaces( session, TEST_REPO_ID, "org.apache");
-            assertThat(namespaces).isNotNull().isNotEmpty().hasSize(1).contains("maven");
+                namespaces = getRepository( ).getNamespaces( session, TEST_REPO_ID, "org.apache" );
+                assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "maven" );
 
-            namespaces = repository.getNamespaces( session, TEST_REPO_ID, "org.apache.maven");
-            assertThat(namespaces).isNotNull().isNotEmpty().hasSize(1).contains("shared");
+                namespaces = getRepository( ).getNamespaces( session, TEST_REPO_ID, "org.apache.maven" );
+                assertThat( namespaces ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "shared" );
 
+            } );
         }
     }
 
     @Test
-    public void testGetNamespacesWithProjectsPresent()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testGetNamespacesWithProjectsPresent( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
             String namespace = "org.apache.maven.shared";
-            repository.updateNamespace( session, TEST_REPO_ID, namespace);
+            getRepository( ).updateNamespace( session, TEST_REPO_ID, namespace );
 
-            ProjectVersionMetadata metadata = new ProjectVersionMetadata();
-            metadata.setId(TEST_PROJECT_VERSION);
-            repository.updateProjectVersion( session, TEST_REPO_ID, namespace, TEST_PROJECT, metadata);
+            ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
+            metadata.setId( TEST_PROJECT_VERSION );
+            getRepository( ).updateProjectVersion( session, TEST_REPO_ID, namespace, TEST_PROJECT, metadata );
 
-            Collection<String> namespaces = repository.getNamespaces( session, TEST_REPO_ID, namespace);
+            Collection<String> namespaces = getRepository( ).getNamespaces( session, TEST_REPO_ID, namespace );
 
-            assertThat(namespaces).isNotNull().isEmpty();
+            assertThat( namespaces ).isNotNull( ).isEmpty( );
 
 
         }
     }
 
     @Test
-    public void testGetProjectsWithOtherNamespacesPresent()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ProjectMetadata projectMetadata = new ProjectMetadata();
-            projectMetadata.setId(TEST_PROJECT);
-            projectMetadata.setNamespace("org.apache.maven");
-            repository.updateProject( session, TEST_REPO_ID, projectMetadata);
+    public void testGetProjectsWithOtherNamespacesPresent( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ProjectMetadata projectMetadata = new ProjectMetadata( );
+            projectMetadata.setId( TEST_PROJECT );
+            projectMetadata.setNamespace( "org.apache.maven" );
+            getRepository( ).updateProject( session, TEST_REPO_ID, projectMetadata );
 
-            repository.updateNamespace( session, TEST_REPO_ID, "org.apache.maven.shared");
+            getRepository( ).updateNamespace( session, TEST_REPO_ID, "org.apache.maven.shared" );
 
-            Collection<String> projects = repository.getProjects( session, TEST_REPO_ID, "org.apache.maven");
+            Collection<String> projects = getRepository( ).getProjects( session, TEST_REPO_ID, "org.apache.maven" );
 
-            assertThat(projects).isNotNull().isNotEmpty().hasSize(1).contains(TEST_PROJECT);
+            assertThat( projects ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( TEST_PROJECT );
 
         }
     }
 
     @Test
-    public void testGetProjectVersionsWithOtherNamespacesPresent()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testGetProjectVersionsWithOtherNamespacesPresent( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 // an unusual case but technically possible where a project namespace matches another project's name
 
-            ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
-            versionMetadata.setId(TEST_PROJECT_VERSION);
-            repository.updateProjectVersion( session, TEST_REPO_ID, "org.apache.maven", TEST_PROJECT, versionMetadata);
+            ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata( );
+            versionMetadata.setId( TEST_PROJECT_VERSION );
+            getRepository( ).updateProjectVersion( session, TEST_REPO_ID, "org.apache.maven", TEST_PROJECT, versionMetadata );
 
-            repository.updateProjectVersion( session, TEST_REPO_ID, "org.apache.maven." + TEST_PROJECT,
-                    "other-project", versionMetadata);
+            getRepository( ).updateProjectVersion( session, TEST_REPO_ID, "org.apache.maven." + TEST_PROJECT,
+                "other-project", versionMetadata );
 
             Collection<String> versions =
-                    repository.getProjectVersions( session, TEST_REPO_ID, "org.apache.maven." + TEST_PROJECT, "other-project");
-            assertThat(versions).isNotNull().isNotEmpty().contains(TEST_PROJECT_VERSION);
+                getRepository( ).getProjectVersions( session, TEST_REPO_ID, "org.apache.maven." + TEST_PROJECT, "other-project" );
+            assertThat( versions ).isNotNull( ).isNotEmpty( ).contains( TEST_PROJECT_VERSION );
 
-            versions = repository.getProjectVersions( session, TEST_REPO_ID, "org.apache.maven", TEST_PROJECT);
+            versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, "org.apache.maven", TEST_PROJECT );
 
-            assertThat(versions).isNotNull().isNotEmpty().contains(TEST_PROJECT_VERSION);
+            assertThat( versions ).isNotNull( ).isNotEmpty( ).contains( TEST_PROJECT_VERSION );
 
         }
     }
 
     @Test
-    public void testGetArtifactsByChecksumSingleResultMd5()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
-            session.save();
+    public void testGetArtifactsByChecksumSingleResultMd5( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+            session.save( );
 
-            assertEquals(Collections.singletonList(artifact),
-                    new ArrayList<>(repository.getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5)));
+            assertEquals( Collections.singletonList( artifact ),
+                new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 ) ) );
 
         }
     }
 
     @Test
-    public void testGetArtifactsByChecksumSingleResultSha1()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
-            session.save();
+    public void testGetArtifactsByChecksumSingleResultSha1( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+            session.save( );
 
-            assertEquals(Collections.singletonList(artifact),
-                    new ArrayList<>(repository.getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1)));
+            assertEquals( Collections.singletonList( artifact ),
+                new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 ) ) );
 
         }
     }
 
     @Test
-    public void testGetArtifactsByChecksumDeepNamespace()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
+    public void testGetArtifactsByChecksumDeepNamespace( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact = createArtifact( );
             String namespace = "multi.level.ns";
-            artifact.setNamespace(namespace);
-            repository.updateArtifact( session, TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
-            session.save();
+            artifact.setNamespace( namespace );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+            session.save( );
 
-            tryAssert(() -> assertEquals(Collections.singletonList(artifact),
-                    new ArrayList<>(repository.getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1))));
-            tryAssert(() -> assertEquals(Collections.singletonList(artifact),
-                    new ArrayList<>(repository.getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5))));
+            tryAssert( ( ) -> assertEquals( Collections.singletonList( artifact ),
+                new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 ) ) ) );
+            tryAssert( ( ) -> assertEquals( Collections.singletonList( artifact ),
+                new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 ) ) ) );
 
         }
     }
 
     @Test
-    public void testGetArtifactsByChecksumMultipleResult()
-            throws Exception {
+    public void testGetArtifactsByChecksumMultipleResult( )
+        throws Exception
+    {
 
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact1 = createArtifact();
-            repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1);
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact1 = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
 
             String newProjectId = "another-project";
-            ArtifactMetadata artifact2 = createArtifact();
-            artifact2.setProject(newProjectId);
-            repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, newProjectId, TEST_PROJECT_VERSION, artifact2);
-            session.save();
+            ArtifactMetadata artifact2 = createArtifact( );
+            artifact2.setProject( newProjectId );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, newProjectId, TEST_PROJECT_VERSION, artifact2 );
+            session.save( );
 
-            tryAssert(() -> {
+            tryAssert( ( ) -> {
                 List<ArtifactMetadata> artifacts =
-                        new ArrayList<>(repository.getArtifactsByChecksum(session, TEST_REPO_ID, TEST_SHA1));
-                Collections.sort(artifacts, new ArtifactMetadataComparator());
-                assertEquals(Arrays.asList(artifact2, artifact1), artifacts);
-            });
+                    new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_SHA1 ) );
+                Collections.sort( artifacts, new ArtifactMetadataComparator( ) );
+                assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts );
+            } );
 
-            tryAssert(() -> {
-                ArrayList<ArtifactMetadata> artifacts = new ArrayList<>(repository.getArtifactsByChecksum(session, TEST_REPO_ID, TEST_MD5));
-                Collections.sort(artifacts, new ArtifactMetadataComparator());
-                assertEquals(Arrays.asList(artifact2, artifact1), artifacts);
-            });
+            tryAssert( ( ) -> {
+                ArrayList<ArtifactMetadata> artifacts = new ArrayList<>( getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, TEST_MD5 ) );
+                Collections.sort( artifacts, new ArtifactMetadataComparator( ) );
+                assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts );
+            } );
         }
     }
 
     @Test
-    public void testGetArtifactsByChecksumNoResult()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
-
-            Collection<ArtifactMetadata> artifactsByChecksum =
-                    repository.getArtifactsByChecksum( session, TEST_REPO_ID, "not checksum");
-            assertThat(artifactsByChecksum).isNotNull().isEmpty();
+    public void testGetArtifactsByChecksumNoResult( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact = createArtifact( );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
 
-        }
-    }
+            tryAssert( ( ) -> {
+                Collection<ArtifactMetadata> artifactsByChecksum =
+                    getRepository( ).getArtifactsByChecksum( session, TEST_REPO_ID, "not checksum" );
 
-    @Test
-    public void testGetArtifactsByProjectVersionMetadata()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            createArtifactWithGenericMetadataFacet( session,10);
-            Collection<ArtifactMetadata> artifactsByMetadata =
-                    repository.getArtifactsByProjectVersionMetadata( session, TEST_METADATA_KEY, TEST_METADATA_VALUE, TEST_REPO_ID);
-            assertThat(artifactsByMetadata).hasSize(1);
-            ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator().next();
-            assertThat(artifactMetadata.getId()).isEqualTo("projectId-1.0.jar");
-            assertThat(artifactMetadata.getSha1()).isEqualTo(TEST_SHA1);
-            assertThat(artifactMetadata.getRepositoryId()).isEqualTo(TEST_REPO_ID);
+                assertThat( artifactsByChecksum ).isNotNull( ).isEmpty( );
+            } );
 
         }
     }
 
     @Test
-    public void testGetArtifactsByProjectVersionMetadataNoRepository()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            createArtifactWithGenericMetadataFacet(session);
-            Collection<ArtifactMetadata> artifactsByMetadata =
-                    repository.getArtifactsByProjectVersionMetadata( session, TEST_METADATA_KEY, TEST_METADATA_VALUE, null);
-            assertThat(artifactsByMetadata).hasSize(1);
-            assertThat(artifactsByMetadata.iterator().next().getRepositoryId()).isNotNull().isNotEmpty();
+    public void testGetArtifactsByProjectVersionMetadata( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            createArtifactWithGenericMetadataFacet( session, 10 );
+
+            tryAssert( ( ) -> {
+                Collection<ArtifactMetadata> artifactsByMetadata =
+                    getRepository( ).getArtifactsByProjectVersionMetadata( session, TEST_METADATA_KEY, TEST_METADATA_VALUE, TEST_REPO_ID );
 
+                assertThat( artifactsByMetadata ).hasSize( 1 );
+                ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator( ).next( );
+                assertThat( artifactMetadata.getId( ) ).isEqualTo( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
+                assertThat( artifactMetadata.getSha1( ) ).isEqualTo( TEST_SHA1 );
+                assertThat( artifactMetadata.getRepositoryId( ) ).isEqualTo( TEST_REPO_ID );
+            } );
         }
     }
 
     @Test
-    public void testGetArtifactsByProjectVersionMetadataAllRepositories()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            createArtifactWithGenericMetadataFacet(session);
-            Collection<ArtifactMetadata> artifactsByMetadata =
-                    repository.getArtifactsByProjectVersionMetadata( session, TEST_METADATA_KEY, TEST_METADATA_VALUE, null);
-            assertThat(artifactsByMetadata).hasSize(1);
+    public void testGetArtifactsByProjectVersionMetadataNoRepository( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            createArtifactWithGenericMetadataFacet( session );
+            tryAssert( ( ) -> {
 
+                Collection<ArtifactMetadata> artifactsByMetadata =
+                    getRepository( ).getArtifactsByProjectVersionMetadata( session, TEST_METADATA_KEY, TEST_METADATA_VALUE, null );
+                assertThat( artifactsByMetadata ).hasSize( 1 );
+                assertThat( artifactsByMetadata.iterator( ).next( ).getRepositoryId( ) ).isNotNull( ).isNotEmpty( );
+            } );
         }
     }
 
     @Test
-    public void testGetArtifactsByMetadataAllRepositories()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            createArtifactWithMavenArtifactFacet(session);
-            tryAssert(() -> {
+    public void testGetArtifactsByProjectVersionMetadataAllRepositories( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            createArtifactWithGenericMetadataFacet( session );
+            tryAssert( ( ) -> {
+
                 Collection<ArtifactMetadata> artifactsByMetadata =
-                        repository.getArtifactsByMetadata(session, "foo", TEST_METADATA_VALUE, null);
-                assertThat(artifactsByMetadata).hasSize(1);
-                ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator().next();
-                assertThat(artifactMetadata.getId()).isEqualTo("projectId-1.0.jar");
-                assertThat(artifactMetadata.getSha1()).isEqualTo(TEST_SHA1);
-                assertThat(artifactMetadata.getRepositoryId()).isEqualTo(TEST_REPO_ID);
-                MetadataFacet facet = artifactMetadata.getFacet(TEST_FACET_ID);
-                assertThat(facet).isNotNull();
-                assertThat(facet.toProperties()).isEqualTo(Collections.singletonMap("foo", TEST_METADATA_VALUE));
-            });
+                    getRepository( ).getArtifactsByProjectVersionMetadata( session, TEST_METADATA_KEY, TEST_METADATA_VALUE, null );
+                assertThat( artifactsByMetadata ).hasSize( 1 );
+            } );
         }
     }
 
     @Test
-    public void testGetArtifactsByPropertySingleResult()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            createArtifactWithData(session);
+    public void testGetArtifactsByMetadataAllRepositories( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            createArtifactWithMavenArtifactFacet( session );
+            tryAssert( ( ) -> {
+                Collection<ArtifactMetadata> artifactsByMetadata =
+                    getRepository( ).getArtifactsByMetadata( session, "foo", TEST_METADATA_VALUE, null );
+                assertThat( artifactsByMetadata ).hasSize( 1 );
+                ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator( ).next( );
+                assertThat( artifactMetadata.getId( ) ).isEqualTo( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
+                assertThat( artifactMetadata.getSha1( ) ).isEqualTo( TEST_SHA1 );
+                assertThat( artifactMetadata.getRepositoryId( ) ).isEqualTo( TEST_REPO_ID );
+                MetadataFacet facet = artifactMetadata.getFacet( TEST_FACET_ID );
+                assertThat( facet ).isNotNull( );
+                assertThat( facet.toProperties( ) ).isEqualTo( Collections.singletonMap( "foo", TEST_METADATA_VALUE ) );
+            } );
+        }
+    }
+
+    @Test
+    public void testGetArtifactsByPropertySingleResult( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            createArtifactWithData( session );
             // only works on JCR implementation
-            // Collection<ArtifactMetadata> artifactsByProperty = repository.getArtifactsByProperty( "org.name", TEST_ORGANIZATION.getName(), TEST_REPO_ID );
-            Collection<ArtifactMetadata> artifactsByProperty = repository.getArtifactsByProperty( session, "url", TEST_URL, TEST_REPO_ID);
-            assertThat(artifactsByProperty).hasSize(1);
-            ArtifactMetadata artifactMetadata = artifactsByProperty.iterator().next();
-            assertThat(artifactMetadata.getId()).isEqualTo("projectId-1.0.jar");
-            assertThat(artifactMetadata.getSha1()).isEqualTo(TEST_SHA1);
-            assertThat(artifactMetadata.getRepositoryId()).isEqualTo(TEST_REPO_ID);
+            // Collection<ArtifactMetadata> artifactsByProperty = getRepository().getArtifactsByProperty( "org.name", TEST_ORGANIZATION.getName(), TEST_REPO_ID );
+            tryAssert( ( ) -> {
+
+                Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).getArtifactsByProperty( session, "url", TEST_URL, TEST_REPO_ID );
+                assertThat( artifactsByProperty ).hasSize( 1 );
+                ArtifactMetadata artifactMetadata = artifactsByProperty.iterator( ).next( );
+                assertThat( artifactMetadata.getId( ) ).isEqualTo( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
+                assertThat( artifactMetadata.getSha1( ) ).isEqualTo( TEST_SHA1 );
+                assertThat( artifactMetadata.getRepositoryId( ) ).isEqualTo( TEST_REPO_ID );
+            } );
 
         }
     }
 
     @Test
-    public void testDeleteRepository()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testDeleteRepository( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 
-            repository.updateNamespace(session, TEST_REPO_ID, TEST_NAMESPACE);
+            getRepository( ).updateNamespace( session, TEST_REPO_ID, TEST_NAMESPACE );
 
-            ProjectMetadata project1 = new ProjectMetadata();
-            project1.setNamespace(TEST_NAMESPACE);
-            project1.setId("project1");
-            repository.updateProject(session, TEST_REPO_ID, project1);
-            ProjectMetadata project2 = new ProjectMetadata();
-            project2.setNamespace(TEST_NAMESPACE);
-            project2.setId("project2");
-            repository.updateProject(session, TEST_REPO_ID, project2);
+            ProjectMetadata project1 = new ProjectMetadata( );
+            project1.setNamespace( TEST_NAMESPACE );
+            project1.setId( "project1" );
+            getRepository( ).updateProject( session, TEST_REPO_ID, project1 );
+            ProjectMetadata project2 = new ProjectMetadata( );
+            project2.setNamespace( TEST_NAMESPACE );
+            project2.setId( "project2" );
+            getRepository( ).updateProject( session, TEST_REPO_ID, project2 );
 
-            ArtifactMetadata artifact1 = createArtifact();
-            artifact1.setProject("project1");
-            repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, "project1", TEST_PROJECT_VERSION, artifact1);
-            ArtifactMetadata artifact2 = createArtifact();
-            artifact2.setProject("project2");
-            repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, "project2", TEST_PROJECT_VERSION, artifact2);
-            session.save();
+            ArtifactMetadata artifact1 = createArtifact( );
+            artifact1.setProject( "project1" );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, "project1", TEST_PROJECT_VERSION, artifact1 );
+            ArtifactMetadata artifact2 = createArtifact( );
+            artifact2.setProject( "project2" );
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, "project2", TEST_PROJECT_VERSION, artifact2 );
+            session.save( );
 
-            List<ArtifactMetadata> expected = Arrays.asList(artifact1, artifact2);
-            Collections.sort(expected, new ArtifactMetadataComparator());
+            List<ArtifactMetadata> expected = Arrays.asList( artifact1, artifact2 );
+            Collections.sort( expected, new ArtifactMetadataComparator( ) );
 
 
-            tryAssert(() -> {
+            tryAssert( ( ) -> {
                 List<ArtifactMetadata> actual =
-                        new ArrayList<>(repository.getArtifactsByDateRange(session, TEST_REPO_ID, null, null));
-                Collections.sort(actual, new ArtifactMetadataComparator());
-                assertEquals(expected, actual);
-            });
+                    new ArrayList<>( getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, null ) );
+                Collections.sort( actual, new ArtifactMetadataComparator( ) );
+                assertEquals( expected, actual );
+            } );
 
-            repository.removeRepository(session, TEST_REPO_ID);
+            getRepository( ).removeRepository( session, TEST_REPO_ID );
 
-            assertTrue(repository.getArtifacts(session, TEST_REPO_ID).isEmpty());
-            assertTrue(repository.getRootNamespaces(session, TEST_REPO_ID).isEmpty());
+            tryAssert( ( ) -> {
+                assertTrue( getRepository( ).getArtifacts( session, TEST_REPO_ID ).isEmpty( ) );
+                assertTrue( getRepository( ).getRootNamespaces( session, TEST_REPO_ID ).isEmpty( ) );
+            } );
         }
     }
 
 
     @Test
-    public void testDeleteArtifact()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testDeleteArtifact( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 
-            ArtifactMetadata artifact = createArtifact();
-            artifact.addFacet(new TestMetadataFacet("value"));
+            ArtifactMetadata artifact = createArtifact( );
+            artifact.addFacet( new TestMetadataFacet( "value" ) );
 
-            repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
 
-            assertThat(repository.getArtifacts(session, TEST_REPO_ID, TEST_NAMESPACE,
-                    TEST_PROJECT, TEST_PROJECT_VERSION)).containsExactly(artifact);
+            assertThat( getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
+                TEST_PROJECT, TEST_PROJECT_VERSION ) ).containsExactly( artifact );
 
-            repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION_2_0, artifact);
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION_2_0, artifact );
 
-            Collection<String> versions = repository.getProjectVersions(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT);
+            Collection<String> versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
 
-            log.info("versions {}", versions);
+            log.info( "versions {}", versions );
 
-            assertThat(versions).isNotNull().isNotEmpty().hasSize(2).contains("1.0", "2.0");
+            assertThat( versions ).isNotNull( ).isNotEmpty( ).hasSize( 2 ).contains( "1.0", "2.0" );
 
-            repository.removeArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId());
+            getRepository( ).removeArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId( ) );
 
-            versions = repository.getProjectVersions(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT);
+            versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
 
-            log.info("versions {}", versions);
+            log.info( "versions {}", versions );
 
-            assertThat(versions).isNotNull().isNotEmpty().hasSize(1).contains("2.0");
+            assertThat( versions ).isNotNull( ).isNotEmpty( ).hasSize( 1 ).contains( "2.0" );
 
-            assertThat(repository.getArtifacts(session, TEST_REPO_ID, TEST_NAMESPACE,
-                    TEST_PROJECT, TEST_PROJECT_VERSION)).isNotNull().isEmpty();
+            assertThat( getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
+                TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNotNull( ).isEmpty( );
 
-            assertThat(repository.getArtifacts(session, TEST_REPO_ID, TEST_NAMESPACE,
-                    TEST_PROJECT, TEST_PROJECT_VERSION_2_0)).isNotEmpty().hasSize(1);
+            assertThat( getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE,
+                TEST_PROJECT, TEST_PROJECT_VERSION_2_0 ) ).isNotEmpty( ).hasSize( 1 );
         }
     }
 
     @Test
-    public void deleteArtifact()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
-            artifact.addFacet(new TestMetadataFacet("value"));
+    public void deleteArtifact( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact = createArtifact( );
+            artifact.addFacet( new TestMetadataFacet( "value" ) );
 
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
 
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
 
-            Collection<ArtifactMetadata> artifacts =
-                    repository.getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
+            tryAssert( ( ) -> {
+                Collection<ArtifactMetadata> artifacts =
+                    getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
 
-            assertEquals(Collections.singletonList(artifact), new ArrayList<>(artifacts));
+                assertEquals( Collections.singletonList( artifact ), new ArrayList<>( artifacts ) );
 
-            repository.removeArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId());
+            } );
 
-            artifacts = repository.getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
+            getRepository( ).removeArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId( ) );
 
-            assertThat(artifacts).isNotNull().isEmpty();
+            tryAssert( ( ) -> {
+                Collection<ArtifactMetadata> artifacts = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+
+                assertThat( artifacts ).isNotNull( ).isEmpty( );
+            } );
 
         }
     }
 
     @Test
-    public void deleteVersion()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
-            artifact.addFacet(new TestMetadataFacet("value"));
+    public void deleteVersion( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact = createArtifact( );
+            artifact.addFacet( new TestMetadataFacet( "value" ) );
+
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
 
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
 
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
+            tryAssert( ( ) -> {
 
-            Collection<String> versions = repository.getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT);
+                Collection<String> versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
 
-            assertThat(versions).isNotNull().isNotEmpty().hasSize(1);
+                assertThat( versions ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
+            } );
 
-            repository.removeProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
+            getRepository( ).removeProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
 
-            versions = repository.getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT);
+            tryAssert( ( ) -> {
 
-            assertThat(versions).isNotNull().isEmpty();
+                Collection<String> versions1 = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
 
+                assertThat( versions1 ).isNotNull( ).isEmpty( );
+            } );
         }
     }
 
     @Test
-    public void deleteProject()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            ArtifactMetadata artifact = createArtifact();
-            artifact.addFacet(new TestMetadataFacet("value"));
+    public void deleteProject( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            ArtifactMetadata artifact = createArtifact( );
+            artifact.addFacet( new TestMetadataFacet( "value" ) );
 
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
 
-            repository.updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
 
-            assertEquals(1, repository.getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT).size());
+            assertEquals( 1, getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ).size( ) );
 
-            repository.removeProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT);
+            getRepository( ).removeProject( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
 
-            Collection<String> versions = repository.getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT);
+            Collection<String> versions = getRepository( ).getProjectVersions( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT );
 
-            assertThat(versions).isNotNull().isEmpty();
+            assertThat( versions ).isNotNull( ).isEmpty( );
 
         }
     }
 
 
     @Test
-    public void deleteSnapshotVersion()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void deleteSnapshotVersion( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 
-            ArtifactMetadata artifactOne = createArtifact();
-            artifactOne.setVersion("2.0-20120618.214127-1");
-            artifactOne.setProjectVersion("2.0-SNAPSHOT");
-            artifactOne.addFacet(new TestMetadataFacet("value"));
-            artifactOne.setId(TEST_PROJECT + "-" + "2.0-20120618.214127-1" + "." + "jar");
+            ArtifactMetadata artifactOne = createArtifact( );
+            artifactOne.setVersion( "2.0-20120618.214127-1" );
+            artifactOne.setProjectVersion( "2.0-SNAPSHOT" );
+            artifactOne.addFacet( new TestMetadataFacet( "value" ) );
+            artifactOne.setId( TEST_PROJECT + "-" + "2.0-20120618.214127-1" + "." + "jar" );
 
-            repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT", artifactOne);
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT", artifactOne );
 
-            ArtifactMetadata artifactTwo = createArtifact();
-            artifactTwo.setVersion("2.0-20120618.214135-2");
-            artifactTwo.setProjectVersion("2.0-SNAPSHOT");
-            artifactTwo.addFacet(new TestMetadataFacet("value"));
-            artifactTwo.setId(TEST_PROJECT + "-" + "2.0-20120618.214135-2" + "." + "jar");
+            ArtifactMetadata artifactTwo = createArtifact( );
+            artifactTwo.setVersion( "2.0-20120618.214135-2" );
+            artifactTwo.setProjectVersion( "2.0-SNAPSHOT" );
+            artifactTwo.addFacet( new TestMetadataFacet( "value" ) );
+            artifactTwo.setId( TEST_PROJECT + "-" + "2.0-20120618.214135-2" + "." + "jar" );
 
-            repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT", artifactTwo);
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT", artifactTwo );
 
             Collection<ArtifactMetadata> artifactMetadatas =
-                    repository.getArtifacts(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT");
+                getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
 
-            assertThat(artifactMetadatas).isNotNull().isNotEmpty().hasSize(2);
+            assertThat( artifactMetadatas ).isNotNull( ).isNotEmpty( ).hasSize( 2 );
 
-            log.info("artifactMetadatas: {}", artifactMetadatas);
+            log.info( "artifactMetadatas: {}", artifactMetadatas );
 
-            repository.removeArtifact(session, artifactOne, "2.0-SNAPSHOT");
+            getRepository( ).removeArtifact( session, artifactOne, "2.0-SNAPSHOT" );
 
-            artifactMetadatas = repository.getArtifacts(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT");
+            artifactMetadatas = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
 
-            assertThat(artifactMetadatas).isNotNull().isNotEmpty().hasSize(1);
+            assertThat( artifactMetadatas ).isNotNull( ).isNotEmpty( ).hasSize( 1 );
 
-            repository.removeArtifact(session, artifactTwo, "2.0-SNAPSHOT");
+            getRepository( ).removeArtifact( session, artifactTwo, "2.0-SNAPSHOT" );
 
-            artifactMetadatas = repository.getArtifacts(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT");
+            artifactMetadatas = getRepository( ).getArtifacts( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, "2.0-SNAPSHOT" );
 
-            assertThat(artifactMetadatas).isNotNull().isEmpty();
+            assertThat( artifactMetadatas ).isNotNull( ).isEmpty( );
         }
     }
 
 
     @Test
-    public void testgetProjectReferences()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testgetProjectReferences( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 
-            ProjectVersionMetadata metadata = new ProjectVersionMetadata();
-            metadata.setId(TEST_PROJECT_VERSION);
+            ProjectVersionMetadata metadata = new ProjectVersionMetadata( );
+            metadata.setId( TEST_PROJECT_VERSION );
 
-            metadata.setName("project name");
-            metadata.setDescription("project description");
-            metadata.setUrl("the url");
+            metadata.setName( "project name" );
+            metadata.setDescription( "project description" );
+            metadata.setUrl( "the url" );
 
-            Dependency d = new Dependency();
-            d.setArtifactId("artifactId");
-            d.setClassifier("classifier");
-            d.setGroupId("groupId");
-            d.setScope("scope");
-            d.setSystemPath("system path");
-            d.setType("type");
-            d.setVersion("version");
-            d.setOptional(true);
-            metadata.addDependency(d);
+            Dependency d = new Dependency( );
+            d.setArtifactId( "artifactId" );
+            d.setClassifier( "classifier" );
+            d.setGroupId( "groupId" );
+            d.setScope( "scope" );
+            d.setSystemPath( "system path" );
+            d.setType( "type" );
+            d.setVersion( "version" );
+            d.setOptional( true );
+            metadata.addDependency( d );
 
-            d = new Dependency();
-            d.setArtifactId("artifactId1");
-            d.setClassifier("classifier");
-            d.setGroupId("groupId");
-            d.setScope("scope");
-            d.setSystemPath("system path");
-            d.setType("type");
-            d.setVersion("version1");
-            d.setOptional(true);
-            metadata.addDependency(d);
+            d = new Dependency( );
+            d.setArtifactId( "artifactId1" );
+            d.setClassifier( "classifier" );
+            d.setGroupId( "groupId" );
+            d.setScope( "scope" );
+            d.setSystemPath( "system path" );
+            d.setType( "type" );
+            d.setVersion( "version1" );
+            d.setOptional( true );
+            metadata.addDependency( d );
 
-            repository.updateProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
+            getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
 
-            session.save();
+            session.save( );
 
-            metadata = repository.getProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
+            metadata = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+            final Dependency dd = d;
 
-            Collection<ProjectVersionReference> references =
-                    repository.getProjectReferences(session, TEST_REPO_ID, d.getGroupId(), d.getArtifactId(), d.getVersion());
 
-            log.info("references: {}", references);
+            tryAssert( ( ) -> {
 
-            assertThat(references).isNotNull().hasSize(1).contains(
-                    new ProjectVersionReference(ProjectVersionReference.ReferenceType.DEPENDENCY, TEST_PROJECT, TEST_NAMESPACE,
-                            TEST_PROJECT_VERSION));
+                Collection<ProjectVersionReference> references =
+                    getRepository( ).getProjectReferences( session, TEST_REPO_ID, dd.getGroupId( ), dd.getArtifactId( ), dd.getVersion( ) );
+                    log.info( "references: {}", references );
+                assertThat( references ).isNotNull( ).hasSize( 1 ).contains(
+                    new ProjectVersionReference( ProjectVersionReference.ReferenceType.DEPENDENCY, TEST_PROJECT, TEST_NAMESPACE,
+                        TEST_PROJECT_VERSION ));
+            }
+            );
 
         }
     }
 
     @Test
-    public void testSearchArtifactsByKey()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            createArtifactWithData(session);
-            session.refreshAndDiscard();
-            Collection<ArtifactMetadata> artifactsByProperty = repository.searchArtifacts( session, TEST_REPO_ID, "url", TEST_URL, false);
-            assertThat(artifactsByProperty).isNotNull().isNotEmpty();
+    public void testSearchArtifactsByKey( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            createArtifactWithData( session );
+        }
 
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            session.refreshAndDiscard( );
+            tryAssert( ( ) -> {
+                Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, "url", TEST_URL, false );
+                assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
+            } );
         }
     }
 
     @Test
-    public void testSearchArtifactsByKeyExact()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            createArtifactWithData(session);
-            Collection<ArtifactMetadata> artifactsByProperty = repository.searchArtifacts( session, TEST_REPO_ID, "url", TEST_URL, true);
-            assertThat(artifactsByProperty).isNotNull().isNotEmpty();
-            artifactsByProperty = repository.searchArtifacts( session, TEST_REPO_ID, "org.name", "pache", true);
-            assertThat(artifactsByProperty).isNotNull().isEmpty();
-
+    public void testSearchArtifactsByKeyExact( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            createArtifactWithData( session );
+        }
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            session.refreshAndDiscard( );
+            tryAssert( ( ) -> {
+                Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, "url", TEST_URL, true );
+                assertThat( artifactsByProperty ).describedAs( "Artifact search by url=%s must give a result.", TEST_URL ).isNotNull( ).isNotEmpty( );
+                artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, "org.name", "pache", true );
+                assertThat( artifactsByProperty ).describedAs( "Artifact search by text org.name='pache' must be empty" ).isNotNull( ).isEmpty( );
+            } );
         }
     }
 
     @Test
-    public void testSearchArtifactsByFacetKey()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            createArtifactWithGenericMetadataFacet(session);
-        }
-        // Thread.currentThread().sleep(5000);
-        try (RepositorySession session = sessionFactory.createSession()) {
-            session.refresh();
-            System.out.println(repository.getRootNamespaces(session, TEST_REPO_ID));
-
-            Collection<ArtifactMetadata> artifactsByProperty = repository.searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_KEY, TEST_METADATA_VALUE, false);
-            assertThat(artifactsByProperty).isNotNull().isNotEmpty();
+    public void testSearchArtifactsByFacetKey( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            createArtifactWithGenericMetadataFacet( session );
+            tryAssert( ( ) -> {
+                Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_KEY, TEST_METADATA_VALUE, false );
+                assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
+            } );
 
         }
     }
 
     @Test
-    public void testSearchArtifactsByFacetKeyAllRepos()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
+    public void testSearchArtifactsByFacetKeyAllRepos( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
 
-            createArtifactWithGenericMetadataFacet(session);
-            tryAssert(() -> {
-                Collection<ArtifactMetadata> artifactsByProperty = repository.searchArtifacts(session, null, TEST_METADATA_KEY, TEST_METADATA_VALUE, false);
-                assertThat(artifactsByProperty).isNotNull().isNotEmpty();
-            });
+            createArtifactWithGenericMetadataFacet( session );
+            tryAssert( ( ) -> {
+                Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, null, TEST_METADATA_KEY, TEST_METADATA_VALUE, false );
+                assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
+            } );
         }
     }
 
     @Test
-    public void testSearchArtifactsFullText()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            createArtifactWithGenericMetadataFacet(session);
+    public void testSearchArtifactsFullText( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            createArtifactWithGenericMetadataFacet( session );
             // only works in JCR
-            // Collection<ArtifactMetadata> artifactsByProperty = repository.searchArtifacts( TEST_URL, TEST_REPO_ID, false );
-            Collection<ArtifactMetadata> artifactsByProperty =
-                    repository.searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE, false);
-            assertThat(artifactsByProperty).isNotNull().isNotEmpty();
+            // Collection<ArtifactMetadata> artifactsByProperty = getRepository().searchArtifacts( TEST_URL, TEST_REPO_ID, false );
+            tryAssert( ( ) -> {
+                Collection<ArtifactMetadata> artifactsByProperty =
+                    getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE, false );
+                assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
+            } );
 
         }
     }
 
     @Test
-    public void testSearchArtifactsFullTextExact()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            createArtifactWithGenericMetadataFacet(session);
+    public void testSearchArtifactsFullTextExact( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            createArtifactWithGenericMetadataFacet( session );
             // only works in JCR
-            // Collection<ArtifactMetadata> artifactsByProperty = repository.searchArtifacts( TEST_URL, TEST_REPO_ID, true );
-            Collection<ArtifactMetadata> artifactsByProperty =
-                    repository.searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE, true);
-            assertThat(artifactsByProperty).isNotNull().isNotEmpty();
-            artifactsByProperty = repository.searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE.substring(2), true);
-            assertThat(artifactsByProperty).isNotNull().isEmpty();
+            // Collection<ArtifactMetadata> artifactsByProperty = getRepository().searchArtifacts( TEST_URL, TEST_REPO_ID, true );
+
+            tryAssert( ( ) -> {
+                Collection<ArtifactMetadata> artifactsByProperty =
+                    getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE, true );
+                assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
+            } );
+            tryAssert( ( ) -> {
 
+                Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE.substring( 2 ), true );
+                assertThat( artifactsByProperty ).isNotNull( ).isEmpty( );
+            } );
         }
     }
 
     @Test
-    public void testSearchArtifactsFullTextByFacet()
-            throws Exception {
-        try (RepositorySession session = sessionFactory.createSession()) {
-            createArtifactWithGenericMetadataFacet(session);
-            Collection<ArtifactMetadata> artifactsByProperty = repository.searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE, false);
-            assertThat(artifactsByProperty).isNotNull().isNotEmpty();
-    
+    public void testSearchArtifactsFullTextByFacet( )
+        throws Exception
+    {
+        try ( RepositorySession session = getSessionFactory( ).createSession( ) )
+        {
+            createArtifactWithGenericMetadataFacet( session );
+            tryAssert( ( ) -> {
+                Collection<ArtifactMetadata> artifactsByProperty = getRepository( ).searchArtifacts( session, TEST_REPO_ID, TEST_METADATA_VALUE, false );
+                assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
+            } );
+
         }
     }
 
-    private static ProjectMetadata createProject() {
-        return createProject(TEST_NAMESPACE);
+    private static ProjectMetadata createProject( )
+    {
+        return createProject( TEST_NAMESPACE );
     }
 
-    private static ProjectMetadata createProject(String ns) {
-        ProjectMetadata project = new ProjectMetadata();
-        project.setId(TEST_PROJECT);
-        project.setNamespace(ns);
+    private static ProjectMetadata createProject( String ns )
+    {
+        ProjectMetadata project = new ProjectMetadata( );
+        project.setId( TEST_PROJECT );
+        project.setNamespace( ns );
         return project;
     }
 
-    private void createArtifactWithGenericMetadataFacet(RepositorySession session)
-            throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException {
-        createArtifactWithGenericMetadataFacet( session,1);
+    private void createArtifactWithGenericMetadataFacet( RepositorySession session )
+        throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
+    {
+        createArtifactWithGenericMetadataFacet( session, 1 );
     }
 
-    private void createArtifactWithGenericMetadataFacet(RepositorySession session, int artifacts)
-            throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException {
-        MetadataFacet metadataFacet = new GenericMetadataFacet();
-        Map<String, String> properties = new HashMap<>();
-        properties.put(TEST_METADATA_KEY, TEST_METADATA_VALUE);
-        metadataFacet.fromProperties(properties);
-        createArtifactWithFacet(session, artifacts, null, metadataFacet);
+    private void createArtifactWithGenericMetadataFacet( RepositorySession session, int artifacts )
+        throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
+    {
+        MetadataFacet metadataFacet = new GenericMetadataFacet( );
+        Map<String, String> properties = new HashMap<>( );
+        properties.put( TEST_METADATA_KEY, TEST_METADATA_VALUE );
+        metadataFacet.fromProperties( properties );
+        createArtifactWithFacet( session, artifacts, null, metadataFacet );
     }
 
-    private void createArtifactWithMavenArtifactFacet(RepositorySession session)
-            throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException {
-        createArtifactWithMavenArtifactFacet(session, 1);
+    private void createArtifactWithMavenArtifactFacet( RepositorySession session )
+        throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
+    {
+        createArtifactWithMavenArtifactFacet( session, 1 );
     }
 
-    private void createArtifactWithMavenArtifactFacet(RepositorySession session, int artifacts)
-            throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException {
-        TestMetadataFacet facet = new TestMetadataFacet(TEST_METADATA_VALUE);
-        createArtifactWithFacet(session, artifacts, facet, null);
+    private void createArtifactWithMavenArtifactFacet( RepositorySession session, int artifacts )
+        throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
+    {
+        TestMetadataFacet facet = new TestMetadataFacet( TEST_METADATA_VALUE );
+        createArtifactWithFacet( session, artifacts, facet, null );
     }
 
-    private void createArtifactWithFacet(RepositorySession session, int artifacts, MetadataFacet artifactFacet,
-                                         MetadataFacet projectVersionMetadataFacet)
-            throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException {
-            for (int i = 0; i < artifacts; i++) {
-                ArtifactMetadata artifact = createArtifact();
-                if (artifactFacet != null) {
-                    artifact.addFacet(artifactFacet);
-                }
-                repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
-            }
-            if (projectVersionMetadataFacet != null) {
-                ProjectVersionMetadata metadata =
-                        repository.getProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
-                metadata.addFacet(projectVersionMetadataFacet);
-                metadata.setOrganization(TEST_ORGANIZATION);
-                metadata.setUrl(TEST_URL);
-                repository.updateProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
+    private void createArtifactWithFacet( RepositorySession session, int artifacts, MetadataFacet artifactFacet,
+                                          MetadataFacet projectVersionMetadataFacet )
+        throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
+    {
+        for ( int i = 0; i < artifacts; i++ )
+        {
+            ArtifactMetadata artifact = createArtifact( );
+            if ( artifactFacet != null )
+            {
+                artifact.addFacet( artifactFacet );
             }
-            session.save();
-    }
-
-    private void createArtifactWithData(RepositorySession session)
-            throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException {
-            ArtifactMetadata artifact = createArtifact();
-            repository.updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
+            getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+        }
+        if ( projectVersionMetadataFacet != null )
+        {
             ProjectVersionMetadata metadata =
-                    repository.getProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
-            metadata.setOrganization(TEST_ORGANIZATION);
-            metadata.setUrl(TEST_URL);
-
-            repository.updateProjectVersion(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
-            session.save();
-    }
-
-    private static ArtifactMetadata createArtifact() {
-        return createArtifact("jar");
-    }
-
-    private static ArtifactMetadata createArtifact(String type) {
-        ArtifactMetadata artifact = new ArtifactMetadata();
-        artifact.setId(TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type);
-        artifact.setWhenGathered(new Date());
-        artifact.setNamespace(TEST_NAMESPACE);
-        artifact.setProject(TEST_PROJECT);
-        artifact.setRepositoryId(TEST_REPO_ID);
-        artifact.setFileLastModified(System.currentTimeMillis());
-        artifact.setVersion(TEST_PROJECT_VERSION);
-        artifact.setProjectVersion(TEST_PROJECT_VERSION);
-        artifact.setMd5(TEST_MD5);
-        artifact.setSha1(TEST_SHA1);
+                getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+            metadata.addFacet( projectVersionMetadataFacet );
+            metadata.setOrganization( TEST_ORGANIZATION );
+            metadata.setUrl( TEST_URL );
+            getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
+        }
+        session.save( );
+    }
+
+    protected void createArtifactWithData( RepositorySession session )
+        throws MetadataRepositoryException, MetadataResolutionException, MetadataSessionException
+    {
+        ArtifactMetadata artifact = createArtifact( );
+        getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+        ProjectVersionMetadata metadata =
+            getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+        metadata.setOrganization( TEST_ORGANIZATION );
+        metadata.setUrl( TEST_URL );
+
+        getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
+        session.save( );
+    }
+
+    private static ArtifactMetadata createArtifact( )
+    {
+        return createArtifact( "jar" );
+    }
+
+    private static ArtifactMetadata createArtifact( String type )
+    {
+        ArtifactMetadata artifact = new ArtifactMetadata( );
+        artifact.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type );
+        artifact.setWhenGathered( new Date( ) );
+        artifact.setNamespace( TEST_NAMESPACE );
+        artifact.setProject( TEST_PROJECT );
+        artifact.setRepositoryId( TEST_REPO_ID );
+        artifact.setFileLastModified( System.currentTimeMillis( ) );
+        artifact.setVersion( TEST_PROJECT_VERSION );
+        artifact.setProjectVersion( TEST_PROJECT_VERSION );
+        artifact.setMd5( TEST_MD5 );
+        artifact.setSha1( TEST_SHA1 );
         return artifact;
     }
 
     private static class ArtifactMetadataComparator
-            implements Comparator<ArtifactMetadata> {
+        implements Comparator<ArtifactMetadata>
+    {
         @Override
-        public final int compare(ArtifactMetadata a, ArtifactMetadata b) {
-            return a.getProject().compareTo(b.getProject());
+        public final int compare( ArtifactMetadata a, ArtifactMetadata b )
+        {
+            return a.getProject( ).compareTo( b.getProject( ) );
         }
     }
 
     private static class KindOfRepositoryStatistics
-            implements MetadataFacet {
+        implements MetadataFacet
+    {
         private String value;
 
         private Date date;
 
         static final String SCAN_TIMESTAMP_FORMAT = "yyyy/MM/dd/HHmmss.SSS";
 
-        private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone("UTC");
+        private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
 
-        private KindOfRepositoryStatistics(String value, Date date) {
+        private KindOfRepositoryStatistics( String value, Date date )
+        {
             this.value = value;
             this.date = date;
         }
 
         @Override
-        public String getName() {
-            return createNameFormat().format(date);
+        public String getName( )
+        {
+            return createNameFormat( ).format( date );
         }
 
-        private static SimpleDateFormat createNameFormat() {
-            SimpleDateFormat fmt = new SimpleDateFormat(SCAN_TIMESTAMP_FORMAT);
-            fmt.setTimeZone(UTC_TIME_ZONE);
+        private static SimpleDateFormat createNameFormat( )
+        {
+            SimpleDateFormat fmt = new SimpleDateFormat( SCAN_TIMESTAMP_FORMAT );
+            fmt.setTimeZone( UTC_TIME_ZONE );
             return fmt;
         }
 
         @Override
-        public String getFacetId() {
-            return KindOfRepositoryStatistics.class.getName();
+        public String getFacetId( )
+        {
+            return KindOfRepositoryStatistics.class.getName( );
         }
 
         @Override
-        public Map<String, String> toProperties() {
-            return Collections.emptyMap();
+        public Map<String, String> toProperties( )
+        {
+            return Collections.emptyMap( );
         }
 
         @Override
-        public void fromProperties(Map<String, String> properties) {
+        public void fromProperties( Map<String, String> properties )
+        {
             // no op
         }
     }
 
     private static class TestMetadataFacet
-            implements MetadataFacet {
+        implements MetadataFacet
+    {
         private String testFacetId;
 
         private Map<String, String> additionalProps;
 
         private String value;
 
-        private TestMetadataFacet(String value) {
+        private TestMetadataFacet( String value )
+        {
             this.value = value;
             testFacetId = TEST_FACET_ID;
         }
 
-        private TestMetadataFacet(String facetId, String value) {
+        private TestMetadataFacet( String facetId, String value )
+        {
             this.value = value;
             testFacetId = facetId;
         }
 
-        private TestMetadataFacet(String facetId, String value, Map<String, String> additionalProps) {
-            this(facetId, value);
+        private TestMetadataFacet( String facetId, String value, Map<String, String> additionalProps )
+        {
+            this( facetId, value );
             this.additionalProps = additionalProps;
         }
 
         @Override
-        public String getFacetId() {
+        public String getFacetId( )
+        {
             return testFacetId;
         }
 
         @Override
-        public String getName() {
+        public String getName( )
+        {
             return TEST_NAME;
         }
 
         @Override
-        public Map<String, String> toProperties() {
-            if (value != null) {
-                if (additionalProps == null) {
-                    return Collections.singletonMap("foo", value);
-                } else {
-                    Map<String, String> props = new HashMap<>();
-                    props.put("foo", value);
-
-                    for (String key : additionalProps.keySet()) {
-                        props.put(key, additionalProps.get(key));
+        public Map<String, String> toProperties( )
+        {
+            if ( value != null )
+            {
+                if ( additionalProps == null )
+                {
+                    return Collections.singletonMap( "foo", value );
+                }
+                else
+                {
+                    Map<String, String> props = new HashMap<>( );
+                    props.put( "foo", value );
+
+                    for ( String key : additionalProps.keySet( ) )
+                    {
+                        props.put( key, additionalProps.get( key ) );
                     }
                     return props;
                 }
-            } else {
-                return Collections.emptyMap();
+            }
+            else
+            {
+                return Collections.emptyMap( );
             }
         }
 
         @Override
-        public void fromProperties(Map<String, String> properties) {
-            String value = properties.get("foo");
-            if (value != null) {
+        public void fromProperties( Map<String, String> properties )
+        {
+            String value = properties.get( "foo" );
+            if ( value != null )
+            {
                 this.value = value;
             }
 
-            properties.remove("foo");
+            properties.remove( "foo" );
 
-            if (additionalProps == null) {
-                additionalProps = new HashMap<>();
+            if ( additionalProps == null )
+            {
+                additionalProps = new HashMap<>( );
             }
 
-            for (String key : properties.keySet()) {
-                additionalProps.put(key, properties.get(key));
+            for ( String key : properties.keySet( ) )
+            {
+                additionalProps.put( key, properties.get( key ) );
             }
         }
 
-        public String getValue() {
+        public String getValue( )
+        {
             return value;
         }
 
         @Override
-        public String toString() {
+        public String toString( )
+        {
             return "TestMetadataFacet{" + "value='" + value + '\'' + '}';
         }
 
         @Override
-        public boolean equals(Object o) {
-            if (this == o) {
+        public boolean equals( Object o )
+        {
+            if ( this == o )
+            {
                 return true;
             }
-            if (o == null || getClass() != o.getClass()) {
+            if ( o == null || getClass( ) != o.getClass( ) )
+            {
                 return false;
             }
 
             TestMetadataFacet that = (TestMetadataFacet) o;
 
-            if (value != null ? !value.equals(that.value) : that.value != null) {
+            if ( value != null ? !value.equals( that.value ) : that.value != null )
+            {
                 return false;
             }
 
@@ -1955,8 +2329,9 @@ public abstract class AbstractMetadataRepositoryTest
         }
 
         @Override
-        public int hashCode() {
-            return value != null ? value.hashCode() : 0;
+        public int hashCode( )
+        {
+            return value != null ? value.hashCode( ) : 0;
         }
     }
 }
diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java
index edb7115..6bd8c28 100644
--- a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java
+++ b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java
@@ -21,6 +21,8 @@ package org.apache.archiva.metadata.repository.cassandra;
 
 import org.apache.archiva.metadata.model.MetadataFacetFactory;
 import org.apache.archiva.metadata.repository.AbstractMetadataRepositoryTest;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.RepositorySessionFactory;
 import org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel;
 import org.junit.After;
 import org.junit.Before;
@@ -47,6 +49,18 @@ public class CassandraMetadataRepositoryTest
 
     CassandraMetadataRepository cmr;
 
+    @Override
+    protected RepositorySessionFactory getSessionFactory( )
+    {
+        return null;
+    }
+
+    @Override
+    protected MetadataRepository getRepository( )
+    {
+        return cmr;
+    }
+
     @Before
     @Override
     public void setUp()
@@ -63,7 +77,6 @@ public class CassandraMetadataRepositoryTest
         Map<String, MetadataFacetFactory> factories = createTestMetadataFacetFactories();
 
         this.cmr = new CassandraMetadataRepository( factories, null, cassandraArchivaManager );
-        this.repository = this.cmr;
 
         clearReposAndNamespace( cassandraArchivaManager );
     }
@@ -90,7 +103,7 @@ public class CassandraMetadataRepositoryTest
         this.cmr.removeProjectVersion( null, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
 
         assertThat(
-            repository.getProjectVersion( null , TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNull();
+            cmr.getProjectVersion( null , TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNull();
 
         assertThat( cmr.getMailingLists( key ) ).isNotNull().isEmpty();
 
diff --git a/archiva-modules/plugins/metadata-store-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java b/archiva-modules/plugins/metadata-store-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java
index 346c5c7..93ef8ce 100644
--- a/archiva-modules/plugins/metadata-store-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java
+++ b/archiva-modules/plugins/metadata-store-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java
@@ -24,6 +24,8 @@ import org.apache.archiva.configuration.Configuration;
 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.archiva.metadata.model.MetadataFacetFactory;
 import org.apache.archiva.metadata.repository.AbstractMetadataRepositoryTest;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.RepositorySessionFactory;
 import org.junit.Before;
 import org.junit.Ignore;
 
@@ -39,6 +41,21 @@ public class FileMetadataRepositoryTest
     extends AbstractMetadataRepositoryTest
 {
 
+    private FileMetadataRepository repository;
+    private RepositorySessionFactory sessionFactory = null;
+
+    @Override
+    protected MetadataRepository getRepository( )
+    {
+        return this.repository;
+    }
+
+    @Override
+    protected RepositorySessionFactory getSessionFactory( )
+    {
+        return this.sessionFactory;
+    }
+
     @Before
     @Override
     public void setUp()
diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrConstants.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrConstants.java
new file mode 100644
index 0000000..e4faa4e
--- /dev/null
+++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrConstants.java
@@ -0,0 +1,46 @@
+package org.apache.archiva.metadata.repository.jcr;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Node types and properties defined in the schema.
+ *
+ * @author Martin Stockhammer <ma...@apache.org>
+ */
+public interface JcrConstants
+{
+    String BASE_NODE_TYPE = "archiva:base";
+    String NAMESPACE_NODE_TYPE = "archiva:namespace";
+    String PROJECT_NODE_TYPE = "archiva:project";
+    String PROJECT_VERSION_NODE_TYPE = "archiva:projectVersion";
+    String ARTIFACT_NODE_TYPE = "archiva:artifact";
+    String REPOSITORY_NODE_TYPE = "archiva:repository";
+    String FACET_NODE_TYPE = "archiva:facet";
+    String MIXIN_META_SCM = "archiva:meta_scm";
+    String MIXIN_META_CI = "archiva:meta_ci";
+    String MIXIN_META_ISSUE = "archiva:meta_issue";
+    String MIXIN_META_ORGANIZATION = "archiva:meta_organization";
+    String MIXIN_META_LICENSE = "archiva:meta_license";
+    String MIXIN_META_MAILINGLIST = "archiva:meta_mailinglist";
+    String DEPENDENCY_NODE_TYPE = "archiva:dependency";
+
+    // Must be alphabetically ordered!
+    String[] PROJECT_VERSION_VERSION_PROPERTIES = {"ci.system","ci.url", "description", "incomplete", "issue.system","issue.url", "name", "org.name", "org.url", "url", "scm.connection", "scm.developerConnection", "scm.url"};
+}
diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java
index 47c4861..f9df40d 100644
--- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java
+++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java
@@ -42,7 +42,10 @@ import org.apache.archiva.metadata.repository.RepositorySession;
 import org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics;
 import org.apache.archiva.metadata.repository.stats.model.RepositoryStatisticsProvider;
 import org.apache.commons.lang.StringUtils;
+import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.commons.JcrUtils;
+import org.apache.jackrabbit.commons.cnd.CndImporter;
+import org.apache.jackrabbit.commons.cnd.ParseException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -63,6 +66,9 @@ import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
 import javax.jcr.query.Row;
 import javax.jcr.query.RowIterator;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
@@ -77,6 +83,10 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 
+import static javax.jcr.Property.JCR_LAST_MODIFIED;
+import static org.apache.archiva.metadata.repository.jcr.JcrConstants.DEPENDENCY_NODE_TYPE;
+import static org.apache.archiva.metadata.repository.jcr.JcrConstants.PROJECT_VERSION_VERSION_PROPERTIES;
+
 /**
  * TODO below: revise storage format for project version metadata
  * TODO revise reference storage
@@ -85,34 +95,23 @@ public class JcrMetadataRepository
     implements MetadataRepository, RepositoryStatisticsProvider
 {
 
-    private static final String JCR_LAST_MODIFIED = "jcr:lastModified";
-
-    static final String NAMESPACE_NODE_TYPE = "archiva:namespace";
-
-    static final String PROJECT_NODE_TYPE = "archiva:project";
-
-    static final String PROJECT_VERSION_NODE_TYPE = "archiva:projectVersion";
-
-    static final String ARTIFACT_NODE_TYPE = "archiva:artifact";
-    private static final String QUERY_ARTIFACT_1 = "SELECT * FROM [" + ARTIFACT_NODE_TYPE + "] AS artifact WHERE ISDESCENDANTNODE(artifact,'/";
 
-    static final String FACET_NODE_TYPE = "archiva:facet";
+    private static final String QUERY_ARTIFACT_1 = "SELECT * FROM [" + org.apache.archiva.metadata.repository.jcr.JcrConstants.ARTIFACT_NODE_TYPE + "] AS artifact WHERE ISDESCENDANTNODE(artifact,'/";
 
-    static final String QUERY_ARTIFACTS_BY_PROJECT_VERSION_1 = "SELECT * FROM [" + PROJECT_VERSION_NODE_TYPE + "] AS projectVersion INNER JOIN [" + ARTIFACT_NODE_TYPE
-        + "] AS artifact ON ISCHILDNODE(artifact, projectVersion) INNER JOIN [" + FACET_NODE_TYPE
+    static final String QUERY_ARTIFACTS_BY_PROJECT_VERSION_1 = "SELECT * FROM [" + org.apache.archiva.metadata.repository.jcr.JcrConstants.PROJECT_VERSION_NODE_TYPE + "] AS projectVersion INNER JOIN [" + org.apache.archiva.metadata.repository.jcr.JcrConstants.ARTIFACT_NODE_TYPE
+        + "] AS artifact ON ISCHILDNODE(artifact, projectVersion) INNER JOIN [" + org.apache.archiva.metadata.repository.jcr.JcrConstants.FACET_NODE_TYPE
         + "] AS facet ON ISCHILDNODE(facet, projectVersion) WHERE ([facet].[";
     static final String QUERY_ARTIFACTS_BY_PROJECT_VERSION_2= "] = $value)";
 
-    static final String QUERY_ARTIFACTS_BY_METADATA_1 = "SELECT * FROM [" + ARTIFACT_NODE_TYPE + "] AS artifact INNER JOIN [" + FACET_NODE_TYPE
+    static final String QUERY_ARTIFACTS_BY_METADATA_1 = "SELECT * FROM [" + org.apache.archiva.metadata.repository.jcr.JcrConstants.ARTIFACT_NODE_TYPE + "] AS artifact INNER JOIN [" + org.apache.archiva.metadata.repository.jcr.JcrConstants.FACET_NODE_TYPE
         + "] AS facet ON ISCHILDNODE(facet, artifact) WHERE ([facet].[";
     static final String QUERY_ARTIFACTS_BY_METADATA_2 = "] = $value)";
 
-    static final String QUERY_ARTIFACTS_BY_PROPERTY_1 = "SELECT * FROM [" + PROJECT_VERSION_NODE_TYPE + "] AS projectVersion INNER JOIN [" + ARTIFACT_NODE_TYPE
+    static final String QUERY_ARTIFACTS_BY_PROPERTY_1 = "SELECT * FROM [" + org.apache.archiva.metadata.repository.jcr.JcrConstants.PROJECT_VERSION_NODE_TYPE + "] AS projectVersion INNER JOIN [" + org.apache.archiva.metadata.repository.jcr.JcrConstants.ARTIFACT_NODE_TYPE
            + "] AS artifact ON ISCHILDNODE(artifact, projectVersion) WHERE ([projectVersion].[";
     static final String QUERY_ARTIFACTS_BY_PROPERTY_2 = "] = $value)";
 
 
-    private static final String DEPENDENCY_NODE_TYPE = "archiva:dependency";
     private static final String QUERY_ARTIFACT_2 = "')";
 
     private final Map<String, MetadataFacetFactory> metadataFacetFactories;
@@ -148,12 +147,29 @@ public class JcrMetadataRepository
         }
 
         NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
-        registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.NAMESPACE_NODE_TYPE );
-        registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.PROJECT_NODE_TYPE );
-        registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.PROJECT_VERSION_NODE_TYPE );
-        registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.ARTIFACT_NODE_TYPE );
-        registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.FACET_NODE_TYPE );
-        registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.DEPENDENCY_NODE_TYPE );
+        try(
+            Reader cndReader = new InputStreamReader(
+                Thread.currentThread( ).getContextClassLoader( ).getResourceAsStream( "org/apache/archiva/metadata/repository/jcr/jcr-schema.cnd" ) ))
+        {
+            CndImporter.registerNodeTypes( cndReader, session );
+        }
+        catch ( ParseException e )
+        {
+            e.printStackTrace( );
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace( );
+        }
+
+
+//        registerMixinNodeType( nodeTypeManager, REPOSITORY_NODE_TYPE );
+//        registerMixinNodeType( nodeTypeManager, NAMESPACE_NODE_TYPE );
+//        registerMixinNodeType( nodeTypeManager, PROJECT_NODE_TYPE );
+//        registerMixinNodeType( nodeTypeManager, PROJECT_VERSION_NODE_TYPE );
+//        registerMixinNodeType( nodeTypeManager, ARTIFACT_NODE_TYPE );
+//        registerMixinNodeType( nodeTypeManager, FACET_NODE_TYPE );
+//        registerMixinNodeType( nodeTypeManager, DEPENDENCY_NODE_TYPE );
 
 
     }
@@ -168,13 +184,14 @@ public class JcrMetadataRepository
             NodeTypeTemplate nodeType = nodeTypeManager.createNodeTypeTemplate();
             nodeType.setMixin( true );
             nodeType.setName( name );
+            nodeType.setQueryable( true );
             nodeTypeManager.registerNodeType( nodeType, false );
         }
     }
 
     private Session getSession(RepositorySession repositorySession) throws MetadataRepositoryException {
-        if (repositorySession instanceof JcrSession) {
-            return ( (JcrSession) repositorySession ).getJcrSession();
+        if (repositorySession instanceof JcrRepositorySession ) {
+            return ( (JcrRepositorySession) repositorySession ).getJcrSession();
         } else {
             throw new MetadataRepositoryException( "The given session object is not a JcrSession instance: " + repositorySession.getClass( ).getName( ) );
         }
@@ -216,6 +233,7 @@ public class JcrMetadataRepository
             Node node =
                 getOrAddArtifactNode( jcrSession, repositoryId, namespace, projectId, projectVersion, artifactMeta.getId() );
 
+            node.setProperty( "id", artifactMeta.getId( ) );
             Calendar cal = Calendar.getInstance();
             cal.setTime( artifactMeta.getFileLastModified() );
             node.setProperty( JCR_LAST_MODIFIED, cal );
@@ -245,8 +263,8 @@ public class JcrMetadataRepository
                 if ( metadataFacet != null )
                 {
                     // recreate, to ensure properties are removed
-                    Node n = node.addNode( facetId );
-                    n.addMixin( FACET_NODE_TYPE );
+                    Node n = node.addNode( facetId);
+                    n.addMixin( org.apache.archiva.metadata.repository.jcr.JcrConstants.FACET_NODE_TYPE );
 
                     for ( Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet() )
                     {
@@ -273,9 +291,9 @@ public class JcrMetadataRepository
         {
             Node versionNode =
                 getOrAddProjectVersionNode( jcrSession, repositoryId, namespace, projectId, versionMetadata.getId() );
-
-            versionNode.setProperty( "name", versionMetadata.getName() );
-            versionNode.setProperty( "description", versionMetadata.getDescription() );
+            versionNode.setProperty( "id", versionMetadata.getId( ) );
+            versionNode.setProperty( "name", StringUtils.isEmpty( versionMetadata.getName() ) ? "" : versionMetadata.getName() );
+            versionNode.setProperty( "description", StringUtils.isEmpty( versionMetadata.getDescription() ) ? "" : versionMetadata.getDescription() );
             versionNode.setProperty( "url", versionMetadata.getUrl() );
             versionNode.setProperty( "incomplete", versionMetadata.isIncomplete() );
 
@@ -343,8 +361,8 @@ public class JcrMetadataRepository
                     }
                     id += "." + dependency.getType();
 
-                    Node n = JcrUtils.getOrAddNode( dependenciesNode, id );
-                    n.addMixin( DEPENDENCY_NODE_TYPE );
+                    Node n = JcrUtils.getOrAddNode( dependenciesNode, id, DEPENDENCY_NODE_TYPE );
+                    n.setProperty( "id", id );
 
                     // FIXME: remove temp code just to make it keep working
                     n.setProperty( "groupId", dependency.getGroupId() );
@@ -379,7 +397,7 @@ public class JcrMetadataRepository
                     versionNode.getNode( facet.getFacetId() ).remove();
                 }
                 Node n = versionNode.addNode( facet.getFacetId() );
-                n.addMixin( FACET_NODE_TYPE );
+                n.addMixin( org.apache.archiva.metadata.repository.jcr.JcrConstants.FACET_NODE_TYPE );
 
                 for ( Map.Entry<String, String> entry : facet.toProperties().entrySet() )
                 {
@@ -398,6 +416,7 @@ public class JcrMetadataRepository
         try
         {
             Node node = getOrAddNamespaceNode( jcrSession, repositoryId, namespace );
+            node.setProperty( "id", namespace );
             node.setProperty( "namespace", namespace );
         }
         catch ( RepositoryException e )
@@ -429,7 +448,7 @@ public class JcrMetadataRepository
                 while ( nodeIterator.hasNext() )
                 {
                     Node node = nodeIterator.next();
-                    if ( node.isNodeType( PROJECT_NODE_TYPE ) && projectId.equals( node.getName() ) )
+                    if ( node.isNodeType( org.apache.archiva.metadata.repository.jcr.JcrConstants.PROJECT_NODE_TYPE ) && projectId.equals( node.getName() ) )
                     {
                         node.remove();
                     }
@@ -593,7 +612,7 @@ public class JcrMetadataRepository
             if ( root.hasNode( path ) )
             {
                 Node node = root.getNode( path );
-                if ( node.isNodeType( NAMESPACE_NODE_TYPE ) )
+                if ( node.isNodeType( org.apache.archiva.metadata.repository.jcr.JcrConstants.NAMESPACE_NODE_TYPE ) )
                 {
                     node.remove();
                 }
@@ -729,11 +748,20 @@ public class JcrMetadataRepository
         return artifacts;
     }
 
-    private List<ArtifactMetadata> runJcrQuery( Session jcrSession, String repositoryId, String q, Map<String, String> bindings )
+    public List<ArtifactMetadata> runJcrQuery( Session jcrSession, String repositoryId, String q, Map<String, String> bindingParam)
         throws MetadataRepositoryException
     {
+        return runJcrQuery( jcrSession, repositoryId, q, bindingParam, true );
+    }
+
+    public List<ArtifactMetadata> runJcrQuery( final Session jcrSession, final String repositoryId, final String qParam,
+                                               final Map<String, String> bindingParam, final boolean checkPath )
+        throws MetadataRepositoryException
+    {
+
+        String q = qParam;
         List<ArtifactMetadata> artifacts;
-        if ( repositoryId != null )
+        if ( repositoryId != null && checkPath )
         {
             q += " AND ISDESCENDANTNODE(artifact,'/" + getRepositoryContentPath( repositoryId ) + "')";
         }
@@ -742,17 +770,7 @@ public class JcrMetadataRepository
 
         try
         {
-            Query query = jcrSession.getWorkspace().getQueryManager().createQuery( q, Query.JCR_SQL2 );
-            ValueFactory valueFactory = jcrSession.getValueFactory();
-            for ( Entry<String, String> entry : bindings.entrySet() )
-            {
-                query.bindValue( entry.getKey(), valueFactory.createValue( entry.getValue() ) );
-            }
-            long start = Calendar.getInstance().getTimeInMillis();
-            QueryResult result = query.execute();
-            long end = Calendar.getInstance().getTimeInMillis();
-            log.info( "JCR Query ran in {} milliseconds: {}", end - start, q );
-
+            QueryResult result = runNativeJcrQuery( jcrSession, q, bindingParam );
             artifacts = new ArrayList<>();
             RowIterator rows = result.getRows();
             while ( rows.hasNext() )
@@ -774,6 +792,36 @@ public class JcrMetadataRepository
         return artifacts;
     }
 
+    public QueryResult runNativeJcrQuery( final Session jcrSession, final String q, final Map<String, String> bindingParam)
+        throws MetadataRepositoryException
+    {
+        Map<String, String> bindings;
+        if (bindingParam==null) {
+            bindings = new HashMap<>( );
+        } else {
+            bindings = bindingParam;
+        }
+
+        try
+        {
+            Query query = jcrSession.getWorkspace().getQueryManager().createQuery( q, Query.JCR_SQL2 );
+            ValueFactory valueFactory = jcrSession.getValueFactory();
+            for ( Entry<String, String> entry : bindings.entrySet() )
+            {
+                query.bindValue( entry.getKey(), valueFactory.createValue( entry.getValue() ) );
+            }
+            long start = System.currentTimeMillis( );
+            QueryResult result = query.execute();
+            long end = System.currentTimeMillis( );
+            log.info( "JCR Query ran in {} milliseconds: {}", end - start, q );
+            return result;
+        }
+        catch ( RepositoryException e )
+        {
+            throw new MetadataRepositoryException( e.getMessage(), e );
+        }
+    }
+
     @Override
     public List<ArtifactMetadata> getArtifactsByProjectVersionMetadata( RepositorySession session, String key, String value, String repositoryId )
         throws MetadataRepositoryException
@@ -841,7 +889,7 @@ public class JcrMetadataRepository
             artifacts = new ArrayList<>();
             for ( Node n : JcrUtils.getNodes( result ) )
             {
-                if ( n.isNodeType( ARTIFACT_NODE_TYPE ) )
+                if ( n.isNodeType( org.apache.archiva.metadata.repository.jcr.JcrConstants.ARTIFACT_NODE_TYPE ) )
                 {
                     artifacts.add( getArtifactFromNode( repositoryId, n ) );
                 }
@@ -1061,7 +1109,7 @@ public class JcrMetadataRepository
     {
         for ( Node n : JcrUtils.getChildNodes( node ) )
         {
-            if ( n.isNodeType( FACET_NODE_TYPE ) )
+            if ( n.isNodeType( org.apache.archiva.metadata.repository.jcr.JcrConstants.FACET_NODE_TYPE ) )
             {
                 String name = n.getName();
                 MetadataFacetFactory factory = metadataFacetFactories.get( name );
@@ -1202,7 +1250,7 @@ public class JcrMetadataRepository
 
         try
         {
-            return getNodeNames( getSession(session), path, NAMESPACE_NODE_TYPE );
+            return getNodeNames( getSession(session), path, org.apache.archiva.metadata.repository.jcr.JcrConstants.NAMESPACE_NODE_TYPE );
         }
         catch ( MetadataRepositoryException e )
         {
@@ -1216,7 +1264,7 @@ public class JcrMetadataRepository
     {
         try
         {
-            return getNodeNames( getSession(session), getNamespacePath( repositoryId, namespace ), PROJECT_NODE_TYPE );
+            return getNodeNames( getSession(session), getNamespacePath( repositoryId, namespace ), org.apache.archiva.metadata.repository.jcr.JcrConstants.PROJECT_NODE_TYPE );
         }
         catch ( MetadataRepositoryException e )
         {
@@ -1230,7 +1278,7 @@ public class JcrMetadataRepository
     {
         try
         {
-            return getNodeNames( getSession(session), getProjectPath( repositoryId, namespace, projectId ), PROJECT_VERSION_NODE_TYPE );
+            return getNodeNames( getSession(session), getProjectPath( repositoryId, namespace, projectId ), org.apache.archiva.metadata.repository.jcr.JcrConstants.PROJECT_VERSION_NODE_TYPE );
         }
         catch ( MetadataRepositoryException e )
         {
@@ -1258,7 +1306,7 @@ public class JcrMetadataRepository
 
                 for ( Node n : JcrUtils.getChildNodes( node ) )
                 {
-                    if ( n.isNodeType( ARTIFACT_NODE_TYPE ) )
+                    if ( n.isNodeType( org.apache.archiva.metadata.repository.jcr.JcrConstants.ARTIFACT_NODE_TYPE ) )
                     {
                         if ( n.hasProperty( "version" ) )
                         {
@@ -1297,7 +1345,7 @@ public class JcrMetadataRepository
 
             for ( Node node : JcrUtils.getChildNodes( nodeAtPath ) )
             {
-                if ( node.isNodeType( PROJECT_VERSION_NODE_TYPE ) && StringUtils.equals( projectVersion,
+                if ( node.isNodeType( org.apache.archiva.metadata.repository.jcr.JcrConstants.PROJECT_VERSION_NODE_TYPE ) && StringUtils.equals( projectVersion,
                                                                                          node.getName() ) )
                 {
                     node.remove();
@@ -1333,7 +1381,7 @@ public class JcrMetadataRepository
 
             for ( Node node : JcrUtils.getChildNodes( nodeAtPath ) )
             {
-                if ( node.isNodeType( PROJECT_VERSION_NODE_TYPE ) //
+                if ( node.isNodeType( org.apache.archiva.metadata.repository.jcr.JcrConstants.PROJECT_VERSION_NODE_TYPE ) //
                     && StringUtils.equals( node.getName(), projectVersion ) )
                 {
                     node.remove();
@@ -1363,7 +1411,7 @@ public class JcrMetadataRepository
 
                 for ( Node n : JcrUtils.getChildNodes( node ) )
                 {
-                    if ( n.isNodeType( ARTIFACT_NODE_TYPE ) )
+                    if ( n.isNodeType( org.apache.archiva.metadata.repository.jcr.JcrConstants.ARTIFACT_NODE_TYPE ) )
                     {
                         ArtifactMetadata artifactMetadata = getArtifactFromNode( repositoryId, n );
                         log.debug( "artifactMetadata: {}", artifactMetadata );
@@ -1409,7 +1457,7 @@ public class JcrMetadataRepository
 
                 for ( Node n : JcrUtils.getChildNodes( node ) )
                 {
-                    if ( n.isNodeType( ARTIFACT_NODE_TYPE ) )
+                    if ( n.isNodeType( org.apache.archiva.metadata.repository.jcr.JcrConstants.ARTIFACT_NODE_TYPE ) )
                     {
                         artifacts.add( getArtifactFromNode( repositoryId, n ) );
                     }
@@ -1462,20 +1510,34 @@ public class JcrMetadataRepository
     }
 
     @Override
-    public List<ArtifactMetadata> searchArtifacts( RepositorySession session, String repositoryId, String key, String text, boolean e )
+    public List<ArtifactMetadata> searchArtifacts( RepositorySession session, String repositoryId, String key, String text, boolean exact )
         throws MetadataRepositoryException
     {
         final Session jcrSession = getSession( session );
         String theKey = key == null ? "*" : "[" + key + "]";
         String projectVersionCondition =
-            e ? "(projectVersion." + theKey + " = $value)" : "contains([projectVersion]." + theKey + ", $value)";
-        String facetCondition = e ? "(facet." + theKey + " = $value)" : "contains([facet]." + theKey + ", $value)";
-        String q =
-            "SELECT * FROM [" + PROJECT_VERSION_NODE_TYPE + "] AS projectVersion LEFT OUTER JOIN [" + ARTIFACT_NODE_TYPE
-                + "] AS artifact ON ISCHILDNODE(artifact, projectVersion) LEFT OUTER JOIN [" + FACET_NODE_TYPE
-                + "] AS facet ON ISCHILDNODE(facet, projectVersion) WHERE (" + projectVersionCondition + " OR "
-                + facetCondition + ")";
-        return runJcrQuery( jcrSession, repositoryId, q, ImmutableMap.of( "value", text ) );
+            exact ? "(projectVersion." + theKey + " = $value)" : "contains([projectVersion]." + theKey + ", $value)";
+        String facetCondition = exact ? "(facet." + theKey + " = $value)" : "contains([facet]." + theKey + ", $value)";
+        String descendantCondition = repositoryId == null ?
+            " AND [projectVersion].[jcr:path] LIKE '/repositories/%/content/%'" :
+            " AND ISDESCENDANTNODE(projectVersion,'/" + getRepositoryContentPath( repositoryId ) + "')";
+        List<ArtifactMetadata> result = new ArrayList<>( );
+        if (key!=null && Arrays.binarySearch( PROJECT_VERSION_VERSION_PROPERTIES, key )>=0)
+        {
+            // We search only for project version properties if the key is a valid property name
+            String q1 =
+                "SELECT * FROM [" + org.apache.archiva.metadata.repository.jcr.JcrConstants.PROJECT_VERSION_NODE_TYPE
+                    + "] AS projectVersion LEFT OUTER JOIN [" + org.apache.archiva.metadata.repository.jcr.JcrConstants.ARTIFACT_NODE_TYPE
+                    + "] AS artifact ON ISCHILDNODE(artifact, projectVersion) WHERE " + projectVersionCondition + descendantCondition;
+             result.addAll(runJcrQuery( jcrSession, repositoryId, q1, ImmutableMap.of( "value", text ), false ));
+        }
+        String q2 =
+            "SELECT * FROM [" + org.apache.archiva.metadata.repository.jcr.JcrConstants.PROJECT_VERSION_NODE_TYPE
+                + "] AS projectVersion LEFT OUTER JOIN [" + org.apache.archiva.metadata.repository.jcr.JcrConstants.ARTIFACT_NODE_TYPE
+                + "] AS artifact ON ISCHILDNODE(artifact, projectVersion) LEFT OUTER JOIN [" + org.apache.archiva.metadata.repository.jcr.JcrConstants.FACET_NODE_TYPE
+                + "] AS facet ON ISCHILDNODE(facet, projectVersion) WHERE " + facetCondition + descendantCondition;
+        result.addAll( runJcrQuery( jcrSession, repositoryId, q2, ImmutableMap.of( "value", text ), false ) );
+        return result;
     }
 
     private ArtifactMetadata getArtifactFromNode( String repositoryId, Node artifactNode )
@@ -1611,15 +1673,18 @@ public class JcrMetadataRepository
     private Node getOrAddNodeByPath( Node baseNode, String name, String nodeType )
         throws RepositoryException
     {
-        log.debug( "getOrAddNodeByPath" + baseNode + " " + name + " " + nodeType );
+        log.debug( "getOrAddNodeByPath " + baseNode + " " + name + " " + nodeType );
         Node node = baseNode;
         for ( String n : name.split( "/" ) )
         {
             node = JcrUtils.getOrAddNode( node, n );
-            if ( nodeType != null )
+            if ( nodeType != null && !node.isNodeType( nodeType ))
             {
                 node.addMixin( nodeType );
             }
+            if (!node.hasProperty( "id" )) {
+                node.setProperty( "id", n );
+            }
         }
         return node;
     }
@@ -1636,7 +1701,13 @@ public class JcrMetadataRepository
         Node root = jcrSession.getRootNode();
         Node node = JcrUtils.getOrAddNode( root, "repositories" );
         log.debug( "Repositories " + node );
-        node = JcrUtils.getOrAddNode( node, repositoryId );
+        node = JcrUtils.getOrAddNode( node, repositoryId, JcrConstants.NT_UNSTRUCTURED );
+        if (!node.isNodeType( org.apache.archiva.metadata.repository.jcr.JcrConstants.REPOSITORY_NODE_TYPE )) {
+            node.addMixin( org.apache.archiva.metadata.repository.jcr.JcrConstants.REPOSITORY_NODE_TYPE );
+        }
+        if (!node.hasProperty( "id" )) {
+            node.setProperty( "id", repositoryId );
+        }
         return node;
     }
 
@@ -1651,7 +1722,7 @@ public class JcrMetadataRepository
         throws RepositoryException
     {
         Node repo = getOrAddRepositoryContentNode( jcrSession, repositoryId );
-        return getOrAddNodeByPath( repo, namespace.replace( '.', '/' ), NAMESPACE_NODE_TYPE );
+        return getOrAddNodeByPath( repo, namespace.replace( '.', '/' ), org.apache.archiva.metadata.repository.jcr.JcrConstants.NAMESPACE_NODE_TYPE );
     }
 
     private Node getOrAddProjectNode( Session jcrSession, String repositoryId, String namespace, String projectId )
@@ -1659,7 +1730,14 @@ public class JcrMetadataRepository
     {
         Node namespaceNode = getOrAddNamespaceNode( jcrSession, repositoryId, namespace );
         Node node = JcrUtils.getOrAddNode( namespaceNode, projectId );
-        node.addMixin( PROJECT_NODE_TYPE );
+        if (!node.isNodeType( org.apache.archiva.metadata.repository.jcr.JcrConstants.PROJECT_NODE_TYPE ))
+        {
+            node.addMixin( org.apache.archiva.metadata.repository.jcr.JcrConstants.PROJECT_NODE_TYPE );
+        }
+        if (!node.hasProperty( "id" ))
+        {
+            node.setProperty( "id", projectId );
+        }
         return node;
     }
 
@@ -1668,9 +1746,19 @@ public class JcrMetadataRepository
         throws RepositoryException
     {
         Node projectNode = getOrAddProjectNode( jcrSession, repositoryId, namespace, projectId );
-        Node node = JcrUtils.getOrAddNode( projectNode, projectVersion );
-        node.addMixin( PROJECT_VERSION_NODE_TYPE );
-        return node;
+        log.debug( "Project node {}", projectNode );
+        Node projectVersionNode = JcrUtils.getOrAddNode( projectNode, projectVersion, JcrConstants.NT_UNSTRUCTURED);
+        if (!projectVersionNode.isNodeType( org.apache.archiva.metadata.repository.jcr.JcrConstants.PROJECT_VERSION_NODE_TYPE ))
+        {
+            projectVersionNode.addMixin( org.apache.archiva.metadata.repository.jcr.JcrConstants.PROJECT_VERSION_NODE_TYPE );
+        }
+        if (!projectVersionNode.hasProperty( "id" ))
+        {
+            projectVersionNode.setProperty( "id", projectVersion );
+        }
+
+        log.debug( "Project version node {}", projectVersionNode );
+        return projectVersionNode;
     }
 
     private Node getOrAddArtifactNode( Session jcrSession, String repositoryId, String namespace, String projectId, String projectVersion,
@@ -1678,8 +1766,14 @@ public class JcrMetadataRepository
         throws RepositoryException
     {
         Node versionNode = getOrAddProjectVersionNode( jcrSession, repositoryId, namespace, projectId, projectVersion );
-        Node node = JcrUtils.getOrAddNode( versionNode, id );
-        node.addMixin( ARTIFACT_NODE_TYPE );
+        Node node = JcrUtils.getOrAddNode( versionNode, id);
+        if (!node.isNodeType( org.apache.archiva.metadata.repository.jcr.JcrConstants.ARTIFACT_NODE_TYPE ))
+        {
+            node.addMixin( org.apache.archiva.metadata.repository.jcr.JcrConstants.ARTIFACT_NODE_TYPE );
+        }
+        if (!node.hasProperty( "id" )) {
+            node.setProperty( "id", id );
+        }
         return node;
     }
 
diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrSession.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySession.java
similarity index 93%
rename from archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrSession.java
rename to archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySession.java
index 4b4c455..c914c9a 100644
--- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrSession.java
+++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySession.java
@@ -34,15 +34,15 @@ import javax.jcr.Session;
  *
  * @author Martin Stockhammer <ma...@apache.org>
  */
-public class JcrSession extends RepositorySession implements AutoCloseable
+public class JcrRepositorySession extends RepositorySession implements AutoCloseable
 {
 
-    private static final Logger log = LoggerFactory.getLogger( JcrSession.class );
+    private static final Logger log = LoggerFactory.getLogger( JcrRepositorySession.class );
 
     private Session jcrSession;
     private JcrMetadataRepository repository;
 
-    public JcrSession( JcrMetadataRepository metadataRepository, MetadataResolver resolver) throws RepositoryException
+    public JcrRepositorySession( JcrMetadataRepository metadataRepository, MetadataResolver resolver) throws RepositoryException
     {
         super( metadataRepository, resolver );
         this.repository = metadataRepository;
diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySessionFactory.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySessionFactory.java
index 5e0e8dd..f1f6798 100644
--- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySessionFactory.java
+++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrRepositorySessionFactory.java
@@ -62,7 +62,7 @@ public class JcrRepositorySessionFactory extends AbstractRepositorySessionFactor
     @Inject
     private RepositorySessionFactoryBean repositorySessionFactoryBean;
 
-    private RepositoryFactory repositoryFactory;
+    private OakRepositoryFactory repositoryFactory;
 
     private JcrMetadataRepository jcrMetadataRepository;
 
@@ -71,7 +71,7 @@ public class JcrRepositorySessionFactory extends AbstractRepositorySessionFactor
     {
         try
         {
-            return new JcrSession( jcrMetadataRepository, getMetadataResolver() );
+            return new JcrRepositorySession( jcrMetadataRepository, getMetadataResolver() );
         }
         catch ( RepositoryException e )
         {
@@ -83,7 +83,7 @@ public class JcrRepositorySessionFactory extends AbstractRepositorySessionFactor
     // Lazy evaluation to avoid problems with circular dependencies during initialization
     private MetadataResolver getMetadataResolver()
     {
-        if ( this.metadataResolver == null )
+        if ( this.metadataResolver == null && applicationContext!=null)
         {
             this.metadataResolver = applicationContext.getBean( MetadataResolver.class );
         }
@@ -126,7 +126,7 @@ public class JcrRepositorySessionFactory extends AbstractRepositorySessionFactor
         try
         {
 
-            repositoryFactory = new RepositoryFactory();
+            repositoryFactory = new OakRepositoryFactory();
             // FIXME this need to be configurable
             Path directoryPath = Paths.get( System.getProperty( "appserver.base" ), "data/jcr" );
             repositoryFactory.setRepositoryPath( directoryPath );
@@ -137,7 +137,7 @@ public class JcrRepositorySessionFactory extends AbstractRepositorySessionFactor
                 throw new RuntimeException("Fatal error. Could not create metadata repository.");
             }
             jcrMetadataRepository = new JcrMetadataRepository( metadataFacetFactories, repository );
-            try (JcrSession session = new JcrSession( jcrMetadataRepository, metadataResolver )) {
+            try ( JcrRepositorySession session = new JcrRepositorySession( jcrMetadataRepository, metadataResolver )) {
                 JcrMetadataRepository.initializeNodeTypes( session.getJcrSession() );
                 // Saves automatically with close
             }
@@ -153,6 +153,7 @@ public class JcrRepositorySessionFactory extends AbstractRepositorySessionFactor
 
     @Override
     protected void shutdown() {
+        logger.info( "Shutting down JcrRepositorySessionFactory" );
         repositoryFactory.close();
     }
 
diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/OakRepositoryFactory.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/OakRepositoryFactory.java
new file mode 100644
index 0000000..677bf27
--- /dev/null
+++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/OakRepositoryFactory.java
@@ -0,0 +1,684 @@
+package org.apache.archiva.metadata.repository.jcr;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import org.apache.commons.lang.time.StopWatch;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.jcr.Jcr;
+import org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoService;
+import org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoServiceImpl;
+import org.apache.jackrabbit.oak.plugins.index.IndexInfoProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexPathService;
+import org.apache.jackrabbit.oak.plugins.index.IndexPathServiceImpl;
+import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
+import org.apache.jackrabbit.oak.plugins.index.aggregate.SimpleNodeAggregator;
+import org.apache.jackrabbit.oak.plugins.index.lucene.IndexAugmentorFactory;
+import org.apache.jackrabbit.oak.plugins.index.lucene.IndexCopier;
+import org.apache.jackrabbit.oak.plugins.index.lucene.IndexTracker;
+import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexInfoProvider;
+import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider;
+import org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory;
+import org.apache.jackrabbit.oak.plugins.index.lucene.directory.BufferedOakDirectory;
+import org.apache.jackrabbit.oak.plugins.index.lucene.directory.LuceneIndexImporter;
+import org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.DocumentQueue;
+import org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.ExternalObserverBuilder;
+import org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.LocalIndexObserver;
+import org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.NRTIndexFactory;
+import org.apache.jackrabbit.oak.plugins.index.lucene.property.PropertyIndexCleaner;
+import org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReaderFactory;
+import org.apache.jackrabbit.oak.plugins.index.lucene.score.ScorerProviderFactory;
+import org.apache.jackrabbit.oak.plugins.index.lucene.score.impl.ScorerProviderFactoryImpl;
+import org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder;
+import org.apache.jackrabbit.oak.plugins.index.search.ExtractedTextCache;
+import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
+import org.apache.jackrabbit.oak.plugins.name.Namespaces;
+import org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders;
+import org.apache.jackrabbit.oak.segment.file.FileStore;
+import org.apache.jackrabbit.oak.segment.file.FileStoreBuilder;
+import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
+import org.apache.jackrabbit.oak.spi.blob.FileBlobStore;
+import org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore;
+import org.apache.jackrabbit.oak.spi.commit.BackgroundObserver;
+import org.apache.jackrabbit.oak.spi.commit.Observer;
+import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
+import org.apache.jackrabbit.oak.spi.mount.MountInfoProvider;
+import org.apache.jackrabbit.oak.spi.mount.Mounts;
+import org.apache.jackrabbit.oak.spi.namespace.NamespaceConstants;
+import org.apache.jackrabbit.oak.spi.query.QueryIndex;
+import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
+import org.apache.jackrabbit.oak.spi.state.Clusterable;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.stats.StatisticsProvider;
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nonnull;
+import javax.jcr.Repository;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.archiva.metadata.repository.jcr.OakRepositoryFactory.StoreType.IN_MEMORY_TYPE;
+import static org.apache.archiva.metadata.repository.jcr.OakRepositoryFactory.StoreType.SEGMENT_FILE_TYPE;
+import static org.apache.commons.io.FileUtils.ONE_MB;
+import static org.apache.jackrabbit.JcrConstants.*;
+import static org.apache.jackrabbit.oak.api.Type.NAME;
+import static org.apache.archiva.metadata.repository.jcr.JcrConstants.*;
+import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean;
+import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.scheduleWithFixedDelay;
+
+/**
+ * Created by martin on 14.06.17.
+ *
+ * @author Martin Stockhammer
+ * @since 3.0.0
+ */
+public class OakRepositoryFactory
+{
+
+    private Logger log = LoggerFactory.getLogger( OakRepositoryFactory.class );
+
+    private FileStore fileStore;
+
+    private NodeStore nodeStore;
+
+    private IndexTracker tracker;
+
+    private DocumentQueue documentQueue;
+
+    private NRTIndexFactory nrtIndexFactory;
+
+    private IndexCopier indexCopier;
+
+    private ExecutorService executorService;
+    private ExtractedTextCache extractedTextCache;
+
+    private boolean hybridIndex = true;
+    private boolean prefetchEnabled = true;
+    private boolean enableAsyncIndexOpen = true;
+    int queueSize = 10000;
+    int cleanerInterval = 10*60;
+    boolean enableCopyOnWrite = true;
+    boolean enableCopyOnRead = true;
+    int cacheSizeInMB = 20;
+    int cacheExpiryInSecs = 300;
+    int threadPoolSize = 5;
+
+    private StatisticsProvider statisticsProvider;
+
+    private MountInfoProvider mountInfoProvider =  Mounts.defaultMountInfoProvider();
+
+    private AsyncIndexInfoService asyncIndexInfoService = null;
+
+    private LuceneIndexProvider indexProvider;
+
+    private ScorerProviderFactory scorerFactory = new ScorerProviderFactoryImpl( );
+    private IndexAugmentorFactory augmentorFactory = new IndexAugmentorFactory( );
+
+    private ActiveDeletedBlobCollectorFactory.ActiveDeletedBlobCollector activeDeletedBlobCollector = ActiveDeletedBlobCollectorFactory.NOOP;
+
+    private QueryIndex.NodeAggregator nodeAggregator = new SimpleNodeAggregator( );
+
+    private BackgroundObserver backgroundObserver;
+
+    private BackgroundObserver externalIndexObserver;
+
+    private GarbageCollectableBlobStore blobStore;
+
+    private PropertyIndexCleaner cleaner;
+
+    private IndexPathService indexPathService;
+
+    private LuceneIndexEditorProvider editorProvider;
+
+    private Path indexDir;
+
+    public enum StoreType
+    {
+        SEGMENT_FILE_TYPE,
+        IN_MEMORY_TYPE;
+    }
+
+    private StoreType storeType = SEGMENT_FILE_TYPE;
+
+    private Path repositoryPath = Paths.get( "repository" );
+
+    public OakRepositoryFactory() {
+        final OakRepositoryFactory repositoryFactory = this;
+        Runtime.getRuntime().addShutdownHook( new Thread( ( ) -> {
+            if (repositoryFactory!=null)
+            {
+                repositoryFactory.close( );
+            }
+        } ) );
+    }
+
+    private void initializeExtractedTextCache( StatisticsProvider statisticsProvider) {
+        boolean alwaysUsePreExtractedCache = false;
+
+        extractedTextCache = new ExtractedTextCache(
+            cacheSizeInMB * ONE_MB,
+            cacheExpiryInSecs,
+            alwaysUsePreExtractedCache,
+            indexDir.toFile(), statisticsProvider);
+    }
+
+    private IndexTracker createTracker() throws IOException {
+        IndexTracker tracker;
+        if (enableCopyOnRead){
+            initializeIndexCopier();
+            log.info("Enabling CopyOnRead support. Index files would be copied under {}", indexDir.toAbsolutePath());
+            if (hybridIndex) {
+                nrtIndexFactory = new NRTIndexFactory(indexCopier, statisticsProvider);
+            }
+            tracker = new IndexTracker(new DefaultIndexReaderFactory(mountInfoProvider, indexCopier), nrtIndexFactory);
+        } else {
+            tracker = new IndexTracker(new DefaultIndexReaderFactory(mountInfoProvider, null));
+        }
+
+        tracker.setAsyncIndexInfoService(asyncIndexInfoService);
+        tracker.refresh();
+        return tracker;
+    }
+
+    private void initializeIndexCopier() throws IOException {
+        if(indexCopier != null){
+            return;
+        }
+
+        if (prefetchEnabled){
+            log.info("Prefetching of index files enabled. Index would be opened after copying all new files locally");
+        }
+
+        indexCopier = new IndexCopier(getExecutorService(), indexDir.toFile(), prefetchEnabled);
+
+    }
+
+    ExecutorService getExecutorService(){
+        if (executorService == null){
+            executorService = createExecutor();
+        }
+        return executorService;
+    }
+
+    private ExecutorService createExecutor() {
+        ThreadPoolExecutor executor = new ThreadPoolExecutor(threadPoolSize, threadPoolSize, 60L, TimeUnit.SECONDS,
+            new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {
+            private final AtomicInteger counter = new AtomicInteger();
+            private final Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler() {
+                @Override
+                public void uncaughtException(Thread t, Throwable e) {
+                    log.warn("Error occurred in asynchronous processing ", e);
+                }
+            };
+            @Override
+            public Thread newThread(@NotNull Runnable r) {
+                Thread thread = new Thread(r, createName());
+                thread.setDaemon(true);
+                thread.setPriority(Thread.MIN_PRIORITY);
+                thread.setUncaughtExceptionHandler(handler);
+                return thread;
+            }
+
+            private String createName() {
+                return "oak-lucene-" + counter.getAndIncrement();
+            }
+        });
+        executor.setKeepAliveTime(1, TimeUnit.MINUTES);
+        executor.allowCoreThreadTimeOut(true);
+        return executor;
+    }
+
+    private void initialize(){
+        if(indexProvider == null){
+            return;
+        }
+
+        if(nodeAggregator != null){
+            log.debug("Using NodeAggregator {}", nodeAggregator.getClass());
+        }
+
+        indexProvider.setAggregator(nodeAggregator);
+    }
+
+    private void registerObserver() {
+        Observer observer = indexProvider;
+        if (enableAsyncIndexOpen) {
+            backgroundObserver = new BackgroundObserver(indexProvider, getExecutorService(), 5);
+            log.info("Registering the LuceneIndexProvider as a BackgroundObserver");
+        }
+    }
+
+    private void registerLocalIndexObserver(IndexTracker tracker) {
+        if (!hybridIndex){
+            log.info("Hybrid indexing feature disabled");
+            return;
+        }
+        documentQueue = new DocumentQueue( queueSize, tracker, getExecutorService(), statisticsProvider);
+        LocalIndexObserver localIndexObserver = new LocalIndexObserver(documentQueue, statisticsProvider);
+
+        int observerQueueSize = 1000;
+        int builderMaxSize = 5000;
+        // regs.add(bundleContext.registerService(JournalPropertyService.class.getName(),
+        //    new LuceneJournalPropertyService(builderMaxSize), null));
+        ExternalObserverBuilder builder = new ExternalObserverBuilder(documentQueue, tracker, statisticsProvider,
+            getExecutorService(), observerQueueSize);
+        log.info("Configured JournalPropertyBuilder with max size {} and backed by BackgroundObserver " +
+            "with queue size {}", builderMaxSize, observerQueueSize);
+
+        Observer observer = builder.build();
+        externalIndexObserver = builder.getBackgroundObserver();
+        log.info("Hybrid indexing enabled for configured indexes with queue size of {}", queueSize );
+    }
+
+    private IndexInfoProvider registerIndexInfoProvider() {
+        return new LuceneIndexInfoProvider(nodeStore, asyncIndexInfoService, getIndexCheckDir().toFile());
+    }
+
+    private Path getIndexCheckDir() {
+        return checkNotNull(indexDir).resolve("indexCheckDir");
+    }
+
+    private LuceneIndexImporter registerIndexImporterProvider() {
+        return new LuceneIndexImporter(blobStore);
+    }
+
+    private void registerPropertyIndexCleaner( ) {
+
+        if (cleanerInterval <= 0) {
+            log.info("Property index cleaner would not be registered");
+            return;
+        }
+
+        cleaner = new PropertyIndexCleaner(nodeStore, indexPathService, asyncIndexInfoService, statisticsProvider);
+
+        //Proxy check for DocumentNodeStore
+        if (nodeStore instanceof Clusterable ) {
+            cleaner.setRecursiveDelete(true);
+            log.info("PropertyIndexCleaner configured to perform recursive delete");
+        }
+        log.info("Property index cleaner configured to run every [{}] seconds", cleanerInterval);
+    }
+
+    private void registerIndexEditor( IndexTracker tracker) throws IOException {
+        boolean enableCopyOnWrite = true;
+        if (enableCopyOnWrite){
+            initializeIndexCopier();
+            editorProvider = new LuceneIndexEditorProvider(indexCopier, tracker, extractedTextCache,
+                augmentorFactory,  mountInfoProvider, activeDeletedBlobCollector, null, statisticsProvider);
+            log.info("Enabling CopyOnWrite support. Index files would be copied under {}", indexDir.toAbsolutePath());
+        } else {
+            editorProvider = new LuceneIndexEditorProvider(null, tracker, extractedTextCache, augmentorFactory,
+                mountInfoProvider, activeDeletedBlobCollector, null, statisticsProvider);
+        }
+        editorProvider.setBlobStore(blobStore);
+
+        if (hybridIndex){
+            editorProvider.setIndexingQueue(checkNotNull(documentQueue));
+        }
+
+
+    }
+
+    public Repository createRepository()
+        throws IOException, InvalidFileStoreVersionException
+    {
+
+        indexDir = repositoryPath.resolve( ".index-lucene" );
+        if (!Files.exists( indexDir )) {
+            Files.createDirectories( indexDir );
+        }
+        blobStore = new FileBlobStore( indexDir.resolve( "blobs" ).toAbsolutePath().toString() );
+
+        statisticsProvider = StatisticsProvider.NOOP;
+
+        if ( SEGMENT_FILE_TYPE == storeType )
+        {
+            fileStore = FileStoreBuilder.fileStoreBuilder( repositoryPath.toFile() )
+                .withStatisticsProvider( statisticsProvider )
+                .build();
+            nodeStore = SegmentNodeStoreBuilders.builder( fileStore ) //
+                .withStatisticsProvider( statisticsProvider ) //
+                .build();
+        }
+        else if ( IN_MEMORY_TYPE == storeType )
+        {
+            nodeStore = new MemoryNodeStore( );
+        }
+        else
+        {
+            throw new IllegalArgumentException( "Store type " + storeType + " not recognized" );
+        }
+
+        asyncIndexInfoService = new AsyncIndexInfoServiceImpl( nodeStore );
+
+        indexPathService = new IndexPathServiceImpl( nodeStore, mountInfoProvider );
+
+        BufferedOakDirectory.setEnableWritingSingleBlobIndexFile( true );
+
+        initializeExtractedTextCache( statisticsProvider );
+
+        tracker = createTracker();
+
+        indexProvider = new LuceneIndexProvider(tracker, scorerFactory, augmentorFactory);
+
+        initialize();
+        registerObserver();
+        registerLocalIndexObserver(tracker);
+        registerIndexInfoProvider();
+        registerIndexImporterProvider();
+        registerPropertyIndexCleaner();
+
+        registerIndexEditor(tracker);
+
+
+
+        RepositoryInitializer repoInitializer = new RepositoryInitializer( )
+        {
+            private IndexDefinitionBuilder.PropertyRule initRegexAll( IndexDefinitionBuilder.IndexRule rule ) {
+                return rule
+                    .indexNodeName( )
+                    .property(JCR_LASTMODIFIED ).propertyIndex().type( "Date" ).ordered()
+                    .property(JCR_PRIMARYTYPE).propertyIndex()
+                    .property(JCR_MIXINTYPES).propertyIndex()
+                    .property(JCR_PATH).propertyIndex().ordered()
+                    .property( FulltextIndexConstants.REGEX_ALL_PROPS, true )
+                    .propertyIndex().analyzed( ).nodeScopeIndex();
+            }
+
+            private IndexDefinitionBuilder.PropertyRule initBaseRule( IndexDefinitionBuilder.IndexRule rule ) {
+                return rule
+                    .sync()
+                    .indexNodeName( )
+                    .property(JCR_CREATED).propertyIndex().type("Date").ordered()
+                    .property(JCR_LASTMODIFIED ).propertyIndex().type( "Date" ).ordered()
+                    .property(JCR_PRIMARYTYPE).propertyIndex()
+                    .property(JCR_MIXINTYPES).propertyIndex()
+                    .property(JCR_PATH).propertyIndex().ordered()
+                    .property( "id" ).propertyIndex().analyzed( );
+            }
+
+            @Override
+            public void initialize( @Nonnull NodeBuilder root )
+            {
+                NodeBuilder namespaces;
+                if ( !root.hasChildNode( NamespaceConstants.REP_NAMESPACES ) )
+                {
+                    namespaces = Namespaces.createStandardMappings( root );
+                    Namespaces.buildIndexNode( namespaces ); // index node for faster lookup
+                }
+                else
+                {
+                    namespaces = root.getChildNode( NamespaceConstants.REP_NAMESPACES );
+                }
+                Namespaces.addCustomMapping( namespaces, "http://archiva.apache.org/jcr/", "archiva" );
+
+                log.info( "Creating index " );
+
+                NodeBuilder oakIdx = IndexUtils.getOrCreateOakIndex( root );
+                if (!oakIdx.hasChildNode( "repo-lucene" ))
+                {
+                    NodeBuilder lucene = oakIdx.child( "repo-lucene" );
+                    lucene.setProperty( JCR_PRIMARYTYPE, "oak:QueryIndexDefinition", NAME );
+
+                    lucene.setProperty( "compatVersion", 2 );
+                    lucene.setProperty( "type", "lucene" );
+                    // lucene.setProperty("async", "async");
+                    // lucene.setProperty( INCLUDE_PROPERTY_TYPES, ImmutableSet.of(  ), Type.STRINGS );
+                    // lucene.setProperty("refresh",true);
+                    NodeBuilder rules = lucene.child( "indexRules" ).
+                        setProperty( JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME );
+                    rules.setProperty( ":childOrder", ImmutableSet.of(
+                        REPOSITORY_NODE_TYPE,
+                        NAMESPACE_NODE_TYPE, //
+                        PROJECT_NODE_TYPE,
+                        PROJECT_VERSION_NODE_TYPE, //
+                        ARTIFACT_NODE_TYPE, //
+                        FACET_NODE_TYPE //
+                    ), Type.STRINGS );
+                    IndexDefinitionBuilder idxBuilder = new IndexDefinitionBuilder( lucene );
+                    idxBuilder.async( "async", "nrt" ).includedPaths( "/repositories" ).evaluatePathRestrictions();
+
+                    initBaseRule(idxBuilder.indexRule( REPOSITORY_NODE_TYPE ));
+                    initBaseRule(idxBuilder.indexRule( NAMESPACE_NODE_TYPE ))
+                        .property( "namespace" ).propertyIndex().analyzed();
+                    initBaseRule(idxBuilder.indexRule( PROJECT_NODE_TYPE ))
+                        .property( "name" ).propertyIndex().analyzed().notNullCheckEnabled().nullCheckEnabled();
+                    initBaseRule( idxBuilder.indexRule( PROJECT_VERSION_NODE_TYPE ) )
+                        .property("name").propertyIndex().analyzed().notNullCheckEnabled().nullCheckEnabled()
+                        .property("description").propertyIndex().analyzed().notNullCheckEnabled().nullCheckEnabled()
+                        .property("url").propertyIndex().analyzed( ).notNullCheckEnabled().nullCheckEnabled()
+                        .property("incomplete").type("Boolean").propertyIndex()
+                        .property("mailinglist/name").propertyIndex().analyzed()
+                        .property("license/license.name").propertyIndex().analyzed();
+                    initBaseRule(idxBuilder.indexRule( ARTIFACT_NODE_TYPE ))
+                        .property( "whenGathered" ).type("Date").propertyIndex().analyzed().ordered()
+                        .property("size").type("Long").propertyIndex().analyzed().ordered()
+                        .property("version").propertyIndex().analyzed().ordered();
+                    initRegexAll( idxBuilder.indexRule( FACET_NODE_TYPE ) );
+                    idxBuilder.indexRule( MIXIN_META_SCM )
+                        .property( "scm.connection" ).propertyIndex()
+                        .property( "scm.developerConnection" ).propertyIndex()
+                        .property( "scm.url").type("URI").propertyIndex().analyzed();
+                    idxBuilder.indexRule( MIXIN_META_CI )
+                        .property( "ci.system" ).propertyIndex( )
+                        .property( "ci.ur" ).propertyIndex( ).analyzed( );
+                    idxBuilder.indexRule( MIXIN_META_ISSUE )
+                        .property( "issue.system").propertyIndex()
+                        .property("issue.url").propertyIndex().analyzed();
+                    idxBuilder.indexRule( MIXIN_META_ORGANIZATION )
+                        .property( "org.name" ).propertyIndex( ).analyzed( )
+                        .property( "org.url" ).propertyIndex( ).analyzed( );
+                    idxBuilder.indexRule( MIXIN_META_LICENSE )
+                        .property( "license.name" ).propertyIndex( ).analyzed( )
+                        .property( "license.url" ).propertyIndex( ).analyzed( );
+                    idxBuilder.indexRule( MIXIN_META_MAILINGLIST )
+                        .property( "name" ).propertyIndex().analyzed();
+                    initBaseRule(idxBuilder.indexRule( DEPENDENCY_NODE_TYPE ))
+                        .property( "groupId" ).propertyIndex().analyzed().ordered()
+                        .property( "artifactId").propertyIndex().analyzed().ordered()
+                        .property("version").propertyIndex().analyzed().ordered()
+                        .property("type").propertyIndex().analyzed().ordered()
+                        .property( "classifier" ).propertyIndex().ordered()
+                        .property("scope").propertyIndex()
+                        .property("systemPath").propertyIndex().analyzed()
+                        .property("optional").type("Boolean").propertyIndex();
+
+                    idxBuilder.aggregateRule( PROJECT_VERSION_NODE_TYPE ).include( "dependencies")
+                        .path("dependencies/*" ).relativeNode();
+
+                    idxBuilder.build( );
+
+                    IndexUtils.createIndexDefinition( oakIdx, "baseIndexes", true, false, ImmutableList.of( "jcr:uuid", "rep:principalName" ), null );
+
+                    log.info( "Index: {} repo-lucene: {}", lucene, lucene.getChildNode( "repo-lucene" ) );
+                    log.info( "repo-lucene Properties: {}", lucene.getChildNode( "repo-lucene" ).getProperties( ) );
+                } else {
+
+                    NodeBuilder lucene = oakIdx.child( "repo-lucene" );
+                    lucene.setProperty( "reindex", true );
+                    log.info( "No Index update" );
+                }
+                // IndexUtils.createIndexDefinition(  )
+
+            }
+        };
+
+        //        ExternalObserverBuilder builder = new ExternalObserverBuilder(queue, tracker, statsProvider,
+//            executorService, queueSize);
+//        Observer observer = builder.build();
+//        builder.getBackgroundObserver();
+
+
+
+        log.info( "Starting Jcr repo with nodeStore {}", nodeStore );
+        Jcr jcr = new Jcr( nodeStore ).with( editorProvider ) //
+            .with( backgroundObserver ) //
+            .with( externalIndexObserver )
+            // .with(observer)
+            .with( (QueryIndexProvider) indexProvider )
+            .with (repoInitializer)
+            .withAsyncIndexing( "async", 5 );
+            //
+            //.withAsyncIndexing( "async", 5 );
+        StopWatch stopWatch = new StopWatch();
+        stopWatch.start();
+        Repository r = jcr.createRepository();
+        stopWatch.stop();
+        log.info( "time to create jcr repository: {} ms", stopWatch.getTime() );
+//        try
+//        {
+//            Thread.currentThread().sleep( 1000 );
+//        }
+//        catch ( InterruptedException e )
+//        {
+//            log.error( e.getMessage(), e );
+//        }
+        return r;
+
+
+    }
+
+    public void close()
+    {
+        log.info( "Closing JCR RepositoryFactory" );
+        if ( fileStore != null )
+        {
+            fileStore.close();
+        }
+
+        if (backgroundObserver != null){
+            backgroundObserver.close();
+        }
+
+        if (externalIndexObserver != null){
+            externalIndexObserver.close();
+        }
+
+        if (indexProvider != null) {
+            indexProvider.close();
+            indexProvider = null;
+        }
+
+        if (documentQueue != null){
+            try
+            {
+                documentQueue.close();
+            }
+            catch ( IOException e )
+            {
+                e.printStackTrace( );
+            }
+        }
+
+        if (nrtIndexFactory != null){
+            try
+            {
+                nrtIndexFactory.close();
+            }
+            catch ( IOException e )
+            {
+                e.printStackTrace( );
+            }
+        }
+
+        //Close the copier first i.e. before executorService
+        if (indexCopier != null){
+            try
+            {
+                indexCopier.close();
+            }
+            catch ( IOException e )
+            {
+                e.printStackTrace( );
+            }
+        }
+
+        if (executorService != null){
+            executorService.shutdown();
+            try
+            {
+                executorService.awaitTermination(1, TimeUnit.MINUTES);
+            }
+            catch ( InterruptedException e )
+            {
+                e.printStackTrace( );
+            }
+        }
+
+        if (extractedTextCache != null) {
+            extractedTextCache.close();
+        }
+
+    }
+
+    public StoreType getStoreType()
+    {
+        return storeType;
+    }
+
+    public void setStoreType( StoreType storeType )
+    {
+        this.storeType = storeType;
+    }
+
+    public Path getRepositoryPath()
+    {
+        return repositoryPath;
+    }
+
+    public void setRepositoryPath( Path repositoryPath )
+    {
+        this.repositoryPath = repositoryPath;
+    }
+
+    public void setRepositoryPath( String repositoryPath )
+    {
+        this.repositoryPath = Paths.get( repositoryPath );
+        if ( !Files.exists( this.repositoryPath ) )
+        {
+            try
+            {
+                Files.createDirectories( this.repositoryPath );
+            }
+            catch ( IOException e )
+            {
+                log.error( e.getMessage(), e );
+                throw new IllegalArgumentException( "cannot create directory:" + repositoryPath, e );
+            }
+        }
+    }
+
+
+}
diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/RepositoryFactory.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/RepositoryFactory.java
deleted file mode 100644
index d2f0b11..0000000
--- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/RepositoryFactory.java
+++ /dev/null
@@ -1,367 +0,0 @@
-package org.apache.archiva.metadata.repository.jcr;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import com.google.common.collect.ImmutableSet;
-import org.apache.commons.lang.time.StopWatch;
-import org.apache.jackrabbit.oak.Oak;
-import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.jcr.Jcr;
-import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
-import org.apache.jackrabbit.oak.plugins.index.lucene.IndexCopier;
-import org.apache.jackrabbit.oak.plugins.index.lucene.IndexTracker;
-import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider;
-import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider;
-import org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.DocumentQueue;
-import org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.LocalIndexObserver;
-import org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.NRTIndexFactory;
-import org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReaderFactory;
-import org.apache.jackrabbit.oak.plugins.index.search.ExtractedTextCache;
-import org.apache.jackrabbit.oak.plugins.name.Namespaces;
-import org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders;
-import org.apache.jackrabbit.oak.segment.file.FileStore;
-import org.apache.jackrabbit.oak.segment.file.FileStoreBuilder;
-import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
-import org.apache.jackrabbit.oak.spi.commit.Observer;
-import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
-import org.apache.jackrabbit.oak.spi.mount.MountInfoProvider;
-import org.apache.jackrabbit.oak.spi.mount.Mounts;
-import org.apache.jackrabbit.oak.spi.namespace.NamespaceConstants;
-import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
-import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
-import org.apache.jackrabbit.oak.spi.state.NodeStore;
-import org.apache.jackrabbit.oak.stats.StatisticsProvider;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.annotation.Nonnull;
-import javax.jcr.Repository;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import static org.apache.archiva.metadata.repository.jcr.RepositoryFactory.StoreType.IN_MEMORY_TYPE;
-import static org.apache.archiva.metadata.repository.jcr.RepositoryFactory.StoreType.SEGMENT_FILE_TYPE;
-import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
-import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED;
-import static org.apache.jackrabbit.oak.api.Type.NAME;
-import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INCLUDE_PROPERTY_TYPES;
-
-/**
- * Created by martin on 14.06.17.
- *
- * @author Martin Stockhammer
- * @since 3.0.0
- */
-public class RepositoryFactory
-{
-
-    private Logger log = LoggerFactory.getLogger( RepositoryFactory.class );
-
-    private FileStore fileStore;
-
-    private NodeStore nodeStore;
-
-    private ExecutorService executorService;
-
-    public enum StoreType
-    {
-        SEGMENT_FILE_TYPE,
-        IN_MEMORY_TYPE;
-    }
-
-    private StoreType storeType = SEGMENT_FILE_TYPE;
-
-    private Path repositoryPath = Paths.get( "repository" );
-
-    public Repository createRepository()
-        throws IOException, InvalidFileStoreVersionException
-    {
-        createExecutor();
-
-        if ( SEGMENT_FILE_TYPE == storeType )
-        {
-            fileStore = FileStoreBuilder.fileStoreBuilder( repositoryPath.toFile() ).build();
-            nodeStore = SegmentNodeStoreBuilders.builder( fileStore ) //
-                .withStatisticsProvider( StatisticsProvider.NOOP ) //
-                .build();
-        }
-        else if ( IN_MEMORY_TYPE == storeType )
-        {
-            nodeStore = null;
-        }
-        else
-        {
-            throw new IllegalArgumentException( "Store type " + storeType + " not recognized" );
-        }
-
-        Oak oak = nodeStore == null ? new Oak() : new Oak( nodeStore );
-        oak.with( new RepositoryInitializer()
-        {
-            @Override
-            public void initialize( @Nonnull NodeBuilder root )
-            {
-                NodeBuilder namespaces;
-                if (!root.hasChildNode(NamespaceConstants.REP_NAMESPACES)) {
-                    namespaces = Namespaces.createStandardMappings(root);
-                    Namespaces.buildIndexNode(namespaces); // index node for faster lookup
-                } else {
-                    namespaces = root.getChildNode(NamespaceConstants.REP_NAMESPACES);
-                }
-                Namespaces.addCustomMapping(namespaces, "http://archiva.apache.org/jcr/", "archiva");
-
-                log.info( "Creating index " );
-                NodeBuilder lucene = IndexUtils.getOrCreateOakIndex( root ).child( "lucene" );
-                lucene.setProperty( JCR_PRIMARYTYPE, "oak:QueryIndexDefinition", NAME );
-
-                lucene.setProperty( "compatVersion", 2 );
-                lucene.setProperty( "type", "lucene" );
-                // lucene.setProperty("async", "async");
-                lucene.setProperty( INCLUDE_PROPERTY_TYPES, ImmutableSet.of( "String" ), Type.STRINGS );
-                // lucene.setProperty("refresh",true);
-                lucene.setProperty( "async", ImmutableSet.of( "async", "sync" ), Type.STRINGS );
-                NodeBuilder rules = lucene.child( "indexRules" ).
-                    setProperty( JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME );
-                rules.setProperty( ":childOrder", ImmutableSet.of( "archiva:projectVersion", //
-                                                                   "archiva:artifact", //
-                                                                   "archiva:facet", //
-                                                                   "archiva:namespace", //
-                                                                   "archiva:project" ), //
-                                   Type.STRINGS );
-                NodeBuilder allProps = rules.child( "archiva:projectVersion" )
-                        .setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME)//
-                    .child( "properties" ) //
-                    .setProperty( JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME ) //
-                    .setProperty( ":childOrder", ImmutableSet.of( "allProps" ), Type.STRINGS ) //
-                    .setProperty( "indexNodeName", true ) //
-                    .child( "allProps" ) //
-                    .setProperty( JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME );
-                allProps.setProperty( "name", ".*" );
-                allProps.setProperty( "isRegexp", true );
-                allProps.setProperty( "nodeScopeIndex", true );
-                allProps.setProperty( "index", true );
-                allProps.setProperty( "analyzed", true );
-                // allProps.setProperty("propertyIndex",true);
-                allProps = rules.child("archiva:artifact") //
-                        .setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME)
-                        .child("properties") //
-                        .setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME) //
-                        .setProperty(":childOrder", ImmutableSet.of("allProps"), Type.STRINGS) //
-                        .setProperty("indexNodeName", true)
-                        .child("allProps")
-                            .setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME);
-                allProps.setProperty( "name", ".*" );
-                allProps.setProperty( "isRegexp", true );
-                allProps.setProperty( "nodeScopeIndex", true );
-                allProps.setProperty( "index", true );
-                allProps.setProperty( "analyzed", true );
-                allProps = rules.child( "archiva:facet" ) //
-                        .setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME)
-                    .child( "properties" ) //
-                    .setProperty( JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME ) //
-                    .setProperty( ":childOrder", ImmutableSet.of( "allProps" ), Type.STRINGS ) //
-                    .setProperty( "indexNodeName", true ) //
-                    .child( "allProps" ) //
-                    .setProperty( JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME );
-                allProps.setProperty( "name", ".*" );
-                allProps.setProperty( "isRegexp", true );
-                allProps.setProperty( "nodeScopeIndex", true );
-                allProps.setProperty( "index", true );
-                allProps.setProperty( "analyzed", true );
-                allProps = rules.child( "archiva:namespace" ) //
-                        .setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME)
-                    .child( "properties" ) //
-                    .setProperty( JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME ) //
-                    .setProperty( ":childOrder", ImmutableSet.of( "allProps" ), Type.STRINGS ) //
-                    .setProperty( "indexNodeName", true ) //
-                    .child( "allProps" ) //
-                    .setProperty( JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME );
-                allProps.setProperty( "name", ".*" );
-                allProps.setProperty( "isRegexp", true );
-                allProps.setProperty( "nodeScopeIndex", true );
-                allProps.setProperty( "index", true );
-                allProps.setProperty( "analyzed", true );
-                allProps = rules.child( "archiva:project" ) //
-                        .setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME)
-                    .child( "properties" ) //
-                    .setProperty( JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME ) //
-                    .setProperty( ":childOrder", ImmutableSet.of( "allProps" ), Type.STRINGS ) //
-                    .setProperty( "indexNodeName", true ) //
-                    .child( "allProps" ) //
-                    .setProperty( JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME );
-                allProps.setProperty( "name", ".*" );
-                allProps.setProperty( "isRegexp", true );
-                allProps.setProperty( "nodeScopeIndex", true );
-                allProps.setProperty( "index", true );
-                allProps.setProperty( "analyzed", true );
-
-                log.info( "Index: {} myIndex {}", lucene, lucene.getChildNode( "myIndex" ) );
-                log.info( "myIndex {}", lucene.getChildNode( "myIndex" ).getProperties() );
-                // IndexUtils.createIndexDefinition(  )
-
-            }
-        } );
-
-        StatisticsProvider statsProvider = StatisticsProvider.NOOP;
-        int queueSize = Integer.getInteger( "queueSize", 10000 );
-        Path indexDir = Files.createTempDirectory( "archiva_index" );
-        log.info( "Queue Index {}", indexDir.toString() );
-        IndexCopier indexCopier = new IndexCopier( executorService, indexDir.toFile(), true );
-        NRTIndexFactory nrtIndexFactory = new NRTIndexFactory( indexCopier, statsProvider );
-        MountInfoProvider mountInfoProvider = Mounts.defaultMountInfoProvider();
-        IndexTracker tracker =
-            new IndexTracker( new DefaultIndexReaderFactory( mountInfoProvider, indexCopier ), nrtIndexFactory );
-        DocumentQueue queue = new DocumentQueue( queueSize, tracker, executorService, statsProvider );
-        LocalIndexObserver localIndexObserver = new LocalIndexObserver( queue, statsProvider );
-        LuceneIndexProvider provider = new LuceneIndexProvider( tracker );
-
-        //        ExternalObserverBuilder builder = new ExternalObserverBuilder(queue, tracker, statsProvider,
-//            executorService, queueSize);
-//        Observer observer = builder.build();
-//        builder.getBackgroundObserver();
-
-        LuceneIndexEditorProvider editorProvider = //
-            new LuceneIndexEditorProvider( null, tracker, //
-                                           new ExtractedTextCache( 0, 0 ), //
-                                           null, mountInfoProvider );
-        editorProvider.setIndexingQueue( queue );
-
-        log.info( "Oak: {} with nodeStore {}", oak, nodeStore );
-        Jcr jcr = new Jcr( oak ).with( editorProvider ) //
-            .with( (Observer) provider ) //
-            .with( localIndexObserver )
-            // .with(observer)
-            .with( (QueryIndexProvider) provider ); //
-            //.withAsyncIndexing( "async", 5 );
-        StopWatch stopWatch = new StopWatch();
-        stopWatch.start();
-        Repository r = jcr.createRepository();
-        stopWatch.stop();
-        log.info( "time to create jcr repository: {} ms", stopWatch.getTime() );
-//        try
-//        {
-//            Thread.currentThread().sleep( 1000 );
-//        }
-//        catch ( InterruptedException e )
-//        {
-//            log.error( e.getMessage(), e );
-//        }
-        return r;
-
-
-    }
-
-    public void close()
-    {
-        if ( fileStore != null )
-        {
-            fileStore.close();
-        }
-        if (executorService != null)
-        {
-            executorService.shutdownNow();
-        }
-    }
-
-    public StoreType getStoreType()
-    {
-        return storeType;
-    }
-
-    public void setStoreType( StoreType storeType )
-    {
-        this.storeType = storeType;
-    }
-
-    public Path getRepositoryPath()
-    {
-        return repositoryPath;
-    }
-
-    public void setRepositoryPath( Path repositoryPath )
-    {
-        this.repositoryPath = repositoryPath;
-    }
-
-    public void setRepositoryPath( String repositoryPath )
-    {
-        this.repositoryPath = Paths.get( repositoryPath );
-        if ( !Files.exists( this.repositoryPath ) )
-        {
-            try
-            {
-                Files.createDirectories( this.repositoryPath );
-            }
-            catch ( IOException e )
-            {
-                log.error( e.getMessage(), e );
-                throw new IllegalArgumentException( "cannot create directory:" + repositoryPath, e );
-            }
-        }
-    }
-
-    private void createExecutor()
-    {
-        if (executorService ==null )
-        {
-            executorService = Executors.newCachedThreadPool();
-        }
-
-//
-//        ThreadPoolExecutor executor =
-//            new ThreadPoolExecutor( 0, 5, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),
-//                                    new ThreadFactory()
-//                                    {
-//                                        private final AtomicInteger counter = new AtomicInteger();
-//
-//                                        private final Thread.UncaughtExceptionHandler handler =
-//                                            new Thread.UncaughtExceptionHandler()
-//                                            {
-//                                                @Override
-//                                                public void uncaughtException( Thread t, Throwable e )
-//                                                {
-//                                                    log.warn( "Error occurred in asynchronous processing ", e );
-//                                                }
-//                                            };
-//
-//                                        @Override
-//                                        public Thread newThread( @Nonnull Runnable r )
-//                                        {
-//                                            Thread thread = new Thread( r, createName() );
-//                                            thread.setDaemon( true );
-//                                            thread.setPriority( Thread.MIN_PRIORITY );
-//                                            thread.setUncaughtExceptionHandler( handler );
-//                                            return thread;
-//                                        }
-//
-//                                        private String createName()
-//                                        {
-//                                            return "oak-lucene-" + counter.getAndIncrement();
-//                                        }
-//                                    } );
-//        executor.setKeepAliveTime( 1, TimeUnit.MINUTES );
-//        executor.allowCoreThreadTimeOut( true );
-//        return executor;
-    }
-
-}
diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/resources/org/apache/archiva/metadata/repository/jcr/jcr-schema.cnd b/archiva-modules/plugins/metadata-store-jcr/src/main/resources/org/apache/archiva/metadata/repository/jcr/jcr-schema.cnd
new file mode 100644
index 0000000..e63d5fd
--- /dev/null
+++ b/archiva-modules/plugins/metadata-store-jcr/src/main/resources/org/apache/archiva/metadata/repository/jcr/jcr-schema.cnd
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+<archiva = 'http://archiva.apache.org/jcr'>
+[archiva:base] abstract mixin
+  - id (string)
+  - jcr:lastModified (date)
+
+[archiva:repository] > archiva:base mixin
+ + content (archiva:content) primary
+
+[archiva:content] > archiva:base mixin
+ + * (archiva:namespace) multiple
+
+[archiva:namespace] > archiva:base mixin
+ - namespace (string)
+ + * (archiva:namespace) multiple
+ + * (archiva:project) multiple
+
+[archiva:project] > archiva:base mixin
+ - name (string)
+ + * (archiva:projectVersion) multiple
+
+[archiva:meta_scm] mixin
+  - scm.connection (string)
+  - scm.developerConnection (string)
+  - scm.url (uri)
+
+[archiva:meta_ci] mixin
+  - ci.system (string)
+  - ci.url (uri)
+
+[archiva:meta_issue] mixin
+ - issue.system (string)
+ - issue.url (uri)
+
+[archiva:meta_organization] mixin
+ - org.name (string)
+ - org.url (uri)
+
+[archiva:meta_license] > archiva:base mixin
+ - index (long)
+ - license.name (string)
+ - license.url (uri)
+
+[archiva:meta_mailinglist] > archiva:base
+ - index (long)
+ - name (string)
+ - archive (string)
+ - post (string)
+ - unsubscribe (string)
+ - subscribe (string)
+ - otherArchives (string) multiple
+
+[archiva:dependency] > archiva:base
+ - groupId (string)
+ - artifactId (string)
+ - version (string)
+ - type (string)
+ - classifier (string)
+ - scope (string)
+ - systemPath (string)
+ - optional (boolean)
+
+[archiva:dependencies] mixin
+ + * (archiva:dependency) multiple
+
+[archiva:checksum]
+ - type (string)
+ - value (string)
+
+[archiva:projectVersion] > archiva:base, archiva:meta_scm, archiva:meta_ci, archiva:meta_issue, archiva:meta_organization mixin
+ - name (string)
+ - description (string)
+ - url (uri)
+ - incomplete (boolean)
+ + * (archiva:artifact) multiple
+ + license (archiva:meta_license) multiple
+ + mailinglist (archiva:meta_mailinglist) multiple
+ + dependencies (archiva:dependencies)
+ + * (archiva:facet) multiple
+
+[archiva:artifact] > archiva:base mixin
+ - whenGathered (date)
+ - size (long)
+ - md5 (string)
+ - sha1 (string)
+ - version (string)
+ + checksum (archiva:checksum) multiple
+ + * (archiva:facet) multiple
+
+[archiva:facet] > archiva:base mixin
\ No newline at end of file
diff --git a/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java b/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java
index bb7b74a..171d6be 100644
--- a/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java
+++ b/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java
@@ -19,99 +19,164 @@ package org.apache.archiva.metadata.repository.jcr;
  * under the License.
  */
 
+import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.model.MetadataFacetFactory;
 import org.apache.archiva.metadata.repository.AbstractMetadataRepositoryTest;
 import org.apache.archiva.metadata.repository.DefaultMetadataResolver;
-import org.apache.archiva.metadata.repository.MetadataResolver;
+import org.apache.archiva.metadata.repository.MetadataRepositoryException;
+import org.apache.archiva.metadata.repository.MetadataSessionException;
+import org.apache.archiva.metadata.repository.RepositorySession;
 import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
-import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
-import org.springframework.context.ApplicationContext;
+import org.junit.Test;
 
-import javax.inject.Inject;
-import javax.jcr.Repository;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.Row;
+import javax.jcr.query.RowIterator;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.Collection;
 import java.util.Map;
 
+import static org.apache.archiva.metadata.repository.jcr.JcrConstants.PROJECT_VERSION_NODE_TYPE;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Using static sessionFactory and repository, because initialization is expensive if we rebuild the whole repository for
+ * each test.
+ */
 public class JcrMetadataRepositoryTest
     extends AbstractMetadataRepositoryTest
 {
 
-    @Inject
-    private ApplicationContext applicationContext;
+    private static JcrRepositorySessionFactory sessionFactory;
+    private static JcrMetadataRepository repository;
 
-    private static Repository jcrRepository;
+    @Override
+    public JcrMetadataRepository getRepository( )
+    {
+        return repository;
+    }
+
+    @Override
+    public JcrRepositorySessionFactory getSessionFactory( )
+    {
+        return sessionFactory;
+    }
 
     @BeforeClass
-    public static void setupSpec() throws IOException, InvalidFileStoreVersionException
+    public static void setupSpec( ) throws IOException, InvalidFileStoreVersionException
     {
         Path directory = Paths.get( "target/test-repositories" );
-        if (Files.exists(directory) )
+        if ( Files.exists( directory ) )
         {
             org.apache.archiva.common.utils.FileUtils.deleteDirectory( directory );
         }
-        RepositoryFactory factory = new RepositoryFactory();
-        factory.setRepositoryPath( directory.toString());
-        jcrRepository = factory.createRepository();
+
+        Map<String, MetadataFacetFactory> factories = createTestMetadataFacetFactories( );
+        JcrRepositorySessionFactory jcrSessionFactory = new JcrRepositorySessionFactory( );
+        jcrSessionFactory.setMetadataResolver( new DefaultMetadataResolver( ) );
+        jcrSessionFactory.setMetadataFacetFactories( factories );
+
+        jcrSessionFactory.open( );
+        sessionFactory = jcrSessionFactory;
+        repository = jcrSessionFactory.getMetadataRepository( );
+
     }
 
     @Before
-    @Override
-    public void setUp()
-        throws Exception
+    public void setup() throws MetadataRepositoryException, RepositoryException, MetadataSessionException
     {
-        super.setUp();
-
-
-        Map<String, MetadataFacetFactory> factories = createTestMetadataFacetFactories();
-
-//        // TODO: probably don't need to use Spring for this
-//        jcrMetadataRepository = new JcrMetadataRepository( factories, jcrRepository );
-//
-//        try
-//        {
-//            Session session = jcrMetadataRepository.login();
-//
-//            // set up namespaces, etc.
-//            JcrMetadataRepository.initializeNodeTypes( session );
-//
-//            // removing content is faster than deleting and re-copying the files from target/jcr
-//            session.getRootNode().getNode( "repositories" ).remove();
-//            session.save();
-//        }
-//        catch ( RepositoryException e )
-//        {
-//            // ignore
-//        }
-
-        // this.repository = jcrMetadataRepository;
-        JcrRepositorySessionFactory jcrSessionFactory = new JcrRepositorySessionFactory();
-        jcrSessionFactory.setMetadataResolver(new DefaultMetadataResolver());
-        jcrSessionFactory.setMetadataFacetFactories(factories);
-
-        jcrSessionFactory.open();
-        this.sessionFactory = jcrSessionFactory;
-        this.repository = jcrSessionFactory.getMetadataRepository();
+        try( JcrRepositorySession session = (JcrRepositorySession) getSessionFactory().createSession() ) {
+            Session jcrSession = session.getJcrSession( );
+            if (jcrSession.itemExists( "/repositories/test" ))
+            {
+                jcrSession.removeItem( "/repositories/test" );
+                session.save( );
+            }
+        }
+    }
 
+    @AfterClass
+    public static void stopSpec( )
+        throws Exception
+    {
+        if ( repository != null )
+        {
+            try
+            {
+                repository.close( );
+            }
+            catch ( Throwable e )
+            {
+                //
+            }
+        }
+        if ( sessionFactory != null )
+        {
+            try
+            {
+                sessionFactory.close( );
+            }
+            catch ( Throwable e )
+            {
+                //
+            }
+        }
     }
 
 
-    @After
-    @Override
-    public void tearDown()
+    @Test
+    public void testSearchArtifactsByKey( )
         throws Exception
     {
-        repository.close();
-        sessionFactory.close();
+        try ( RepositorySession session = sessionFactory.createSession( ) )
+        {
+            createArtifactWithData( session );
+        }
+
+
+        tryAssert( ( ) -> {
+            try ( RepositorySession session = sessionFactory.createSession( ) )
+            {
+                session.refreshAndDiscard( );
+                Session jcrSession = ( (JcrRepositorySession) session ).getJcrSession( );
+                assertThat(jcrSession.propertyExists( "/repositories/test/content/mytest/myproject/1.0/url" )).isTrue();
+
+                Collection<ArtifactMetadata> artifactsByProperty = repository.searchArtifacts( session, TEST_REPO_ID, "url", TEST_URL, false );
+                assertThat( artifactsByProperty ).isNotNull( ).isNotEmpty( );
+            }
+        } );
 
-        super.tearDown();
     }
 
 
+    @Test
+    public void testSearchArtifactsByKeyExact()
+        throws Exception {
+        try (RepositorySession session = sessionFactory.createSession())
+        {
+            createArtifactWithData( session );
+        }
+        try (RepositorySession session = sessionFactory.createSession())
+        {
+            session.refreshAndDiscard();
+            tryAssert(() -> {
+                Session jcrSession = ( (JcrRepositorySession) session ).getJcrSession( );
+                assertThat(jcrSession.propertyExists( "/repositories/test/content/mytest/myproject/1.0/url" )).isTrue();
+                Collection<ArtifactMetadata> artifactsByProperty = repository.searchArtifacts( session, TEST_REPO_ID, "url", TEST_URL, true);
+                assertThat(artifactsByProperty).describedAs( "Artifact search by url=%s must give a result.", TEST_URL ).isNotNull().isNotEmpty();
+                artifactsByProperty = repository.searchArtifacts( session, TEST_REPO_ID, "org.name", "pache", true );
+                assertThat( artifactsByProperty ).describedAs( "Artifact search by text org.name='pache' must be empty" ).isNotNull( ).isEmpty( );
+            } );
+        }
+    }
 }
diff --git a/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java b/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java
index e123284..6fe7da2 100644
--- a/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java
+++ b/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java
@@ -22,26 +22,25 @@ package org.apache.archiva.metadata.repository.stats;
 import junit.framework.TestCase;
 import org.apache.archiva.metadata.model.MetadataFacetFactory;
 import org.apache.archiva.metadata.repository.AbstractMetadataRepositoryTest;
+import org.apache.archiva.metadata.repository.DefaultMetadataResolver;
+import org.apache.archiva.metadata.repository.MetadataRepositoryException;
 import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.RepositorySessionFactory;
 import org.apache.archiva.metadata.repository.jcr.JcrMetadataRepository;
 import org.apache.archiva.metadata.repository.jcr.JcrRepositorySessionFactory;
-import org.apache.archiva.metadata.repository.jcr.RepositoryFactory;
+import org.apache.archiva.metadata.repository.jcr.JcrRepositorySession;
 import org.apache.archiva.metadata.repository.stats.model.DefaultRepositoryStatistics;
 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 import org.apache.jackrabbit.commons.JcrUtils;
 import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
 import org.junit.After;
-import org.junit.Before;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.context.ApplicationContext;
 import org.springframework.test.context.ContextConfiguration;
 
-import javax.inject.Inject;
 import javax.jcr.ImportUUIDBehavior;
 import javax.jcr.Node;
 import javax.jcr.Repository;
@@ -69,15 +68,8 @@ public class JcrRepositoryStatisticsGatheringTest
 
     private static final String TEST_REPO = "test-repo";
 
-    JcrMetadataRepository repository;
-    JcrRepositorySessionFactory sessionFactory;
-
-
-    @Inject
-    private RepositorySessionFactory repositorySessionFactory;
-
-    @Inject
-    private ApplicationContext applicationContext;
+    static JcrMetadataRepository repository;
+    static JcrRepositorySessionFactory sessionFactory;
 
     Session jcrSession;
 
@@ -94,45 +86,38 @@ public class JcrRepositoryStatisticsGatheringTest
         {
             org.apache.archiva.common.utils.FileUtils.deleteDirectory( directory );
         }
-        RepositoryFactory factory = new RepositoryFactory();
-        factory.setRepositoryPath( directory.toString() );
-        factory.setStoreType( RepositoryFactory.StoreType.IN_MEMORY_TYPE );
-        jcrRepository = factory.createRepository();
-    }
+        directory = Paths.get( "target/jcr" );
+        if (Files.exists( directory )) {
+            org.apache.archiva.common.utils.FileUtils.deleteDirectory( directory );
+        }
 
+        Map<String, MetadataFacetFactory> factories = AbstractMetadataRepositoryTest.createTestMetadataFacetFactories();
 
-    @Before
-    public void setUp()
-        throws Exception
-    {
 
-        Map<String, MetadataFacetFactory> factories = AbstractMetadataRepositoryTest.createTestMetadataFacetFactories();
+        JcrRepositorySessionFactory jcrSessionFactory = new JcrRepositorySessionFactory();
+        jcrSessionFactory.setMetadataResolver(new DefaultMetadataResolver());
+        jcrSessionFactory.setMetadataFacetFactories(factories);
 
-        assertNotNull( jcrRepository );
-        // TODO: probably don't need to use Spring for this
-        JcrMetadataRepository jcrMetadataRepository = new JcrMetadataRepository( factories, jcrRepository );
+        jcrSessionFactory.open();
+        sessionFactory = jcrSessionFactory;
+        repository = jcrSessionFactory.getMetadataRepository();
+    }
 
-        jcrSession = jcrMetadataRepository.login();
 
+    @AfterClass
+    public static void stopSpec() {
         try
         {
-            jcrSession = jcrMetadataRepository.login();
-
-            // set up namespaces, etc.
-            JcrMetadataRepository.initializeNodeTypes(jcrSession);
-
-            // removing content is faster than deleting and re-copying the files from target/jcr
-            jcrSession.getRootNode().getNode( "repositories" ).remove();
+            repository.close();
         }
-        catch ( RepositoryException e )
+        catch ( MetadataRepositoryException e )
         {
-            // ignore
+            e.printStackTrace( );
         }
-
-        this.repository = jcrMetadataRepository;
-        this.sessionFactory = new JcrRepositorySessionFactory();
+        sessionFactory.close();
     }
 
+
     private static void registerMixinNodeType( NodeTypeManager nodeTypeManager, String type )
         throws RepositoryException
     {
@@ -148,8 +133,22 @@ public class JcrRepositoryStatisticsGatheringTest
     {
         if ( repository != null )
         {
-            repository.close();
+            try
+            {
+                repository.close( );
+            } catch (Throwable e) {
+                //
+            }
+        }
+        if (sessionFactory!=null) {
+            try
+            {
+                sessionFactory.close( );
+            } catch (Throwable e) {
+                //
+            }
         }
+        super.tearDown();
 
     }
 
@@ -163,8 +162,8 @@ public class JcrRepositoryStatisticsGatheringTest
             cal.add(Calendar.HOUR, -1);
             Date startTime = cal.getTime();
 
-            loadContentIntoRepo(TEST_REPO);
-            loadContentIntoRepo("another-repo");
+            loadContentIntoRepo(repSession, TEST_REPO);
+            loadContentIntoRepo( repSession, "another-repo");
 
             DefaultRepositoryStatistics testedStatistics = new DefaultRepositoryStatistics();
             testedStatistics.setNewFileCount(NEW_FILE_COUNT);
@@ -214,17 +213,18 @@ public class JcrRepositoryStatisticsGatheringTest
         }
     }
 
-    private void loadContentIntoRepo( String repoId )
-        throws RepositoryException, IOException
+    private void loadContentIntoRepo( RepositorySession repoSession, String repoId )
+        throws RepositoryException, IOException, MetadataRepositoryException
     {
-        Node n = JcrUtils.getOrAddNode( jcrSession.getRootNode(), "repositories" );
+            jcrSession = ((JcrRepositorySession) repoSession).getJcrSession();
+        Node n = JcrUtils.getOrAddNode( jcrSession.getRootNode( ), "repositories" );
         n = JcrUtils.getOrAddNode( n, repoId );
         n = JcrUtils.getOrAddNode( n, "content" );
         n = JcrUtils.getOrAddNode( n, "org" );
         n = JcrUtils.getOrAddNode( n, "apache" );
 
-        GZIPInputStream inputStream = new GZIPInputStream( getClass().getResourceAsStream( "/artifacts.xml.gz" ) );
-        jcrSession.importXML( n.getPath(), inputStream, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW );
-        jcrSession.save();
+        GZIPInputStream inputStream = new GZIPInputStream( getClass( ).getResourceAsStream( "/artifacts.xml.gz" ) );
+        jcrSession.importXML( n.getPath( ), inputStream, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW );
+        jcrSession.save( );
     }
 }
diff --git a/archiva-modules/plugins/metadata-store-jcr/src/test/resources/log4j2-test.xml b/archiva-modules/plugins/metadata-store-jcr/src/test/resources/log4j2-test.xml
index a2eb7ab..b991147 100644
--- a/archiva-modules/plugins/metadata-store-jcr/src/test/resources/log4j2-test.xml
+++ b/archiva-modules/plugins/metadata-store-jcr/src/test/resources/log4j2-test.xml
@@ -29,8 +29,10 @@
 
   </appenders>
   <loggers>
-    <logger name="org.apache.jackrabbit" level="info"/>
-    <logger name="org.apache.jackrabbit.oak" level="debug"/>
+    <logger name="org.apache.jackrabbit" level="trace"/>
+    <logger name="org.apache.jackrabbit.oak.segment" level="info" />
+    <logger name="org.apache.jackrabbit.oak.cache.CacheLIRS" level="info"/>
+    <logger name="org.apache.archiva.metadata" level="debug" />
     <root level="info" includeLocation="true">
       <appender-ref ref="console"/>
     </root>