Search in sources :

Example 21 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.

the class GridComponentFilterUtilsTest method shouldReturnFieldDefinitionForThreeLevelsDeepPath.

@Test
public final void shouldReturnFieldDefinitionForThreeLevelsDeepPath() {
    // given
    DataDefinition firstBtDataDef = mock(DataDefinition.class);
    mockBelongsToField("firstBelongsTo", dataDefinition, firstBtDataDef);
    DataDefinition secondBtDataDef = mock(DataDefinition.class);
    mockBelongsToField("secondBelongsTo", firstBtDataDef, secondBtDataDef);
    DataDefinition thirdBtDataDef = mock(DataDefinition.class);
    mockBelongsToField("thirdBelongsTo", secondBtDataDef, thirdBtDataDef);
    FieldDefinition fieldDefinition = mockFieldDefinition("fieldName", String.class, thirdBtDataDef);
    String field = "firstBelongsTo.secondBelongsTo.thirdBelongsTo.fieldName";
    // when
    final FieldDefinition res = GridComponentFilterUtils.getFieldDefinition(dataDefinition, field);
    // then
    assertEquals(fieldDefinition, res);
}
Also used : FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 22 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.

the class GridComponentFilterUtilsTest method shouldFilterColumnWithFourLevelsDeepPathInExpressionWithBracketsAndSafetyNavOp.

@Test
public final void shouldFilterColumnWithFourLevelsDeepPathInExpressionWithBracketsAndSafetyNavOp() throws GridComponentFilterException {
    // given
    DataDefinition firstBtDataDef = mock(DataDefinition.class);
    FieldDefinition firstBtFieldDef = mockBelongsToField("firstBt", dataDefinition, firstBtDataDef);
    DataDefinition secondBtDataDef = mock(DataDefinition.class);
    mockBelongsToField("secondBt", firstBtDataDef, secondBtDataDef);
    DataDefinition thirdBtDataDef = mock(DataDefinition.class);
    mockBelongsToField("thirdBt", secondBtDataDef, thirdBtDataDef);
    DataDefinition fourthBtDataDef = mock(DataDefinition.class);
    mockBelongsToField("fourthBt", thirdBtDataDef, fourthBtDataDef);
    mockFieldDefinition(TEST_FIELD, Integer.class, fourthBtDataDef);
    // when
    performFiltering("3", buildGridComponentColumn(TEST_COL, firstBtFieldDef, "#firstBt['secondBt']?.get('thirdBt')?.get('fourthBt')?.get('" + TEST_FIELD + "')"));
    // then
    PowerMockito.verifyStatic();
    SearchRestrictions.eq("fourthBt_a." + TEST_FIELD, 3);
    PowerMockito.verifyStatic(never());
    SearchRestrictions.eq(TEST_FIELD, 3);
    SearchRestrictions.eq("firstBt_a." + TEST_FIELD, 3);
    SearchRestrictions.eq("secondBt_a." + TEST_FIELD, 3);
    SearchRestrictions.eq("thirdBt_a." + TEST_FIELD, 3);
}
Also used : FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 23 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.

the class MenuServiceImplTest method shouldCreateCategory.

@Test
public final void shouldCreateCategory() {
    // given
    MenuCategoryDefinition menuCategoryDefinition = new MenuCategoryDefinition(PLUGIN_IDENTIFIER, "categoryName", ROLE_VISIBLE);
    given(menuCrudService.getCategory(menuCategoryDefinition)).willReturn(null);
    given(menuCrudService.createEntity(QcadooViewConstants.MODEL_CATEGORY)).willAnswer(new Answer<Entity>() {

        @Override
        public Entity answer(final InvocationOnMock invocation) throws Throwable {
            DataDefinition dataDefinition = mock(DataDefinition.class);
            return new DefaultEntity(dataDefinition);
        }
    });
    given(menuCrudService.getTotalNumberOfCategories()).willReturn(3);
    // when
    menuService.createCategory(menuCategoryDefinition);
    // then
    verify(menuCrudService).save(entityCaptor.capture());
    Entity savedItem = entityCaptor.getValue();
    assertEquals(PLUGIN_IDENTIFIER, savedItem.getStringField(MenuCategoryFields.PLUGIN_IDENTIFIER));
    assertEquals("categoryName", savedItem.getStringField(MenuCategoryFields.NAME));
    assertEquals(3, savedItem.getField(MenuCategoryFields.SUCCESSION));
    assertEquals(ROLE_VISIBLE, savedItem.getStringField(MenuCategoryFields.AUTH_ROLE));
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) MenuCategoryDefinition(com.qcadoo.view.internal.menu.definitions.MenuCategoryDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 24 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.

the class MenuServiceImplTest method shouldCreateViewForUrlItem.

@Test
public final void shouldCreateViewForUrlItem() {
    // given
    MenuItemDefinition menuUrlItemDefinition = MenuItemDefinition.create(PLUGIN_IDENTIFIER, "itemName", "categoryName", ROLE_VISIBLE, true).forUrl("someUrl");
    given(menuCrudService.getView(menuUrlItemDefinition)).willReturn(null);
    given(menuCrudService.createEntity(QcadooViewConstants.MODEL_VIEW)).willAnswer(new Answer<Entity>() {

        @Override
        public Entity answer(final InvocationOnMock invocation) throws Throwable {
            DataDefinition dataDefinition = mock(DataDefinition.class);
            return new DefaultEntity(dataDefinition);
        }
    });
    // when
    menuService.addView(menuUrlItemDefinition);
    // then
    verify(menuCrudService).save(entityCaptor.capture());
    Entity savedView = entityCaptor.getValue();
    assertEquals("somePlugin", savedView.getStringField(ViewFields.PLUGIN_IDENTIFIER));
    assertEquals("itemName", savedView.getStringField(ViewFields.NAME));
    assertNull(savedView.getStringField(ViewFields.VIEW));
    assertEquals("someUrl", savedView.getStringField(ViewFields.URL));
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) MenuItemDefinition(com.qcadoo.view.internal.menu.definitions.MenuItemDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 25 with DataDefinition

use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.

the class GridComponentPatternTest method shouldHaveDefaultValues.

@Test
public void shouldHaveDefaultValues() throws Exception {
    // given
    DataDefinition dataDefinition = mock(DataDefinition.class);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    given(viewDefinition.getDataDefinition()).willReturn(dataDefinition);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    // when
    pattern.initialize();
    // then
    JSONObject options = getJsOptions(pattern);
    assertFalse(options.has("correspondingView"));
    assertFalse(options.has("correspondingComponent"));
    assertFalse(options.has("belongsToFieldName"));
    assertTrue(options.getBoolean("paginable"));
    assertFalse(options.getBoolean("lookup"));
    assertFalse(options.getBoolean("creatable"));
    assertFalse(options.getBoolean("deletable"));
    assertFalse(options.getBoolean("prioritizable"));
    assertFalse(options.getBoolean("fullscreen"));
    assertEquals(300, options.getInt("width"));
    assertEquals(300, options.getInt("height"));
    assertEquals(0, options.getJSONArray("orderableColumns").length());
    assertEquals(0, options.getJSONArray("searchableColumns").length());
    assertEquals(0, options.getJSONArray("columns").length());
}
Also used : GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) JSONObject(org.json.JSONObject) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) DataDefinition(com.qcadoo.model.api.DataDefinition) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Aggregations

DataDefinition (com.qcadoo.model.api.DataDefinition)415 Entity (com.qcadoo.model.api.Entity)285 Test (org.junit.Test)165 BigDecimal (java.math.BigDecimal)53 FieldDefinition (com.qcadoo.model.api.FieldDefinition)48 List (java.util.List)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)32 Service (org.springframework.stereotype.Service)31 Autowired (org.springframework.beans.factory.annotation.Autowired)27 Date (java.util.Date)26 Map (java.util.Map)26 Collectors (java.util.stream.Collectors)26 FormComponent (com.qcadoo.view.api.components.FormComponent)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)22 IOException (java.io.IOException)21 Objects (java.util.Objects)21 GridComponent (com.qcadoo.view.api.components.GridComponent)20 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)20 Lists (com.google.common.collect.Lists)16