Search in sources :

Example 11 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class InitializationTest method shouldGetDataDefinitionFromHasManyTypeScopeFieldDefinition.

@Test
public void shouldGetDataDefinitionFromHasManyTypeScopeFieldDefinition() throws Exception {
    // given
    HasManyType fieldType = mock(HasManyType.class);
    FieldDefinition fieldDefinition = mock(FieldDefinition.class);
    given(fieldDefinition.getType()).willReturn(fieldType);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    given(dataDefinition.getField("field")).willReturn(fieldDefinition);
    DataDefinition belongsToDefinition = mock(DataDefinition.class);
    given(fieldType.getDataDefinition()).willReturn(belongsToDefinition);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("parent", viewDefinition));
    setField(parent, "dataDefinition", dataDefinition);
    setField(parent, "initialized", true);
    AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", null, "field", parent, viewDefinition));
    // when
    pattern.initialize();
    // then
    Assert.assertEquals(belongsToDefinition, getField(pattern, "dataDefinition"));
    Assert.assertEquals(fieldDefinition, getField(pattern, "scopeFieldDefinition"));
}
Also used : HasManyType(com.qcadoo.model.api.types.HasManyType) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 12 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class InitializationTest method shouldTakeDataDefinitionFromView.

@Test
public void shouldTakeDataDefinitionFromView() throws Exception {
    // given
    DataDefinition dataDefinition = mock(DataDefinition.class);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    given(viewDefinition.getDataDefinition()).willReturn(dataDefinition);
    AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", viewDefinition));
    // when
    pattern.initialize();
    // then
    Assert.assertEquals(dataDefinition, ReflectionTestUtils.getField(pattern, "dataDefinition"));
}
Also used : InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 13 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class CrudControllerTest method shouldReturnValidView.

@Test
public void shouldReturnValidView() throws Exception {
    // given
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    ViewDefinitionService viewDefinitionService = mock(ViewDefinitionService.class);
    given(viewDefinitionService.get("testPlugin", "testView")).willReturn(viewDefinition);
    Map<String, String> arguments = new HashMap<String, String>();
    arguments.put("context", "");
    CrudService crud = new CrudServiceImpl();
    ReflectionTestUtils.setField(crud, "viewDefinitionService", viewDefinitionService);
    // when
    ModelAndView mav = crud.prepareView("testPlugin", "testView", arguments, Locale.ENGLISH);
    // then
    assertEquals("crud/crudView", mav.getViewName());
    assertEquals("testView", mav.getModel().get("viewName"));
    assertEquals("testPlugin", mav.getModel().get("pluginIdentifier"));
    assertEquals(Locale.ENGLISH.getLanguage(), mav.getModel().get("locale"));
    assertNull(mav.getModel().get("context"));
    assertEquals(false, mav.getModel().get("popup"));
}
Also used : CrudService(com.qcadoo.view.api.crud.CrudService) ViewDefinitionService(com.qcadoo.view.internal.api.ViewDefinitionService) HashMap(java.util.HashMap) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ModelAndView(org.springframework.web.servlet.ModelAndView) CrudServiceImpl(com.qcadoo.view.internal.crud.CrudServiceImpl) Test(org.junit.Test)

Example 14 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class CrudControllerTest method shouldReturnValidViewWithContextAndPopup.

@Test
public void shouldReturnValidViewWithContextAndPopup() throws Exception {
    // given
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    given(viewDefinition.translateContextReferences("testContext")).willReturn("{context: translatedTestContext}");
    ViewDefinitionService viewDefinitionService = mock(ViewDefinitionService.class);
    given(viewDefinitionService.get("testPlugin", "testView")).willReturn(viewDefinition);
    Map<String, String> arguments = new HashMap<String, String>();
    arguments.put("context", "testContext");
    arguments.put("popup", "true");
    CrudService crud = new CrudServiceImpl();
    ReflectionTestUtils.setField(crud, "viewDefinitionService", viewDefinitionService);
    // when
    ModelAndView mav = crud.prepareView("testPlugin", "testView", arguments, Locale.ENGLISH);
    // then
    assertEquals("crud/crudView", mav.getViewName());
    assertEquals("testView", mav.getModel().get("viewName"));
    assertEquals("testPlugin", mav.getModel().get("pluginIdentifier"));
    assertEquals(Locale.ENGLISH.getLanguage(), mav.getModel().get("locale"));
    assertEquals("{context: translatedTestContext}", mav.getModel().get("context"));
    assertEquals(true, mav.getModel().get("popup"));
}
Also used : CrudService(com.qcadoo.view.api.crud.CrudService) ViewDefinitionService(com.qcadoo.view.internal.api.ViewDefinitionService) HashMap(java.util.HashMap) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ModelAndView(org.springframework.web.servlet.ModelAndView) CrudServiceImpl(com.qcadoo.view.internal.crud.CrudServiceImpl) Test(org.junit.Test)

Example 15 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class CrudControllerTest method shouldPerformEvent.

@Test
public void shouldPerformEvent() throws Exception {
    // given
    InternalViewDefinitionState state = mock(InternalViewDefinitionState.class, Mockito.withSettings().extraInterfaces(InternalComponentState.class));
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    ViewDefinitionService viewDefinitionService = mock(ViewDefinitionService.class);
    given(viewDefinitionService.get("testPlugin", "testView")).willReturn(viewDefinition);
    JSONObject jsonBody = new JSONObject();
    jsonBody.put("test", "testVal1");
    JSONObject jsonResult = new JSONObject();
    jsonResult.put("test", "testVal2");
    CrudService crud = new CrudServiceImpl();
    ReflectionTestUtils.setField(crud, "viewDefinitionService", viewDefinitionService);
    given(viewDefinition.performEvent(jsonBody, Locale.ENGLISH)).willReturn(state);
    given(((InternalComponentState) state).render()).willReturn(jsonResult);
    // when
    Object result = crud.invokeEventAndRenderView("testPlugin", "testView", jsonBody, Locale.ENGLISH);
    // then
    assertEquals(jsonResult, result);
}
Also used : CrudService(com.qcadoo.view.api.crud.CrudService) ViewDefinitionService(com.qcadoo.view.internal.api.ViewDefinitionService) JSONObject(org.json.JSONObject) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) JSONObject(org.json.JSONObject) CrudServiceImpl(com.qcadoo.view.internal.crud.CrudServiceImpl) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test)

Aggregations

InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)49 Test (org.junit.Test)40 DataDefinition (com.qcadoo.model.api.DataDefinition)25 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)21 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)15 FieldDefinition (com.qcadoo.model.api.FieldDefinition)14 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)14 ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)13 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)11 JSONObject (org.json.JSONObject)10 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)9 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)9 ComponentOption (com.qcadoo.view.internal.ComponentOption)8 ComponentState (com.qcadoo.view.api.ComponentState)7 ViewDefinitionImpl (com.qcadoo.view.internal.internal.ViewDefinitionImpl)7 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)6 BelongsToType (com.qcadoo.model.api.types.BelongsToType)5 HasManyType (com.qcadoo.model.api.types.HasManyType)5 ModuleException (com.qcadoo.plugin.api.ModuleException)4 EnumType (com.qcadoo.model.internal.types.EnumType)3