TransactionAwareContextSourceProxy extends DelegatingBaseLdapPathContextSourceSupport implements ContextSource { @Override public DirContext getReadWriteContext() { DirContextHolder contextHolder = (DirContextHolder) TransactionSynchronizationManager .getResource(target); DirContext ctx = null; if (contextHolder != null) { ctx = contextHolder.getCtx(); } if (ctx == null) { ctx = target.getReadWriteContext(); if (contextHolder != null) { contextHolder.setCtx(ctx); } } return getTransactionAwareDirContextProxy(ctx, target); } TransactionAwareContextSourceProxy(ContextSource target); @Override ContextSource getTarget(); @Override DirContext getReadOnlyContext(); @Override DirContext getReadWriteContext(); @Override DirContext getContext(String principal, String credentials);  }
@Test public void testGetReadWriteContext_LdapContext() { when(contextSourceMock.getReadWriteContext()).thenReturn(ldapContextMock); DirContext result = tested.getReadWriteContext(); assertThat(result).isNotNull(); assertThat(result instanceof LdapContext).isTrue(); assertThat(result instanceof DirContextProxy).isTrue(); }
@Test public void testGetReadWriteContext_DirContext() { when(contextSourceMock.getReadWriteContext()).thenReturn(dirContextMock); DirContext result = tested.getReadWriteContext(); assertThat(result).as("Result should not be null").isNotNull(); assertThat(result instanceof DirContext).isTrue(); assertThat(result instanceof LdapContext).isFalse(); assertThat(result instanceof DirContextProxy).isTrue(); }