Search in sources :

Example 51 with DataIntegrityViolationException

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\"");
    }
}
Also used : Vote(com.icthh.xm.ms.entity.domain.Vote) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 52 with DataIntegrityViolationException

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\"");
    }
}
Also used : Calendar(com.icthh.xm.ms.entity.domain.Calendar) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 53 with DataIntegrityViolationException

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\"");
    }
}
Also used : Link(com.icthh.xm.ms.entity.domain.Link) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 54 with DataIntegrityViolationException

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()));
    }
}
Also used : ReportGridRecord(org.finos.waltz.schema.tables.records.ReportGridRecord) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 55 with DataIntegrityViolationException

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");
    }
}
Also used : ObjectId(org.bson.types.ObjectId) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.jupiter.api.Test)

Aggregations

DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)117 Test (org.junit.Test)26 HashMap (java.util.HashMap)12 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)11 Transactional (org.springframework.transaction.annotation.Transactional)11 Test (org.junit.jupiter.api.Test)10 Transactional (javax.transaction.Transactional)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 User (ca.corefacility.bioinformatics.irida.model.user.User)8 SQLException (java.sql.SQLException)8 ConstraintViolation (javax.validation.ConstraintViolation)8 HashSet (java.util.HashSet)7 Locale (java.util.Locale)6 ConstraintViolationException (javax.validation.ConstraintViolationException)6 Date (java.util.Date)5 List (java.util.List)5 Set (java.util.Set)5 EntityExistsException (ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException)4 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)4 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)4