This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pradeep Thomas
committed
Oct 11, 2016
1 parent
60b04bb
commit 307a5d3
Showing
9 changed files
with
611 additions
and
140 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/main/java/uk/gov/justice/artemis/EmbeddedArtemisInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package uk.gov.justice.artemis; | ||
|
||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
import org.apache.activemq.artemis.core.security.CheckType; | ||
import org.apache.activemq.artemis.core.security.Role; | ||
import org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS; | ||
import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class EmbeddedArtemisInitializer { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(EmbeddedArtemisInitializer.class); | ||
|
||
private EmbeddedArtemisInitializer() {} | ||
|
||
public static EmbeddedJMS initialize(final EmbeddedJMS jmsServer){ | ||
jmsServer.setConfigResourcePath("broker.xml"); | ||
// override the security manager to cater for multiple test configurations | ||
// users and passwords | ||
jmsServer.setSecurityManager(getSecurityManager()); | ||
return jmsServer; | ||
} | ||
|
||
public static void checkLoggers() { | ||
// ensure that the loggers are in the classpath and loaded | ||
org.apache.activemq.artemis.core.server.ActiveMQServerLogger.class.getCanonicalName(); | ||
org.apache.activemq.artemis.core.server.ActiveMQServerLogger_$logger.class | ||
.getCanonicalName(); | ||
} | ||
|
||
public static ActiveMQSecurityManager getSecurityManager() { | ||
|
||
return new ActiveMQSecurityManager() { | ||
@Override | ||
public boolean validateUser(final String user, final String password) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean validateUserAndRole(final String user, final String password, | ||
final Set<Role> roles, final CheckType checkType) { | ||
return true; | ||
} | ||
}; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/uk/gov/justice/artemis/EmbeddedJMSServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package uk.gov.justice.artemis; | ||
|
||
import org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS; | ||
|
||
public class EmbeddedJMSServer { | ||
|
||
private EmbeddedJMS jmsServer; | ||
|
||
private volatile boolean initialised; | ||
|
||
public void start() throws Exception { | ||
|
||
if (initialised) { | ||
return; | ||
} | ||
|
||
jmsServer.start(); | ||
|
||
initialised = true; | ||
} | ||
|
||
public boolean stop() throws Exception { | ||
|
||
if (initialised) { | ||
|
||
jmsServer.stop(); | ||
|
||
initialised = false; | ||
} | ||
|
||
return initialised; | ||
} | ||
|
||
public EmbeddedJMS getJmsServer() { | ||
return jmsServer; | ||
} | ||
|
||
public EmbeddedJMSServer setJmsServer(EmbeddedJMS jmsServer) { | ||
this.jmsServer = jmsServer; | ||
return this; | ||
} | ||
|
||
public boolean isInitialised() { | ||
return initialised; | ||
} | ||
|
||
public void setInitialised(boolean initialised) { | ||
this.initialised = initialised; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package uk.gov.justice.artemis; | ||
|
||
import java.util.concurrent.Semaphore; | ||
|
||
/** | ||
* | ||
* Permit for starting and stopping the Artemis Server | ||
* | ||
*/ | ||
public class ServerPermit implements AutoCloseable { | ||
|
||
private Semaphore semaphore; | ||
|
||
public ServerPermit() { | ||
semaphore = new Semaphore(1, true); | ||
} | ||
|
||
public ServerPermit acquire() throws InterruptedException { | ||
semaphore.acquire(); | ||
return this; | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
semaphore.release(); | ||
} | ||
|
||
public Semaphore getSemaphore() { | ||
return semaphore; | ||
} | ||
|
||
public ServerPermit setSemaphore(Semaphore semaphore) { | ||
this.semaphore = semaphore; | ||
return this; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/test/java/uk/gov/justice/artemis/EmbeddedArtemisInitializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package uk.gov.justice.artemis; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.doThrow; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Modifier; | ||
import java.util.Collections; | ||
import java.util.function.Supplier; | ||
|
||
import org.apache.activemq.artemis.core.security.CheckType; | ||
import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager; | ||
import org.junit.Test; | ||
|
||
public class EmbeddedArtemisInitializerTest { | ||
|
||
|
||
@Test | ||
public void shouldTestActiveMQSecurityManagerAlwaysTrue() { | ||
ActiveMQSecurityManager activeMQSecurityManager = | ||
EmbeddedArtemisInitializer.getSecurityManager(); | ||
assertNotNull(activeMQSecurityManager); | ||
assertTrue(activeMQSecurityManager.validateUser("user", "password")); | ||
assertTrue(activeMQSecurityManager.validateUserAndRole("user", "password", | ||
Collections.emptySet(), CheckType.SEND)); | ||
} | ||
|
||
@Test | ||
public void shouldTestPrivateConstructor() | ||
throws InstantiationException, IllegalAccessException, IllegalArgumentException, | ||
InvocationTargetException, NoSuchMethodException, SecurityException { | ||
Constructor<EmbeddedArtemisInitializer> constructor = | ||
EmbeddedArtemisInitializer.class.getDeclaredConstructor(); | ||
assertTrue(Modifier.isPrivate(constructor.getModifiers())); | ||
constructor.setAccessible(true); | ||
// to improve code coverage | ||
constructor.newInstance(); | ||
} | ||
|
||
@Test | ||
public void shouldTestLoggersClassesAreAvailable(){ | ||
EmbeddedArtemisInitializer.checkLoggers(); | ||
} | ||
|
||
} |
Oops, something went wrong.