Search in sources :

Example 6 with MenuItemDefinition

use of com.qcadoo.view.internal.menu.definitions.MenuItemDefinition in project qcadoo by qcadoo.

the class MenuServiceImplTest method shouldDoNothingIfItemExistsAndHasTheSameView.

@Test
public final void shouldDoNothingIfItemExistsAndHasTheSameView() {
    // given
    MenuItemDefinition menuItemDefinition = MenuItemDefinition.create(PLUGIN_IDENTIFIER, "itemName", "categoryName", ROLE_VISIBLE, true).forView(PLUGIN_IDENTIFIER, "viewName");
    Entity itemEntity = mock(Entity.class);
    given(menuCrudService.getItem(menuItemDefinition)).willReturn(itemEntity);
    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);
    stubBelongsToField(itemEntity, MenuItemFields.VIEW, viewEntity);
    // when
    menuService.createItem(menuItemDefinition);
    // then
    verify(menuCrudService, never()).save(any(Entity.class));
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) MenuItemDefinition(com.qcadoo.view.internal.menu.definitions.MenuItemDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with MenuItemDefinition

use of com.qcadoo.view.internal.menu.definitions.MenuItemDefinition in project qcadoo by qcadoo.

the class MenuServiceImplTest method shouldUpdateItemIfExists.

@Test
public final void shouldUpdateItemIfExists() {
    // given
    MenuItemDefinition menuItemDefinition = MenuItemDefinition.create(PLUGIN_IDENTIFIER, "itemName", "categoryName", ROLE_VISIBLE, true).forView(PLUGIN_IDENTIFIER, "viewName");
    Entity itemEntity = mock(Entity.class);
    given(menuCrudService.getItem(menuItemDefinition)).willReturn(itemEntity);
    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);
    // when
    menuService.createItem(menuItemDefinition);
    // then
    verify(menuCrudService).save(entityCaptor.capture());
    Entity savedItem = entityCaptor.getValue();
    verify(savedItem).setField(MenuItemFields.VIEW, viewEntity);
    verify(savedItem).setField(MenuItemFields.CATEGORY, categoryEntity);
    verify(savedItem).setField(MenuItemFields.SUCCESSION, 1);
    verify(savedItem).setField(MenuItemFields.AUTH_ROLE, ROLE_VISIBLE);
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) MenuItemDefinition(com.qcadoo.view.internal.menu.definitions.MenuItemDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with MenuItemDefinition

use of com.qcadoo.view.internal.menu.definitions.MenuItemDefinition in project qcadoo by qcadoo.

the class MenuServiceImplTest method shouldCreateItem.

@Test
public final void shouldCreateItem() {
    // given
    MenuItemDefinition menuItemDefinition = MenuItemDefinition.create(PLUGIN_IDENTIFIER, "itemName", "categoryName", ROLE_VISIBLE, true).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));
    assertTrue(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));
}
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) MenuItemDefinition(com.qcadoo.view.internal.menu.definitions.MenuItemDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with MenuItemDefinition

use of com.qcadoo.view.internal.menu.definitions.MenuItemDefinition in project qcadoo by qcadoo.

the class MenuServiceImplTest method shouldAddViewThrowsAnExceptionIfViewDoesNotExistAndUrlIsNull.

@Test
public final void shouldAddViewThrowsAnExceptionIfViewDoesNotExistAndUrlIsNull() {
    // given
    MenuItemDefinition menuViewItemDefinition = MenuItemDefinition.create(PLUGIN_IDENTIFIER, "itemName", "categoryName", ROLE_VISIBLE, true).forView("viewPlugin", "viewName");
    given(menuCrudService.getView(menuViewItemDefinition)).willReturn(null);
    given(viewDefinitionService.viewExists(PLUGIN_IDENTIFIER, "viewName")).willReturn(false);
    // when & then
    try {
        menuService.addView(menuViewItemDefinition);
        Assert.fail();
    } catch (IllegalStateException ignored) {
    // SUccess
    } catch (Exception ignored) {
        Assert.fail();
    }
}
Also used : MenuItemDefinition(com.qcadoo.view.internal.menu.definitions.MenuItemDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

MenuItemDefinition (com.qcadoo.view.internal.menu.definitions.MenuItemDefinition)9 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 Entity (com.qcadoo.model.api.Entity)6 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)6 DataDefinition (com.qcadoo.model.api.DataDefinition)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4