Thank you for your reply, Matt!
I have tried a solution for that NullPointerException
without any success. Because I'm feeling completelly idiot,
I decided to post again. I'm so sorry for
this newbie question again.
I add some code to my test case method and I see a 100% sure
that the populate method doesn't load my bean. Your suggestion
about case sensitive for the properties names was accepted and
I changed all to lower case, but the error remains.
Any help are welcome!
--
celeraman+
============================================================
>>> Output for mvn test -Dtest=DepartamentDaoTest -Dsurefire.useFile=false
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.appfuse.tutorial.dao.DepartamentDaoTest
[tutorial] INFO [main] DepartamentDaoTest.loadContextLocations(177) |
Loading co
ntext for locations:
classpath*:/applicationContext-resources.xml,classpath*:/ap
plicationContext-dao.xml,classpath*:/applicationContext.xml,classpath:**/applica
tionContext*.xml
AbandonedObjectPool is used
([EMAIL PROTECTED]
)
LogAbandoned: false
RemoveAbandoned: true
RemoveAbandonedTimeout: 60
[tutorial] INFO [main] DepartamentDaoTest.startNewTransaction(314) | Began
trans
action (1): transaction manager
[org.springframework.orm.hibernate3.HibernateTra
[EMAIL PROTECTED]; default rollback = true
[tutorial] DEBUG [main] DepartamentDaoTest.testCrud(39) | Checking Resource
Bund
le for this test...
[tutorial] DEBUG [main] DepartamentDaoTest.testCrud(51) | Resource bundle:
key:n
ame value: MARKETING
[tutorial] DEBUG [main] DepartamentDaoTest.testCrud(51) | Resource bundle:
key:i
d value: 3
[tutorial] DEBUG [main] DepartamentDaoTest.testCrud(55) | Populate and
Insert fr
om
src/test/resources/org.appfuse.tutorial.dao.DepartamentDaoTest.properties...
[tutorial] DEBUG [main] DepartamentDaoTest.testCrud(60) | Populated
[EMAIL PROTECTED]
id=0
name=<null>
timestamp=2007-04-22 20:38:11.156
]
[tutorial] INFO [main] DepartamentDaoTest.endTransaction(281) | Rolled back
transaction after test execution
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 10.234 sec
<<< FAILURE!
testCrud(org.appfuse.tutorial.dao.DepartamentDaoTest) Time elapsed: 10.093
sec <<< ERROR!
java.lang.NullPointerException
at
org.appfuse.tutorial.dao.DepartamentDaoTest.testCrud(DepartamentDaoTest.java:62)
at
org.appfuse.tutorial.dao.DepartamentDaoTest.testCrud(DepartamentDaoTest.java:62)
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)
Results :
Tests in error:
testCrud(org.appfuse.tutorial.dao.DepartamentDaoTest)
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO]
------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO]
------------------------------------------------------------------------
[INFO] There are test failures.
[INFO]
------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 45 seconds
[INFO] Finished at: Sun Apr 22 20:38:11 GMT 2007
[INFO] Final Memory: 15M/28M
[INFO]
------------------------------------------------------------------------
============================================================
>>> 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 testCrud() throws Exception {
// 0.
log.debug("Checking Resource Bundle for this test...");
ResourceBundle rb = null;
String className = this.getClass().getName();
try {
rb = ResourceBundle.getBundle(className);
} catch (MissingResourceException mre) {
log.warn("No resource bundle found for: " + className);
}
for (Enumeration<String> keys = rb.getKeys();
keys.hasMoreElements();) {
String key = keys.nextElement();
log.debug("Resource bundle: key:"+ key + " value: " +
rb.getString(key));
}
// 1.
log.debug("Populate and Insert from src/test/resources/" + className
+ ".properties...");
Departament Departament = new Departament();
Departament = (Departament) populate(Departament);
log.debug("Populated " + Departament.toString());
DepartamentDao.save(Departament); // <-== <<< NullPointerException
at this code line
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 continua na Base de Dados...");
} catch (DataAccessException dae) {
log.debug("Expected Exception: " + dae.getMessage());
assertNotNull(dae);
}
}
}
============================================================
>>> Departament Class
@Entity
@Table(name="tmx_Departaments")
public class Departament extends BaseObject {
// (1)
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;
}
// others Methods
}
============================================================
== DepartamentDaoTest.properties
id=3
nome=MARKETING
timestamp=2007-04-22 00:00:00.0
--
View this message in context:
http://www.nabble.com/NullPointerException-when-trying-to-populate-in-test-case-tf3604674s2369.html#a10128690
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]