Skip to content
Merged
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
2 changes: 2 additions & 0 deletions bitrepository-core/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/activemq-data
/test-output
/bin
statistic-*

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
package org.bitrepository.common.utils;

import org.bitrepository.common.settings.Settings;
import org.bitrepository.settings.referencesettings.PillarIntegrityDetails;
import org.bitrepository.settings.referencesettings.PillarType;
import org.bitrepository.settings.repositorysettings.Collection;

import java.math.BigInteger;
Expand Down Expand Up @@ -98,6 +100,42 @@ public static String getCollectionName(String collectionID) {
return name;
}

/**
* Get the hostname for the given pillarID from the ReferenceSettings.
*
* @param pillarID The pillarID for which the hostname is wanted.
* @return Returns the hostname for the given pillar ID.
*/
public static String getHostname(String pillarID) {
PillarIntegrityDetails details = settings.getReferenceSettings().getIntegrityServiceSettings().getPillarIntegrityDetails();
if (details != null) {
for (PillarIntegrityDetails.PillarDetails d : details.getPillarDetails()) {
if (d.getPillarID().equals(pillarID)) {
return d.getPillarHostname();
}
}
}
return null;
}

/**
* Get the {@link PillarType} for the given Pillar ID.
*
* @param pillarID The pillar ID for which the {@link PillarType} is wanted.
* @return Returns the {@link PillarType} for the given pillar ID.
*/
public static PillarType getPillarType(String pillarID) {
PillarIntegrityDetails details = settings.getReferenceSettings().getIntegrityServiceSettings().getPillarIntegrityDetails();
if (details != null) {
for (PillarIntegrityDetails.PillarDetails d : details.getPillarDetails()) {
if (d.getPillarID().equals(pillarID)) {
return d.getPillarType();
}
}
}
return null;
}

/**
* Get the name of the repository
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,14 @@
Directory must be write and readable by integrity service.
-->
<IntegrityReportsDir>/var/integrity-reports/</IntegrityReportsDir>

<PillarIntegrityDetails>
<PillarDetails>
<PillarID>Pillar1</PillarID>
<PillarHostname>test@kb.dk</PillarHostname>
<PillarType>FILE</PillarType>
</PillarDetails>
</PillarIntegrityDetails>
</IntegrityServiceSettings>

<!-- Settings for the Monitoring / Status service -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/*
* #%L
* Bitrepository Protocol
*
*
* $Id$
* $HeadURL$
* %%
* Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* 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
*
* 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>.
* #L%
Expand All @@ -28,28 +28,27 @@
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.Arrays;
import java.util.List;

public class SettingsLoaderTest extends ExtendedTestCase {
private static final String PATH_TO_SETTINGS = "settings/xml/bitrepository-devel";
private static final String PATH_TO_EXAMPLE_SETTINGS = "examples/settings";

@Test(groups = { "regressiontest" })
public void testDevelopmentCollectionSettingsLoading() throws Exception {
SettingsProvider settingsLoader =
@Test(groups = {"regressiontest"})
public void testDevelopmentCollectionSettingsLoading() {
SettingsProvider settingsLoader =
new SettingsProvider(new XMLFileSettingsLoader(PATH_TO_SETTINGS), getClass().getSimpleName());

Settings settings = settingsLoader.getSettings();
List<String> expectedPillarIDs = Arrays.asList(new String[] {"Pillar1", "Pillar2"});
List<String> expectedPillarIDs = List.of("Pillar1", "Pillar2");
Assert.assertEquals(
settings.getRepositorySettings().getCollections().getCollection().get(0).getPillarIDs().getPillarID(),
expectedPillarIDs);
}
@Test(groups = { "regressiontest" })
public void testExampleSettingsLoading() throws Exception {
SettingsProvider settingsLoader =

@Test(groups = {"regressiontest"})
public void testExampleSettingsLoading() {
SettingsProvider settingsLoader =
new SettingsProvider(new XMLFileSettingsLoader(PATH_TO_EXAMPLE_SETTINGS), getClass().getSimpleName());

settingsLoader.getSettings();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/*
* #%L
* Bitrepository Common
*
*
* $Id$
* $HeadURL$
* %%
* Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* 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
*
* 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>.
* #L%
Expand Down Expand Up @@ -55,36 +55,27 @@
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;

/**
* Contains the generic parts for integration testing.
*/
public abstract class IntegrationTest extends ExtendedTestCase {
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;

/** Settings for the Component-Under-Test */
protected static Settings settingsForCUT;
/** Settings for the Test components */
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_AUDITINFORMATION;
protected String DEFAULT_AUDIT_INFORMATION;

protected String testMethodName;

Expand All @@ -94,8 +85,7 @@ public void initializeSuite(ITestContext testContext) {
settingsForTestClient = loadSettings("TestSuiteInitialiser");
makeUserSpecificSettings(settingsForCUT);
makeUserSpecificSettings(settingsForTestClient);
httpServerConfiguration = new HttpServerConfiguration(
settingsForTestClient.getReferenceSettings().getFileExchangeSettings());
httpServerConfiguration = new HttpServerConfiguration(settingsForTestClient.getReferenceSettings().getFileExchangeSettings());
collectionID = settingsForTestClient.getCollections().get(0).getID();

securityManager = createSecurityManager();
Expand All @@ -117,6 +107,7 @@ protected void registerMessageReceivers() {
alarmReceiver = new MessageReceiver(settingsForCUT.getAlarmDestination(), testEventManager);
addReceiver(alarmReceiver);
}

protected void addReceiver(MessageReceiver receiver) {
receiverManager.addReceiver(receiver);
}
Expand All @@ -125,7 +116,7 @@ protected void addReceiver(MessageReceiver receiver) {
public void initMessagebus() {
setupMessageBus();
}

@AfterSuite(alwaysRun = true)
public void shutdownSuite() {
teardownMessageBus();
Expand All @@ -140,22 +131,21 @@ public final void beforeMethod(Method method) {
testMethodName = method.getName();
setupSettings();
NON_DEFAULT_FILE_ID = TestFileHelper.createUniquePrefix(testMethodName);
DEFAULT_AUDITINFORMATION = testMethodName;
DEFAULT_AUDIT_INFORMATION = testMethodName;
receiverManager = new MessageReceiverManager(messageBus);
registerMessageReceivers();
messageBus.setCollectionFilter(Arrays.asList(new String[]{}));
messageBus.setComponentFilter(Arrays.asList(new String[]{}));
messageBus.setCollectionFilter(List.of());
messageBus.setComponentFilter(List.of());
receiverManager.startListeners();
initializeCUT();
}
/**
* To be overridden by concrete tests wishing to do stuff. Remember to call super if this is overridden.
*/


protected void initializeCUT() {}

@AfterMethod(alwaysRun = true)
public final void afterMethod(ITestResult testResult) {
if ( receiverManager != null ) {
if (receiverManager != null) {
receiverManager.stopListeners();
}
if (testResult.isSuccess()) {
Expand All @@ -165,7 +155,7 @@ public final void afterMethod(ITestResult testResult) {
}

/**
* May be used by by concrete tests for general verification when the test method has finished. Will only be run
* May be used by specific tests for general verification when the test method has finished. Will only be run
* if the test has passed (so far).
*/
protected void afterMethodVerification() {
Expand All @@ -178,8 +168,9 @@ protected void afterMethodVerification() {
protected void clearReceivers() {
receiverManager.clearMessagesInReceivers();
}

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

Expand All @@ -197,33 +188,35 @@ protected void setupSettings() {
makeUserSpecificSettings(settingsForTestClient);
}

/** Can be overloaded by tests needing to load custom settings */

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

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

@BeforeTest (alwaysRun = true)
@BeforeTest(alwaysRun = true)
public void writeLogStatus() {
if (System.getProperty("enableLogStatus", "false").equals("true")) {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
StatusPrinter.print(lc);
}
}

/** Indicated whether an embedded active MQ should be started and used */
/**
* 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 */
/**
* Indicated whether an embedded http server should be started and used
*/
public boolean useEmbeddedHttpServer() {
return System.getProperty("useEmbeddedHttpServer", "false").equals("true");
}
Expand All @@ -232,7 +225,7 @@ public boolean useEmbeddedHttpServer() {
* Hooks up the message bus.
*/
protected void setupMessageBus() {
if(useEmbeddedMessageBus()) {
if (useEmbeddedMessageBus()) {
if (messageBus == null) {
messageBus = new SimpleMessageBus();
}
Expand All @@ -253,7 +246,7 @@ private void teardownMessageBus() {
}
}

if(broker != null) {
if (broker != null) {
try {
broker.stop();
broker = null;
Expand All @@ -273,8 +266,9 @@ protected void teardownHttpServer() {
}

/**
* Returns the postfix string to use when accessing user specific topics, which is the mechanism we use in the
* 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() {
Expand Down
Loading