Search in sources :

Example 1 with CrudService

use of com.qcadoo.view.api.crud.CrudService 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 2 with CrudService

use of com.qcadoo.view.api.crud.CrudService 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 3 with CrudService

use of com.qcadoo.view.api.crud.CrudService 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)

Example 4 with CrudService

use of com.qcadoo.view.api.crud.CrudService in project mes by qcadoo.

the class BasicControllerTest method shouldPrepareViewForParameters.

@Test
public void shouldPrepareViewForParameters() throws Exception {
    // // given
    Map<String, String> arguments = ImmutableMap.of("context", "{\"form.id\":\"13\"}");
    ModelAndView expectedMav = mock(ModelAndView.class);
    CrudService crudController = mock(CrudService.class);
    given(crudController.prepareView(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.VIEW_GENERAL_PARAMETERS, arguments, Locale.ENGLISH)).willReturn(expectedMav);
    ParameterService parameterService = mock(ParameterService.class);
    given(parameterService.getParameterId()).willReturn(13L);
    BasicController basicController = new BasicController();
    setField(basicController, "crudService", crudController);
    setField(basicController, "parameterService", parameterService);
    // // when
    ModelAndView mav = basicController.getGeneralParameterPageView(Locale.ENGLISH);
    // // then
    assertEquals(expectedMav, mav);
}
Also used : CrudService(com.qcadoo.view.api.crud.CrudService) ModelAndView(org.springframework.web.servlet.ModelAndView) BasicController(com.qcadoo.mes.basic.controllers.BasicController) Test(org.junit.Test)

Aggregations

CrudService (com.qcadoo.view.api.crud.CrudService)4 Test (org.junit.Test)4 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)3 ViewDefinitionService (com.qcadoo.view.internal.api.ViewDefinitionService)3 CrudServiceImpl (com.qcadoo.view.internal.crud.CrudServiceImpl)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 HashMap (java.util.HashMap)2 BasicController (com.qcadoo.mes.basic.controllers.BasicController)1 InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)1 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)1 JSONObject (org.json.JSONObject)1