use of com.qcadoo.model.api.FieldDefinition in project qcadoo by qcadoo.
the class EntityTreeImplTest method shouldFailIfThereAreMultipleRoots.
@Test(expected = IllegalStateException.class)
public void shouldFailIfThereAreMultipleRoots() throws Exception {
// given
Entity entity1 = mock(Entity.class);
given(entity1.getId()).willReturn(1L);
Entity entity2 = mock(Entity.class);
given(entity2.getId()).willReturn(2L);
List<Entity> entities = Arrays.asList(new Entity[] { entity1, entity2 });
BelongsToType fieldType = mock(BelongsToType.class);
InternalDataDefinition dataDefinition = mock(InternalDataDefinition.class, RETURNS_DEEP_STUBS);
given(fieldType.getDataDefinition()).willReturn(dataDefinition);
FieldDefinition fieldDefinition = mock(FieldDefinition.class);
given(fieldDefinition.getType()).willReturn(fieldType);
given(fieldDefinition.getName()).willReturn("field");
given(dataDefinition.getField("tree")).willReturn(fieldDefinition);
given(dataDefinition.find().add(SearchRestrictions.belongsTo("field", dataDefinition, 1L)).addOrder(SearchOrders.asc("priority")).list().getEntities()).willReturn(entities);
EntityTreeImpl tree = new EntityTreeImpl(dataDefinition, "tree", 1L);
// when
tree.size();
}
use of com.qcadoo.model.api.FieldDefinition in project qcadoo by qcadoo.
the class EntityTreeImplTest method shouldFailIfThereIsNoRoot.
@Test(expected = IllegalStateException.class)
public void shouldFailIfThereIsNoRoot() throws Exception {
// given
Entity entity = mock(Entity.class);
given(entity.getBelongsToField("parent")).willReturn(entity);
List<Entity> entities = Collections.singletonList(entity);
BelongsToType fieldType = mock(BelongsToType.class);
InternalDataDefinition dataDefinition = mock(InternalDataDefinition.class, RETURNS_DEEP_STUBS);
given(fieldType.getDataDefinition()).willReturn(dataDefinition);
FieldDefinition fieldDefinition = mock(FieldDefinition.class);
given(fieldDefinition.getType()).willReturn(fieldType);
given(fieldDefinition.getName()).willReturn("field");
given(dataDefinition.getField("tree")).willReturn(fieldDefinition);
given(dataDefinition.find().add(SearchRestrictions.belongsTo("field", dataDefinition, 1L)).addOrder(SearchOrders.asc("priority")).list().getEntities()).willReturn(entities);
EntityTreeImpl tree = new EntityTreeImpl(dataDefinition, "tree", 1L);
// when
tree.size();
}
use of com.qcadoo.model.api.FieldDefinition in project qcadoo by qcadoo.
the class FormComponentStateTest method init.
@Before
public void init() throws Exception {
entity = mock(Entity.class);
given(entity.getField("name")).willReturn("text");
viewDefinitionState = mock(ViewDefinitionState.class);
translationService = mock(TranslationService.class);
fieldDefinition = mock(FieldDefinition.class);
given(fieldDefinition.getType()).willReturn(new StringType());
given(fieldDefinition.getName()).willReturn("name");
dataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
given(dataDefinition.get(12L)).willReturn(null);
given(dataDefinition.get(13L)).willReturn(entity);
given(dataDefinition.getPluginIdentifier()).willReturn("plugin");
given(dataDefinition.getName()).willReturn("name");
given(dataDefinition.getField("name")).willReturn(fieldDefinition);
given(dataDefinition.delete(any(Long.class))).willReturn(EntityOpResult.successfull());
given(dataDefinition.create(anyLong())).willAnswer(new Answer<Entity>() {
@Override
public Entity answer(final InvocationOnMock invocation) throws Throwable {
Long id = (Long) invocation.getArguments()[0];
return new DefaultEntity(dataDefinition, id);
}
});
FieldComponentPattern namePattern = mock(FieldComponentPattern.class);
given(namePattern.isRequired()).willReturn(false);
given(namePattern.isPersistent()).willReturn(true);
name = new FieldComponentState(namePattern);
name.setTranslationService(translationService);
name.setName("name");
name.initialize(new JSONObject(), Locale.ENGLISH);
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn("'static expression'");
applicationContext = mock(ApplicationContext.class);
setField(pattern, "applicationContext", applicationContext);
SecurityRolesService securityRolesService = mock(SecurityRolesService.class);
given(applicationContext.getBean(SecurityRolesService.class)).willReturn(securityRolesService);
form = new FormComponentState(pattern);
form.setDataDefinition(dataDefinition);
form.setTranslationService(translationService);
form.addFieldEntityIdChangeListener("name", name);
form.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
new ExpressionServiceImpl().init();
}
use of com.qcadoo.model.api.FieldDefinition in project qcadoo by qcadoo.
the class GridComponentStateTest method shouldGetValueUsingExpression.
@Test
public void shouldGetValueUsingExpression() throws Exception {
// given
FieldDefinition nameFieldDefinition = mock(FieldDefinition.class);
given(productDataDefinition.getField("name")).willReturn(nameFieldDefinition);
FieldType nameFieldType = mock(FieldType.class);
given(nameFieldDefinition.getType()).willReturn(nameFieldType);
given(nameFieldType.toString(anyString(), any(Locale.class))).willAnswer(invocation -> Objects.toString(invocation.getArguments()[0]));
GridComponentColumn column = new GridComponentColumn("name");
column.setExpression("#name + ' ' + #id");
Entity entity = new DefaultEntity(productDataDefinition, 13L, ImmutableMap.of("name", (Object) "John"));
// when
String value = column.getValue(entity, Locale.ENGLISH);
// then
assertEquals("John 13", value);
}
use of com.qcadoo.model.api.FieldDefinition in project qcadoo by qcadoo.
the class GridComponentStateTest method shouldGetValueUsingFields.
@Test
public void shouldGetValueUsingFields() throws Exception {
// given
FieldDefinition field1 = mock(FieldDefinition.class);
given(field1.getName()).willReturn("name");
given(field1.getValue("John", Locale.ENGLISH)).willReturn("Johny");
FieldDefinition field2 = mock(FieldDefinition.class);
given(field2.getName()).willReturn("lastname");
given(field2.getValue("Smith", Locale.ENGLISH)).willReturn("Smithy");
GridComponentColumn column = new GridComponentColumn("name");
column.addField(field1);
column.addField(field2);
Entity entity = new DefaultEntity(productDataDefinition, 13L, ImmutableMap.of("name", (Object) "John", "lastname", (Object) "Smith"));
// when
String value = column.getValue(entity, Locale.ENGLISH);
// then
assertEquals("Johny, Smithy", value);
}
Aggregations