Search in sources :

Example 1 with StringType

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");
}
Also used : StringType(com.qcadoo.model.internal.types.StringType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 2 with StringType

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();
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) StringType(com.qcadoo.model.internal.types.StringType) FieldComponentPattern(com.qcadoo.view.internal.components.FieldComponentPattern) FieldDefinition(com.qcadoo.model.api.FieldDefinition) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) DataDefinition(com.qcadoo.model.api.DataDefinition) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) TranslationService(com.qcadoo.localization.api.TranslationService) FieldComponentState(com.qcadoo.view.internal.components.FieldComponentState) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) SecurityRolesService(com.qcadoo.security.api.SecurityRolesService) Matchers.anyLong(org.mockito.Matchers.anyLong) ExpressionServiceImpl(com.qcadoo.model.internal.ExpressionServiceImpl) Before(org.junit.Before)

Example 3 with StringType

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);
}
Also used : SecurityRole(com.qcadoo.security.api.SecurityRole) CustomViewService(com.qcadoo.view.beans.sample.CustomViewService) StringType(com.qcadoo.model.internal.types.StringType) ViewDefinitionServiceImpl(com.qcadoo.view.internal.ViewDefinitionServiceImpl) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) DataDefinition(com.qcadoo.model.api.DataDefinition) RibbonParserService(com.qcadoo.view.internal.ribbon.RibbonParserService) ApplicationContext(org.springframework.context.ApplicationContext) HasManyType(com.qcadoo.model.api.types.HasManyType) BelongsToType(com.qcadoo.model.api.types.BelongsToType) TranslationService(com.qcadoo.localization.api.TranslationService) SecurityRolesService(com.qcadoo.security.api.SecurityRolesService) Before(org.junit.Before)

Example 4 with StringType

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);
}
Also used : IntegerType(com.qcadoo.model.internal.types.IntegerType) Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) StringType(com.qcadoo.model.internal.types.StringType) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) FieldDefinitionImpl(com.qcadoo.model.internal.FieldDefinitionImpl) Test(org.junit.Test)

Example 5 with StringType

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());
}
Also used : StringType(com.qcadoo.model.internal.types.StringType) FieldType(com.qcadoo.model.api.types.FieldType) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Aggregations

StringType (com.qcadoo.model.internal.types.StringType)10 FieldDefinition (com.qcadoo.model.api.FieldDefinition)9 Test (org.junit.Test)8 DataDefinition (com.qcadoo.model.api.DataDefinition)3 Entity (com.qcadoo.model.api.Entity)3 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)3 InternalFieldDefinition (com.qcadoo.model.internal.api.InternalFieldDefinition)3 TranslationService (com.qcadoo.localization.api.TranslationService)2 FieldDefinitionImpl (com.qcadoo.model.internal.FieldDefinitionImpl)2 IntegerType (com.qcadoo.model.internal.types.IntegerType)2 SecurityRolesService (com.qcadoo.security.api.SecurityRolesService)2 JSONObject (org.json.JSONObject)2 Before (org.junit.Before)2 ApplicationContext (org.springframework.context.ApplicationContext)2 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)1 BelongsToType (com.qcadoo.model.api.types.BelongsToType)1 FieldType (com.qcadoo.model.api.types.FieldType)1 HasManyType (com.qcadoo.model.api.types.HasManyType)1 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)1 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)1