Search in sources :

Example 81 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project irida by phac-nml.

the class ClientsControllerTest method testSubmitEditClientError.

@Test
public void testSubmitEditClientError() {
    IridaClientDetails client = new IridaClientDetails();
    Long id = 1L;
    client.setId(id);
    client.setAutoApprovableScopes(ImmutableSet.of(""));
    ExtendedModelMap model = new ExtendedModelMap();
    when(clientDetailsService.read(id)).thenReturn(client);
    DataIntegrityViolationException ex = new DataIntegrityViolationException("Error: " + IridaClientDetails.CLIENT_ID_CONSTRAINT_NAME);
    when(clientDetailsService.update(any(IridaClientDetails.class))).thenThrow(ex);
    String postCreateClient = controller.postEditClient(id, 0, "", "", "", "", "", "", 0, "", model, locale);
    assertEquals(ClientsController.EDIT_CLIENT_PAGE, postCreateClient);
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) IridaClientDetails(ca.corefacility.bioinformatics.irida.model.IridaClientDetails) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test)

Example 82 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project irida by phac-nml.

the class ClientsControllerTest method testPostCreateClientError.

@Test
public void testPostCreateClientError() {
    IridaClientDetails client = new IridaClientDetails();
    client.setId(1L);
    ExtendedModelMap model = new ExtendedModelMap();
    Locale locale = LocaleContextHolder.getLocale();
    String scope_read = "read";
    String scope_write = "";
    DataIntegrityViolationException ex = new DataIntegrityViolationException("Error: " + IridaClientDetails.CLIENT_ID_CONSTRAINT_NAME);
    when(clientDetailsService.create(client)).thenThrow(ex);
    String postCreateClient = controller.postCreateClient(client, scope_read, scope_write, "", "", "", model, locale);
    assertEquals(ClientsController.ADD_CLIENT_PAGE, postCreateClient);
    assertTrue(model.containsAttribute("errors"));
    @SuppressWarnings("unchecked") Map<String, String> errors = (Map<String, String>) model.get("errors");
    assertTrue(errors.containsKey("clientId"));
    verify(clientDetailsService).create(client);
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) IridaClientDetails(ca.corefacility.bioinformatics.irida.model.IridaClientDetails) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test)

Example 83 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project irida by phac-nml.

the class RemoteAPIControllerTest method testPostCreateRemoteAPIError.

@Test
public void testPostCreateRemoteAPIError() {
    RemoteAPI client = new RemoteAPI("name", "http://uri", "a description", "id", "secret");
    client.setId(1L);
    ExtendedModelMap model = new ExtendedModelMap();
    Locale locale = LocaleContextHolder.getLocale();
    DataIntegrityViolationException ex = new DataIntegrityViolationException("Error: " + RemoteAPI.SERVICE_URI_CONSTRAINT_NAME);
    when(remoteAPIService.create(client)).thenThrow(ex);
    String postCreateClient = remoteAPIController.postCreateRemoteAPI(client, model, locale);
    assertEquals(RemoteAPIController.ADD_API_PAGE, postCreateClient);
    assertTrue(model.containsAttribute("errors"));
    @SuppressWarnings("unchecked") Map<String, String> errors = (Map<String, String>) model.get("errors");
    assertTrue(errors.containsKey("serviceURI"));
    verify(remoteAPIService).create(client);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) Locale(java.util.Locale) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Map(java.util.Map) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test)

Example 84 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project irida by phac-nml.

the class ProjectServiceImplTest method testAlreadyRelatedProject.

@Test(expected = EntityExistsException.class)
public void testAlreadyRelatedProject() {
    Project p1 = new Project("project 1");
    Project p2 = new Project("project 2");
    when(relatedProjectRepository.save(any(RelatedProjectJoin.class))).thenThrow(new DataIntegrityViolationException("relation already exists"));
    projectService.addRelatedProject(p1, p2);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test)

Example 85 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project irida by phac-nml.

the class ProjectServiceImplTest method testAddSampleToProjectAlreadyAdded.

@Test(expected = EntityExistsException.class)
public void testAddSampleToProjectAlreadyAdded() {
    Project p = project();
    Sample s = new Sample();
    s.setSampleName("name");
    Set<ConstraintViolation<Sample>> noViolations = new HashSet<>();
    when(validator.validate(s)).thenReturn(noViolations);
    when(sampleRepository.save(s)).thenReturn(s);
    when(psjRepository.save(any(ProjectSampleJoin.class))).thenThrow(new DataIntegrityViolationException("duplicate"));
    projectService.addSampleToProject(p, s, true);
    verify(sampleRepository).save(s);
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ConstraintViolation(javax.validation.ConstraintViolation) HashSet(java.util.HashSet) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.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