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));
}
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);
}
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));
}
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();
}
}
Aggregations