Search in sources :

Example 1 with ExpressionServiceImpl

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);
}
Also used : ExpressionServiceImpl(com.qcadoo.model.internal.ExpressionServiceImpl) Before(org.junit.Before)

Example 2 with ExpressionServiceImpl

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));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) JSONObject(org.json.JSONObject) TranslationService(com.qcadoo.localization.api.TranslationService) ExpressionServiceImpl(com.qcadoo.model.internal.ExpressionServiceImpl) DataDefinition(com.qcadoo.model.api.DataDefinition) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Example 3 with ExpressionServiceImpl

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();
}
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 4 with ExpressionServiceImpl

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);
}
Also used : TranslationService(com.qcadoo.localization.api.TranslationService) ExpressionServiceImpl(com.qcadoo.model.internal.ExpressionServiceImpl) Before(org.junit.Before)

Example 5 with ExpressionServiceImpl

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();
}
Also used : Locale(java.util.Locale) Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) JSONArray(org.json.JSONArray) GridComponentColumn(com.qcadoo.view.internal.components.grid.GridComponentColumn) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Matchers.anyString(org.mockito.Matchers.anyString) DataDefinition(com.qcadoo.model.api.DataDefinition) HasManyType(com.qcadoo.model.api.types.HasManyType) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) ApplicationContext(org.springframework.context.ApplicationContext) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) JSONObject(org.json.JSONObject) TranslationService(com.qcadoo.localization.api.TranslationService) GridComponentState(com.qcadoo.view.internal.components.grid.GridComponentState) SecurityRolesService(com.qcadoo.security.api.SecurityRolesService) ExpressionServiceImpl(com.qcadoo.model.internal.ExpressionServiceImpl) Before(org.junit.Before)

Aggregations

ExpressionServiceImpl (com.qcadoo.model.internal.ExpressionServiceImpl)5 TranslationService (com.qcadoo.localization.api.TranslationService)4 Before (org.junit.Before)4 DataDefinition (com.qcadoo.model.api.DataDefinition)3 JSONObject (org.json.JSONObject)3 ApplicationContext (org.springframework.context.ApplicationContext)3 Entity (com.qcadoo.model.api.Entity)2 FieldDefinition (com.qcadoo.model.api.FieldDefinition)2 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)2 SecurityRolesService (com.qcadoo.security.api.SecurityRolesService)2 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)2 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)2 FormComponentState (com.qcadoo.view.internal.components.form.FormComponentState)2 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)1 HasManyType (com.qcadoo.model.api.types.HasManyType)1 StringType (com.qcadoo.model.internal.types.StringType)1 FieldComponentPattern (com.qcadoo.view.internal.components.FieldComponentPattern)1 FieldComponentState (com.qcadoo.view.internal.components.FieldComponentState)1 GridComponentColumn (com.qcadoo.view.internal.components.grid.GridComponentColumn)1 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)1