Search in sources :

Example 6 with IdentifiableTestEntity

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

Example 7 with IdentifiableTestEntity

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());
}
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 8 with IdentifiableTestEntity

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

Example 9 with IdentifiableTestEntity

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

Example 10 with IdentifiableTestEntity

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();
    }
}
Also used : IdentifiableTestEntity(ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity) ConstraintViolationException(javax.validation.ConstraintViolationException) 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