#1 - Restructuring of internals to fix ordering not being applied.
Introduced PluginRegistrySupport base class to make sure we create a copy of the plugin list on first access to it as otherwise the sorting calls get lost in the proxy created by the AbstractTypeAwareSupport. Removed MutablePluginRegistry interfaces and implementation along the way as it causes more bad than good currently and there doesn't seem to be a real need for it.
This commit is contained in:
@@ -1,49 +0,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.
|
||||
*/
|
||||
package org.springframework.plugin.core;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.plugin.core.MutablePluginRegistry;
|
||||
|
||||
/**
|
||||
* Unit test for implementations of {@link MutablePluginRegistry}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public abstract class AbstractMutablePluginRegistryUnitTest {
|
||||
|
||||
private SamplePlugin plugin = new SamplePluginImplementation();
|
||||
|
||||
@Test
|
||||
public void allowsAddingPluginsAfterCreation() throws Exception {
|
||||
|
||||
MutablePluginRegistry<SamplePlugin, String> registry = getRegistry();
|
||||
registry.addPlugin(plugin);
|
||||
|
||||
assertTrue(registry.contains(plugin));
|
||||
assertThat(registry.getPlugins().size(), is(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link MutablePluginRegistry} to test.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract MutablePluginRegistry<SamplePlugin, String> getRegistry();
|
||||
}
|
||||
@@ -23,7 +23,6 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.core.Ordered;
|
||||
@@ -49,12 +48,6 @@ public class OrderAwarePluginRegistryUnitTest extends SimplePluginRegistryUnitTe
|
||||
secondPlugin = new SecondImplementation();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OrderAwarePluginRegistry<SamplePlugin, String> getRegistry() {
|
||||
|
||||
return OrderAwarePluginRegistry.create();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void honorsOrderOnAddPlugins() throws Exception {
|
||||
|
||||
@@ -63,16 +56,6 @@ public class OrderAwarePluginRegistryUnitTest extends SimplePluginRegistryUnitTe
|
||||
assertOrder(registry, secondPlugin, firstPlugin);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void assertsOrderOnAddingPlugins() throws Exception {
|
||||
|
||||
MutablePluginRegistry<TestPlugin, String> registry = OrderAwarePluginRegistry.create(Arrays.asList(firstPlugin));
|
||||
registry.addPlugin(secondPlugin);
|
||||
|
||||
assertOrder(registry, secondPlugin, firstPlugin);
|
||||
}
|
||||
|
||||
private void assertOrder(PluginRegistry<TestPlugin, String> registry, TestPlugin... plugins) {
|
||||
|
||||
List<TestPlugin> result = registry.getPluginsFor(null);
|
||||
|
||||
@@ -19,21 +19,19 @@ package org.springframework.plugin.core;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.plugin.core.MutablePluginRegistry;
|
||||
import org.springframework.plugin.core.Plugin;
|
||||
import org.springframework.plugin.core.SimplePluginRegistry;
|
||||
|
||||
/**
|
||||
* Unit test for {@link SimplePluginRegistry}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SimplePluginRegistryUnitTest extends AbstractMutablePluginRegistryUnitTest {
|
||||
public class SimplePluginRegistryUnitTest {
|
||||
|
||||
SamplePlugin plugin;
|
||||
|
||||
@@ -49,16 +47,6 @@ public class SimplePluginRegistryUnitTest extends AbstractMutablePluginRegistryU
|
||||
registry = SimplePluginRegistry.create();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.plugin.core.AbstractMutablePluginRegistryUnitTest#getRegistry()
|
||||
*/
|
||||
@Override
|
||||
protected MutablePluginRegistry<SamplePlugin, String> getRegistry() {
|
||||
|
||||
return SimplePluginRegistry.create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the registry contains the plugin it was initialized with.
|
||||
*
|
||||
@@ -67,7 +55,7 @@ public class SimplePluginRegistryUnitTest extends AbstractMutablePluginRegistryU
|
||||
@Test
|
||||
public void assertRegistryInitialized() throws Exception {
|
||||
|
||||
registry.addPlugin(plugin);
|
||||
registry = SimplePluginRegistry.create(Arrays.asList(plugin));
|
||||
|
||||
assertThat(registry.countPlugins(), is(1));
|
||||
assertTrue(registry.contains(plugin));
|
||||
@@ -79,7 +67,7 @@ public class SimplePluginRegistryUnitTest extends AbstractMutablePluginRegistryU
|
||||
@Test
|
||||
public void assertFindsEmailNotificationProvider() {
|
||||
|
||||
registry.addPlugin(plugin);
|
||||
registry = SimplePluginRegistry.create(Arrays.asList(plugin));
|
||||
|
||||
String delimiter = "FOO";
|
||||
|
||||
@@ -135,7 +123,10 @@ public class SimplePluginRegistryUnitTest extends AbstractMutablePluginRegistryU
|
||||
@Test
|
||||
public void handlesAddingNullPluginsCorrecty() throws Exception {
|
||||
|
||||
registry.addPlugin(null);
|
||||
List<SamplePlugin> plugins = new ArrayList<SamplePlugin>();
|
||||
plugins.add(null);
|
||||
|
||||
registry = SimplePluginRegistry.create(plugins);
|
||||
|
||||
assertThat(registry.countPlugins(), is(0));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package org.springframework.plugin.core.support;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.plugin.core.OrderAwarePluginRegistry;
|
||||
import org.springframework.plugin.core.Plugin;
|
||||
import org.springframework.plugin.core.support.AbstractTypeAwareSupport.BeansOfTypeTargetSource;
|
||||
|
||||
//@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class OrderAwarePluginRegistryIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
ApplicationContext context;
|
||||
|
||||
// @Test
|
||||
public void considersJdkProxiedOrderedImplementation() {
|
||||
BeansOfTypeTargetSource targetSource = new AbstractTypeAwareSupport.BeansOfTypeTargetSource(context,
|
||||
TestPlugin.class, false);
|
||||
|
||||
ProxyFactory factory = new ProxyFactory(List.class, targetSource);
|
||||
List<TestPlugin> beans = (List<TestPlugin>) factory.getProxy();
|
||||
OrderAwarePluginRegistry<TestPlugin, String> registry = OrderAwarePluginRegistry.create(beans);
|
||||
|
||||
List<TestPlugin> plugins = registry.getPlugins();
|
||||
}
|
||||
|
||||
private static interface TestPlugin extends Plugin<String> {
|
||||
|
||||
}
|
||||
|
||||
@Order(5)
|
||||
private static class FirstImplementation implements TestPlugin {
|
||||
|
||||
@Override
|
||||
public boolean supports(String delimiter) {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
private static class SecondImplementation implements TestPlugin {
|
||||
|
||||
@Override
|
||||
public boolean supports(String delimiter) {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ThirdImplementation implements TestPlugin, Ordered {
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(String delimiter) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user