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