use of com.qcadoo.model.internal.types.StringType in project qcadoo by qcadoo.
the class EntityServiceImplTest method shouldThrownAnExceptionWhileSettingNotExistingField.
@Test(expected = IllegalStateException.class)
public void shouldThrownAnExceptionWhileSettingNotExistingField() throws Exception {
// given
SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(1L);
FieldDefinition fieldDefinition = new FieldDefinitionImpl(new DataDefinitionImpl("", "", null), "unknown").withType(new StringType());
// when
entityService.setField(databaseEntity, fieldDefinition, "XXX");
}
use of com.qcadoo.model.internal.types.StringType 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.internal.types.StringType in project qcadoo by qcadoo.
the class ViewDefinitionParserImplTest method init.
@Before
public void init() throws Exception {
applicationContext = mock(ApplicationContext.class);
dataDefinitionService = mock(DataDefinitionService.class);
translationService = mock(TranslationService.class);
RibbonParserService ribbonService = new RibbonParserService();
contextualHelpService = mock(ContextualHelpService.class);
securityRolesService = mock(SecurityRolesService.class);
viewDefinitionService = new ViewDefinitionServiceImpl();
hookFactory = new HookFactory();
setField(hookFactory, "applicationContext", applicationContext);
viewDefinitionParser = new ViewDefinitionParserImpl();
setField(viewDefinitionParser, "dataDefinitionService", dataDefinitionService);
setField(viewDefinitionParser, "viewDefinitionService", viewDefinitionService);
setField(viewDefinitionParser, "hookFactory", hookFactory);
setField(viewDefinitionParser, "translationService", translationService);
setField(viewDefinitionParser, "applicationContext", applicationContext);
setField(viewDefinitionParser, "contextualHelpService", contextualHelpService);
setField(viewDefinitionParser, "viewComponentsResolver", viewComponentsResolver);
setField(viewDefinitionParser, "ribbonService", ribbonService);
setField(viewDefinitionParser, "securityRolesService", securityRolesService);
userRoleMock = mock(SecurityRole.class);
given(securityRolesService.getRoleByIdentifier("ROLE_USER")).willReturn(userRoleMock);
adminRoleMock = mock(SecurityRole.class);
given(securityRolesService.getRoleByIdentifier("ROLE_ADMIN")).willReturn(adminRoleMock);
xml1 = "view/test1.xml";
xml2 = "view/test2.xml";
given(applicationContext.getBean(CustomViewService.class)).willReturn(new CustomViewService());
dataDefinitionA = mock(DataDefinition.class);
dataDefinitionB = mock(DataDefinition.class);
FieldDefinition nameA = mock(FieldDefinition.class, "nameA");
FieldDefinition nameB = mock(FieldDefinition.class, "nameB");
FieldDefinition hasManyB = mock(FieldDefinition.class, "hasManyB");
FieldDefinition belongToA = mock(FieldDefinition.class, "belongsToA");
HasManyType hasManyBType = mock(HasManyType.class);
BelongsToType belongToAType = mock(BelongsToType.class);
given(nameA.getDataDefinition()).willReturn(dataDefinitionA);
given(nameA.getType()).willReturn(new StringType());
given(nameB.getType()).willReturn(new StringType());
given(nameB.getDataDefinition()).willReturn(dataDefinitionA);
given(hasManyB.getType()).willReturn(hasManyBType);
given(hasManyB.getDataDefinition()).willReturn(dataDefinitionB);
given(belongToA.getType()).willReturn(belongToAType);
given(belongToA.getDataDefinition()).willReturn(dataDefinitionB);
given(hasManyBType.getDataDefinition()).willReturn(dataDefinitionB);
given(belongToAType.getDataDefinition()).willReturn(dataDefinitionA);
given(dataDefinitionA.getField("beansB")).willReturn(hasManyB);
given(dataDefinitionA.getField("name")).willReturn(nameA);
given(dataDefinitionB.getField("activeA")).willReturn(nameA);
given(dataDefinitionB.getField("activeB")).willReturn(nameA);
given(dataDefinitionB.getField("activeC")).willReturn(nameA);
given(dataDefinitionB.getField("beanA")).willReturn(belongToA);
given(dataDefinitionB.getField("beanM")).willReturn(belongToA);
given(dataDefinitionB.getField("beanB")).willReturn(belongToA);
given(dataDefinitionB.getField("name")).willReturn(nameB);
given(dataDefinitionA.getName()).willReturn("beanA");
given(dataDefinitionB.getName()).willReturn("beanB");
given(dataDefinitionA.getFields()).willReturn(ImmutableMap.of("name", nameA, "beansB", hasManyB));
given(dataDefinitionB.getFields()).willReturn(ImmutableMap.of("name", nameB, "beanA", belongToA));
given(dataDefinitionService.get("sample", "beanA")).willReturn(dataDefinitionA);
given(dataDefinitionService.get("sample", "beanB")).willReturn(dataDefinitionB);
}
use of com.qcadoo.model.internal.types.StringType in project qcadoo by qcadoo.
the class ExpressionUtilTest method shouldReturnJoinedStringRepresentationsOfMultipleFieldWithoutExpression.
@Test
public void shouldReturnJoinedStringRepresentationsOfMultipleFieldWithoutExpression() throws Exception {
// given
Entity entity = new DefaultEntity(null, 1L);
entity.setField("name", "Mr T");
entity.setField("age", 33);
entity.setField("sex", "F");
FieldDefinition fieldDefinitionName = new FieldDefinitionImpl(null, "name").withType(new StringType());
FieldDefinition fieldDefinitionAge = new FieldDefinitionImpl(null, "age").withType(new IntegerType());
FieldDefinition fieldDefinitionSex = new FieldDefinitionImpl(null, "sex").withType(new StringType());
// when
String value = expressionService.getValue(entity, Lists.newArrayList(fieldDefinitionName, fieldDefinitionAge, fieldDefinitionSex), Locale.ENGLISH);
// then
assertEquals("Mr T, 33, F", value);
}
use of com.qcadoo.model.internal.types.StringType in project qcadoo by qcadoo.
the class FieldTypeFactoryTest method shouldReturnStringType.
@Test
public void shouldReturnStringType() throws Exception {
// when
FieldType fieldType = new StringType();
// then
assertEquals(String.class, fieldType.getType());
assertTrue(fieldType.toObject(fieldDefinition, "test").isValid());
assertTrue(fieldType.toObject(fieldDefinition, StringUtils.repeat("a", 255)).isValid());
assertTrue(fieldType.toObject(fieldDefinition, StringUtils.repeat("a", 300)).isValid());
}
Aggregations