package org.realityforge.replicant.server.ee;

import javax.annotation.Nonnull;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.transaction.TransactionSynchronizationRegistry;
import org.realityforge.guiceyloops.server.TestInitialContextFactory;
import org.realityforge.guiceyloops.server.TestTransactionSynchronizationRegistry;
import org.realityforge.replicant.server.ServerConstants;
import static org.testng.Assert.*;

public final class RegistryUtil
{
  private RegistryUtil()
  {
  }

  @Nonnull
  public static TransactionSynchronizationRegistry bind()
  {
    try
    {
      TestInitialContextFactory.reset();
      final Context context = TestInitialContextFactory.getContext().createSubcontext( "java:comp" );
      final TestTransactionSynchronizationRegistry registry = new TestTransactionSynchronizationRegistry();
      registry.putResource( ServerConstants.REPLICATION_INVOCATION_KEY, "Ignored" );
      context.bind( "TransactionSynchronizationRegistry", registry );
      return registry;
    }
    catch ( final NamingException e )
    {
      fail( "Unexpected exception", e );
      throw new IllegalStateException();
    }
  }
}

@@ -139,16 +139,55 @@
 eption;%0A
+import javax.naming.spi.NamingManager;%0A
 import j
@@ -637,24 +637,219 @@
   try%0A    %7B%0A
+      if ( !NamingManager.hasInitialContextFactoryBuilder() )%0A      %7B%0A        NamingManager.setInitialContextFactoryBuilder( environment -%3E e -%3E TestInitialContextFactory.getContext() );%0A      %7D%0A
       TestIn

Make sure naming tests work - even when eclipselink naming provider present