use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class MenuServiceImplTest method shouldCreateDeactivatedItem.
@Test
public final void shouldCreateDeactivatedItem() {
// given
MenuItemDefinition menuItemDefinition = MenuItemDefinition.create(PLUGIN_IDENTIFIER, "itemName", "categoryName", ROLE_VISIBLE, false).forView(PLUGIN_IDENTIFIER, "viewName");
given(menuCrudService.getItem(menuItemDefinition)).willReturn(null);
Entity categoryEntity = mockCategory(PLUGIN_IDENTIFIER, "categoryName", ROLE_VISIBLE, Collections.<Entity>emptyList());
given(menuCrudService.getCategory(menuItemDefinition)).willReturn(categoryEntity);
Entity viewEntity = mockViewEntity(PLUGIN_IDENTIFIER, "viewName");
given(menuCrudService.getView(menuItemDefinition)).willReturn(viewEntity);
given(menuCrudService.createEntity(QcadooViewConstants.MODEL_ITEM)).willAnswer(new Answer<Entity>() {
@Override
public Entity answer(final InvocationOnMock invocation) throws Throwable {
DataDefinition dataDefinition = mock(DataDefinition.class);
return new DefaultEntity(dataDefinition);
}
});
// when
menuService.createItem(menuItemDefinition);
// then
verify(menuCrudService).save(entityCaptor.capture());
Entity savedItem = entityCaptor.getValue();
assertEquals(PLUGIN_IDENTIFIER, savedItem.getStringField(MenuItemFields.PLUGIN_IDENTIFIER));
assertEquals("itemName", savedItem.getStringField(MenuItemFields.NAME));
assertFalse(savedItem.getBooleanField(MenuItemFields.ACTIVE));
assertEquals(viewEntity, savedItem.getField(MenuItemFields.VIEW));
assertEquals(categoryEntity, savedItem.getField(MenuItemFields.CATEGORY));
assertEquals(1, savedItem.getField(MenuItemFields.SUCCESSION));
assertEquals(ROLE_VISIBLE, savedItem.getStringField(MenuItemFields.AUTH_ROLE));
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class InitializationTest method shouldTakeDataDefinitionFromParent.
@Test
public void shouldTakeDataDefinitionFromParent() throws Exception {
// given
DataDefinition dataDefinition = mock(DataDefinition.class);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("parent", viewDefinition));
setField(parent, "dataDefinition", dataDefinition);
AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", parent, viewDefinition));
// when
pattern.initialize();
// then
Assert.assertEquals(dataDefinition, getField(pattern, "dataDefinition"));
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class InitializationTest method shouldGetDataDefinitionFromBelongsToTypeFieldDefinition.
@Test
public void shouldGetDataDefinitionFromBelongsToTypeFieldDefinition() throws Exception {
// given
BelongsToType fieldType = mock(BelongsToType.class);
FieldDefinition fieldDefinition = mock(FieldDefinition.class);
given(fieldDefinition.getType()).willReturn(fieldType);
DataDefinition dataDefinition = mock(DataDefinition.class);
given(dataDefinition.getField("field")).willReturn(fieldDefinition);
DataDefinition belongsToDefinition = mock(DataDefinition.class);
given(fieldType.getDataDefinition()).willReturn(belongsToDefinition);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("parent", viewDefinition));
setField(parent, "dataDefinition", dataDefinition);
setField(parent, "initialized", true);
AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", "field", null, parent, viewDefinition));
// when
pattern.initialize();
// then
Assert.assertEquals(belongsToDefinition, getField(pattern, "dataDefinition"));
Assert.assertEquals(fieldDefinition, getField(pattern, "fieldDefinition"));
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class InitializationTest method shouldTakeDataDefinitionFromScopeComponent.
@Test
public void shouldTakeDataDefinitionFromScopeComponent() throws Exception {
// given
FieldDefinition fieldDefinition = mock(FieldDefinition.class);
DataDefinition dataDefinition = mock(DataDefinition.class);
given(dataDefinition.getField("field")).willReturn(fieldDefinition);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
AbstractComponentPattern sourceComponent = new TextInputComponentPattern(getComponentDefinition("component", viewDefinition));
setField(sourceComponent, "dataDefinition", dataDefinition);
setField(sourceComponent, "initialized", true);
given(viewDefinition.getComponentByReference("component")).willReturn(sourceComponent);
AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", null, "#{component}.field", null, viewDefinition));
// when
pattern.initialize();
// then
Assert.assertEquals(dataDefinition, getField(pattern, "dataDefinition"));
Assert.assertEquals(fieldDefinition, getField(pattern, "scopeFieldDefinition"));
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class InitializationTest method shouldGetDataDefinitionFromHasManyTypeScopeFieldDefinition.
@Test
public void shouldGetDataDefinitionFromHasManyTypeScopeFieldDefinition() throws Exception {
// given
HasManyType fieldType = mock(HasManyType.class);
FieldDefinition fieldDefinition = mock(FieldDefinition.class);
given(fieldDefinition.getType()).willReturn(fieldType);
DataDefinition dataDefinition = mock(DataDefinition.class);
given(dataDefinition.getField("field")).willReturn(fieldDefinition);
DataDefinition belongsToDefinition = mock(DataDefinition.class);
given(fieldType.getDataDefinition()).willReturn(belongsToDefinition);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("parent", viewDefinition));
setField(parent, "dataDefinition", dataDefinition);
setField(parent, "initialized", true);
AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", null, "field", parent, viewDefinition));
// when
pattern.initialize();
// then
Assert.assertEquals(belongsToDefinition, getField(pattern, "dataDefinition"));
Assert.assertEquals(fieldDefinition, getField(pattern, "scopeFieldDefinition"));
}
Aggregations