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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations