use of com.qcadoo.model.api.search.SearchResult in project qcadoo by qcadoo.
the class DataAccessServiceFindTest method shouldReturnValidEntities.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldReturnValidEntities() throws Exception {
// given
List<SampleSimpleDatabaseObject> databaseObjects = new ArrayList<SampleSimpleDatabaseObject>();
databaseObjects.add(createDatabaseObject(1L, "name1", 1));
databaseObjects.add(createDatabaseObject(2L, "name2", 2));
databaseObjects.add(createDatabaseObject(3L, "name3", 3));
databaseObjects.add(createDatabaseObject(4L, "name4", 4));
SearchCriteriaBuilder searchCriteriaBuilder = dataDefinition.find().setFirstResult(0).setMaxResults(4);
given(hibernateService.getTotalNumberOfEntities(Mockito.any(Criteria.class))).willReturn(4);
given(hibernateService.list(Mockito.any(Criteria.class))).willReturn((List) databaseObjects);
// when
SearchResult resultSet = searchCriteriaBuilder.list();
// then
assertEquals(4, resultSet.getTotalNumberOfEntities());
assertEquals(4, resultSet.getEntities().size());
assertEquals(Long.valueOf(1L), resultSet.getEntities().get(0).getId());
assertEquals(Long.valueOf(2L), resultSet.getEntities().get(1).getId());
assertEquals(Long.valueOf(3L), resultSet.getEntities().get(2).getId());
assertEquals(Long.valueOf(4L), resultSet.getEntities().get(3).getId());
}
use of com.qcadoo.model.api.search.SearchResult in project qcadoo by qcadoo.
the class DictionaryServiceImpl method createIfNotExists.
@Override
@Transactional
@Monitorable
public void createIfNotExists(final String pluginIdentifier, final String name, final String... values) {
SearchResult serachResult = getDictionaryDataDefinition().find().add(SearchRestrictions.eq(DictionaryFields.NAME, name)).list();
if (serachResult.getTotalNumberOfEntities() > 0) {
Entity dictionaryEntity = serachResult.getEntities().get(0);
dictionaryEntity.setField(DictionaryFields.ACTIVE, true);
getDictionaryDataDefinition().save(dictionaryEntity);
return;
}
Entity dictionary = getDictionaryDataDefinition().create();
dictionary.setField(DictionaryFields.PLUGIN_IDENTIFIER, pluginIdentifier);
dictionary.setField(DictionaryFields.NAME, name);
dictionary.setField(DictionaryFields.ACTIVE, true);
dictionary = getDictionaryDataDefinition().save(dictionary);
for (String value : values) {
Entity item = getItemDataDefinition().create();
item.setField(DictionaryItemFields.DICTIONARY, dictionary);
item.setField(DictionaryItemFields.DESCRIPTION, "");
item.setField(DictionaryItemFields.NAME, value);
getItemDataDefinition().save(item);
}
}
use of com.qcadoo.model.api.search.SearchResult in project qcadoo by qcadoo.
the class GridComponentStateTest method shouldNotModeDownSelectedEntityOnFail.
@Test(expected = IllegalStateException.class)
public void shouldNotModeDownSelectedEntityOnFail() throws Exception {
// given
FieldEntityIdChangeListener listener = mock(FieldEntityIdChangeListener.class);
SearchResult result = mock(SearchResult.class);
given(substituteCriteria.list()).willReturn(result);
given(result.getTotalNumberOfEntities()).willReturn(0);
given(result.getEntities()).willReturn(Collections.<Entity>emptyList());
willThrow(new IllegalStateException()).given(substituteDataDefinition).move(13L, 1);
grid.initialize(json, Locale.ENGLISH);
grid.addFieldEntityIdChangeListener("field", listener);
// when
grid.performEvent(viewDefinitionState, "moveDown");
}
use of com.qcadoo.model.api.search.SearchResult in project qcadoo by qcadoo.
the class GridComponentStateTest method shouldRefresh.
@Test
public void shouldRefresh() throws Exception {
// given
FieldEntityIdChangeListener listener = mock(FieldEntityIdChangeListener.class);
SearchResult result = mock(SearchResult.class);
given(substituteCriteria.list()).willReturn(result);
given(result.getTotalNumberOfEntities()).willReturn(0);
given(result.getEntities()).willReturn(Collections.<Entity>emptyList());
grid.initialize(json, Locale.ENGLISH);
grid.addFieldEntityIdChangeListener("field", listener);
// when
grid.performEvent(viewDefinitionState, "refresh");
}
use of com.qcadoo.model.api.search.SearchResult in project qcadoo by qcadoo.
the class GridComponentStateTest method shouldSelectEntity.
@Test
public void shouldSelectEntity() throws Exception {
// given
FieldEntityIdChangeListener listener = mock(FieldEntityIdChangeListener.class);
SearchResult result = mock(SearchResult.class);
given(substituteCriteria.list()).willReturn(result);
given(result.getTotalNumberOfEntities()).willReturn(0);
given(result.getEntities()).willReturn(Collections.<Entity>emptyList());
grid.initialize(json, Locale.ENGLISH);
grid.addFieldEntityIdChangeListener("field", listener);
// when
grid.performEvent(viewDefinitionState, "select");
// then
verify(listener).onFieldEntityIdChange(13L);
}
Aggregations