Search in sources :

Example 6 with InternalComponentState

use of com.qcadoo.view.internal.api.InternalComponentState in project qcadoo by qcadoo.

the class ComponentStateTest method shouldHaveFieldValueAfterInitialize.

@Test
public void shouldHaveFieldValueAfterInitialize() throws Exception {
    // given
    InternalComponentState componentState = new SimpleComponentState();
    JSONObject json = new JSONObject();
    JSONObject jsonContent = new JSONObject();
    jsonContent.put(AbstractComponentState.JSON_VALUE, "text");
    json.put(AbstractComponentState.JSON_CONTENT, jsonContent);
    // when
    componentState.initialize(json, Locale.ENGLISH);
    // then
    assertEquals("text", componentState.getFieldValue());
}
Also used : JSONObject(org.json.JSONObject) SimpleComponentState(com.qcadoo.view.internal.components.SimpleComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test)

Example 7 with InternalComponentState

use of com.qcadoo.view.internal.api.InternalComponentState in project qcadoo by qcadoo.

the class ContainerStateTest method shouldHaveNoChildren.

@Test
public void shouldHaveNoChildren() throws Exception {
    // given
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn(null);
    setField(pattern, "applicationContext", applicationContext);
    FormComponentState container = new FormComponentState(pattern);
    // when
    Map<String, InternalComponentState> children = container.getChildren();
    // then
    assertNotNull(children);
    assertEquals(0, children.size());
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test)

Example 8 with InternalComponentState

use of com.qcadoo.view.internal.api.InternalComponentState in project qcadoo by qcadoo.

the class ContainerStateTest method shouldRenderChildren.

@Test
public void shouldRenderChildren() throws Exception {
    // given
    JSONObject component1Json = new JSONObject();
    component1Json.put(AbstractComponentState.JSON_CONTENT, "test1");
    JSONObject component2Json = new JSONObject();
    component2Json.put(AbstractComponentState.JSON_CONTENT, "test2");
    InternalComponentState component1 = createMockComponent("component1");
    given(component1.render()).willReturn(component1Json);
    InternalComponentState component2 = createMockComponent("component2");
    given(component2.render()).willReturn(component2Json);
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn(null);
    setField(pattern, "applicationContext", applicationContext);
    FormComponentState container = new FormComponentState(pattern);
    container.addChild(component1);
    container.addChild(component2);
    // when
    JSONObject json = container.render();
    // then
    verify(component1).render();
    verify(component2).render();
    assertEquals("test1", json.getJSONObject(AbstractComponentState.JSON_CHILDREN).getJSONObject("component1").getString(AbstractComponentState.JSON_CONTENT));
    assertEquals("test2", json.getJSONObject(AbstractComponentState.JSON_CHILDREN).getJSONObject("component2").getString(AbstractComponentState.JSON_CONTENT));
}
Also used : JSONObject(org.json.JSONObject) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Example 9 with InternalComponentState

use of com.qcadoo.view.internal.api.InternalComponentState in project qcadoo by qcadoo.

the class AbstractContainerState method initialize.

@Override
public final void initialize(final JSONObject json, final Locale locale) throws JSONException {
    super.initialize(json, locale);
    JSONObject childerJson = null;
    if (json.has(JSON_CHILDREN)) {
        childerJson = json.getJSONObject(JSON_CHILDREN);
    }
    final boolean containerIsPermanentlyDisabled = containerIsPermanentlyDisabled(json);
    for (Map.Entry<String, InternalComponentState> child : children.entrySet()) {
        JSONObject childJson = null;
        if (childerJson == null) {
            childJson = new JSONObject();
        } else {
            childJson = childerJson.getJSONObject(child.getKey());
        }
        if (containerIsPermanentlyDisabled) {
            childJson.put(JSON_PERMANENTLY_DISABLED, true);
        }
        child.getValue().initialize(childJson, locale);
    }
}
Also used : JSONObject(org.json.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState)

Example 10 with InternalComponentState

use of com.qcadoo.view.internal.api.InternalComponentState in project qcadoo by qcadoo.

the class AbstractContainerState method findChild.

@Override
public InternalComponentState findChild(final String name) {
    checkNotNull(name, "name should be given");
    InternalComponentState referencedComponent = getChildren().get(name);
    if (referencedComponent != null) {
        return referencedComponent;
    }
    for (InternalComponentState component : getChildren().values()) {
        if (component instanceof ContainerState) {
            ContainerState innerContainer = (ContainerState) component;
            referencedComponent = innerContainer.findChild(name);
            if (referencedComponent != null) {
                return referencedComponent;
            }
        }
    }
    return null;
}
Also used : ContainerState(com.qcadoo.view.internal.api.ContainerState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState)

Aggregations

InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)29 Test (org.junit.Test)20 JSONObject (org.json.JSONObject)17 SimpleComponentState (com.qcadoo.view.internal.components.SimpleComponentState)8 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)8 FormComponentState (com.qcadoo.view.internal.components.form.FormComponentState)7 ContainerState (com.qcadoo.view.internal.api.ContainerState)4 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)4 Map (java.util.Map)4 ComponentState (com.qcadoo.view.api.ComponentState)3 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)3 JSONArray (org.json.JSONArray)3 ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)2 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)2 ViewDefinitionStateImpl (com.qcadoo.view.internal.internal.ViewDefinitionStateImpl)2 AbstractContainerState (com.qcadoo.view.internal.states.AbstractContainerState)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 DataDefinition (com.qcadoo.model.api.DataDefinition)1 CrudService (com.qcadoo.view.api.crud.CrudService)1