Search in sources :

Example 66 with DataDefinition

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));
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 67 with DataDefinition

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());
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 68 with DataDefinition

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();
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) StringType(com.qcadoo.model.internal.types.StringType) FieldComponentPattern(com.qcadoo.view.internal.components.FieldComponentPattern) FieldDefinition(com.qcadoo.model.api.FieldDefinition) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) DataDefinition(com.qcadoo.model.api.DataDefinition) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) TranslationService(com.qcadoo.localization.api.TranslationService) FieldComponentState(com.qcadoo.view.internal.components.FieldComponentState) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) SecurityRolesService(com.qcadoo.security.api.SecurityRolesService) Matchers.anyLong(org.mockito.Matchers.anyLong) ExpressionServiceImpl(com.qcadoo.model.internal.ExpressionServiceImpl) Before(org.junit.Before)

Example 69 with DataDefinition

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));
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) JSONObject(org.json.JSONObject) TranslationService(com.qcadoo.localization.api.TranslationService) AbstractComponentState(com.qcadoo.view.internal.states.AbstractComponentState) DataDefinition(com.qcadoo.model.api.DataDefinition) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 70 with DataDefinition

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));
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) Map(java.util.Map) Test(org.junit.Test)

Aggregations

DataDefinition (com.qcadoo.model.api.DataDefinition)415 Entity (com.qcadoo.model.api.Entity)285 Test (org.junit.Test)165 BigDecimal (java.math.BigDecimal)53 FieldDefinition (com.qcadoo.model.api.FieldDefinition)48 List (java.util.List)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)32 Service (org.springframework.stereotype.Service)31 Autowired (org.springframework.beans.factory.annotation.Autowired)27 Date (java.util.Date)26 Map (java.util.Map)26 Collectors (java.util.stream.Collectors)26 FormComponent (com.qcadoo.view.api.components.FormComponent)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)22 IOException (java.io.IOException)21 Objects (java.util.Objects)21 GridComponent (com.qcadoo.view.api.components.GridComponent)20 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)20 Lists (com.google.common.collect.Lists)16