Search in sources :

Example 1 with IdentifiableTestEntity

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

Example 2 with IdentifiableTestEntity

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

Example 3 with IdentifiableTestEntity

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

Example 4 with IdentifiableTestEntity

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

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

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