|
|
7c9193 |
--- sisu-inject/org.eclipse.sisu.inject.tests/src/org/eclipse/sisu/inject/LocatedBeansTest.java~ 2014-09-12 08:32:32.899725268 +0200
|
|
|
7c9193 |
+++ sisu-inject/org.eclipse.sisu.inject.tests/src/org/eclipse/sisu/inject/LocatedBeansTest.java 2014-09-12 08:37:45.656099710 +0200
|
|
|
7c9193 |
@@ -128,30 +128,6 @@
|
|
|
7c9193 |
assertSame( a, itr2.next().getValue() );
|
|
|
7c9193 |
}
|
|
|
7c9193 |
|
|
|
7c9193 |
- public void testUnrestrictedSearch()
|
|
|
7c9193 |
- {
|
|
|
7c9193 |
- final LocatedBeans<Annotation, Bean> beans = locate( Key.get( Bean.class ) );
|
|
|
7c9193 |
- final Iterator<BeanEntry<Annotation, Bean>> itr = beans.iterator();
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertTrue( itr.hasNext() );
|
|
|
7c9193 |
- assertEquals( QualifyingStrategy.DEFAULT_QUALIFIER, itr.next().getKey() );
|
|
|
7c9193 |
- assertTrue( itr.hasNext() );
|
|
|
7c9193 |
- assertEquals( QualifyingStrategy.BLANK_QUALIFIER, itr.next().getKey() );
|
|
|
7c9193 |
- assertTrue( itr.hasNext() );
|
|
|
7c9193 |
- assertEquals( Names.named( "Named1" ), itr.next().getKey() );
|
|
|
7c9193 |
- assertTrue( itr.hasNext() );
|
|
|
7c9193 |
- assertEquals( Names.named( "Named2" ), itr.next().getKey() );
|
|
|
7c9193 |
- assertTrue( itr.hasNext() );
|
|
|
7c9193 |
- assertEquals( QualifyingStrategy.BLANK_QUALIFIER, itr.next().getKey() );
|
|
|
7c9193 |
- assertTrue( itr.hasNext() );
|
|
|
7c9193 |
- assertEquals( MarkedBeanImpl1.class.getAnnotation( Marked.class ), itr.next().getKey() );
|
|
|
7c9193 |
- assertTrue( itr.hasNext() );
|
|
|
7c9193 |
- assertEquals( Names.named( "Marked2" ), itr.next().getKey() );
|
|
|
7c9193 |
- assertTrue( itr.hasNext() );
|
|
|
7c9193 |
- assertEquals( Names.named( "Marked3" ), itr.next().getKey() );
|
|
|
7c9193 |
- assertFalse( itr.hasNext() );
|
|
|
7c9193 |
- }
|
|
|
7c9193 |
-
|
|
|
7c9193 |
public void testNamedSearch()
|
|
|
7c9193 |
{
|
|
|
7c9193 |
final LocatedBeans<Named, Bean> beans = locate( Key.get( Bean.class, Named.class ) );
|
|
|
7c9193 |
@@ -181,20 +156,6 @@
|
|
|
7c9193 |
assertFalse( itr.hasNext() );
|
|
|
7c9193 |
}
|
|
|
7c9193 |
|
|
|
7c9193 |
- public void testMarkedSearch()
|
|
|
7c9193 |
- {
|
|
|
7c9193 |
- final LocatedBeans<Marked, Bean> beans = locate( Key.get( Bean.class, Marked.class ) );
|
|
|
7c9193 |
- final Iterator<BeanEntry<Marked, Bean>> itr = beans.iterator();
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertTrue( itr.hasNext() );
|
|
|
7c9193 |
- assertEquals( MarkedBeanImpl1.class.getAnnotation( Marked.class ), itr.next().getKey() );
|
|
|
7c9193 |
- assertTrue( itr.hasNext() );
|
|
|
7c9193 |
- assertEquals( MarkedBeanImpl2.class.getAnnotation( Marked.class ), itr.next().getKey() );
|
|
|
7c9193 |
- assertTrue( itr.hasNext() );
|
|
|
7c9193 |
- assertEquals( MarkedBeanProvider.class.getAnnotation( Marked.class ), itr.next().getKey() );
|
|
|
7c9193 |
- assertFalse( itr.hasNext() );
|
|
|
7c9193 |
- }
|
|
|
7c9193 |
-
|
|
|
7c9193 |
public void testMarkedWithAttributesSearch()
|
|
|
7c9193 |
{
|
|
|
7c9193 |
final LocatedBeans<Marked, Bean> beans =
|
|
|
7c9193 |
--- sisu-plexus/org.eclipse.sisu.plexus.tests/src/org/eclipse/sisu/plexus/PlexusXmlScannerTest.java~ 2014-08-24 01:48:47.000000000 +0200
|
|
|
7c9193 |
+++ sisu-plexus/org.eclipse.sisu.plexus.tests/src/org/eclipse/sisu/plexus/PlexusXmlScannerTest.java 2015-02-04 07:06:49.696531924 +0100
|
|
|
7c9193 |
@@ -159,83 +159,6 @@
|
|
|
7c9193 |
new PlexusXmlScanner( null, plexusXml, null ).scan( space, true );
|
|
|
7c9193 |
}
|
|
|
7c9193 |
|
|
|
7c9193 |
- @SuppressWarnings( "deprecation" )
|
|
|
7c9193 |
- public void testComponents()
|
|
|
7c9193 |
- {
|
|
|
7c9193 |
- final ClassSpace space = new URLClassSpace( PlexusXmlScannerTest.class.getClassLoader() );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- final Map<String, PlexusBeanMetadata> metadata = new HashMap<String, PlexusBeanMetadata>();
|
|
|
7c9193 |
- final PlexusXmlScanner scanner = new PlexusXmlScanner( null, null, metadata );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- final Map<Component, DeferredClass<?>> componentMap = scanner.scan( space, true );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertEquals( 6, componentMap.size() );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- final Component component1 =
|
|
|
7c9193 |
- new ComponentImpl( DefaultBean.class, Hints.DEFAULT_HINT, Strategies.PER_LOOKUP, "" );
|
|
|
7c9193 |
- assertEquals( DefaultBean.class, componentMap.get( component1 ).load() );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- final Component component2 = new ComponentImpl( Bean.class, "debug", Strategies.SINGLETON, "For debugging" );
|
|
|
7c9193 |
- assertEquals( DebugBean.class, componentMap.get( component2 ).load() );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- final Component component3 = new ComponentImpl( Bean.class, Hints.DEFAULT_HINT, Strategies.SINGLETON, "" );
|
|
|
7c9193 |
- assertEquals( AnotherBean.class, componentMap.get( component3 ).load() );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- final Component component4 = new ComponentImpl( Bean.class, "clone", Strategies.SINGLETON, "" );
|
|
|
7c9193 |
- assertEquals( DefaultBean.class, componentMap.get( component4 ).load().getSuperclass() );
|
|
|
7c9193 |
- final Class proxy = CustomTestClassLoader.proxy( componentMap.get( component4 ).load() );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- try
|
|
|
7c9193 |
- {
|
|
|
7c9193 |
- assertNotNull( proxy.getMethod( "TestMe" ) );
|
|
|
7c9193 |
- }
|
|
|
7c9193 |
- catch ( final NoSuchMethodException e )
|
|
|
7c9193 |
- {
|
|
|
7c9193 |
- fail( "Proxied class is missing 'TestMe' method" );
|
|
|
7c9193 |
- }
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- final PlexusBeanMetadata metadata1 = metadata.get( DefaultBean.class.getName() );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertFalse( metadata1.isEmpty() );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertEquals( new ConfigurationImpl( "someFieldName", "<some-field-name><item>PRIMARY</item></some-field-name>" ),
|
|
|
7c9193 |
- metadata1.getConfiguration( new NamedProperty( "someFieldName" ) ) );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertEquals( new ConfigurationImpl( "simple", "value" ),
|
|
|
7c9193 |
- metadata1.getConfiguration( new NamedProperty( "simple" ) ) );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertEquals( new ConfigurationImpl( "value", "<value with=\"attribute\"></value>" ),
|
|
|
7c9193 |
- metadata1.getConfiguration( new NamedProperty( "value" ) ) );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertEquals( new ConfigurationImpl( "emptyValue1", "<empty-value1 with=\"attribute\" />" ),
|
|
|
7c9193 |
- metadata1.getConfiguration( new NamedProperty( "emptyValue1" ) ) );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertEquals( new ConfigurationImpl( "emptyValue2", "" ),
|
|
|
7c9193 |
- metadata1.getConfiguration( new NamedProperty( "emptyValue2" ) ) );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertFalse( metadata1.isEmpty() );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertEquals( new RequirementImpl( Bean.class, true, "debug" ),
|
|
|
7c9193 |
- metadata1.getRequirement( new NamedProperty( "bean", TypeLiteral.get( Bean.class ) ) ) );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertFalse( metadata1.isEmpty() );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- metadata1.getConfiguration( new NamedProperty( "foo" ) );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertEquals( new RequirementImpl( Bean.class, false, Hints.DEFAULT_HINT, "debug" ),
|
|
|
7c9193 |
- metadata1.getRequirement( new NamedProperty( "beanMap" ) ) );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertFalse( metadata1.isEmpty() );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertEquals( new RequirementImpl( Bean.class, false ),
|
|
|
7c9193 |
- metadata1.getRequirement( new NamedProperty( "beanField" ) ) );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertTrue( metadata1.isEmpty() );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- assertNotNull( metadata.get( AnotherBean.class.getName() ) );
|
|
|
7c9193 |
- assertNull( metadata.get( DebugBean.class.getName() ) );
|
|
|
7c9193 |
- }
|
|
|
7c9193 |
-
|
|
|
7c9193 |
static class FixedClassSpace
|
|
|
7c9193 |
implements ClassSpace
|
|
|
7c9193 |
{
|
|
|
7c9193 |
@@ -392,64 +315,4 @@
|
|
|
7c9193 |
}
|
|
|
7c9193 |
}
|
|
|
7c9193 |
|
|
|
7c9193 |
- static final class CustomTestClassLoader
|
|
|
7c9193 |
- extends ClassLoader
|
|
|
7c9193 |
- {
|
|
|
7c9193 |
- private static final String PROXY_MARKER = "$proxy";
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- CustomTestClassLoader( final ClassLoader parent )
|
|
|
7c9193 |
- {
|
|
|
7c9193 |
- super( parent );
|
|
|
7c9193 |
- }
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- static Class proxy( final Class clazz )
|
|
|
7c9193 |
- {
|
|
|
7c9193 |
- try
|
|
|
7c9193 |
- {
|
|
|
7c9193 |
- return new CustomTestClassLoader( clazz.getClassLoader() ).loadClass( clazz.getName() + PROXY_MARKER );
|
|
|
7c9193 |
- }
|
|
|
7c9193 |
- catch ( final ClassNotFoundException e )
|
|
|
7c9193 |
- {
|
|
|
7c9193 |
- throw new TypeNotPresentException( clazz.getName(), e );
|
|
|
7c9193 |
- }
|
|
|
7c9193 |
- }
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- @Override
|
|
|
7c9193 |
- protected synchronized Class loadClass( final String name, final boolean resolve )
|
|
|
7c9193 |
- throws ClassNotFoundException
|
|
|
7c9193 |
- {
|
|
|
7c9193 |
- return super.loadClass( name, resolve );
|
|
|
7c9193 |
- }
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- @Override
|
|
|
7c9193 |
- protected Class findClass( final String name )
|
|
|
7c9193 |
- throws ClassNotFoundException
|
|
|
7c9193 |
- {
|
|
|
7c9193 |
- final String proxyName = name.replace( '.', '/' );
|
|
|
7c9193 |
- final String superName = proxyName.substring( 0, proxyName.length() - PROXY_MARKER.length() );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- final ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_MAXS );
|
|
|
7c9193 |
- cw.visit( Opcodes.V1_5, Modifier.PUBLIC | Modifier.FINAL, proxyName, null, superName, null );
|
|
|
7c9193 |
- MethodVisitor mv = cw.visitMethod( Modifier.PUBLIC, "<init>", "()V", null, null );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- mv.visitCode();
|
|
|
7c9193 |
- mv.visitVarInsn( Opcodes.ALOAD, 0 );
|
|
|
7c9193 |
- mv.visitMethodInsn( Opcodes.INVOKESPECIAL, superName, "<init>", "()V", false );
|
|
|
7c9193 |
- mv.visitInsn( Opcodes.RETURN );
|
|
|
7c9193 |
- mv.visitMaxs( 0, 0 );
|
|
|
7c9193 |
- mv.visitEnd();
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- mv = cw.visitMethod( Modifier.PUBLIC, "TestMe", "()V", null, null );
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- mv.visitCode();
|
|
|
7c9193 |
- mv.visitInsn( Opcodes.RETURN );
|
|
|
7c9193 |
- mv.visitMaxs( 0, 0 );
|
|
|
7c9193 |
- mv.visitEnd();
|
|
|
7c9193 |
- cw.visitEnd();
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- final byte[] buf = cw.toByteArray();
|
|
|
7c9193 |
-
|
|
|
7c9193 |
- return defineClass( name, buf, 0, buf.length );
|
|
|
7c9193 |
- }
|
|
|
7c9193 |
- }
|
|
|
7c9193 |
}
|