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