use of com.qcadoo.model.internal.ExpressionServiceImpl in project qcadoo by qcadoo.
the class LookupComponentStateTest method init.
@Before
public void init() throws JSONException {
MockitoAnnotations.initMocks(this);
when(componentPattern.isPersistent()).thenReturn(true);
lookup = new LookupComponentState(scopeField, "fieldCode", "expression", componentPattern);
lookup.initialize(json, Locale.ENGLISH);
lookup.setDataDefinition(dataDefinition);
esi = new ExpressionServiceImpl();
ReflectionTestUtils.invokeMethod(esi, "initialise", expressionService);
}
use of com.qcadoo.model.internal.ExpressionServiceImpl in project qcadoo by qcadoo.
the class ComponentStateTest method shouldHaveRequestUpdateStateFlag.
@Test
public void shouldHaveRequestUpdateStateFlag() throws Exception {
// given
new ExpressionServiceImpl().init();
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");
ApplicationContext applicationContext = mock(ApplicationContext.class);
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
assertTrue(json.getBoolean(AbstractComponentState.JSON_UPDATE_STATE));
}
use of com.qcadoo.model.internal.ExpressionServiceImpl 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.model.internal.ExpressionServiceImpl in project qcadoo by qcadoo.
the class ExpressionUtilTest method init.
@Before
public void init() {
expressionService = new ExpressionServiceImpl();
translationService = mock(TranslationService.class);
setField(expressionService, "translationService", translationService);
}
use of com.qcadoo.model.internal.ExpressionServiceImpl in project qcadoo by qcadoo.
the class GridComponentStateTest method init.
@Before
public void init() throws Exception {
JSONObject jsonContent = new JSONObject();
jsonContent.put(GridComponentState.JSON_SELECTED_ENTITY_ID, 13L);
jsonContent.put(GridComponentState.JSON_MULTISELECT_MODE, false);
JSONObject jsonSelected = new JSONObject();
jsonSelected.put("13", true);
jsonContent.put(GridComponentState.JSON_SELECTED_ENTITIES, jsonSelected);
jsonContent.put(GridComponentState.JSON_BELONGS_TO_ENTITY_ID, 1L);
jsonContent.put(GridComponentState.JSON_FIRST_ENTITY, 60);
jsonContent.put(GridComponentState.JSON_MAX_ENTITIES, 30);
jsonContent.put(GridComponentState.JSON_FILTERS_ENABLED, true);
JSONArray jsonOrder = new JSONArray();
jsonOrder.put(ImmutableMap.of("column", "asd", "direction", "asc"));
jsonContent.put(GridComponentState.JSON_ORDER, jsonOrder);
JSONObject jsonFilters = new JSONObject();
jsonFilters.put("asd", "test");
jsonFilters.put("qwe", "test2");
jsonContent.put(GridComponentState.JSON_FILTERS, jsonFilters);
json = new JSONObject(Collections.singletonMap(AbstractComponentState.JSON_CONTENT, jsonContent));
Entity entity = mock(Entity.class);
given(entity.getField("name")).willReturn("text");
viewDefinitionState = mock(ViewDefinitionState.class);
productDataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
substituteDataDefinition = mock(DataDefinition.class, "substituteDataDefinition");
HasManyType substitutesFieldType = mock(HasManyType.class);
given(substitutesFieldType.getDataDefinition()).willReturn(substituteDataDefinition);
given(substitutesFieldType.getJoinFieldName()).willReturn("product");
substitutesFieldDefinition = mock(FieldDefinition.class);
given(substitutesFieldDefinition.getType()).willReturn(substitutesFieldType);
given(substitutesFieldDefinition.getName()).willReturn("substitutes");
given(substitutesFieldDefinition.getDataDefinition()).willReturn(substituteDataDefinition);
substituteCriteria = mock(SearchCriteriaBuilder.class);
given(substituteDataDefinition.getPluginIdentifier()).willReturn("plugin");
given(substituteDataDefinition.getName()).willReturn("substitute");
given(substituteDataDefinition.find()).willReturn(substituteCriteria);
given(productDataDefinition.getPluginIdentifier()).willReturn("plugin");
given(productDataDefinition.getName()).willReturn("product");
given(productDataDefinition.getField("substitutes")).willReturn(substitutesFieldDefinition);
columns = new LinkedHashMap<String, GridComponentColumn>();
TranslationService translationService = mock(TranslationService.class);
given(translationService.translate(Mockito.anyString(), Mockito.any(Locale.class))).willReturn("i18n");
given(translationService.translate(Mockito.anyString(), Mockito.anyString(), Mockito.any(Locale.class))).willReturn("i18n");
given(translationService.translate(Mockito.anyString(), Mockito.any(Locale.class))).willReturn("i18n");
GridComponentPattern pattern = mock(GridComponentPattern.class);
given(pattern.getColumns()).willReturn(columns);
given(pattern.getBelongsToFieldDefinition()).willReturn(substitutesFieldDefinition);
given(pattern.isActivable()).willReturn(false);
given(pattern.isWeakRelation()).willReturn(false);
ApplicationContext applicationContext = mock(ApplicationContext.class);
setField(pattern, "applicationContext", applicationContext);
SecurityRolesService securityRolesService = mock(SecurityRolesService.class);
given(applicationContext.getBean(SecurityRolesService.class)).willReturn(securityRolesService);
grid = new GridComponentState(productDataDefinition, pattern);
grid.setDataDefinition(substituteDataDefinition);
grid.setTranslationService(translationService);
new ExpressionServiceImpl().init();
}
Aggregations