@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public List<Experiment> list(String schearch) { if (Strings.isNullOrEmpty(schearch)) return repository.all(QExperiment.experiment, createConstructiorExpression()); return repository.list( QExperiment.experiment, QExperiment.experiment.name.containsIgnoreCase(schearch), createConstructiorExpression()); }
@Test(expected = AppException.class) public void deleteWithError() throws AppException { Mockito.when(repository.findById(ID, SampleEntity.class)) .thenThrow(new IllegalArgumentException("Error")); service.delete(ID); Mockito.verify(repository).delete(createSampleEntity(ID, null)); }
@Test public void delete() throws AppException { Mockito.when(repository.findById(ID, SampleEntity.class)) .thenReturn(createSampleEntity(ID, null)); service.delete(ID); Mockito.verify(repository).delete(createSampleEntity(ID, null)); }
@Test public void create() throws AppException { SampleEntity sample = createSampleEntity(ID, "IPI"); Mockito.when(repository.save(sample)).thenReturn(createSampleEntity(ID, "IPI")); SampleEntity newSample = service.create(sample); Mockito.verify(repository).save(sample); MatcherAssert.assertThat(newSample.id, Matchers.equalTo(ID)); }
@Test public void find() throws AppException { Mockito.when(repository.findById(ID, SampleEntity.class)) .thenReturn(createSampleEntity(ID, null)); SampleEntity sample = service.find(ID); Mockito.verify(repository).findById(ID, SampleEntity.class); MatcherAssert.assertThat(sample, Matchers.equalTo(createSampleEntity(ID, null))); }
@Test public void listAll() { Mockito.when(repository.all(QSampleEntity.sampleEntity, QSampleEntity.sampleEntity)) .thenReturn(getList()); List<SampleEntity> list = service.list(""); Mockito.verify(repository).all(QSampleEntity.sampleEntity, QSampleEntity.sampleEntity); MatcherAssert.assertThat(list, Matchers.hasSize(1)); MatcherAssert.assertThat(list, Matchers.contains(createSampleEntity(ID, null))); }
@Test public void listWithError() { String schearch = "search"; Mockito.when( repository.list( QSampleEntity.sampleEntity, service.getFilter(schearch), QSampleEntity.sampleEntity)) .thenReturn(getList()); List<SampleEntity> list = service.list(schearch); Mockito.verify(repository) .list(QSampleEntity.sampleEntity, service.getFilter(schearch), QSampleEntity.sampleEntity); MatcherAssert.assertThat(list, Matchers.hasSize(1)); MatcherAssert.assertThat(list, Matchers.contains(createSampleEntity(ID, null))); }
@Test(expected = AppException.class) public void createWithError() throws AppException { when(repository.save(createSampleEntity(ID, null))) .thenThrow(new IllegalArgumentException("Error")); service.create(createSampleEntity(ID, null)); }
@Test(expected = AppException.class) public void findByIdWithError() throws AppException { when(repository.findById(ID, SampleEntity.class)) .thenThrow(new IllegalArgumentException("Error")); service.find(ID); }