If you put your DepartamentoDaoTest.properties file in
src/test/resources/org/appfuse/tutorial/dao, it should work. Maven
expects your .java files to be in src/test/java and all other files to
be in src/test/resources.  If you'd like to put them alongside the
.java files, you'll need to change your pom.xml to be:

       <testResources>
           <testResource>
               <directory>src/test/resources</directory>
               <filtering>true</filtering>
           </testResource>
           <testResource>
               <directory>src/test/java</directory>
               <includes>
                   <include>**/*.properties</include>
               </includes>
           </testResource>
       </testResources>

Matt


On 4/18/07, celeraman+ <[EMAIL PROTECTED]> wrote:

I'm trying to do a test case based on Person Hibernate Tutorial. The news is
that I want to do this using a .properties file, like the same tutorial for
AppFuse 1.x. I'm using a AppFuse 2.0M4.

However, I got a NullPointerException on the code that will populate the
object.
I couldn't see what is getting wrong...

Thank you so much for any help.
And thank you for AppFuse: that's much more that a amazing starter point! :)

--
celeraman+



The error is as following:

Test set: org.appfuse.tutorial.dao.DepartamentoDaoTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 6.5 sec <<<
FAILURE!
testCrudDepartamento(org.appfuse.tutorial.dao.DepartamentoDaoTest)  Time
elapsed: 6.406 sec  <<< ERROR!
java.lang.NullPointerException
        at org.appfuse.dao.BaseDaoTestCase.populate(BaseDaoTestCase.java:58)
        at
org.appfuse.tutorial.dao.DepartamentoDaoTest.testCrudDepartamento(DepartamentoDaoTest.java:40)
        at
org.appfuse.tutorial.dao.DepartamentoDaoTest.testCrudDepartamento(DepartamentoDaoTest.java:40)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at junit.framework.TestCase.runTest(TestCase.java:164)
        at junit.framework.TestCase.runBare(TestCase.java:130)
        at
org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:120)
        at junit.framework.TestSuite.runTest(TestSuite.java:230)
        at junit.framework.TestSuite.run(TestSuite.java:225)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at
org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
        at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138)
        at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125)
        at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:290)
        at
org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:818)



Classes are following :

// DepartamentDaoTest Class

public class DepartamentDaoTest extends BaseDaoTestCase {

    private DepartamentDao departamentDao = null;

    public void DepartamentDao(DepartamentDao departamentDao) {
        this.departamentDao = departamentDao;
    }

    // CRUD (Create, Read, Update e Delete) Test
    public void testCrudDepartament() throws Exception {

        // 1.
        log.debug("Populate and Insert from
<classname>DaoTest.properties...");

        Departament departament = new Departament();
        departament = (Departament) this.populate(departament); // <-- here
we are the line 40

        departamentDao.save(departament);
        flush();

        // 2.
        log.debug("Reading ...");
        departament = (Departament) departamentDao.get(departament.getId());

        log.debug("Checking Data...");
        assertEquals("MARKETING", departament.getName());
        assertNotNull(departament.getId());

        // 3.
        log.debug("Removing...");
        departamentDao.remove(departament.getId());
        flush();

        try {
            departamentDao.get(departament.getId());
            fail("Departament stays on the database...");
        } catch (DataAccessException dae) {
            log.debug("Expected Exception: " + dae.getMessage());
            assertNotNull(dae);
        }
    }
}

// DepartamentDaoTest.properties
//----------------------------------------------------
id=3
name=MARKETING
timestamp=2007-04-02 00:00:00.0


// Departament Class
-------------------------------------------------------


@Entity
@Table(name="tmx_departaments")
public class Departament extends BaseObject {


    private static final long serialVersionUID = 0x1L;


    // Attributes ---------------------------

    @Id
    @Column(name= "dpr_id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name= "dpr_name", nullable=false, length=25)
    private String name;

    @Column(name= "dpr_timestamp")
    private Timestamp timestamp;


    // Constructors ---------------------------

    public Departament() {
        timestamp = new Timestamp(System.currentTimeMillis());
    }


    // Methods ---------------------------

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Timestamp getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Timestamp timestamp) {
        this.timestamp = timestamp;
    }

        // Other methods

}


--
View this message in context: 
http://www.nabble.com/NullPointerException-when-trying-to-populate-in-test-case-tf3604674s2369.html#a10071049
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--
http://raibledesigns.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to