use of ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity in project irida by phac-nml.
the class CRUDServiceImplTest method testList.
@Test
public void testList() {
int itemCount = 10;
List<IdentifiableTestEntity> entities = new ArrayList<>();
for (int i = 0; i < itemCount; i++) {
entities.add(new IdentifiableTestEntity());
}
when(crudRepository.findAll()).thenReturn(entities);
Iterable<IdentifiableTestEntity> items = crudService.findAll();
assertEquals(entities, items);
}
use of ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity in project irida by phac-nml.
the class CRUDServiceImplTest method testSearchSortEmptyString.
@Test
@SuppressWarnings("unchecked")
public void testSearchSortEmptyString() {
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());
}
use of ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity in project irida by phac-nml.
the class CRUDServiceImplTest method testUpdateNotExists.
@Test(expected = EntityNotFoundException.class)
public void testUpdateNotExists() {
IdentifiableTestEntity i = new IdentifiableTestEntity();
i.setId(1L);
when(crudRepository.exists(1L)).thenReturn(false);
crudService.update(i);
}
use of ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity in project irida by phac-nml.
the class CRUDServiceImplTest method testUpdateWithBadPropertyName.
@Test
public void testUpdateWithBadPropertyName() {
IdentifiableTestEntity entity = new IdentifiableTestEntity();
entity.setId(1L);
Map<String, Object> updatedProperties = new HashMap<>();
updatedProperties.put("noSuchField", 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 testAddValidObject.
@Test
public void testAddValidObject() {
IdentifiableTestEntity i = new IdentifiableTestEntity();
i.setNonNull("Definitely not null.");
i.setLabel("labelled");
try {
crudService.create(i);
} catch (ConstraintViolationException constraintViolations) {
fail();
}
}
Aggregations