use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CrudIntegrationTest method shouldHardDeleteEntity.
@Test
public void shouldHardDeleteEntity() throws Exception {
// given
DataDefinition productDataDefinition = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
Entity product = productDataDefinition.save(createProduct("asd", "asd"));
verifyHooks.clear();
// when
productDataDefinition.delete(product.getId());
// then
int total = jdbcTemplate.queryForInt("select count(*) from " + TABLE_NAME_PRODUCT);
assertEquals(0, total);
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.SAVE));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.CREATE));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.COPY));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.UPDATE));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.DELETE));
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CrudIntegrationTest method shouldGetEntity.
@Test
public void shouldGetEntity() throws Exception {
// given
DataDefinition machineDataDefinition = dataDefinitionService.get(PLUGIN_MACHINES_NAME, ENTITY_NAME_MACHINE);
Entity savedMachine = machineDataDefinition.save(createMachine("asd"));
// when
Entity machine = machineDataDefinition.get(savedMachine.getId());
// then
assertNotNull(machine);
assertEquals(savedMachine.getId(), machine.getId());
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class FormComponentStateTest method init.
@Before
public void init() throws Exception {
entity = mock(Entity.class);
given(entity.getField("name")).willReturn("text");
viewDefinitionState = mock(ViewDefinitionState.class);
translationService = mock(TranslationService.class);
fieldDefinition = mock(FieldDefinition.class);
given(fieldDefinition.getType()).willReturn(new StringType());
given(fieldDefinition.getName()).willReturn("name");
dataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
given(dataDefinition.get(12L)).willReturn(null);
given(dataDefinition.get(13L)).willReturn(entity);
given(dataDefinition.getPluginIdentifier()).willReturn("plugin");
given(dataDefinition.getName()).willReturn("name");
given(dataDefinition.getField("name")).willReturn(fieldDefinition);
given(dataDefinition.delete(any(Long.class))).willReturn(EntityOpResult.successfull());
given(dataDefinition.create(anyLong())).willAnswer(new Answer<Entity>() {
@Override
public Entity answer(final InvocationOnMock invocation) throws Throwable {
Long id = (Long) invocation.getArguments()[0];
return new DefaultEntity(dataDefinition, id);
}
});
FieldComponentPattern namePattern = mock(FieldComponentPattern.class);
given(namePattern.isRequired()).willReturn(false);
given(namePattern.isPersistent()).willReturn(true);
name = new FieldComponentState(namePattern);
name.setTranslationService(translationService);
name.setName("name");
name.initialize(new JSONObject(), Locale.ENGLISH);
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn("'static expression'");
applicationContext = mock(ApplicationContext.class);
setField(pattern, "applicationContext", applicationContext);
SecurityRolesService securityRolesService = mock(SecurityRolesService.class);
given(applicationContext.getBean(SecurityRolesService.class)).willReturn(securityRolesService);
form = new FormComponentState(pattern);
form.setDataDefinition(dataDefinition);
form.setTranslationService(translationService);
form.addFieldEntityIdChangeListener("name", name);
form.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
new ExpressionServiceImpl().init();
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class FormComponentStateTest method shouldRenderFormEntityId.
@Test
public void shouldRenderFormEntityId() throws Exception {
// given
TranslationService translationService = mock(TranslationService.class);
DataDefinition dataDefinition = mock(DataDefinition.class);
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn("2");
setField(pattern, "applicationContext", applicationContext);
AbstractComponentState componentState = new FormComponentState(pattern);
componentState.setTranslationService(translationService);
componentState.setDataDefinition(dataDefinition);
componentState.setFieldValue(13L);
componentState.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
// when
JSONObject json = componentState.render();
// then
assertEquals(13L, json.getJSONObject(AbstractComponentState.JSON_CONTENT).getLong(FormComponentState.JSON_ENTITY_ID));
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CrudListDtoIntegrationTest method shouldCopyEntity.
@Test
public void shouldCopyEntity() throws Exception {
// given
DataDefinition productListDtoDataDefinition = getProductListDtoDataDefinition();
DataDefinition productDataDefinition = getProductDataDefinition();
Entity product = productDataDefinition.save(createProduct("asd", "def"));
Entity productListDto = productListDtoDataDefinition.get(product.getId());
verifyHooks.clear();
// when
Entity productListDtoCopy = productListDtoDataDefinition.copy(product.getId()).get(0);
// then
assertEquals(productListDto.getField("name"), productListDtoCopy.getField("name"));
assertEquals(productListDto.getField("number") + "(1)", productListDtoCopy.getField("number"));
assertNotNull(productListDtoCopy.getId());
assertFalse(productListDtoCopy.getId().equals(productListDto.getId()));
assertTrue(productListDtoCopy.isValid());
// copy return master model object!
// assertEquals(productListDto.getDataDefinition().getName(), productListDtoCopy.getDataDefinition().getName());
assertEquals(productDataDefinition.getName(), productListDtoCopy.getDataDefinition().getName());
assertEquals(productListDto.getDataDefinition().getPluginIdentifier(), productListDtoCopy.getDataDefinition().getPluginIdentifier());
List<Map<String, Object>> result = jdbcTemplate.queryForList("select * from " + TABLE_NAME_PRODUCT + " order by id asc");
assertNotNull(result);
assertEquals(2, result.size());
assertEquals(product.getId(), result.get(0).get("id"));
assertEquals(productListDtoCopy.getId(), result.get(1).get("id"));
assertEquals("asd", result.get(0).get("name"));
assertEquals("asd", result.get(1).get("name"));
assertEquals("def", result.get(0).get("number"));
assertEquals("def(1)", result.get(1).get("number"));
assertEquals(1, verifyHooks.getNumOfInvocations(HookType.SAVE));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.CREATE));
assertEquals(1, verifyHooks.getNumOfInvocations(HookType.COPY));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.UPDATE));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.DELETE));
}
Aggregations