|
From: Colin S. <col...@ex...> - 2004-12-05 04:36:04
|
You can autowire by name if you autowire the fields instead of properties...
Dion Almaer wrote:
>The class is working perfectly for me. Thanks again.
>
>There is one thing I noticed:
>
>The class does a:
>
>this.applicationContext.getBeanFactory().autowireBeanProperties(this,
> AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
>
>Maybe I am wrong, but I think there are some use cases where it would be
>nice to have auto-wiring by name.
>
>In fact, my use case would want to be something totally different:
>
>Testing Web Actions:
>
>I want to put in my own BaseTestCase class:
>
> private Action action;
>
> public Action getAction() {
> return action;
> }
>
> public void setAction(Action action) {
> this.action = action;
> }
>
>Then I want to wire up the actual action via:
>
><bean id="addSiteTest" class="foo.web.actions.AddSiteTest">
> <property name="action"><ref bean="addSiteAction"/></property>
></bean>
>
>addSiteAction is a bean id setup in another applicationContext.xml.
>
>So, my ideal would be for Spring to:
>
>- Be able to look in the context to find a bean from the class of the test
>(foo.web.actions.AddSiteTest)
>- Then set the properties on itself, based on the explicit wiring(
>this.setAction( ... Get the addSiteAction bean ... )
>
>Am I thinking about this correctly?
>
>At the moment I have each test class with methods like:
>
> //
>------------------------------------------------------------------------
> // Spring Dependencies: BaseTestCase will autowire by type
> //
>------------------------------------------------------------------------
> private AddSite action;
>
> public AddSite getAction() {
> return action;
> }
>
> public void setAction(AddSite action) {
> this.action = action;
> }
>
>Cheers guys!
>
>D
>
>
>
>-----Original Message-----
>From: Dmitriy Kopylenko [mailto:dko...@ru...]
>Sent: Saturday, December 04, 2004 1:36 PM
>To: spr...@li...
>Subject: Re: [Springframework-developer] Injecting Dependencies into Unit
>Test classes
>
>Colin,
>
>right at the same minute :-)
>
>Colin Sampaleanu wrote:
>
>
>
>>Dion,
>>
>>This already exists. Take a look at the org.springframework.test
>>package which is included with spring-mock.jar. In there you're find
>>AbstractDependencyInjectionSpringContextTests,
>>AbstractTransactionalSpringContextTests, and
>>AbstractTransactionalDataSourceSpringContextTests. They can all inject
>>dependencies via setter injection, or alternately field injection, and
>>the latter two classes also create a transaction around each test, and
>>roll back after each test (by default), so that your database tests
>>can do any kind of db work they need to, verify the results, and then
>>the rollback ensures the original state of the db isn't changed.
>>
>>Colin
>>
>>Dion Almaer wrote:
>>
>>
>>
>>>Hi guys -
>>>
>>>Rather than having FooTest.java do getBean("someBean") it would be
>>>nice to just have setFooBean(...) on the test itself, and have the
>>>dependencies injected.
>>>
>>>I am wondering if people have done this before, and if so, how they
>>>went about it.
>>>
>>>Can you just create a base class which bootstraps everything and
>>>injects the dependencies on the subclass itself?
>>>
>>>Cheers,
>>>
>>>Dion
>>>
>>>
>>>
>>>-------------------------------------------------------
>>>SF email is sponsored by - The IT Product Guide Read honest & candid
>>>reviews on hundreds of IT Products from real users.
>>>Discover which products truly live up to the hype. Start reading now.
>>>http://productguide.itmanagersjournal.com/
>>>_______________________________________________
>>>Springframework-developer mailing list
>>>Spr...@li...
>>>https://lists.sourceforge.net/lists/listinfo/springframework-develope
>>>r
>>>
>>>
>>>
>>>
>>
>>-------------------------------------------------------
>>SF email is sponsored by - The IT Product Guide Read honest & candid
>>reviews on hundreds of IT Products from real users.
>>Discover which products truly live up to the hype. Start reading now.
>>http://productguide.itmanagersjournal.com/
>>_______________________________________________
>>Springframework-developer mailing list
>>Spr...@li...
>>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>>
>>
>
>
>
>
>-------------------------------------------------------
>SF email is sponsored by - The IT Product Guide Read honest & candid reviews
>on hundreds of IT Products from real users.
>Discover which products truly live up to the hype. Start reading now.
>http://productguide.itmanagersjournal.com/
>_______________________________________________
>Springframework-developer mailing list
>Spr...@li...
>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
>
>
>-------------------------------------------------------
>SF email is sponsored by - The IT Product Guide
>Read honest & candid reviews on hundreds of IT Products from real users.
>Discover which products truly live up to the hype. Start reading now.
>http://productguide.itmanagersjournal.com/
>_______________________________________________
>Springframework-developer mailing list
>Spr...@li...
>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
|