Skip to content

Commit

Permalink
Update Test Environment to use its own local.cfg INSTEAD OF dspace.cf…
Browse files Browse the repository at this point in the history
…g.more / merging multiple configs
  • Loading branch information
tdonohue committed Jan 25, 2016
1 parent 9d2af78 commit 628783f
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 390 deletions.
69 changes: 1 addition & 68 deletions dspace-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,80 +219,13 @@
</executions>
</plugin>

<!-- FileWeaver plugin is in charge of initializing & "weaving" together
the dspace.cfg file to be used by the Unit Testing environment.
It weaves two files, the default 'dspace.cfg' and 'dspace.cfg.more',
both of which are included in the testEnvironment.zip. -->
<plugin>
<groupId>edu.iu.ul.maven.plugins</groupId>
<artifactId>fileweaver</artifactId>
<version>1.0</version>
<configuration>
<outputs>
<output>
<outputPath>${agnostic.build.dir}/testing</outputPath>
<name>dspace.cfg.woven</name>
<parts>
<part>
<path>${agnostic.build.dir}/testing/dspace/config/dspace.cfg</path>
</part>
<part>
<path>${agnostic.build.dir}/testing/dspace.cfg.more</path>
</part>
</parts>
<properties>
<dspace.install.dir>${agnostic.build.dir}/testing/dspace</dspace.install.dir>
</properties>
</output>
</outputs>
</configuration>
<executions>
<execution>
<id>edit-dspace-cfg</id>
<phase>process-test-resources</phase>
<goals>
<goal>weave</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- The ant plugin below ensures that the final "woven" dspace.cfg
ends up in the /target/testing/dspace/ directory. This becomes
our final dspace.cfg for the Unit Testing environment. The dspace
service manager needs this "woven" configuration file when it starts.-->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-test-resources</phase>
<configuration>
<target>
<!-- Ant task to copy dspace.cfg.woven to location of test dspace.cfg file -->
<copy file="${agnostic.build.dir}/testing/dspace.cfg.woven" tofile="${agnostic.build.dir}/testing/dspace/config/dspace.cfg" />
<!-- Now, do one final filter of our Test configs, replacing any remaining "${dspace.dir}"
placeholders, with the full path of our Unit Test directory -->
<!-- NOTE: This final filtering is necessary, because dspace.dir doesn't get filled out
in our test dspace.cfg until Fileweaver runs above. -->
<replace dir="${agnostic.build.dir}/testing/dspace/config/" value="${agnostic.build.dir}/testing/dspace">
<include name="**/*"/>
<replacetoken>${dspace.dir}</replacetoken>
</replace>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- Run Unit Testing! This plugin just kicks off the tests (when enabled). -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<!-- Specify the dspace.dir to use for test environment -->
<!-- This system property is loaded by AbstractDSpaceTest to initialize the test environment -->
<dspace.dir>${agnostic.build.dir}/testing/dspace/</dspace.dir>
<!-- Turn off any DSpace logging -->
<dspace.log.init.disable>true</dspace.log.init.disable>
Expand Down
98 changes: 0 additions & 98 deletions dspace-api/src/test/data/dspaceFolder/config/hibernate.cfg.xml

This file was deleted.

112 changes: 112 additions & 0 deletions dspace-api/src/test/data/dspaceFolder/config/local.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# A "local.cfg" which is used by our Unit/Integration Testing framework
#
# Any configurations added to this file will automatically OVERRIDE configurations
# of the same name in any of the DSpace *.cfg files.
#
# While some sample configurations are provided below, you may also copy
# ANY configuration from ANY DSpace *.cfg file into this "local.cfg" to OVERRIDE
# its default value. This includes any of these files:
# * [dspace]/config/dspace.cfg
# * Or any configuration file that is loaded into 'dspace.cfg'
# (see "include =" settings near the end of dspace.cfg for full list)
#
# You may also specify additional configuration files to load by simply adding:
# include = [file-path]
# The [file-path] should be relative to the [dspace]/config/ folder, e.g.
# include = modules/authentication-ldap.cfg
#
# Any commented out settings in this file are simply ignored. A configuration
# will only override another configuration if it has the EXACT SAME key/name.
# For example, including "dspace.dir" in this local.cfg will override the
# default value of "dspace.dir" in the dspace.cfg file.
#

##########################
# SERVER CONFIGURATION #
##########################

# DSpace installation directory.
# This is the location where you want to install DSpace.
# Windows note: Please remember to use forward slashes for all paths (e.g. C:/dspace)
# NOTE: COMMENTED OUT FOR TEST ENVIRONMENT, AS WE DYNAMICALLY SET THIS VIA
# A SYSTEM PROPERTY (-Ddspace.dir) in the maven-surefire-plugin configuration
#dspace.dir=/dspace

##########################
# DATABASE CONFIGURATION #
##########################

# For Unit Testing we use the H2 (in memory) database
db.driver = org.h2.Driver
db.dialect=org.hibernate.dialect.H2Dialect
# Use a 10 second database lock timeout to avoid occasional JDBC lock timeout errors
db.url = jdbc:h2:mem:test;LOCK_TIMEOUT=10000;
db.username = sa
db.password =
# H2's default schema is PUBLIC
db.schema = PUBLIC

#######################
# EMAIL CONFIGURATION #
#######################

# SMTP mail server (allows DSpace to send email notifications)
mail.server = localhost

# An option is added to disable the mailserver. By default, this property is set to false
# By setting mail.server.disabled = true, DSpace will not send out emails.
# It will instead log the subject of the email which should have been sent
# This is especially useful for development and test environments where production data is used when testing functionality.
mail.server.disabled = true

########################
# HANDLE CONFIGURATION #
########################

# CNRI Handle prefix
# (Defaults to a dummy/fake prefix of 123456789)
handle.prefix = 123456789

#####################
# LOGLEVEL SETTINGS #
#####################
loglevel.other = INFO
# loglevel.other: Log level for other third-party tools/APIs used by DSpace
# Possible values (from most to least info): DEBUG, INFO, WARN, ERROR, FATAL
loglevel.dspace = INFO
# loglevel.dspace: Log level for all DSpace-specific code (org.dspace.*)
# Possible values (from most to least info): DEBUG, INFO, WARN, ERROR, FATAL


###########################################
# CUSTOM UNIT / INTEGRATION TEST SETTINGS #
###########################################
# Configure authority control for Unit Testing (in DSpaceControlledVocabularyTest)
# (This overrides default, commented out settings in dspace.cfg)
plugin.selfnamed.org.dspace.content.authority.ChoiceAuthority = \
org.dspace.content.authority.DCInputAuthority, \
org.dspace.content.authority.DSpaceControlledVocabulary

# Configure some more Plugins for PluginTest class
# NOTE: Plugins are just *interfaces*. So, here we are defining some plugins
# based on java.util.List interface and giving them names.
# (These are used by PluginTest)
plugin.named.java.util.List = \
java.util.ArrayList = MyArrayList, \
java.util.LinkedList = MyLinkedList, \
java.util.AttributeList = MyAttributeList

# Define a single Map plugin (used by PluginTest)
plugin.single.java.util.Map = java.util.HashMap

# Define a sequence of Collection plugins (used by PluginTest)
plugin.sequence.java.util.Collection = \
java.util.ArrayList, \
java.util.LinkedList, \
java.util.Stack, \
java.util.TreeSet

# Enable a test authority control on dc.language.iso field
choices.plugin.dc.language.iso = common_iso_languages
choices.presentation.dc.language.iso = select
authority.controlled.dc.language.iso = true
4 changes: 2 additions & 2 deletions dspace-api/src/test/java/org/dspace/content/ItemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public void testAddMetadata_5args_1() throws SQLException
*/
@Test
public void testAddMetadata_7args_1_authority() throws InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException, SQLException {
//we have enabled an authority control in dspace-test.cfg to run this test
//we have enabled an authority control in our test local.cfg to run this test
//as MetadataAuthorityManager can't be mocked properly

String schema = "dc";
Expand Down Expand Up @@ -504,7 +504,7 @@ public void testAddMetadata_5args_2() throws SQLException {
@Test
public void testAddMetadata_7args_2_authority() throws SQLException
{
//we have enabled an authority control in dspace-test.cfg to run this test
//we have enabled an authority control in our test local.cfg to run this test
//as MetadataAuthorityManager can't be mocked properly

String schema = "dc";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void testGetMatches() throws IOException, ClassNotFoundException
String locale = null;
// This "farm" Controlled Vocab is included in TestEnvironment data
// (under /src/test/data/dspaceFolder/) and it should be auto-loaded
// by test configs in /src/test/data/dspace.cfg.more
// by test configs in /src/test/data/dspaceFolder/config/local.cfg
DSpaceControlledVocabulary instance = (DSpaceControlledVocabulary)
CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(Class.forName(PLUGIN_INTERFACE), "farm");
assertNotNull(instance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
* Tests for Plugin Service.
* <P>
* NOTE: Plugin definitions/configurations which are used for this test are
* defined in /data/dspaceFolder/dspace.cfg.more (and are added into the
* final test dspace.cfg file)
* defined in /src/test/data/dspaceFolder/config/local.cfg
*
* @author Tim Donohue
*/
Expand All @@ -37,7 +36,7 @@ public class PluginServiceTest extends AbstractDSpaceTest
@Test
public void testGetAllPluginNames()
{
// Get all plugins defined from List interface (see dspace.cfg.more)
// Get all plugins defined from List interface (see test local.cfg)
String[] names = pluginService.getAllPluginNames(java.util.List.class);

// There should be exactly 3 List plugins
Expand All @@ -62,7 +61,7 @@ public void testGetNamedPlugin()
assertNull("Plugin 2 doesn't exist", plugin);

// Test for one plugin that is "selfnamed"
// The DCInputAuthority plugin enabled in dspace.cfg.more reads all <form-value-pairs> in input-forms.xml
// The DCInputAuthority plugin enabled in test local.cfg reads all <form-value-pairs> in input-forms.xml
// and defines a self named plugin for each. So, we SHOULD have a "common_types" plugin.
plugin = pluginService.getNamedPlugin(org.dspace.content.authority.ChoiceAuthority.class, "common_types");
assertNotNull("Plugin 3 exists", plugin);
Expand Down Expand Up @@ -112,7 +111,7 @@ public void testGetPluginSequence()
// There should be four of them
assertEquals("Plugin count", 4, plugins.length);

// They should be in an EXACT ORDER (as defined in dspace.cfg.more)
// They should be in an EXACT ORDER (as defined in test local.cfg)
assertTrue("Plugin 0 is ArrayList", plugins[0] instanceof java.util.ArrayList);
assertTrue("Plugin 1 is LinkedList", plugins[1] instanceof java.util.LinkedList);
assertTrue("Plugin 2 is Stack", plugins[2] instanceof java.util.Stack);
Expand Down
Loading

0 comments on commit 628783f

Please sign in to comment.