Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.bitrepository.protocol;

import org.junit.platform.suite.api.ExcludeTags;
import org.junit.platform.suite.api.IncludeTags;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.Suite;
import org.junit.jupiter.api.extension.ExtendWith;
import org.bitrepository.protocol.GlobalSuiteExtension;

/**
* BitrepositoryTestSuite is a JUnit 5 suite class that groups and configures multiple test classes
* for the BitRepository project. This suite uses JUnit 5 annotations to select test classes, packages,
* and tags, and extend the suite with custom extensions.
*
* <p>JUnit 5 Annotations Used:</p>
* <ul>
* <li>{@link Suite}: Indicates that this class is a JUnit 5 suite. It groups multiple test classes
* into a single test suite.</li>
* <li>{@link SelectClasses}: Specifies the test classes to be included in the suite. The value is an array
* of class references to the test classes.</li>
* <li>{@link SelectPackages}: Specifies the test packages to be included in the suite. The value is an array
* of package names.</li>
* <li>{@link IncludeTags}: Specifies the tags to include in the suite. The value is an array of tag names.</li>
* <li>{@link ExcludeTags}: Specifies the tags to exclude from the suite. The value is an array of tag names.</li>
* <li>{@link ExtendWith}: Specifies the extensions to be applied to the suite. The value is an array of
* extension classes.</li>
* </ul>
*
* <p>Options in a JUnit 5 Suite:</p>
* <ul>
* <li><strong>Selecting Test Classes:</strong> Use the {@link SelectClasses} annotation to specify the test
* classes to be included in the suite. The value is an array of class references to the test classes.</li>
* <li><strong>Selecting Test Packages:</strong> Use the {@link SelectPackages} annotation to specify the test
* packages to be included in the suite. The value is an array of package names.</li>
* <li><strong>Selecting Tests by Tag:</strong> Use the {@link IncludeTags} and {@link ExcludeTags} annotations
* to specify the tags to include or exclude in the suite. The value is an array of tag names.</li>
* <li><strong>Extending the Suite:</strong> Use the {@link ExtendWith} annotation to specify custom extensions
* to be applied to the suite. The value is an array of extension classes.</li>
* </ul>
*
* <p>Example Usage:</p>
* <pre>
* {@code
* @Suite
* @SelectClasses({IntegrationTest.class}) // List your test classes here
* @SelectPackages("org.bitrepository.protocol") // List your test packages here
* @IncludeTags("integration") // List your include tags here
* @ExcludeTags("slow") // List your exclude tags here
* @ExtendWith(GlobalSuiteExtension.class)
* public class BitrepositoryTestSuite {
* // No need for methods here; this just groups and extends
* }
* }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does doubling this line do something good?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed them and the public class BitrepositoryTestSutie above

* </pre>
*/
@Suite
@SelectClasses({IntegrationTest.class}) // List your test classes here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure what the effect of including an abstract TestNG test class as a class in a JUnit test suite is?

@ExtendWith(GlobalSuiteExtension.class)
public class BitrepositoryTestSuite {
// No need for methods here; this just groups and extends
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
package org.bitrepository.protocol;

import org.bitrepository.common.settings.Settings;
import org.bitrepository.common.settings.TestSettingsProvider;
import org.bitrepository.common.utils.SettingsUtils;
import org.bitrepository.common.utils.TestFileHelper;
import org.bitrepository.protocol.bus.LocalActiveMQBroker;
import org.bitrepository.protocol.bus.MessageReceiver;
import org.bitrepository.protocol.fileexchange.HttpServerConfiguration;
import org.bitrepository.protocol.http.EmbeddedHttpServer;
import org.bitrepository.protocol.messagebus.MessageBus;
import org.bitrepository.protocol.messagebus.MessageBusManager;
import org.bitrepository.protocol.messagebus.SimpleMessageBus;
import org.bitrepository.protocol.security.DummySecurityManager;
import org.bitrepository.protocol.security.SecurityManager;
import org.jaccept.TestEventManager;
import org.junit.jupiter.api.extension.*;

import javax.jms.JMSException;
import java.net.MalformedURLException;
import java.net.URL;

public class GlobalSuiteExtension implements BeforeAllCallback, AfterAllCallback {

private static boolean initialized = false;
protected static TestEventManager testEventManager = TestEventManager.getInstance();
public static LocalActiveMQBroker broker;
public static EmbeddedHttpServer server;
public static HttpServerConfiguration httpServerConfiguration;
public static MessageBus messageBus;
private MessageReceiverManager receiverManager;
protected static String alarmDestinationID;
protected static MessageReceiver alarmReceiver;
protected static SecurityManager securityManager;
protected static Settings settingsForCUT;
protected static Settings settingsForTestClient;
protected static String collectionID;
protected String NON_DEFAULT_FILE_ID;
protected static String DEFAULT_FILE_ID;
protected static URL DEFAULT_FILE_URL;
protected static String DEFAULT_DOWNLOAD_FILE_ADDRESS;
protected static String DEFAULT_UPLOAD_FILE_ADDRESS;
protected String DEFAULT_AUDIT_INFORMATION;
protected String testMethodName;

@Override
public void beforeAll(ExtensionContext context) {
if (!initialized) {
initialized = true;
settingsForCUT = loadSettings(getComponentID());
settingsForTestClient = loadSettings("TestSuiteInitialiser");
makeUserSpecificSettings(settingsForCUT);
makeUserSpecificSettings(settingsForTestClient);
httpServerConfiguration = new HttpServerConfiguration(settingsForTestClient.getReferenceSettings().getFileExchangeSettings());
collectionID = settingsForTestClient.getCollections().get(0).getID();

securityManager = createSecurityManager();
DEFAULT_FILE_ID = "DefaultFile";
try {
DEFAULT_FILE_URL = httpServerConfiguration.getURL(TestFileHelper.DEFAULT_FILE_ID);
DEFAULT_DOWNLOAD_FILE_ADDRESS = DEFAULT_FILE_URL.toExternalForm();
DEFAULT_UPLOAD_FILE_ADDRESS = DEFAULT_FILE_URL.toExternalForm() + "-" + DEFAULT_FILE_ID;
} catch (MalformedURLException e) {
throw new RuntimeException("Never happens", e);
}
}
}

@Override
public void afterAll(ExtensionContext context) {
if (initialized) {
teardownMessageBus();
teardownHttpServer();
}
}

/**
* May be extended by subclasses needing to have their receivers managed. Remember to still call
* <code>super.registerReceivers()</code> when overriding
*/
protected void registerMessageReceivers() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is not used?

In the IntegrationTest class where you copied it from, it is called from beforeMethod(). Should this copy be called from somewhere too?

There are more unused methods in this class.

alarmReceiver = new MessageReceiver(settingsForCUT.getAlarmDestination(), testEventManager);
addReceiver(alarmReceiver);
}

protected void addReceiver(MessageReceiver receiver) {
receiverManager.addReceiver(receiver);
}
protected void initializeCUT() {}

/**
* Purges all messages from the receivers.
*/
protected void clearReceivers() {
receiverManager.clearMessagesInReceivers();
}

/**
* May be overridden by specific tests wishing to do stuff. Remember to call super if this is overridden.
*/
protected void shutdownCUT() {}

/**
* Initializes the settings. Will postfix the alarm and collection topics with '-${user.name}
*/
protected void setupSettings() {
settingsForCUT = loadSettings(getComponentID());
makeUserSpecificSettings(settingsForCUT);
SettingsUtils.initialize(settingsForCUT);

alarmDestinationID = settingsForCUT.getRepositorySettings().getProtocolSettings().getAlarmDestination();

settingsForTestClient = loadSettings(testMethodName);
makeUserSpecificSettings(settingsForTestClient);
}


protected Settings loadSettings(String componentID) {
return TestSettingsProvider.reloadSettings(componentID);
}

private void makeUserSpecificSettings(Settings settings) {
settings.getRepositorySettings().getProtocolSettings()
.setCollectionDestination(settings.getCollectionDestination() + getTopicPostfix());
settings.getRepositorySettings().getProtocolSettings().setAlarmDestination(settings.getAlarmDestination() + getTopicPostfix());
}

/**
* Indicated whether an embedded active MQ should be started and used
*/
public boolean useEmbeddedMessageBus() {
return System.getProperty("useEmbeddedMessageBus", "true").equals("true");
}

/**
* Indicated whether an embedded http server should be started and used
*/
public boolean useEmbeddedHttpServer() {
return System.getProperty("useEmbeddedHttpServer", "false").equals("true");
}

/**
* Hooks up the message bus.
*/
protected void setupMessageBus() {
if (useEmbeddedMessageBus()) {
if (messageBus == null) {
messageBus = new SimpleMessageBus();
}
}
}

/**
* Shutdown the message bus.
*/
private void teardownMessageBus() {
MessageBusManager.clear();
if (messageBus != null) {
try {
messageBus.close();
messageBus = null;
} catch (JMSException e) {
throw new RuntimeException(e);
}
}

if (broker != null) {
try {
broker.stop();
broker = null;
} catch (Exception e) {
// No reason to pollute the test output with this
}
}
}

/**
* Shutdown the embedded http server if any.
*/
protected void teardownHttpServer() {
if (useEmbeddedHttpServer()) {
server.stop();
}
}

/**
* Returns the postfix string to use when accessing user specific topics, which is the mechanism we use in the
* bit repository tests.
*
* @return The string to postfix all topix names with.
*/
protected String getTopicPostfix() {
return "-" + System.getProperty("user.name");
}

protected String getComponentID() {
return getClass().getSimpleName();
}

protected String createDate() {
return Long.toString(System.currentTimeMillis());
}

protected SecurityManager createSecurityManager() {
return new DummySecurityManager();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public abstract class IntegrationTest extends ExtendedTestCase {

@BeforeSuite(alwaysRun = true)
public void initializeSuite(ITestContext testContext) {
//
}

private void initializationMethod() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I read it correctly, you have moved the call to this method from "before suite" to "before class". Is this correct? Is it necessary?

settingsForCUT = loadSettings(getComponentID());
settingsForTestClient = loadSettings("TestSuiteInitialiser");
makeUserSpecificSettings(settingsForCUT);
Expand Down Expand Up @@ -114,6 +118,7 @@ protected void addReceiver(MessageReceiver receiver) {

@BeforeClass(alwaysRun = true)
public void initMessagebus() {
initializationMethod();
setupMessageBus();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
Expand All @@ -27,7 +27,9 @@
import org.bitrepository.protocol.ProtocolComponentFactory;
import org.bitrepository.protocol.activemq.ActiveMQMessageBus;
import org.bitrepository.protocol.message.ExampleMessageFactory;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;

import javax.jms.Message;
import javax.jms.MessageListener;
Expand All @@ -36,14 +38,7 @@
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

import static org.testng.Assert.assertEquals;

/**
* Runs the GeneralMessageBusTest using a LocalActiveMQBroker (if useEmbeddedMessageBus is true) and a suitable
* MessageBus based on settingsForTestClient. Regression tests utilized that uses JAccept to generate reports.
*/

public class ActiveMQMessageBusTest extends GeneralMessageBusTest {
public class ActiveMQMessageBusTest extends GeneralMessageBusTest { // Assuming it extends a base class

@Override
protected void setupMessageBus() {
Expand All @@ -53,10 +48,10 @@ protected void setupMessageBus() {
}
messageBus = new MessageBusWrapper(ProtocolComponentFactory.getInstance().getMessageBus(
settingsForTestClient, securityManager), testEventManager);

}

@Test(groups = {"regressiontest"})
@Test
@Tag("regressiontest")
public final void collectionFilterTest() throws Exception {
Copy link
Contributor

@ole-v-v ole-v-v Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry, this is not working. When I do mvn package, this test is not being run. And when I run this test class from within IntelliJ IDEA, the tests fail.

addDescription("Test that message bus filters identify requests to other collection, eg. ignores these.");
addStep("Send an identify request with a undefined 'Collection' header property, " +
Expand Down Expand Up @@ -90,7 +85,8 @@ public final void collectionFilterTest() throws Exception {
collectionReceiver.checkNoMessageIsReceived(IdentifyPillarsForDeleteFileRequest.class);
}

@Test(groups = {"regressiontest"})
@Test
@Tag("regressiontest")
public final void sendMessageToSpecificComponentTest() throws Exception {
addDescription("Test that message bus correct uses the 'to' header property to indicated that the message " +
"is meant for a specific component");
Expand All @@ -113,10 +109,11 @@ public void onMessage(Message message) {
messageToSend.setTo(receiverID);
messageBus.sendMessage(messageToSend);
Message receivedMessage = messageList.poll(3, TimeUnit.SECONDS);
assertEquals(receivedMessage.getStringProperty(ActiveMQMessageBus.MESSAGE_TO_KEY), receiverID);
Assertions.assertEquals(receivedMessage.getStringProperty(ActiveMQMessageBus.MESSAGE_TO_KEY), receiverID); // Assertion update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am not mistaken, TestNG and JUnit have the arguments to assertEquals() in opposite orders. JUnit: assertEquals(expected, actual). TestNG: assertEquals(actual, expected). If so, you need to swap the arguments when exchanging one for the other. My suggestion:

        Assertions.assertNotNull(receivedMessage);
        Assertions.assertEquals(receiverID, receivedMessage.getStringProperty(ActiveMQMessageBus.MESSAGE_TO_KEY));

The same argument swap applies everywhere, of course.

poll() may return null, so I added a check for that.

(I didn’t see the long-term value of the comment, so I left it out, but I may be missing something?)

}

@Test(groups = {"regressiontest"})
@Test
@Tag("regressiontest")
public final void toFilterTest() throws Exception {
addDescription("Test that message bus filters identify requests to other components, eg. ignores these.");
addStep("Send an identify request with a undefined 'To' header property, " +
Expand Down Expand Up @@ -174,4 +171,4 @@ public final void toFilterTest() throws Exception {
rawMessagebus.sendMessage(settingsForTestClient.getCollectionDestination(), rq);
collectionReceiver.waitForMessage(DeleteFileRequest.class);
}
}
}
Loading