use of ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity in project irida by phac-nml.
the class CRUDServiceImplTest method testUpdateMultiple.
@Test
public void testUpdateMultiple() {
IdentifiableTestEntity ent1 = new IdentifiableTestEntity();
ent1.setNonNull("Definitely not null.");
ent1.setIntegerValue(Integer.MIN_VALUE);
ent1.setLabel("label");
Long id = 1L;
ent1.setId(id);
IdentifiableTestEntity ent2 = new IdentifiableTestEntity();
ent2.setNonNull("Another entity");
ent2.setIntegerValue(Integer.MAX_VALUE);
ent2.setLabel("label");
Long id2 = 2L;
ent2.setId(id);
when(crudRepository.exists(id)).thenReturn(true);
when(crudRepository.exists(id2)).thenReturn(true);
crudService.updateMultiple(Lists.newArrayList(ent1, ent2));
verify(crudRepository).save(ent1);
verify(crudRepository).save(ent2);
}
use of ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity in project irida by phac-nml.
the class CRUDServiceImplTest method testSearchSortSetProperty.
@Test
@SuppressWarnings("unchecked")
public void testSearchSortSetProperty() {
int page = 1;
int size = 1;
String property = "nonNull";
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, property);
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(property, sort.getProperty());
}
use of ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity in project irida by phac-nml.
the class CRUDServiceImplTest method testSearchSortEmptyArray.
@Test
@SuppressWarnings("unchecked")
public void testSearchSortEmptyArray() {
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, new String[0]);
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 testExists.
@Test
public void testExists() {
IdentifiableTestEntity i = new IdentifiableTestEntity();
i.setId(new Long(1));
when(crudRepository.exists(i.getId())).thenReturn(Boolean.TRUE);
assertTrue(crudService.exists(i.getId()));
}
use of ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity in project irida by phac-nml.
the class CRUDServiceImplTest method testUpdateFields.
@Test
public void testUpdateFields() throws InterruptedException {
IdentifiableTestEntity before = new IdentifiableTestEntity();
before.setNonNull("Definitely not null.");
before.setIntegerValue(Integer.MIN_VALUE);
Long id = 1L;
before.setId(id);
String newNonNull = "new value";
when(crudRepository.exists(id)).thenReturn(Boolean.TRUE);
when(crudRepository.findOne(id)).thenReturn(before);
ArgumentCaptor<IdentifiableTestEntity> pageArgument = ArgumentCaptor.forClass(IdentifiableTestEntity.class);
Map<String, Object> updatedFields = new HashMap<>();
updatedFields.put("nonNull", newNonNull);
// need to sleep for a bit so that the dates are different
Thread.sleep(500L);
crudService.updateFields(id, updatedFields);
verify(crudRepository).save(pageArgument.capture());
IdentifiableTestEntity captured = pageArgument.getValue();
assertEquals(newNonNull, captured.getNonNull());
}
Aggregations