Search in sources :

Example 16 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.

the class ViewNameMethodReturnValueHandlerTests method returnViewNameRedirect.

@Test
public void returnViewNameRedirect() throws Exception {
    ModelMap redirectModel = new RedirectAttributesModelMap();
    this.mavContainer.setRedirectModel(redirectModel);
    this.handler.handleReturnValue("redirect:testView", this.param, this.mavContainer, this.webRequest);
    assertThat(this.mavContainer.getViewName()).isEqualTo("redirect:testView");
    assertThat(this.mavContainer.getModel()).isSameAs(redirectModel);
}
Also used : RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) ModelMap(org.springframework.ui.ModelMap) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) Test(org.junit.jupiter.api.Test)

Example 17 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.

the class RedirectAttributesMethodArgumentResolver method resolveArgument.

@Override
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception {
    Assert.state(mavContainer != null, "RedirectAttributes argument only supported on regular handler methods");
    ModelMap redirectAttributes;
    if (binderFactory != null) {
        DataBinder dataBinder = binderFactory.createBinder(webRequest, null, DataBinder.DEFAULT_OBJECT_NAME);
        redirectAttributes = new RedirectAttributesModelMap(dataBinder);
    } else {
        redirectAttributes = new RedirectAttributesModelMap();
    }
    mavContainer.setRedirectModel(redirectAttributes);
    return redirectAttributes;
}
Also used : ModelMap(org.springframework.ui.ModelMap) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) DataBinder(org.springframework.validation.DataBinder) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)

Example 18 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.

the class ModelAndViewMethodReturnValueHandlerTests method handleRedirectAttributesWithoutRedirect.

@Test
public void handleRedirectAttributesWithoutRedirect() throws Exception {
    RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
    mavContainer.setRedirectModel(redirectAttributes);
    ModelAndView mav = new ModelAndView();
    handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
    ModelMap model = mavContainer.getModel();
    assertThat(mavContainer.getView()).isEqualTo(null);
    assertThat(mavContainer.getModel().isEmpty()).isTrue();
    assertThat(model).as("RedirectAttributes should not be used if controller doesn't redirect").isNotSameAs(redirectAttributes);
}
Also used : RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) ModelMap(org.springframework.ui.ModelMap) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) Test(org.junit.jupiter.api.Test)

Example 19 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project Sermant by huaweicloud.

the class FileEntryControllerTest method testSaveAndGet.

@SuppressWarnings("unchecked")
@Test
public void testSaveAndGet() {
    ModelMap model = new ModelMap();
    String path = "test1-path";
    scriptController.addFolder(getTestUser(), "", path, model);
    // create
    scriptController.createForm(getTestUser(), path, "test.com", "new_file.py", "jython", false, null, new RedirectAttributesModelMap(), model);
    FileEntry script = (FileEntry) model.get("file");
    script.setContent(script.getContent() + "#test comment");
    scriptController.save(getTestUser(), script, null, "", false, model);
    scriptController.validate(getTestUser(), script, "test.com");
    // save and get
    model.clear();
    scriptController.getOne(getTestUser(), script.getPath(), -1L, model);
    FileEntry newScript = (FileEntry) model.get("file");
    assertThat(newScript.getFileName(), is(script.getFileName()));
    assertThat(newScript.getContent(), is(script.getContent()));
    // List<Long> versionList = newScript.getRevisions();
    // reversion list is not implemented yet.
    // assertThat(versionList.size(), is(2));
    model.clear();
    scriptController.search(getTestUser(), "test", model);
    model.clear();
    scriptController.delete(getTestUser(), path, "new_file.py");
    scriptController.getAll(getTestUser(), path, model);
    List<FileEntry> scriptList = (List<FileEntry>) model.get("files");
    assertThat(scriptList.size(), is(0));
}
Also used : ModelMap(org.springframework.ui.ModelMap) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) FileEntry(org.ngrinder.script.model.FileEntry) List(java.util.List) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) AbstractNGrinderTransactionalTest(org.ngrinder.AbstractNGrinderTransactionalTest) Test(org.junit.Test)

Example 20 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project irida by phac-nml.

the class SamplesControllerTest method testRemoveGenomeAssemblyFromSample.

@Test
public void testRemoveGenomeAssemblyFromSample() {
    Long sampleId = 1L;
    Long assemblyId = 2L;
    GenomeAssembly genomeAssembly = TestDataFactory.constructGenomeAssembly();
    Sample sample = new Sample();
    when(sampleService.read(sampleId)).thenReturn(sample);
    when(sampleService.getGenomeAssemblyForSample(sample, assemblyId)).thenReturn(genomeAssembly);
    when(updateSamplePermission.isAllowed(any(Authentication.class), eq(sample))).thenReturn(true);
    RedirectAttributesModelMap attributes = new RedirectAttributesModelMap();
    HttpServletRequest request = new MockHttpServletRequest();
    controller.removeGenomeAssemblyFromSample(attributes, sampleId, assemblyId, request, Locale.US);
    verify(sampleService).removeGenomeAssemblyFromSample(sample, assemblyId);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Authentication(org.springframework.security.core.Authentication) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) GenomeAssembly(ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly) Test(org.junit.Test)

Aggregations

RedirectAttributesModelMap (org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)40 ModelMap (org.springframework.ui.ModelMap)28 Test (org.junit.jupiter.api.Test)24 ModelAndView (org.springframework.web.servlet.ModelAndView)17 Test (org.junit.Test)11 RedirectView (org.springframework.web.servlet.view.RedirectView)6 DBUnitTest (org.orcid.test.DBUnitTest)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 AbstractNGrinderTransactionalTest (org.ngrinder.AbstractNGrinderTransactionalTest)4 FileEntry (org.ngrinder.script.model.FileEntry)3 MethodParameter (org.springframework.core.MethodParameter)3 DataBinder (org.springframework.validation.DataBinder)3 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 List (java.util.List)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 Model (org.springframework.ui.Model)2 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)2 BindingResult (org.springframework.validation.BindingResult)2 BindingAwareModelMap (org.springframework.validation.support.BindingAwareModelMap)2