Major overhaul of entire project infrastructure.
Formatted source with Spring formatter. Fixed license headers and author tags.
This commit is contained in:
@@ -1,68 +1,48 @@
|
||||
/*
|
||||
* Copyright 2008-2010 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
|
||||
*
|
||||
* Copyright 2008-2012 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.
|
||||
* 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.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
/**
|
||||
* Unit test for implementations of {@link MutablePluginRegistry}.
|
||||
*
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public abstract class AbstractMutablePluginRegistryUnitTest {
|
||||
|
||||
private SamplePlugin plugin = new SamplePluginImplementation();
|
||||
private SamplePlugin plugin = new SamplePluginImplementation();
|
||||
|
||||
@Test
|
||||
public void allowsAddingPluginsAfterCreation() throws Exception {
|
||||
|
||||
@Test
|
||||
public void allowsAddingPluginsAfterCreation() throws Exception {
|
||||
MutablePluginRegistry<SamplePlugin, String> registry = getRegistry();
|
||||
registry.addPlugin(plugin);
|
||||
|
||||
MutablePluginRegistry<SamplePlugin, String> registry = getRegistry();
|
||||
registry.addPlugin(plugin);
|
||||
assertTrue(registry.contains(plugin));
|
||||
assertThat(registry.getPlugins().size(), is(1));
|
||||
}
|
||||
|
||||
assertTrue(registry.contains(plugin));
|
||||
assertThat(registry.getPlugins().size(), is(1));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void settingPluginsRemovesOldOnes() throws Exception {
|
||||
|
||||
MutablePluginRegistry<SamplePlugin, String> registry = getRegistry();
|
||||
registry.addPlugin(plugin);
|
||||
|
||||
SamplePlugin anotherPlugin = new SamplePluginImplementation();
|
||||
|
||||
registry.setPlugins(Arrays.asList(anotherPlugin));
|
||||
assertTrue(registry.contains(anotherPlugin));
|
||||
assertFalse(registry.contains(plugin));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the {@link MutablePluginRegistry} to test.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract MutablePluginRegistry<SamplePlugin, String> getRegistry();
|
||||
/**
|
||||
* Return the {@link MutablePluginRegistry} to test.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract MutablePluginRegistry<SamplePlugin, String> getRegistry();
|
||||
}
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
/*
|
||||
* Copyright 2008-2010 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
|
||||
*
|
||||
* Copyright 2008-2012 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.
|
||||
* 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.hamcrest.CoreMatchers.*;
|
||||
@@ -23,151 +22,107 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
|
||||
/**
|
||||
* Unit test for {@link OrderAwarePluginRegistry} that especially concentrates
|
||||
* on testing ordering functionality.
|
||||
* Unit test for {@link OrderAwarePluginRegistry} that especially concentrates on testing ordering functionality.
|
||||
*
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class OrderAwarePluginRegistryUnitTest extends
|
||||
SimplePluginRegistryUnitTest {
|
||||
public class OrderAwarePluginRegistryUnitTest extends SimplePluginRegistryUnitTest {
|
||||
|
||||
private OrderAwarePluginRegistry<TestPlugin, String> registry;
|
||||
TestPlugin firstPlugin;
|
||||
TestPlugin secondPlugin;
|
||||
|
||||
private TestPlugin firstPlugin;
|
||||
private TestPlugin secondPlugin;
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
super.setUp();
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
firstPlugin = new FirstImplementation();
|
||||
secondPlugin = new SecondImplementation();
|
||||
}
|
||||
|
||||
super.setUp();
|
||||
@Override
|
||||
protected OrderAwarePluginRegistry<SamplePlugin, String> getRegistry() {
|
||||
|
||||
registry = OrderAwarePluginRegistry.create();
|
||||
return OrderAwarePluginRegistry.create();
|
||||
}
|
||||
|
||||
firstPlugin = new FirstImplementation();
|
||||
secondPlugin = new SecondImplementation();
|
||||
}
|
||||
@Test
|
||||
public void honorsOrderOnAddPlugins() throws Exception {
|
||||
|
||||
PluginRegistry<TestPlugin, String> registry = OrderAwarePluginRegistry.create(Arrays.asList(firstPlugin,
|
||||
secondPlugin));
|
||||
assertOrder(registry, secondPlugin, firstPlugin);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.synyx.hera.core.SimplePluginRegistryUnitTest#getRegistry()
|
||||
*/
|
||||
@Override
|
||||
protected OrderAwarePluginRegistry<SamplePlugin, String> getRegistry() {
|
||||
@Test
|
||||
@Ignore
|
||||
public void assertsOrderOnAddingPlugins() throws Exception {
|
||||
|
||||
return OrderAwarePluginRegistry.create();
|
||||
}
|
||||
MutablePluginRegistry<TestPlugin, String> registry = OrderAwarePluginRegistry.create(Arrays.asList(firstPlugin));
|
||||
registry.addPlugin(secondPlugin);
|
||||
|
||||
assertOrder(registry, secondPlugin, firstPlugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the plugin implementations in order of their names, expecting the
|
||||
* registry to order them correctly.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void honorsOrderOnAddPlugins() throws Exception {
|
||||
private void assertOrder(PluginRegistry<TestPlugin, String> registry, TestPlugin... plugins) {
|
||||
|
||||
registry.setPlugins(Arrays.asList(firstPlugin, secondPlugin));
|
||||
List<TestPlugin> result = registry.getPluginsFor(null);
|
||||
|
||||
assertOrder(registry, secondPlugin, firstPlugin);
|
||||
}
|
||||
assertThat(plugins.length, is(result.size()));
|
||||
|
||||
for (int i = 0; i < plugins.length; i++) {
|
||||
assertThat(result.get(i), is(result.get(i)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertsOrderOnAddingPlugins() throws Exception {
|
||||
assertThat(registry.getPluginFor(null), is(plugins[0]));
|
||||
}
|
||||
|
||||
registry.setPlugins(Arrays.asList(firstPlugin));
|
||||
registry.addPlugin(secondPlugin);
|
||||
@Test
|
||||
public void createsRevertedRegistryCorrectly() throws Exception {
|
||||
|
||||
assertOrder(registry, secondPlugin, firstPlugin);
|
||||
}
|
||||
OrderAwarePluginRegistry<TestPlugin, String> registry = OrderAwarePluginRegistry.create(Arrays.asList(firstPlugin,
|
||||
secondPlugin));
|
||||
PluginRegistry<TestPlugin, String> reverse = registry.reverse();
|
||||
|
||||
assertOrder(registry, secondPlugin, firstPlugin);
|
||||
assertOrder(reverse, firstPlugin, secondPlugin);
|
||||
}
|
||||
|
||||
private void assertOrder(PluginRegistry<TestPlugin, String> registry,
|
||||
TestPlugin... plugins) {
|
||||
private static interface TestPlugin extends Plugin<String> {
|
||||
|
||||
List<TestPlugin> result = registry.getPluginsFor(null);
|
||||
}
|
||||
|
||||
assertThat(plugins.length, is(result.size()));
|
||||
@Order(5)
|
||||
private static class FirstImplementation implements TestPlugin {
|
||||
|
||||
for (int i = 0; i < plugins.length; i++) {
|
||||
assertThat(result.get(i), is(result.get(i)));
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.synyx.hera.core.Plugin#supports(java.lang.Object)
|
||||
*/
|
||||
public boolean supports(String delimiter) {
|
||||
|
||||
assertThat(registry.getPluginFor(null), is(plugins[0]));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
private static class SecondImplementation implements TestPlugin {
|
||||
|
||||
@Test
|
||||
public void createsRevertedRegistryCorrectly() throws Exception {
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.synyx.hera.core.Plugin#supports(java.lang.Object)
|
||||
*/
|
||||
public boolean supports(String delimiter) {
|
||||
|
||||
basicPrepare();
|
||||
PluginRegistry<TestPlugin, String> reverse = registry.reverse();
|
||||
|
||||
assertOrder(registry, secondPlugin, firstPlugin);
|
||||
assertOrder(reverse, firstPlugin, secondPlugin);
|
||||
}
|
||||
|
||||
|
||||
private void basicPrepare() {
|
||||
|
||||
registry.setPlugins(Arrays.asList(firstPlugin, secondPlugin));
|
||||
assertOrder(registry, secondPlugin, firstPlugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
/*
|
||||
* Copyright 2008-2010 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
|
||||
*
|
||||
* Copyright 2008-2012 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.
|
||||
* 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
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public interface SamplePlugin extends Plugin<String> {
|
||||
|
||||
void pluginMethod();
|
||||
void pluginMethod();
|
||||
}
|
||||
|
||||
@@ -1,44 +1,40 @@
|
||||
/*
|
||||
* Copyright 2008-2010 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
|
||||
*
|
||||
* Copyright 2008-2012 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.
|
||||
* 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
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SamplePluginHost {
|
||||
|
||||
private PluginRegistry<SamplePlugin, String> registry =
|
||||
SimplePluginRegistry.create();
|
||||
private PluginRegistry<SamplePlugin, String> registry = SimplePluginRegistry.create();
|
||||
|
||||
/**
|
||||
* @param registry the registry to set
|
||||
*/
|
||||
public void setRegistry(PluginRegistry<SamplePlugin, String> registry) {
|
||||
|
||||
/**
|
||||
* @param registry the registry to set
|
||||
*/
|
||||
public void setRegistry(PluginRegistry<SamplePlugin, String> registry) {
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
this.registry = registry;
|
||||
}
|
||||
/**
|
||||
* @return the registry
|
||||
*/
|
||||
public PluginRegistry<SamplePlugin, String> getRegistry() {
|
||||
|
||||
|
||||
/**
|
||||
* @return the registry
|
||||
*/
|
||||
public PluginRegistry<SamplePlugin, String> getRegistry() {
|
||||
|
||||
return registry;
|
||||
}
|
||||
return registry;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +1,38 @@
|
||||
/*
|
||||
* Copyright 2008-2010 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
|
||||
*
|
||||
* Copyright 2008-2012 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.
|
||||
* 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
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SamplePluginImplementation implements SamplePlugin {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.synyx.plugin.core.Plugin#supports(java.lang.Object)
|
||||
*/
|
||||
public boolean supports(String delimiter) {
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.synyx.hera.core.Plugin#supports(java.lang.Object)
|
||||
*/
|
||||
public boolean supports(String delimiter) {
|
||||
return "FOO".equals(delimiter);
|
||||
}
|
||||
|
||||
return "FOO".equals(delimiter);
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.synyx.hera.core.SamplePlugin#pluginMethod()
|
||||
*/
|
||||
public void pluginMethod() {
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.synyx.plugin.core.ISamplePlugin#pluginMethod()
|
||||
*/
|
||||
public void pluginMethod() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2008-2010 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
|
||||
*
|
||||
* Copyright 2008-2012 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.
|
||||
* 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;
|
||||
@@ -25,155 +25,115 @@ import java.util.List;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
/**
|
||||
* Unit test for {@link SimplePluginRegistry}.
|
||||
*
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SimplePluginRegistryUnitTest extends
|
||||
AbstractMutablePluginRegistryUnitTest {
|
||||
public class SimplePluginRegistryUnitTest extends AbstractMutablePluginRegistryUnitTest {
|
||||
|
||||
private SamplePlugin plugin;
|
||||
SamplePlugin plugin;
|
||||
|
||||
private SimplePluginRegistry<SamplePlugin, String> registry;
|
||||
SimplePluginRegistry<SamplePlugin, String> registry;
|
||||
|
||||
/**
|
||||
* Initializes a {@code PluginRegistry} and equips it with an {@code EmailNotificationProvider}.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
/**
|
||||
* Initializes a {@code PluginRegistry} and equips it with an {@code
|
||||
* EmailNotificationProvider}.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
plugin = new SamplePluginImplementation();
|
||||
registry = SimplePluginRegistry.create();
|
||||
}
|
||||
|
||||
plugin = new SamplePluginImplementation();
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.synyx.hera.core.AbstractMutablePluginRegistryUnitTest#getRegistry()
|
||||
*/
|
||||
@Override
|
||||
protected MutablePluginRegistry<SamplePlugin, String> getRegistry() {
|
||||
|
||||
registry = SimplePluginRegistry.create();
|
||||
}
|
||||
return SimplePluginRegistry.create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the registry contains the plugin it was initialized with.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void assertRegistryInitialized() throws Exception {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.synyx.hera.core.AbstractMutablePluginRegistryUnitTest#getRegistry()
|
||||
*/
|
||||
@Override
|
||||
protected MutablePluginRegistry<SamplePlugin, String> getRegistry() {
|
||||
registry.addPlugin(plugin);
|
||||
|
||||
return SimplePluginRegistry.create();
|
||||
}
|
||||
assertThat(registry.countPlugins(), is(1));
|
||||
assertTrue(registry.contains(plugin));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts asking for a plugin with the {@code PluginMetadata} provided by the {@link EmailNotificationProvider}.
|
||||
*/
|
||||
@Test
|
||||
public void assertFindsEmailNotificationProvider() {
|
||||
|
||||
/**
|
||||
* Asserts that the registry contains the plugin it was initialized with.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void assertRegistryInitialized() throws Exception {
|
||||
registry.addPlugin(plugin);
|
||||
|
||||
registry.addPlugin(plugin);
|
||||
String delimiter = "FOO";
|
||||
|
||||
assertThat(registry.countPlugins(), is(1));
|
||||
assertTrue(registry.contains(plugin));
|
||||
}
|
||||
List<SamplePlugin> plugins = registry.getPluginsFor(delimiter);
|
||||
assertThat(plugins, is(notNullValue()));
|
||||
assertThat(plugins.size(), is(1));
|
||||
|
||||
SamplePlugin provider = plugins.get(0);
|
||||
assertThat(provider, is(instanceOf(SamplePluginImplementation.class)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts asking for a plugin with the {@code PluginMetadata} provided by
|
||||
* the {@link EmailNotificationProvider}.
|
||||
*/
|
||||
@Test
|
||||
public void assertFindsEmailNotificationProvider() {
|
||||
/**
|
||||
* Expects the given exception to be thrown if no {@link Plugin} found.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void throwsExceptionIfNoPluginFound() {
|
||||
|
||||
registry.addPlugin(plugin);
|
||||
registry.getPluginFor("BAR", new IllegalArgumentException());
|
||||
}
|
||||
|
||||
String delimiter = "FOO";
|
||||
/**
|
||||
* Expects the given exception to be thrown if no {@link Plugin}s found.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void throwsExceptionIfNoPluginsFound() {
|
||||
|
||||
List<SamplePlugin> plugins = registry.getPluginsFor(delimiter);
|
||||
assertThat(plugins, is(notNullValue()));
|
||||
assertThat(plugins.size(), is(1));
|
||||
registry.getPluginsFor("BAR", new IllegalArgumentException());
|
||||
}
|
||||
|
||||
SamplePlugin provider = plugins.get(0);
|
||||
assertThat(provider, is(instanceOf(SamplePluginImplementation.class)));
|
||||
}
|
||||
/**
|
||||
* Expect the defualt plugin to be returned if none found.
|
||||
*/
|
||||
@Test
|
||||
public void returnsDefaultIfNoneFound() {
|
||||
|
||||
SamplePlugin defaultPlugin = new SamplePluginImplementation();
|
||||
|
||||
/**
|
||||
* Expects the given exception to be thrown if no {@link Plugin} found.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void throwsExceptionIfNoPluginFound() {
|
||||
assertThat(registry.getPluginFor("BAR", defaultPlugin), is(defaultPlugin));
|
||||
}
|
||||
|
||||
registry.getPluginFor("BAR", new IllegalArgumentException());
|
||||
}
|
||||
/**
|
||||
* Expect the given default plugins to be returned if none found.
|
||||
*/
|
||||
@Test
|
||||
public void returnsDefaultsIfNoneFound() {
|
||||
|
||||
List<? extends SamplePlugin> defaultPlugins = Arrays.asList(new SamplePluginImplementation());
|
||||
|
||||
/**
|
||||
* Expects the given exception to be thrown if no {@link Plugin}s found.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void throwsExceptionIfNoPluginsFound() {
|
||||
List<SamplePlugin> result = registry.getPluginsFor("BAR", defaultPlugins);
|
||||
assertTrue(result.containsAll(defaultPlugins));
|
||||
}
|
||||
|
||||
registry.getPluginsFor("BAR", new IllegalArgumentException());
|
||||
}
|
||||
@Test
|
||||
public void handlesAddingNullPluginsCorrecty() throws Exception {
|
||||
|
||||
registry.addPlugin(null);
|
||||
|
||||
/**
|
||||
* Expect the defualt plugin to be returned if none found.
|
||||
*/
|
||||
@Test
|
||||
public void returnsDefaultIfNoneFound() {
|
||||
|
||||
SamplePlugin defaultPlugin = new SamplePluginImplementation();
|
||||
|
||||
assertThat(registry.getPluginFor("BAR", defaultPlugin),
|
||||
is(defaultPlugin));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expect the given default plugins to be returned if none found.
|
||||
*/
|
||||
@Test
|
||||
public void returnsDefaultsIfNoneFound() {
|
||||
|
||||
List<? extends SamplePlugin> defaultPlugins =
|
||||
Arrays.asList(new SamplePluginImplementation());
|
||||
|
||||
List<SamplePlugin> result =
|
||||
registry.getPluginsFor("BAR", defaultPlugins);
|
||||
assertTrue(result.containsAll(defaultPlugins));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void handlesAddingNullPluginsCorrecty() throws Exception {
|
||||
|
||||
registry.addPlugin(null);
|
||||
|
||||
assertThat(registry.countPlugins(), is(0));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void doesNotAddNullsOnSettingPlugins() throws Exception {
|
||||
|
||||
registry.setPlugins(Arrays.asList(null, plugin, null));
|
||||
|
||||
assertThat(registry.countPlugins(), is(1));
|
||||
assertThat(registry.getPlugins().size(), is(1));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void dropsNullValuesOnCreation() throws Exception {
|
||||
|
||||
registry =
|
||||
SimplePluginRegistry.create(Arrays.asList(null, plugin, null));
|
||||
|
||||
assertThat(registry.countPlugins(), is(1));
|
||||
assertThat(registry.getPlugins().size(), is(1));
|
||||
}
|
||||
assertThat(registry.countPlugins(), is(0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2008-2012 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.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@@ -14,44 +29,42 @@ 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
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "classpath:application-context.xml")
|
||||
public class PluginConfigurationIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
List<SamplePlugin> samplePlugins;
|
||||
@Autowired
|
||||
List<SamplePlugin> samplePlugins;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("bar")
|
||||
PluginRegistry<SamplePlugin, String> pluginRegistry;
|
||||
@Autowired
|
||||
@Qualifier("bar")
|
||||
PluginRegistry<SamplePlugin, String> pluginRegistry;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("host")
|
||||
SamplePluginHost host;
|
||||
@Autowired
|
||||
@Qualifier("host")
|
||||
SamplePluginHost host;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("otherHost")
|
||||
SamplePluginHost otherHost;
|
||||
@Autowired
|
||||
@Qualifier("otherHost")
|
||||
SamplePluginHost otherHost;
|
||||
|
||||
@Autowired
|
||||
SamplePlugin plugin;
|
||||
@Autowired
|
||||
SamplePlugin plugin;
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
assertNotNull(samplePlugins);
|
||||
|
||||
assertNotNull(samplePlugins);
|
||||
assertSame(pluginRegistry, host.getRegistry());
|
||||
assertNotSame(pluginRegistry, otherHost.getRegistry());
|
||||
|
||||
assertSame(pluginRegistry, host.getRegistry());
|
||||
assertNotSame(pluginRegistry, otherHost.getRegistry());
|
||||
|
||||
assertTrue(samplePlugins.contains(plugin));
|
||||
assertTrue(pluginRegistry.contains(plugin));
|
||||
}
|
||||
assertTrue(samplePlugins.contains(plugin));
|
||||
assertTrue(pluginRegistry.contains(plugin));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2008-2012 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.support;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@@ -15,88 +30,82 @@ import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.Ordered;
|
||||
|
||||
|
||||
/**
|
||||
* Unit test for {@link BeanListFactoryBean}.
|
||||
*
|
||||
* @author Oliver Gierke - gierke@synyx.de
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class BeanListFactoryBeanUnitTest {
|
||||
|
||||
private BeanListFactoryBean<Ordered> factory;
|
||||
BeanListFactoryBean<Ordered> factory;
|
||||
|
||||
@Mock
|
||||
private ApplicationContext context;
|
||||
@Mock
|
||||
ApplicationContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
factory = new BeanListFactoryBean<Ordered>();
|
||||
factory.setApplicationContext(context);
|
||||
factory.setType(Ordered.class);
|
||||
factory.afterPropertiesSet();
|
||||
}
|
||||
|
||||
factory = new BeanListFactoryBean<Ordered>();
|
||||
factory.setApplicationContext(context);
|
||||
factory.setType(Ordered.class);
|
||||
}
|
||||
@Test
|
||||
public void regardsOrderOfBeans() throws Exception {
|
||||
|
||||
// They shall be switched in the result.
|
||||
Ordered first = getOrdered(5);
|
||||
Ordered second = getOrdered(0);
|
||||
|
||||
@Test
|
||||
public void regardsOrderOfBeans() throws Exception {
|
||||
Map<String, Ordered> beans = new HashMap<String, Ordered>();
|
||||
beans.put("first", first);
|
||||
beans.put("second", second);
|
||||
|
||||
// They shall be switched in the result.
|
||||
Ordered first = getOrdered(5);
|
||||
Ordered second = getOrdered(0);
|
||||
when(context.getBeansOfType(Ordered.class, false, false)).thenReturn(beans);
|
||||
|
||||
Map<String, Ordered> beans = new HashMap<String, Ordered>();
|
||||
beans.put("first", first);
|
||||
beans.put("second", second);
|
||||
Object result = factory.getObject();
|
||||
assertTrue(result instanceof List<?>);
|
||||
|
||||
when(context.getBeansOfType(Ordered.class)).thenReturn(beans);
|
||||
List<Ordered> members = type(result);
|
||||
|
||||
Object result = factory.getObject();
|
||||
assertTrue(result instanceof List<?>);
|
||||
assertEquals(0, members.indexOf(second));
|
||||
assertEquals(1, members.indexOf(first));
|
||||
}
|
||||
|
||||
List<Ordered> members = type(result);
|
||||
@Test
|
||||
public void returnsEmptyListIfNoBeansFound() throws Exception {
|
||||
|
||||
assertEquals(0, members.indexOf(second));
|
||||
assertEquals(1, members.indexOf(first));
|
||||
}
|
||||
when(context.getBeansOfType(Ordered.class)).thenReturn(new HashMap<String, Ordered>());
|
||||
|
||||
Object result = factory.getObject();
|
||||
assertTrue(result instanceof List<?>);
|
||||
|
||||
@Test
|
||||
public void returnsEmptyListIfNoBeansFound() throws Exception {
|
||||
List<Ordered> members = type(result);
|
||||
assertTrue(members.isEmpty());
|
||||
}
|
||||
|
||||
when(context.getBeansOfType(Ordered.class)).thenReturn(
|
||||
new HashMap<String, Ordered>());
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> List<T> type(Object list) {
|
||||
|
||||
Object result = factory.getObject();
|
||||
assertTrue(result instanceof List<?>);
|
||||
return (List<T>) list;
|
||||
}
|
||||
|
||||
List<Ordered> members = type(result);
|
||||
assertTrue(members.isEmpty());
|
||||
}
|
||||
/**
|
||||
* Returns an {@link Ordered} with the given order.
|
||||
*
|
||||
* @param order
|
||||
* @return
|
||||
*/
|
||||
public Ordered getOrdered(final int order) {
|
||||
|
||||
return new Ordered() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> List<T> type(Object list) {
|
||||
public int getOrder() {
|
||||
|
||||
return (List<T>) list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an {@link Ordered} with the given order.
|
||||
*
|
||||
* @param order
|
||||
* @return
|
||||
*/
|
||||
public Ordered getOrdered(final int order) {
|
||||
|
||||
return new Ordered() {
|
||||
|
||||
public int getOrder() {
|
||||
|
||||
return order;
|
||||
}
|
||||
};
|
||||
}
|
||||
return order;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
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
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n
|
||||
|
||||
# Root logger option
|
||||
log4j.rootLogger=WARN, stdout
|
||||
|
||||
Reference in New Issue
Block a user