Я пытаюсь запустить несколько тестов junit, и я сталкивался с этой ошибкой в нескольких тестах. Это ошибки, которые я получаю.
[junit] Could not get property value
[junit] java.lang.IllegalStateException: Could not get property value
[junit] at org.hibernate.validator.ClassValidator.getMemberValue(ClassValidator.java:539)
[junit] at org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:384)
[junit] at org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:352)
[junit] at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:139)
[junit] at org.hibernate.validator.event.ValidateEventListener.onPreInsert(ValidateEventListener.java:172)
[junit] at org.hibernate.action.EntityInsertAction.preInsert(EntityInsertAction.java:177)
[junit] at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:72)
[junit] at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268)
[junit] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:260)
[junit] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:179)
[junit] at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
[junit] at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
[junit] at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
[junit] at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:408)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:375)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:738)
[junit] at org.unavco.pbo.mdm.dao.hibernate.BaseDaoHibernate.saveObject(BaseDaoHibernate.java:52)
[junit] at org.unavco.pbo.mdm.dao.hibernate.StationDaoHibernate.saveStation(StationDaoHibernate.java:201)
[junit] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
[junit] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
[junit] at com.sun.proxy.$Proxy30.saveStation(Unknown Source)
[junit] at org.unavco.pbo.mdm.dao.StationFourcharBackwardCompatTest.createAndSaveStation(StationFourcharBackwardCompatTest.java:228)
[junit] at org.unavco.pbo.mdm.dao.StationFourcharBackwardCompatTest.testStationWithFourcharInherit(StationFourcharBackwardCompatTest.java:49)
[junit] at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:79)
[junit] Caused by: java.lang.IllegalStateException: Unable to invoke validateProjectDate
[junit] at org.hibernate.annotations.common.reflection.java.JavaXMethod.invoke(JavaXMethod.java:66)
[junit] at org.hibernate.validator.ClassValidator.getMemberValue(ClassValidator.java:536)
[junit] Caused by: java.lang.reflect.InvocationTargetException
[junit] at org.hibernate.annotations.common.reflection.java.JavaXMethod.invoke(JavaXMethod.java:57)
[junit] Caused by: java.lang.NullPointerException
[junit] at org.unavco.pbo.mdm.model.Station.validateProjectDate(Station.java:740)
Код последней строки, на которую ссылается.
@AssertTrue
private boolean validateProjectDate() {
if (projectDate.before(this.stationProject.getStartDate())) {
return false;
}
if (projectDate.after(this.stationProject.getEndDate())) {
return false;
}
return true;
}
Тест, который затронут.
publi c void testStationWithFourcharInherit () создает исключение {
String fourCharId = "IOA2";
Date projectDate = new Date();
endTransaction();
Locale locale = createAndSaveLocale(fourCharId);
Site site = createAndSaveSite(locale);
Station station = createAndSaveStation(site, fourCharId);
startNewTransaction();
verifyStationMatches(station, fourCharId);
}
Ссылочная функция в тесте.
protected Station createAndSaveStation(Site site, String fourCharId) {
Station station = new Station();
station.setLongName("MyStationsLongName");
if (fourCharId != null) {
station.setFourCharId(fourCharId);
}
StationType stnType = (StationType) stationDao.getObject(StationType.class, 1L);
station.setStationType(stnType);
StationBuildStatus bldStat = (StationBuildStatus) stationDao.getObject(StationBuildStatus.class, 1L);
station.setStationBuildStatus(bldStat);
Project stnProject = (Project) stationDao.getObject(Project.class, 1L);
station.setStationProject(stnProject);
station.setCommsType(CommsType.CDMA);
station.setLatitude(31.009);
station.setLongitude(128.9930);
station.setElevation(890.3);
station.setStationStatus(StationOperationalStatus.Operable);
station.setLongName("long name");
station.setInstallDate(new Date());
station.setProjectDate(new Date());
site.addStation(station);
stationDao.saveStation(station);
stationDao.validateStartDate(station);
return station;
}
Кто-нибудь знает, как исправить эту ошибку?