Results 1 to 4 of 4

Thread: access bean id by name from my unit testing.

  1. #1

    Default access bean id by name from my unit testing.

    i am writing a test for my spring app.

    what i wanted to do is pre-fillup a set of javabeans, for example:

    Code:
    <bean id="name" class="com.Name">
        <set property="firstname">Sample</property>
        <set property="address">Beverly hiils</property>
    </bean>
    
    <bean id="grades" class="com.Grades">
        <set property="quarter">1rst Quarter</property>
        <set property="grade">80</property>    
    </bean>

    my problem is i need to use those bean from my test case.

    is there a way to access them like this or any way like this:

    Code:
    public void testSample&#40;&#41;&#123;
        Name name = context.get&#40;"name"&#41;;
        Grade grade = context.get&#40;"grade"&#41;;
    &#125;

    any help will be very much appreciated.

    thanks a lot in advance.

  2. #2
    Join Date
    Apr 2005
    Location
    Philippines
    Posts
    35

    Default

    I think this would work,

    as long as the you are creating an ApplicationContext based on the xml above.

    and then get the beans from ApplicationContext.getBean(bean_id)

  3. #3
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default Re: access bean id by name from my unit testing.

    Quote Originally Posted by cyber
    Code:
    public void testSample&#40;&#41;&#123;
        Name name = context.get&#40;"name"&#41;;
        Grade grade = context.get&#40;"grade"&#41;;
    &#125;
    Another approach (if you must use the context for testing) is to use the Spring Mock module which allows you to wire JUnit tests without using the 'get'.

    J. Betancourt

  4. #4

    Default

    thx... will do both of your suggestion.

Similar Threads

  1. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •