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());
}
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());
}
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));
}
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);
}
}
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;
}
Aggregations