* cleaned up folder structure
* OSGiyfied artifact names * polished poms a little * edited Eclipse project names to align artifact id git-svn-id: svn+ssh://svn.synyx.de/var/svn/synyx/opensource/hera/trunk@6618 5a64d73e-33d6-4ccc-9058-23f8668ecac9
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
package org.synyx.hera.core;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
|
||||
/**
|
||||
* Unit test for {@link OrderAwarePluginRegistry} that especially concentrates
|
||||
* on testing ordering functionality.
|
||||
*
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
*/
|
||||
public class OrderAwarePluginRegistryUnitTest extends
|
||||
SimplePluginRegistryUnitTest {
|
||||
|
||||
private PluginRegistry<TestPlugin, String> registry;
|
||||
|
||||
private TestPlugin firstPlugin;
|
||||
private TestPlugin secondPlugin;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
super.setUp();
|
||||
|
||||
registry = OrderAwarePluginRegistry.create();
|
||||
|
||||
firstPlugin = new FirstImplementation();
|
||||
secondPlugin = new SecondImplementation();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the plugin implementations in order of their names, expecting the
|
||||
* registry to order them correctly.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void honorsOrderOnAddPlugins() throws Exception {
|
||||
|
||||
registry.setPlugins(Arrays.asList(firstPlugin, secondPlugin));
|
||||
|
||||
assertOrder();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void assertsOrderOnAddingPlugins() throws Exception {
|
||||
|
||||
registry.setPlugins(Arrays.asList(firstPlugin));
|
||||
registry.addPlugin(secondPlugin);
|
||||
|
||||
assertOrder();
|
||||
}
|
||||
|
||||
|
||||
private void assertOrder() {
|
||||
|
||||
List<TestPlugin> plugins = registry.getPluginsFor(null);
|
||||
|
||||
assertEquals(2, plugins.size());
|
||||
assertEquals(secondPlugin, plugins.get(0));
|
||||
assertEquals(firstPlugin, plugins.get(1));
|
||||
|
||||
assertEquals(secondPlugin, registry.getPluginFor(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple test interface.
|
||||
*
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
*/
|
||||
private static interface TestPlugin extends Plugin<String> {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin implementation, that is orderd right AFTER the second one.
|
||||
*
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
*/
|
||||
@Order(5)
|
||||
private static class FirstImplementation implements TestPlugin {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.synyx.hera.core.Plugin#supports(java.lang.Object)
|
||||
*/
|
||||
public boolean supports(String delimiter) {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin implementation that is ordered BEFORE the first one.
|
||||
*
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
*/
|
||||
@Order(1)
|
||||
private static class SecondImplementation implements TestPlugin {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.synyx.hera.core.Plugin#supports(java.lang.Object)
|
||||
*/
|
||||
public boolean supports(String delimiter) {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
core/src/test/java/org/synyx/hera/core/SamplePlugin.java
Normal file
24
core/src/test/java/org/synyx/hera/core/SamplePlugin.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.synyx.hera.core;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
*/
|
||||
public interface SamplePlugin extends Plugin<String> {
|
||||
|
||||
void pluginMethod();
|
||||
}
|
||||
28
core/src/test/java/org/synyx/hera/core/SamplePluginHost.java
Normal file
28
core/src/test/java/org/synyx/hera/core/SamplePluginHost.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package org.synyx.hera.core;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
*/
|
||||
public class SamplePluginHost {
|
||||
|
||||
private PluginRegistry<SamplePlugin, String> registry =
|
||||
SimplePluginRegistry.create();
|
||||
|
||||
|
||||
/**
|
||||
* @param registry the registry to set
|
||||
*/
|
||||
public void setRegistry(PluginRegistry<SamplePlugin, String> registry) {
|
||||
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the registry
|
||||
*/
|
||||
public PluginRegistry<SamplePlugin, String> getRegistry() {
|
||||
|
||||
return registry;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.synyx.hera.core;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
*/
|
||||
public class SamplePluginImplementation implements SamplePlugin {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.synyx.plugin.core.Plugin#supports(java.lang.Object)
|
||||
*/
|
||||
public boolean supports(String delimiter) {
|
||||
|
||||
return "FOO".equals(delimiter);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.synyx.plugin.core.ISamplePlugin#pluginMethod()
|
||||
*/
|
||||
public void pluginMethod() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.synyx.hera.core;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
/**
|
||||
* Unit test for {@link SimplePluginRegistry}.
|
||||
*
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
*/
|
||||
public class SimplePluginRegistryUnitTest {
|
||||
|
||||
private SamplePlugin plugin;
|
||||
|
||||
private PluginRegistry<SamplePlugin, String> registry;
|
||||
|
||||
|
||||
/**
|
||||
* Initializes a {@code PluginRegistry} and equips it with an {@code
|
||||
* EmailNotificationProvider}.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
plugin = new SamplePluginImplementation();
|
||||
|
||||
registry = SimplePluginRegistry.create(Arrays.asList(plugin));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Asserts that the registry contains the plugin it was initialized with.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void assertRegistryInitialized() throws Exception {
|
||||
|
||||
assertEquals(1, registry.countPlugins());
|
||||
assertTrue(registry.contains(plugin));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Asserts asking for a plugin with the {@code PluginMetadata} provided by
|
||||
* the {@link EmailNotificationProvider}.
|
||||
*/
|
||||
@Test
|
||||
public void assertFindsEmailNotificationProvider() {
|
||||
|
||||
String metadata = "FOO";
|
||||
|
||||
List<SamplePlugin> plugins = registry.getPluginsFor(metadata);
|
||||
assertNotNull(plugins);
|
||||
assertEquals(1, plugins.size());
|
||||
|
||||
SamplePlugin provider = plugins.get(0);
|
||||
assertTrue(provider instanceof SamplePluginImplementation);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expects the given exception to be thrown if no {@link Plugin} found.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void throwsExceptionIfNoPluginFound() {
|
||||
|
||||
registry.getPluginFor("BAR", new IllegalArgumentException());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expects the given exception to be thrown if no {@link Plugin}s found.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void throwsExceptionIfNoPluginsFound() {
|
||||
|
||||
registry.getPluginsFor("BAR", new IllegalArgumentException());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expect the defualt plugin to be returned if none found.
|
||||
*/
|
||||
@Test
|
||||
public void returnsDefaultIfNoneFound() {
|
||||
|
||||
SamplePlugin defaultPlugin = new SamplePluginImplementation();
|
||||
|
||||
assertEquals(defaultPlugin, registry.getPluginFor("BAR", defaultPlugin));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expect the given default plugins to be returned if none found.
|
||||
*/
|
||||
@Test
|
||||
public void returnsDefaultsIfNoneFound() {
|
||||
|
||||
List<? extends SamplePlugin> defaultPlugins =
|
||||
Arrays.asList(new SamplePluginImplementation());
|
||||
|
||||
assertEquals(defaultPlugins, registry.getPluginsFor("BAR",
|
||||
defaultPlugins));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package org.synyx.hera.core.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.synyx.hera.core.PluginRegistry;
|
||||
import org.synyx.hera.core.SamplePlugin;
|
||||
import org.synyx.hera.core.SamplePluginHost;
|
||||
|
||||
|
||||
/**
|
||||
* Integration test to simply check if the configuration gets parsed correctly.
|
||||
*
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "classpath:application-context.xml")
|
||||
public class PluginConfigurationIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
List<SamplePlugin> samplePlugins;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("bar")
|
||||
PluginRegistry<SamplePlugin, String> pluginRegistry;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("host")
|
||||
SamplePluginHost host;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("otherHost")
|
||||
SamplePluginHost otherHost;
|
||||
|
||||
@Autowired
|
||||
SamplePlugin plugin;
|
||||
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
|
||||
assertNotNull(samplePlugins);
|
||||
|
||||
assertSame(pluginRegistry, host.getRegistry());
|
||||
assertNotSame(pluginRegistry, otherHost.getRegistry());
|
||||
|
||||
assertTrue(samplePlugins.contains(plugin));
|
||||
assertTrue(pluginRegistry.contains(plugin));
|
||||
}
|
||||
}
|
||||
24
core/src/test/resources/application-context.xml
Normal file
24
core/src/test/resources/application-context.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:plugin="http://schemas.synyx.org/hera"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://schemas.synyx.org/hera http://schemas.synyx.org/hera/hera.xsd">
|
||||
|
||||
<plugin:list id="foo" class="org.synyx.hera.core.SamplePlugin" />
|
||||
|
||||
<plugin:registry id="bar" class="org.synyx.hera.core.SamplePlugin" />
|
||||
|
||||
<bean class="org.synyx.hera.core.SamplePluginImplementation" />
|
||||
|
||||
<bean id="host" class="org.synyx.hera.core.SamplePluginHost">
|
||||
<property name="registry" ref="bar" />
|
||||
</bean>
|
||||
|
||||
<bean id="otherHost" class="org.synyx.hera.core.SamplePluginHost">
|
||||
<property name="registry">
|
||||
<plugin:registry id="tadaa" class="org.synyx.hera.core.SamplePlugin" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
12
core/src/test/resources/log4j.properties
Normal file
12
core/src/test/resources/log4j.properties
Normal file
@@ -0,0 +1,12 @@
|
||||
# Direct log messages to stdout
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Target=System.out
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
|
||||
|
||||
# Root logger option
|
||||
log4j.rootLogger=WARN, stdout
|
||||
|
||||
# Hibernate logging options (INFO only shows startup messages)
|
||||
log4j.logger.org.springframework=INFO
|
||||
log4j.logger.org.synyx.hera=DEBUG
|
||||
Reference in New Issue
Block a user