History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: APF-998
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Matt Raible
Reporter: Matt Raible
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
AppFuse

PersonDaoTest fails in tutorial-jpa

Created: 07/Jan/08 11:21 AM   Updated: 24/Apr/08 10:31 PM
Component/s: Documentation
Affects Version/s: 2.0.1
Fix Version/s: 2.0.2


 Description  « Hide
From http://www.nabble.com/AppFuse-2.0.1---Error-while-testing-the-tutorial-jpa-module-from-appfuse-demos-to14254631s2369.html#a14254631:

I tried the tutorial-jpa module from appfuse-demos. If you run mvn test -Dtest=PersonDaoTest you get the following error message:

-------------------------------------------------------------------------------
Test set: org.appfuse.tutorial.dao.PersonDaoTest
-------------------------------------------------------------------------------
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.444 sec <<< FAILURE!
testFindPersonByLastName(org.appfuse.tutorial.dao.PersonDaoTest) Time elapsed: 0.401 sec <<<
ERROR!
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean
with name 'org.appfuse.tutorial.dao.PersonDaoTest': Unsatisfied dependency expressed
through bean property 'personDao': Set this property value or disable dependency
checking for this bean.

I only can avoid it if I move the <bean id="personDao" class="org.appfuse.tutorial.dao.jpa.PersonDaoJpa"/> entry from src/main/webapp/WEB-INF/applicationContext.xml to src/main/resources/applicationContext-resources.xml.

If this is the only way to do it then it would be an error in your tutorial, because you mention explicitely that src/main/webapp/WEB-INF/applicationContext.xml is the prefered location if you have a base archetype.

 All   Comments   Change History   FishEye      Sort Order:
vijay - 21/Jan/08 01:17 AM
For me, this issue seems to come up only while running the tests
While running a test, the context path for Spring are set to
 AbstractSingleSpringContextTests.loadContextLocations(210) | Loading context for locations: classpath:/applicationContext-resources.xml,classpath:/applicationContext-dao.xml,classpath*:/applicationContext.xml,classpath:**/applicationContext*.xml
Maybe , the applicationContext.xml in the WEB-INF directory is not present in the path.
As of now, I am using applicationContext-resources for my spring DI

Matt Raible - 26/Jan/08 11:11 AM
I was able to resolve this two ways. The first was to change the testResources section to use src/main/webapp/WEB-INF instead of src/main/webapp.
 
       <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
            <testResource>
                <directory>src/main/webapp/WEB-INF</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </testResource>
        </testResources>

After this, I changed it back to src/main/webapp and ran "mvn -U" to get the latest surefire-plugin. After getting the latest surefire version, the test passes when using the default (src/main/webapp).

Hope this helps,

Matt

Waldo Rochow - 08/Mar/08 06:26 PM
I had the same problem with the tutorial-hibernate.

After reading this ticket, I only had to run "mvn -U", and all my problems went away.

Do you think you could add a note about this to the tutorial-hibernate?

Thanks,

Waldo

Matt Raible - 11/Mar/08 01:52 AM
I'll adjust the documentation if there's more reports of this problem on the mailing list.

Ryan WIthers - 24/Apr/08 09:34 PM
test comment.

Ryan WIthers - 24/Apr/08 09:38 PM
Okay the first was a test I think my session timed out the first time I attempted to post. I'm writing an article on appfuse and as a result I'm passing through the tutorial. I noticed the same issues that have been mentioned above. With one exception the command 'mvn -U' did not work for me. The only thing that seemed to help was modifying the testResources area adding the WEB-INF to the directory. I emailed a colleague earlier today concerning this, and I've pasted a snippet from that email below. Please let me know if you need further information:

Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 1.52 sec <<< FAILURE!
testFindEntryByProjectNumber(com.oci.jnb.timeEntry.dao.TimeEntryDAOTest) Time elapsed: 1.482 sec <<< ERROR!
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.oci.jnb.timeEntry.dao.TimeEntryDAOTest': Unsatisfied dependency expressed through bean property 'timeEntryDao': Set this property value or disable dependency checking for this bean.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.checkDependencies(AbstractAutowireCapableBeanFactory.java:1213)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1038)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:291)
    at org.springframework.test.AbstractDependencyInjectionSpringContextTests.injectDependencies(AbstractDependencyInjectionSpringContextTests.java:230)
    at org.springframework.test.AbstractDependencyInjectionSpringContextTests.prepareTestInstance(AbstractDependencyInjectionSpringContextTests.java:195)


So in my ApplicationContext I have the following definition, this file is located in the src/main/webapp/web-inf/ directory.

    <bean id="timeEntryDao" class="com.oci.jnb.timeEntry.dao.hibernate.TimeEntryDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
   

The TimeEntryDAOTest has the setter that I'm interested in injecting. So from the xml fragment above I'm trying to inject the "bean id=timeEntryDao" with the class TimeEntryDaoImpl. This setter is defined as:

   private TimeEntryDao dao = null;
  
   public void setTimeEntryDao(TimeEntryDao timeEntryDao) {
       dao = timeEntryDao;
   }
  

The other interesting thing to note about the TimeEntryDAOTest is that it extends from BaseDaoTestCase which is an appFuse provided class and that extends from AbstractTransactionalDataSourceSpringContextTests. Inside the BaseDaoTestCase there is the following method that is returning config locations:

    protected String[] getConfigLocations() {
        setAutowireMode(AUTOWIRE_BY_NAME);
        return new String[] {
                "classpath:/applicationContext-resources.xml",
                "classpath:/applicationContext-dao.xml",
                "classpath*:/applicationContext.xml", // for modular projects
                "classpath:**/applicationContext*.xml" // for web projects
            };
    }

There are a couple things I don't understand about the method above, one is the asterisks surrounding the file names. It seems like the entry classpath*:/applicationContext.xml could be incorrect.

Thanks for your time,

Ryan


Matt Raible - 24/Apr/08 10:31 PM
You might try using a specific version of the maven-surefire-plugin:

            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.3.1</version>
            </plugin>

The available versions are listed at:

http://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin