use of com.qcadoo.view.internal.menu.definitions.MenuCategoryDefinition 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.view.internal.menu.definitions.MenuCategoryDefinition in project qcadoo by qcadoo.
the class MenuServiceImplTest method shouldDoNothingIfCategoryAlreadyExists.
@Test
public final void shouldDoNothingIfCategoryAlreadyExists() {
// given
MenuCategoryDefinition menuCategoryDefinition = new MenuCategoryDefinition(PLUGIN_IDENTIFIER, "categoryName", ROLE_VISIBLE);
Entity categoryEntity = mock(Entity.class);
given(menuCrudService.getCategory(menuCategoryDefinition)).willReturn(categoryEntity);
// when
menuService.createCategory(menuCategoryDefinition);
// then
verify(menuCrudService, never()).save(any(Entity.class));
}
use of com.qcadoo.view.internal.menu.definitions.MenuCategoryDefinition in project qcadoo by qcadoo.
the class MenuCategoryModuleFactory method parseElement.
@Override
protected MenuCategoryModule parseElement(final String pluginIdentifier, final Element element) {
String menuCategoryName = getRequiredAttribute(element, "name");
String authRoleIdentifier = getAttribute(element, "defaultAuthorizationRole");
MenuCategoryDefinition menuCategoryDefinition = new MenuCategoryDefinition(pluginIdentifier, menuCategoryName, authRoleIdentifier);
return new MenuCategoryModule(menuService, menuCategoryDefinition);
}
use of com.qcadoo.view.internal.menu.definitions.MenuCategoryDefinition in project qcadoo by qcadoo.
the class MenuServiceImplTest method shouldRemoveCategory.
@Test
public final void shouldRemoveCategory() {
// given
MenuCategoryDefinition menuCategoryDefinition = new MenuCategoryDefinition(PLUGIN_IDENTIFIER, "categoryName", ROLE_VISIBLE);
Entity categoryEntity = mockCategory(PLUGIN_IDENTIFIER, "categoryName", ROLE_VISIBLE, Collections.<Entity>emptyList());
given(menuCrudService.getCategory(menuCategoryDefinition)).willReturn(categoryEntity);
// when
menuService.removeCategory(menuCategoryDefinition);
// then
verify(menuCrudService).delete(categoryEntity);
}
use of com.qcadoo.view.internal.menu.definitions.MenuCategoryDefinition in project qcadoo by qcadoo.
the class MenuServiceImplTest method shouldNotRemoveCategoryIfHasAnyItems.
@Test
public final void shouldNotRemoveCategoryIfHasAnyItems() {
// given
MenuCategoryDefinition menuCategoryDefinition = new MenuCategoryDefinition(PLUGIN_IDENTIFIER, "categoryName", ROLE_VISIBLE);
Entity itemEntity = mock(Entity.class);
Entity categoryEntity = mockCategory(PLUGIN_IDENTIFIER, "categoryName", ROLE_VISIBLE, Lists.newArrayList(itemEntity));
given(menuCrudService.getCategory(menuCategoryDefinition)).willReturn(categoryEntity);
// when
menuService.removeCategory(menuCategoryDefinition);
// then
verify(menuCrudService, never()).delete(categoryEntity);
}
Aggregations