GenericSpringResourceBuilder extends AbstractSpringResourceBuilder<T> { @Override public T build() { final T t = getBean( clazz, beanName ); try { wireMetadata( t.getClass(), t ); } catch ( Exception e ) { LOG.debug( "Couldn't inject metadata.", e ); throw new ResourceInitException( "Couldn't inject metadata.", e ); } return t; } GenericSpringResourceBuilder( final Workspace workspace, final SingleBeanRef singleBeanRef,
                                         final Class<T> clazz, final GenericSpringResourceMetadata<T> metadata ); @Override T build();  }
@Test public void testInjectMetadata() { final TestProvider provider = new TestProvider(); final InputStream testConfig = GenericSpringResourceBuilderTest.class.getClassLoader().getResourceAsStream( "org/deegree/spring/test.xml" ); assertNotNull( testConfig ); @SuppressWarnings("unchecked") final ResourceLocation<SingleBean> location = mock( ResourceLocation.class ); when( location.getAsStream() ).thenReturn( testConfig ); when( location.getIdentifier() ).thenReturn( new DefaultResourceIdentifier<SingleBean>( TestProvider.class, "test" ) ); final ResourceMetadata<SingleBean> metadata = provider.createFromLocation( workspace, location ); assertNotNull( metadata ); final ResourceBuilder<SingleBean> builder = metadata.prepare(); assertNotNull( builder ); final SingleBean beanFromComtext = context.getBean( SingleBean.class ); assertNull( beanFromComtext.getMetadata() ); final SingleBean beanFromBuilder = builder.build(); assertNotNull( beanFromBuilder ); assertEquals( beanFromComtext, beanFromBuilder ); assertEquals( metadata, beanFromBuilder.getMetadata() ); }