use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class MenuServiceImplTest method mockItem.
private Entity mockItem(final String pluginIdentifier, final String name, final boolean active, final String roleIdentifier, final String viewPlugin, final String viewName) {
Entity item = mock(Entity.class);
stubStringField(item, MenuItemFields.PLUGIN_IDENTIFIER, pluginIdentifier);
stubStringField(item, MenuItemFields.NAME, name);
stubBooleanField(item, MenuItemFields.ACTIVE, active);
stubStringField(item, MenuItemFields.AUTH_ROLE, roleIdentifier);
Entity view = mockViewEntity(viewPlugin, viewName);
stubBelongsToField(item, MenuItemFields.VIEW, view);
return item;
}
use of com.qcadoo.model.api.Entity 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));
}
use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class MenuServiceImplTest method mockCategory.
private Entity mockCategory(final String pluginIdentifier, final String name, final String roleIdentifier, final Iterable<Entity> items) {
Entity category = mock(Entity.class);
stubStringField(category, MenuCategoryFields.PLUGIN_IDENTIFIER, pluginIdentifier);
stubStringField(category, MenuCategoryFields.NAME, name);
stubStringField(category, MenuCategoryFields.AUTH_ROLE, roleIdentifier);
stubHasManyField(category, MenuCategoryFields.ITEMS, items);
return category;
}
use of com.qcadoo.model.api.Entity 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));
}
use of com.qcadoo.model.api.Entity 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));
}
Aggregations