Search in sources :

Example 11 with IdentifiableTestEntity

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);
}
Also used : IdentifiableTestEntity(ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity) Test(org.junit.Test)

Example 12 with IdentifiableTestEntity

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());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Order(org.springframework.data.domain.Sort.Order) IdentifiableTestEntity(ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity) Pageable(org.springframework.data.domain.Pageable) IdentifiableTestEntitySpecification(ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntitySpecification) Specification(org.springframework.data.jpa.domain.Specification) Direction(org.springframework.data.domain.Sort.Direction) Test(org.junit.Test)

Example 13 with IdentifiableTestEntity

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());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Order(org.springframework.data.domain.Sort.Order) IdentifiableTestEntity(ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity) Pageable(org.springframework.data.domain.Pageable) IdentifiableTestEntitySpecification(ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntitySpecification) Specification(org.springframework.data.jpa.domain.Specification) Direction(org.springframework.data.domain.Sort.Direction) Test(org.junit.Test)

Example 14 with IdentifiableTestEntity

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()));
}
Also used : IdentifiableTestEntity(ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity) Test(org.junit.Test)

Example 15 with IdentifiableTestEntity

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());
}
Also used : IdentifiableTestEntity(ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

IdentifiableTestEntity (ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity)16 Test (org.junit.Test)16 IdentifiableTestEntitySpecification (ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntitySpecification)4 HashMap (java.util.HashMap)4 PageImpl (org.springframework.data.domain.PageImpl)4 Pageable (org.springframework.data.domain.Pageable)4 Direction (org.springframework.data.domain.Sort.Direction)4 Order (org.springframework.data.domain.Sort.Order)4 Specification (org.springframework.data.jpa.domain.Specification)4 InvalidPropertyException (ca.corefacility.bioinformatics.irida.exceptions.InvalidPropertyException)2 ConstraintViolationException (javax.validation.ConstraintViolationException)2 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 ConstraintViolation (javax.validation.ConstraintViolation)1