Search in sources :

Example 91 with Entity

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity)

Example 92 with Entity

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));
}
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 93 with Entity

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity)

Example 94 with Entity

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));
}
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 95 with Entity

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

Entity (com.qcadoo.model.api.Entity)2833 FormComponent (com.qcadoo.view.api.components.FormComponent)514 Test (org.junit.Test)491 BigDecimal (java.math.BigDecimal)376 DataDefinition (com.qcadoo.model.api.DataDefinition)337 FieldComponent (com.qcadoo.view.api.components.FieldComponent)210 LookupComponent (com.qcadoo.view.api.components.LookupComponent)188 Date (java.util.Date)185 List (java.util.List)149 GridComponent (com.qcadoo.view.api.components.GridComponent)141 Map (java.util.Map)124 Autowired (org.springframework.beans.factory.annotation.Autowired)114 Service (org.springframework.stereotype.Service)112 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)105 Transactional (org.springframework.transaction.annotation.Transactional)101 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)100 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)95 Collectors (java.util.stream.Collectors)87 Lists (com.google.common.collect.Lists)75 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)75