use of org.springframework.dao.DataIntegrityViolationException in project xm-ms-entity by xm-online.
the class VoteResourceExtendedIntTest method checkStartDateIsRequiredInDb.
@Test
@Transactional
public void checkStartDateIsRequiredInDb() throws Exception {
Vote o = voteService.save(vote);
// set the field null
when(startUpdateDateGenerationStrategy.generateStartDate()).thenReturn(null);
o.setEntryDate(null);
voteService.save(o);
try {
voteRepository.flush();
fail("DataIntegrityViolationException exception was expected!");
} catch (DataIntegrityViolationException e) {
assertThat(e.getMostSpecificCause().getMessage()).containsIgnoringCase("NULL not allowed for column \"ENTRY_DATE\"");
}
}
use of org.springframework.dao.DataIntegrityViolationException in project xm-ms-entity by xm-online.
the class CalendarResourceExtendedIntTest method checkStartDateIsRequiredInDb.
@Test
@Transactional
public void checkStartDateIsRequiredInDb() throws Exception {
Calendar cal = calendarService.save(calendar);
// set the field null
when(startUpdateDateGenerationStrategy.generateStartDate()).thenReturn(null);
cal.setStartDate(null);
calendarService.save(cal);
try {
calendarRepository.flush();
fail("DataIntegrityViolationException exception was expected!");
} catch (DataIntegrityViolationException e) {
assertThat(e.getMostSpecificCause().getMessage()).containsIgnoringCase("NULL not allowed for column \"START_DATE\"");
}
}
use of org.springframework.dao.DataIntegrityViolationException in project xm-ms-entity by xm-online.
the class LinkResourceExtendedIntTest method checkStartDateIsRequiredInDb.
@Test
@Transactional
public void checkStartDateIsRequiredInDb() throws Exception {
Link o = linkService.save(link);
// set the field null
when(startUpdateDateGenerationStrategy.generateStartDate()).thenReturn(null);
o.setStartDate(null);
linkService.save(o);
try {
linkRepository.flush();
fail("DataIntegrityViolationException exception was expected!");
} catch (DataIntegrityViolationException e) {
assertThat(e.getMostSpecificCause().getMessage()).containsIgnoringCase("NULL not allowed for column \"START_DATE\"");
}
}
use of org.springframework.dao.DataIntegrityViolationException in project waltz by khartec.
the class ReportGridDao method create.
public long create(ReportGridCreateCommand createCommand, String username) {
ReportGridRecord record = dsl.newRecord(rg);
record.setName(createCommand.name());
record.setExternalId(createCommand.toExtId(username));
record.setDescription(createCommand.description());
record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
record.setLastUpdatedBy(username);
record.setProvenance("waltz");
record.setKind(createCommand.kind().name());
try {
int insert = record.insert();
return record.getId();
} catch (DataIntegrityViolationException exception) {
throw new DataIntegrityViolationException(format("Grid already exists with the name: %s for user.", createCommand.name()));
}
}
use of org.springframework.dao.DataIntegrityViolationException in project spring-data-mongodb by spring-projects.
the class MongoTemplateTests method throwsExceptionForDuplicateIds.
// DATAMONGO-480
@Test
public void throwsExceptionForDuplicateIds() {
MongoTemplate template = new MongoTemplate(factory);
template.setWriteResultChecking(WriteResultChecking.EXCEPTION);
Person person = new Person(new ObjectId(), "Amol");
person.setAge(28);
template.insert(person);
try {
template.insert(person);
fail("Expected DataIntegrityViolationException!");
} catch (DataIntegrityViolationException e) {
assertThat(e.getMessage()).contains("E11000 duplicate key error");
}
}
Aggregations