Search in sources :

Example 11 with FormComponentPattern

use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.

the class ScopeEntityIdChangeListenerTest method shouldHaveScopeListeners.

@Test
public void shouldHaveScopeListeners() throws Exception {
    // given
    ComponentState component1 = createMockComponent("component1");
    ComponentState component2 = createMockComponent("component2");
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn(null);
    ApplicationContext applicationContext = mock(ApplicationContext.class);
    setField(pattern, "applicationContext", applicationContext);
    FormComponentState container = new FormComponentState(pattern);
    container.addScopeEntityIdChangeListener("component1", (ScopeEntityIdChangeListener) component1);
    container.addScopeEntityIdChangeListener("component2", (ScopeEntityIdChangeListener) component2);
    // when
    container.setFieldValue(13L);
    // then
    verify((ScopeEntityIdChangeListener) component1).onScopeEntityIdChange(13L);
    verify((ScopeEntityIdChangeListener) component2).onScopeEntityIdChange(13L);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ScopeEntityIdChangeListener(com.qcadoo.view.internal.ScopeEntityIdChangeListener) ComponentState(com.qcadoo.view.api.ComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Example 12 with FormComponentPattern

use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.

the class FormComponentStateTest method shouldInitialeFormWithEntityId.

@Test
public void shouldInitialeFormWithEntityId() throws Exception {
    // given
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn(null);
    setField(pattern, "applicationContext", applicationContext);
    InternalComponentState componentState = new FormComponentState(pattern);
    JSONObject json = new JSONObject();
    JSONObject jsonContent = new JSONObject();
    jsonContent.put(FormComponentState.JSON_ENTITY_ID, 13L);
    json.put(AbstractComponentState.JSON_CONTENT, jsonContent);
    JSONObject jsonChildren = new JSONObject();
    json.put(AbstractComponentState.JSON_CHILDREN, jsonChildren);
    // when
    componentState.initialize(json, Locale.ENGLISH);
    // then
    assertEquals(13L, componentState.getFieldValue());
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) JSONObject(org.json.JSONObject) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 13 with FormComponentPattern

use of com.qcadoo.view.internal.components.form.FormComponentPattern 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 14 with FormComponentPattern

use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.

the class FormComponentStateTest method shouldRenderFormEntityId.

@Test
public void shouldRenderFormEntityId() throws Exception {
    // given
    TranslationService translationService = mock(TranslationService.class);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn("2");
    setField(pattern, "applicationContext", applicationContext);
    AbstractComponentState componentState = new FormComponentState(pattern);
    componentState.setTranslationService(translationService);
    componentState.setDataDefinition(dataDefinition);
    componentState.setFieldValue(13L);
    componentState.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
    // when
    JSONObject json = componentState.render();
    // then
    assertEquals(13L, json.getJSONObject(AbstractComponentState.JSON_CONTENT).getLong(FormComponentState.JSON_ENTITY_ID));
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) JSONObject(org.json.JSONObject) TranslationService(com.qcadoo.localization.api.TranslationService) AbstractComponentState(com.qcadoo.view.internal.states.AbstractComponentState) DataDefinition(com.qcadoo.model.api.DataDefinition) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 15 with FormComponentPattern

use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.

the class FormComponentStateTest method shouldInitialeFormWithNullEntityId.

@Test
public void shouldInitialeFormWithNullEntityId() throws Exception {
    // given
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn(null);
    setField(pattern, "applicationContext", applicationContext);
    InternalComponentState componentState = new FormComponentState(pattern);
    JSONObject json = new JSONObject();
    JSONObject jsonContent = new JSONObject();
    jsonContent.put(FormComponentState.JSON_ENTITY_ID, (String) null);
    json.put(AbstractComponentState.JSON_CONTENT, jsonContent);
    JSONObject jsonChildren = new JSONObject();
    json.put(AbstractComponentState.JSON_CHILDREN, jsonChildren);
    // when
    componentState.initialize(json, Locale.ENGLISH);
    // then
    assertNull(componentState.getFieldValue());
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) JSONObject(org.json.JSONObject) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Aggregations

FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)28 Test (org.junit.Test)27 FormComponentState (com.qcadoo.view.internal.components.form.FormComponentState)18 InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)8 JSONObject (org.json.JSONObject)8 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)6 ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)6 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)6 ApplicationContext (org.springframework.context.ApplicationContext)6 TranslationService (com.qcadoo.localization.api.TranslationService)5 DataDefinition (com.qcadoo.model.api.DataDefinition)5 ComponentState (com.qcadoo.view.api.ComponentState)5 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)3 ViewEventListenerHook (com.qcadoo.view.internal.hooks.ViewEventListenerHook)3 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)3 FieldDefinition (com.qcadoo.model.api.FieldDefinition)2 ExpressionServiceImpl (com.qcadoo.model.internal.ExpressionServiceImpl)2 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)2 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)2 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)2