Search in sources :

Example 1 with MenuCategoryDefinition

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));
}
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 2 with MenuCategoryDefinition

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));
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) MenuCategoryDefinition(com.qcadoo.view.internal.menu.definitions.MenuCategoryDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with MenuCategoryDefinition

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);
}
Also used : MenuCategoryDefinition(com.qcadoo.view.internal.menu.definitions.MenuCategoryDefinition)

Example 4 with 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);
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) MenuCategoryDefinition(com.qcadoo.view.internal.menu.definitions.MenuCategoryDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with MenuCategoryDefinition

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);
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) MenuCategoryDefinition(com.qcadoo.view.internal.menu.definitions.MenuCategoryDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

MenuCategoryDefinition (com.qcadoo.view.internal.menu.definitions.MenuCategoryDefinition)5 Entity (com.qcadoo.model.api.Entity)4 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 DataDefinition (com.qcadoo.model.api.DataDefinition)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1