use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHaveErrorIfCustomEntityValidatorReturnsFalse.
@Test
public void shouldHaveErrorIfCustomEntityValidatorReturnsFalse() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", "Mr");
entity.setField("age", "18");
dataDefinition.addValidatorHook(new CustomEntityValidator(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "hasAge18AndNameMrT", PLUGIN_IDENTIFIER, applicationContext)));
// when
entity = dataDefinition.save(entity);
// then
verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
assertFalse(entity.isValid());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasErrorsIfBigDecimalValueIsOutsideTheRange.
@Test
public void shouldHasErrorsIfBigDecimalValueIsOutsideTheRange() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("money", "31.22");
fieldDefinitionMoney.withValidator(new RangeValidator(40, 50, true));
// when
entity = dataDefinition.save(entity);
// then
verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
assertFalse(entity.isValid());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ValidatorTest method shouldHasErrorsIfIntegerUnscaledValueAreTooShort.
@Test
public void shouldHasErrorsIfIntegerUnscaledValueAreTooShort() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("age", new Integer("123"));
fieldDefinitionAge.withValidator(new UnscaledValueValidator(5, null, null));
// when
entity = dataDefinition.save(entity);
// then
verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
assertFalse(entity.isValid());
}
use of com.qcadoo.model.internal.DefaultEntity 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));
}
use of com.qcadoo.model.internal.DefaultEntity 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));
}
Aggregations