use of ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity in project irida by phac-nml.
the class CRUDServiceImplTest method testValidDelete.
@Test
public void testValidDelete() {
IdentifiableTestEntity i = new IdentifiableTestEntity();
i.setId(new Long(1));
when(crudService.exists(i.getId())).thenReturn(Boolean.TRUE);
try {
crudService.delete(i.getId());
} catch (EntityNotFoundException e) {
fail();
}
}
use of ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity in project irida by phac-nml.
the class CRUDServiceImplTest method testCreateEntityExists.
@Test(expected = EntityExistsException.class)
public void testCreateEntityExists() {
IdentifiableTestEntity i = new IdentifiableTestEntity();
i.setId(1L);
when(crudRepository.exists(1L)).thenReturn(true);
crudService.create(i);
}
use of ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity in project irida by phac-nml.
the class CRUDServiceImplTest method testUpdateInvalidEntry.
@Test
public void testUpdateInvalidEntry() {
IdentifiableTestEntity i = new IdentifiableTestEntity();
i.setNonNull("Definitely not null.");
i.setIntegerValue(Integer.MIN_VALUE);
Long id = new Long(1);
i.setId(id);
when(crudRepository.exists(id)).thenReturn(Boolean.TRUE);
when(crudRepository.findOne(id)).thenReturn(i);
Map<String, Object> updatedFields = new HashMap<>();
updatedFields.put("nonNull", null);
try {
crudService.updateFields(id, updatedFields);
fail();
} catch (ConstraintViolationException e) {
Set<ConstraintViolation<?>> violations = e.getConstraintViolations();
assertEquals(1, violations.size());
ConstraintViolation<?> v = violations.iterator().next();
assertEquals("nonNull", v.getPropertyPath().toString());
}
}
use of ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity in project irida by phac-nml.
the class CRUDServiceImplTest method testUpdateWithBadPropertyType.
@Test
public void testUpdateWithBadPropertyType() {
IdentifiableTestEntity entity = new IdentifiableTestEntity();
entity.setId(new Long(1));
Map<String, Object> updatedProperties = new HashMap<>();
updatedProperties.put("integerValue", new Object());
when(crudRepository.findOne(1L)).thenReturn(entity);
try {
crudService.updateFields(entity.getId(), updatedProperties);
fail();
} catch (InvalidPropertyException ex) {
assertNotNull(ex.getAffectedClass());
}
}
use of ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity in project irida by phac-nml.
the class CRUDServiceImplTest method testSearch.
@Test
@SuppressWarnings("unchecked")
public void testSearch() {
int page = 1;
int size = 1;
Direction order = Direction.ASC;
Page<IdentifiableTestEntity> idPage = new PageImpl<>(Lists.newArrayList(new IdentifiableTestEntity(), new IdentifiableTestEntity()));
when(crudRepository.findAll(any(Specification.class), any(Pageable.class))).thenReturn(idPage);
Page<IdentifiableTestEntity> search = crudService.search(IdentifiableTestEntitySpecification.search(), page, size, order);
assertEquals(2, search.getTotalElements());
ArgumentCaptor<Pageable> pageArgument = ArgumentCaptor.forClass(Pageable.class);
verify(crudRepository).findAll(any(Specification.class), pageArgument.capture());
// ensure a created date sort property is set
Pageable pagable = pageArgument.getValue();
Order sort = pagable.getSort().iterator().next();
assertEquals("createdDate", sort.getProperty());
}
Aggregations