Skip to content

Commit

Permalink
Correct JNDI name for AuditConnectionFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedFarouk-HMCTS authored and amckenzie committed Aug 11, 2020
1 parent 1705a60 commit 5d86ac8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ConnectionFactoryProducer {
private final Map<String, ConnectionFactory> connectionFactories = new ConcurrentHashMap<>();

@Produces
public ConnectionFactory getConnectionFactory(final String jndiName) {
public ConnectionFactory getConnectionFactory() {
return connectionFactories.computeIfAbsent(DEFAULT_CONNECTION_FACTORY_JNDI_PATTERN, this::connectionFactory);
}

Expand All @@ -56,7 +56,7 @@ private ConnectionFactory connectionFactory(final String jndiName) {
.lookup(jndiName);
return connectionFactory;
} catch (final NamingException e) {
throw new JdbcRepositoryException(format("Failed to lookup ConnectionFactory using jndi name '%s'", jndiName), e);
throw new JndiException(format("Failed to lookup ConnectionFactory using jndi name '%s'", jndiName), e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package uk.gov.justice.services.messaging.jms;

/**
* Exception thrown when there's error accessing database
*/
public class JndiException extends RuntimeException {

private static final long serialVersionUID = 5934757852541630246L;

public JndiException(String message) {
super(message);
}

public JndiException(final String message, final Throwable cause) {
super(message, cause);
}
public JndiException(final Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class ConnectionFactoryProducerTest {
@Test
public void shouldCreateDefaultConnectionFactoryWhenNoConnectionFactoryNameQualifierSet() throws Exception {
when(initialContext.lookup(DEFAULT_CONNECTION_FACTORY_JNDI_PATTERN)).thenReturn(defaultConnectionFactory);
assertThat(connectionFactoryProducer.getConnectionFactory(DEFAULT_CONNECTION_FACTORY_JNDI_PATTERN), is(defaultConnectionFactory));
assertThat(connectionFactoryProducer.getConnectionFactory(), is(defaultConnectionFactory));
}

@Test
Expand Down

0 comments on commit 5d86ac8

Please sign in to comment.