Search in sources :

Example 1 with MenuItemDefinition

use of com.qcadoo.view.internal.menu.definitions.MenuItemDefinition 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));
}
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 2 with MenuItemDefinition

use of com.qcadoo.view.internal.menu.definitions.MenuItemDefinition 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));
}
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 3 with MenuItemDefinition

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

the class MenuUrlModuleFactory method parseElement.

@Override
protected MenuModule parseElement(final String pluginIdentifier, final Element element) {
    String menuName = getRequiredAttribute(element, "name");
    String menuCategory = getRequiredAttribute(element, "category");
    String menuUrl = getRequiredAttribute(element, "url");
    String authRoleIdentifier = getAttribute(element, "defaultAuthorizationRole");
    String itemActiveAttribute = getAttribute(element, "active");
    boolean itemActive = itemActiveAttribute == null ? true : Boolean.parseBoolean(itemActiveAttribute);
    MenuItemDefinition menuItemDefinition = MenuItemDefinition.create(pluginIdentifier, menuName, menuCategory, authRoleIdentifier, itemActive).forUrl(menuUrl);
    return new MenuModule(getIdentifier(), menuService, menuItemDefinition);
}
Also used : MenuItemDefinition(com.qcadoo.view.internal.menu.definitions.MenuItemDefinition)

Example 4 with MenuItemDefinition

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

the class MenuViewModuleFactory method parseElement.

@Override
protected MenuModule parseElement(final String pluginIdentifier, final Element element) {
    String menuName = getRequiredAttribute(element, "name");
    String menuCategory = getRequiredAttribute(element, "category");
    String menuViewName = getRequiredAttribute(element, "view");
    String authRoleIdentifier = getAttribute(element, "defaultAuthorizationRole");
    String itemActiveAttribute = getAttribute(element, "active");
    boolean itemActive = itemActiveAttribute == null ? true : Boolean.parseBoolean(itemActiveAttribute);
    MenuItemDefinition menuItemDefinition = MenuItemDefinition.create(pluginIdentifier, menuName, menuCategory, authRoleIdentifier, itemActive).forView(pluginIdentifier, menuViewName);
    return new MenuModule(getIdentifier(), menuService, menuItemDefinition);
}
Also used : MenuItemDefinition(com.qcadoo.view.internal.menu.definitions.MenuItemDefinition)

Example 5 with MenuItemDefinition

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

the class MenuServiceImplTest method shouldCreateViewForViewItem.

@Test
public final void shouldCreateViewForViewItem() {
    // given
    MenuItemDefinition menuViewItemDefinition = MenuItemDefinition.create(PLUGIN_IDENTIFIER, "itemName", "categoryName", ROLE_VISIBLE, true).forView("viewPlugin", "viewName");
    given(menuCrudService.getView(menuViewItemDefinition)).willReturn(null);
    given(viewDefinitionService.viewExists("viewPlugin", "viewName")).willReturn(true);
    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(menuViewItemDefinition);
    // then
    verify(menuCrudService).save(entityCaptor.capture());
    Entity savedView = entityCaptor.getValue();
    assertEquals("viewPlugin", savedView.getStringField(ViewFields.PLUGIN_IDENTIFIER));
    assertEquals("viewName", savedView.getStringField(ViewFields.NAME));
    assertEquals("viewName", savedView.getStringField(ViewFields.VIEW));
    assertNull(savedView.getStringField(ViewFields.URL));
}
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)

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