use of com.qcadoo.model.internal.DefaultEntity 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.internal.DefaultEntity 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.internal.DefaultEntity 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.internal.DefaultEntity in project qcadoo by qcadoo.
the class HookTest method shouldBeTriggeredInOrderOfAdding2.
@Test
public final void shouldBeTriggeredInOrderOfAdding2() {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "a");
dataDefinition.addSaveHook(buildHook("appendC"));
dataDefinition.addSaveHook(buildHook("appendB"));
dataDefinition.addSaveHook(buildHook("appendD"));
// when
entity = dataDefinition.save(entity);
// then
assertEquals("acbd", entity.getStringField("name"));
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class HookTest method shouldCreateHookNotSeeNewValueOfReadOnlyField.
@Test
public void shouldCreateHookNotSeeNewValueOfReadOnlyField() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition, null);
entity.setField("name", null);
entity.setField("age", null);
entity.setField("readOnly", "youCanNotSeeMe!");
dataDefinition.addCreateHook(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "rewriteReadOnlyField", PLUGIN_IDENTIFIER, applicationContext));
// when
entity = dataDefinition.save(entity);
// then
assertNull(entity.getField("readOnly"));
assertNull(entity.getField("name"));
}
Aggregations